Hi, Thanks for all the tips guys, they were very helpful, and i've made the changes to my code. However, when running the dry run/debug feature of MPLAB the PORTA value never changes, even after changing it to what you have recommended. Here is the new code, coudl you please enlighten me on what I'm doing wrong. Thanks P.S I programmed the chip, and it doesn't flash the LED's as the debugger said. Code--------------------- ;Setup list P=16F877 include "c:\P16F877.inc" errorlevel -302 __CONFIG _CP_OFF & _XT_OSC & _WDT_OFF & _PWRTE_OFF & _BODEN_OFF & _LVP_OFF ;Declarations d1 equ 20h d2 equ 21h d3 equ 22h org 0 call Start Bank1 Macro bsf STATUS,RP0 bcf STATUS,RP1 bcf STATUS,IRP Endm Bank0 Macro bcf STATUS,RP0 bcf STATUS,RP1 bcf STATUS,IRP Endm Init Bank1 movlw b'11110000' ;0,1,2,3 of porta are output movwf TRISA Bank0 ;bank 0 movlw b'00001010' ;all porta low movwf PORTA retlw 0 Delay ;4999993 cycles movlw 0x2C movwf d1 movlw 0xE7 movwf d2 movlw 0x0B movwf d3 Delay_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto Delay_0 ;3 cycles goto $+1 nop ;4 cycles (including call) return Start call Init Main movlw b'00000001' movwf PORTA call Delay movlw b'00000010' movwf PORTA call Delay movlw b'00000100' movwf PORTA call Delay movlw b'00001000' movwf PORTA call Delay goto Main End ----- Original Message ----- From: "Jinx" To: Sent: Friday, November 29, 2002 5:19 PM Subject: Re: [PIC]: First ASM problems > > a book i've read says to declare, then initialize, then other subroutines, > > then start, then main functions. > > Some people do write that way. Personally I prefer my main code at > the start and routines after. I have trouble wading through subroutines > to get to what's calling them. Tidy code is a lot easier to debug > > So, with that bias, my layout preferences and Dr Bartfai's comments > in mind - > > ( = indicates a space, I don't use tabs) > > ====list P=16F877 > ====include "c:\P16F877.inc > > ;---------------------------- > ;You can suppress error messages > ; > =errorlevel -305, -302, -306 > > ;---------------------------- > ;You need to set CONFIG, eg (all on one line) > > =__CONFIG _CP_OFF & _XT_OSC & _WDT_OFF & _PWRTE_OFF & _BODEN_OFF & _LVP_OFF > > ;Declarations > > d1====equ===20 > d2====equ===21 > d3====equ===22 > > ;------------------------------ > ;You can also define variables in a block of memory > > ====cblock 0x20==========;this declares variable RAM address > > ====d1 > ====d2 > ====d3 > > ====endc > > ;specifically define port pins eg > > #define===led1====porta,0 > #define===led2====porta,1 > #define===led3====porta,2 > #define===led4====porta,3 > > ;eg bsf led1 > > ;and make macros for bank selection (there is another way - Olin ?) > > bank0=macro > =========bcf====status,rp0 > =========bcf====status,rp1 > =========bcf====status,irp > =========endm > > bank1=macro > =========bsf====status,rp0 > =========bcf====status,rp1 > =========bcf====status,irp > =========endm > ;------------------------------ > > ====org=0x000 > ====goto=init > > ;----------------------------- > ;If you're using interrupts > > ====org=0x004 > ====goto=isr > ;---------------------------- > > Init=====movlw==b'00000000'======;all porta low > =======movwf==PORTA > > =======bsf====STATUS,RP0=====;bank 1 > =======bcf====STATUS,RP1 > > ;or use the macro to change bank. Simply type > > =======bank1 > > =======movlw==b'11110000'======;0,1,2,3 of porta are output > =======movwf==TRISA > > =======bcf==== STATUS,RP0=====;bank 0 > > ;or > > =======bank0 > > Main===bcf=====PORTA,1========;be aware of read-modify-write > =======nop====================;problems that may occur when > =======bcf=====PORTA,2========;changing port pin data > =======nop > =======bcf=====PORTA,3 > =======nop > =======bsf=====PORTA,0 > =======call=====Delay > > =======goto====main > > Delay===movlw 0x2C===========;4999993 cycles > > =======return > > =end > > ======================================================= > > > I get a stack underflow error > > Because you had org 0x000 set to INIT, not START. The first piece of > code encountered ended with a RETLW that had no CALL > > -- > http://www.piclist.com hint: The list server can filter out subtopics > (like ads or off topics) for you. See http://www.piclist.com/#topics > -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics