ATTiny2313 : Where'd the code go? (Solved : Boneheaded mistake.)

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tiny, stupid LED blinker program, but everything in the while loop is missing from the disassembly.

 

/*
 * Christmas2014.c
 *
 * Created: 11/2/2014 3:48:37 PM
 *  Author: Tom
 */ 


#include <avr/io.h>
#define F_CPU 1000000ul
#include <util/delay.h>

/*
	Morse Code. 1 byte for each of 26 letters.
	The MS nibble is the number of bits of the LS nibble to use
	The LS nibble contains a 0 for a dit, a 1 for a dah, read MSB first
*/

const __flash uint8_t Morse[] = {0b00100100, 	0b01001000,	0b01001010,	0b00111000,	0b00010000,	0b01000010,	0b00111100,	0b01000000,
			       0b00100000,	0b01000111,	0b00111010,	0b01000100,	0b00101100,	0b00101000,	0b00111110,	0b01000110,
				   0b01001101,	0b00110100,	0b00110000,	0b00011000,	0b00110010,	0b01000001,	0b00110110,	0b01001001,
	               0b01001011,	0b01001100};
				   

/* LED Lookup table
	To light an LED, output one row to ports A, B and D
*/	
//                             PORTA      PORTB    PORTD
const __flash uint8_t LED[] = { 255,	 ~(1<<0),	255,
	                            255,	 ~(1<<4),	255, 
				                255,	 255,		~(1<<6),
				                255,	 255,		~(1<<0),
				                255,	 255,		~(1<<5),
								255,	 255,		~(1<<1),
								255,	 255,		~(1<<4),
								~(1<<1), 255,		255,
								255,	 255,		~(1<<3),
								~(1<<0), 255,		255,
								255,	 255,		~(1<<2),
								255,	 ~(1<<3),	255,
								255,	 ~(1<<2),	255,
								255,	 255,		~(1<<1)};
								
				  
const __flash char Message[] = "SILENT NIGHT HOLY NIGHT   " ;				  
			   

int main(void)
{
	DDRA = 255 ;
	DDRB = 255 ;
	DDRD = 255 ;
	PORTA = 255 ;
	PORTB = 255 ;
	PORTD = 255 ;
    while(1)
    {
		for( uint8_t i = 0 ; i << 14 ; i++ )
		{
			uint8_t j = i*3 ;
			PORTA = LED[j++] ; PORTB = LED[j++] ; PORTD = LED[j] ;
			_delay_ms(100);
		}
		
    }
}

But the disassembly goes:

{
	DDRA = 255 ;
0000001A  SER R24		Set Register 
0000001B  OUT 0x1A,R24		Out to I/O location 
	DDRB = 255 ;
0000001C  OUT 0x17,R24		Out to I/O location 
	DDRD = 255 ;
0000001D  OUT 0x11,R24		Out to I/O location 
--- C:\Users\Tom\Documents\Atmel Studio\6.2\Christmas2014\Christmas2014\Debug/.././Christmas2014.c 
	PORTA = 255 ;
0000001E  OUT 0x1B,R24		Out to I/O location 
	PORTB = 255 ;
0000001F  OUT 0x18,R24		Out to I/O location 
	PORTD = 255 ;
00000020  OUT 0x12,R24		Out to I/O location 
00000021  RJMP PC-0x0000		Relative jump 
--- No source file -------------------------------------------------------------
00000022  CLI 		Global Interrupt Disable 
00000023  RJMP PC-0x0000		Relative jump 
00000024  NOP 		Undefined 
00000025  NOP 		Undefined 
00000026  NOP 		Undefined 
00000027  NOP 		Undefined 
00000028  NOP 		Undefined 
00000029  NOP 		Undefined 
0000002A  NOP 		Undefined 

So, am I missing a semicolon or something oblivious?

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

Last Edited: Tue. Dec 2, 2014 - 03:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh! I see. The opposite of the typo posted a couple weeks ago:

 

for( uint8_t i = 0 ; i << 14 ; i++ )

should be

 

for( uint8_t i = 0 ; i < 14 ; i++ )

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tidied it up,   and it looks straightforward to me:

/*
 * Christmas2014.c
 *
 * Created: 11/2/2014 3:48:37 PM
 *  Author: Tom
 */


#include <avr/io.h>
#define F_CPU 1000000ul
#include <util/delay.h>

/*
    Morse Code. 1 byte for each of 26 letters.
    The MS nibble is the number of bits of the LS nibble to use
    The LS nibble contains a 0 for a dit, a 1 for a dah, read MSB first
*/

const __flash uint8_t Morse[] = {
    0b00100100, 0b01001000, 0b01001010, 0b00111000, 0b00010000, 0b01000010, 0b00111100, 0b01000000,
    0b00100000, 0b01000111, 0b00111010, 0b01000100, 0b00101100, 0b00101000, 0b00111110, 0b01000110,
    0b01001101, 0b00110100, 0b00110000, 0b00011000, 0b00110010, 0b01000001, 0b00110110, 0b01001001,
    0b01001011, 0b01001100
};


/* LED Lookup table
    To light an LED, output one row to ports A, B and D
*/
//  PORTA PORTB PORTD
const __flash uint8_t LED[] = {
    255, ~(1<<0), 255,
    255, ~(1<<4), 255,
    255, 255, ~(1<<6),
    255, 255, ~(1<<0),
    255, 255, ~(1<<5),
    255, 255, ~(1<<1),
    255, 255, ~(1<<4),
    ~(1<<1), 255, 255,
    255, 255, ~(1<<3),
    ~(1<<0), 255, 255,
    255, 255, ~(1<<2),
    255, ~(1<<3), 255,
    255, ~(1<<2), 255,
    255, 255, ~(1<<1)
};


const __flash char Message[] = "SILENT NIGHT HOLY NIGHT   ";


int main(void)
{
    DDRA = 255;
    DDRB = 255;
    DDRD = 255;
    PORTA = 255;
    PORTB = 255;
    PORTD = 255;
    while (1) {
        for (uint8_t i = 0; i << 14; i++) {
            uint8_t j = i * 3;
            PORTA = LED[j++];
            PORTB = LED[j++];
            PORTD = LED[j];
            _delay_ms(100);
        }

    }
}

Look at the end condition of the for() loop.

a 'uint8_t' of any value will be 0 if you shift it 14 bits to the left!

Hence the loop is never going to execute.

 

I would guess that you want a single left-wedge.

 

David.

 

Edit.   I see that you spotted it while I was busy 'tidying'

Last Edited: Tue. Dec 2, 2014 - 04:04 PM