# ATmega16A LED blinking code is not working in Dev. Board.

Status
Not open for further replies.

#### ikelectro

##### Member
Hello everyone, I'm new to AVR programming. I'm using a ATmega16A to blinking LED. AVR Studio showing that program is ok but the LED is not blinking in the Development board. I have connected pin no. 10 and 30 to VCC +5V and pin no. 11 & 31 to GND. I'm using a 16Mhz Crystal at pin no. 12 & 13. and also the clock is not happening. what to do???

here is the code:
Code:
.include "m16adef.inc"

.org    \$0000
.DEF    MR  = R16            ;R16 NAMED AS ACC
.DEF    MR0 = R20
.DEF    MR1 = R21

INTL:        LDI        MR,255                ;LOAD R16/ACC 255
OUT        DDRA,MR                ;MAKE PORTD AS OUTPUT
LDI        MR0,00
LDI        MR1,255

START:        OUT        PORTA,MR1                ;SET ALL THE BIT OF PORTA
RCALL    DLY                        ;CALL DLY ROUTINE
OUT        PORTA,MR0                ;CLEAR ALL THE BIT OF PORTA
RCALL    DLY                         ;CALL DLY ROUTINE
RJMP    START                      ; JUMP AGAIN TO START

DLY:          LDI        R17, 04                        ;LOAD R17 WITH 08
DLY1:        LDI        R18, 200                    ;LOAD R18 WITH 200
DLY2:        LDI        R19, 255                    ;LOAD R19 WITH 255

DLY3:        DEC        R19                            ;DECRIMENT R19 WITH 1
BRNE    DLY3

DEC        R18
BRNE    DLY2

DEC        R17
BRNE    DLY1
RET

Last edited:

#### Les Jones

##### Well-Known Member
Have you set the clock selection fuse bit to select the external crystal ? (See page 25 of the data sheet) These fuse bits need to be set separately to programming in the code.
This caught me out when I moved from using PICs to AVR chips.
Have a look at these notes on my website

Also you are setting PORTA but your comments say that you are setting PORTD

Les.

Last edited:

#### ikelectro

##### Member
Have you set the clock selection fuse bit to select the external crystal ? (See page 25 of the data sheet) These fuse bits need to be set separately to programming in the code.
This caught me out when I moved from using PICs to AVR chips.
Have a look at these notes on my website

Also you are setting PORTA but your comments say that you are setting PORTD

Les.
Hi, Jones... thanks for your reply. You are absolutely right. I'm missing that point from last two days (In my case I'm moving from 8051 to AVR). After posting in ETO, i aslo figured it out that I have to configure the Virgin Chip before programming it. bye the way thanks a lot for your reply.

And as far as the comment is concern : I had changed the ports too many times in program as I panicked so mush that little chip is not working! and forgot to change the comments!!!

#### ikelectro

##### Member
And what about my delay (DLY) routine I think I write it wrong?! because blinking is not happening and also cant find any frequency in the port. But later I changed the program as "NOP" instead of writing "RCALL DLY" and I find the frequency 2.02MHz at the ports.

could you plz check my DLY routine also!

#### Les Jones

##### Well-Known Member
I cannot see why your delay routine does not work. I would first try changing the routine to just a few NOPs and a RET instruction. If it works OK like that then just put one of the three delay loops in the routine to see if it still works.

Les.

#### ikelectro

##### Member
I have tried that already but no luck..
here is fuse bit configeration. Am i doing it right???

#### Les Jones

##### Well-Known Member
I have not used the ATmega16a (I have mainly used the ATtiny4313 and it's over a year since I worked with AVR code.) so I am not familiar with all the fuse bits. I would not think that any of the fuse bits would affect the RCALL or RET instructions. There is a limitation on the RCALL instruction on devices with more than 4K of program memory but I do not think it would affect such a small program. You could try the CALL instruction to see if that works.

Les.

#### Les Jones

##### Well-Known Member
I have tried running your code on an ATtiny2313 with a 20 MHZ xtal and using PORTB. It seems to run OK giving about 30 mS on time and 30 mS off time. This is about what I calculate it should be. I do not have an ATmega16A to test it on. I think your problem must be related to the RCALL of the delay routine.

Les.

#### ikelectro

##### Member
Thanks for your reply... I have gone through some of the AVR tutorial on the internet and found that while using RCALL or CALL type of intruction, something have to be done with satck ; SPL SPH. but I cant figure it out...

I have tried running your code on an ATtiny2313 with a 20 MHZ xtal and using PORTB. It seems to run OK giving about 30 mS on time and 30 mS off time. This is about what I calculate it should be. I do not have an ATmega16A to test it on. I think your problem must be related to the RCALL of the delay routine.
And have running the same code on ATtiny2313??? Its great that works on your chip. it's made me happy... But what the wrong in mine!!!!!!

#### atferrari

##### Well-Known Member
Is any simulator for that chip that you could use?

#### ikelectro

##### Member
Yes, I'm using Atmel Studio 6.2

#### ikelectro

##### Member
The code is running now. I just have to define the stack. Thanks every one for their support.....

LDI temp,low(RAMEND) ;temp can be any register from R16 to R31
OUT SPL,temp
LDI temp,high(RAMEND)
OUT SPH,temp

Status
Not open for further replies.