Hi! Personally I write it just a bit different: all my LABELS are in capital letters, so are my DEFINITIONS, EQUATIONS, and MACRO names. At least for me it's a lot easier to read my own code. I also leave one line space between label and the rest of program, like this: LABEL instruction I also use tabulators, so labels are in first column, instructions one tab to the right and comments two tabs to the right. You should also comment your code a bit more, because then you know what you wanted to do with that particular instruction and it's also easier for somebody else to spot a problem. It's also easier for me to give name to flags, like this: btfss FLAG, NAME instead of btfss Counter, 1 cause it's easier to remember a name than bit number. Regards, Samo ----- Original Message ----- From: Peter McNulty To: Sent: Friday, November 29, 2002 3:13 PM Subject: Re: [PIC]: First ASM problems > Hi, > > Thanks very much! Your help is much appreciated. I've got everything working > now and I was trying to see what i could do in asm so here's the new code > below that does the same thing, but i think is a bit neater. > > -Peter > > > Code-------- > > ;Setup > list P=16F877 > include "c:\P16F877.inc" > errorlevel -302 > __CONFIG _CP_OFF & _HS_OSC & _WDT_OFF & _PWRTE_OFF & _BODEN_OFF & _LVP_OFF > ;Declarations > Cblock 20h > CounterA > CounterB > CounterC > LEDPos > Endc > org 0 > goto Start > > Bank1 Macro ;bank switching macros > 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'00000000' ;all porta low > movwf PORTA > movlw b'00000001' > movwf LEDPos > return > > > ;PIC Time Delay = 1.0000006 s with Osc = 20.000000 MHz > Delay movlw D'26' > movwf CounterC > movlw D'119' > movwf CounterB > movlw D'85' > movwf CounterA > goto Delay_0 > > Delay_0 decfsz CounterA,1 > goto Delay_0 > decfsz CounterB,1 > goto Delay_0 > decfsz CounterC,1 > goto Delay_0 > return > > ShowLED movf LEDPos,0 ;outputs f > movwf PORTA > call Delay > movlw b'00000000' > btfsc LEDPos,3 ;checks if at 00001000 and > bsf STATUS,0 ;changes carry bit, etc > btfsc LEDPos,3 > movwf LEDPos > rlf LEDPos,1 ;shifts LEDPos left so i can ouput correct sequence > goto ShowLED > > Start call Init > > Main call ShowLED > goto Main > End > > > ----- Original Message ----- > From: "Jinx" > To: > Sent: Friday, November 29, 2002 9:23 PM > Subject: Re: [PIC]: First ASM problems > > > > > work correctly but it look weird, so would it be better to leave 1 > > > as high, and connect to LEDs to ground? If i don't change > > > anything it works, but instead of turning LEDs on, the default is > > > all 4 on, and turns 1 off in > > > > Doesn't really make a lot of difference. The PIC pins can sink or > > source about the same current. You might find it easier to work > > with non-inverted logic, ie BSF for on, BCF for off, in which case > > the LEDs can go to ground and you drive them > > > > TRIS registers set ports as inputs after reset. I should think an > > LED may be enough of a pull-down that you may not see a very > > brief flash before you explicitly set TRIS, although I've never > > actually looked > > > > -- > > 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 > > -- 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