On Fri, 29 Nov 2002 16:11:11 +0800, Peter McNulty wrote: > >I'm using the PIC16F877 as my first PIC and i'm having difficulty getting my first ASM program to work. >All I'm trying to do is to turn 4 different LEDs on at different times connected to RA0,1,2, and 3. >Below is the code, and i'm using MPLAB to compile and write it. The errors I'm getting are as follows: > >Warning[205] C:\DOCUME~1\ADMINI~1\MYDOCU~1\PIC\LED_1.ASM 2 : Found directive in column 1. (list) >Warning[205] C:\DOCUME~1\ADMINI~1\MYDOCU~1\PIC\LED_1.ASM 3 : Found directive in column 1. (include) >Warning[207] C:\DOCUME~1\ADMINI~1\MYDOCU~1\PIC\LED_1.ASM 6 : Found label after column 1. (d1) >Warning[207] C:\DOCUME~1\ADMINI~1\MYDOCU~1\PIC\LED_1.ASM 7 : Found label after column 1. (d2) >Warning[207] C:\DOCUME~1\ADMINI~1\MYDOCU~1\PIC\LED_1.ASM 8 : Found label after column 1. (d3) >Message[302] C:\DOCUME~1\ADMINI~1\MYDOCU~1\PIC\LED_1.ASM 16 : Register in operand not in bank 0. Ensure that bank bits are correct. >Warning[205] C:\DOCUME~1\ADMINI~1\MYDOCU~1\PIC\LED_1.ASM 59 : Found directive in column 1. (End) > >Code: >------------------------------------------- > >;Setup >list P=16F877 >include "c:\P16F877.inc" The list and include lines need to be indented so that they *don't* start in column 1. > >;Declarations > d1 equ 20 > d2 equ 21 > d3 equ 22 These equates *do* need to start in column 1. Also, unless you're willing to trust the assembler's default radix, you should set it explicitly or use 20h,21h,22h for these definitions. (I always set my radix to decimal at the beginning of my programs.) > org 0 > You need a 'goto start' instruction here. Executing starts at location 0 and you're "falling into" your Init routine rather than calling it. That's what's giving the stack underflow. >Init movlw b'00000000' ;all porta low > movwf PORTA > bsf STATUS,RP0 ;bank 1 > bcf STATUS,RP1 > movlw b'11110000' ;0,1,2,3 of porta are output Putting an 'errorlevel -302' here will kill off the bank warning that you're getting. You know that you're in bank 1; the assembler doesn't. > movwf TRISA > bcf STATUS,RP0 ;bank 0 You can turn error checking back on here with an 'errorlevel +302' here. > 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 You might want to take a look at "PicLoops" to get some ideas on delay routines. It's a very handy program and will show you how to make your routine more readable. www.mnsi.net/~boucher/picloops.html > > ;3 cycles > goto $+1 > nop > > ;4 cycles (including call) > return > >Start call Init >Main bcf PORTA,1 > bcf PORTA,2 > bcf PORTA,3 > bsf PORTA,0 > call Delay > bcf PORTA,0 > bsf PORTA,1 > call Delay > bcf PORTA,1 > bsf PORTA,2 > call Delay > bcf PORTA,2 > bsf PORTA,3 > call Delay > goto Main Using 'bcf' and 'bsf' on I/O ports can cause problems. If you do an archive search on 'read-modify-write' you'll see what I mean. You can move the appropriate patterns into W and write that to PORTA. >End The 'end' needs to be indented so that it *doesn't* start in column 1. Hope this helps. Regards, Bob -- 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