Strange behavior of ATMEGA128 PORT

Mar 10, 2006 2 Replies

I have just started to study the AVR a week ago. The eight LEDs and registors are connected between the VCC and ATMEGA128 PORTB.



I found that some CodeVision C programs does not work as I expected. After careful examination of the codes, I can simplify the problem to the following Assembler coding. (PORTD.0 is connected to the chattering switch)



=2ECSEG _main: ; 8 PORTB=3D0xff; LDI R30,LOW(255) OUT 0x18,R30 ; 9 DDRB=3D0xFF; OUT 0x17,R30 ; 10 ; 11 PORTD=3D0x00; CLR R30 OUT 0x12,R30 ; 12 DDRD&=3D0xFE; CBI 0x11,0 ; 13 ;CALL __LSLB12 ;=3D=3D=3D=3D> If commented OK!!!!! But uncommented??


Did anybody initialize your stack pointer?

Tauno Voipio tauno voipio (at) iki fi

Yes, there's initialization routine just before above code.

;STACK POINTER INITIALIZATION LDI R30,LOW(0x10FF) OUT SPL,R30 LDI R30,HIGH(0x10FF) OUT SPH,R30

;DATA STACK POINTER INITIALIZATION LDI R28,LOW(0x500) LDI R29,HIGH(0x500)

JMP _main

.ESEG .ORG 0 .DB 0 ; FIRST EEPROM LOCATION NOT USED, SEE ATMEL ERRATA SHEETS

.DSEG .ORG 0x500

QH Hong.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required