At 20:30 27/12/99 -0600, you wrote: >Hello, > >I just started to learn Pic programming. Can someone comment on my coments >about this program? > >org 0 > >clrf PORTB ; Clear all the bits in PortB >This line clears PORTB to all 0's right? > >bsf STATUS, RP0 ; Goto bank 1 to set port direction >This switches to bank 1 > >bcf TRISB & 0x07f, 0 ; Set bit 0 to output >Here is where I have trouble. If I understand this correctly, this should >take 00000000 and (and) it >with 01111111. Am I right? No, it takes the address of TRISB (86h) and ANDs this with 7Fh to give the result of 06h. This is the address of the PORTB i/o register in fact. The setting of RP0 in the status reg provides bit-7 of the TRISB address. The ,0 specifies the I/O bit and has nothing to do with the ANDing operation. So: bsf STATUS, RP0 ; Goto bank 1 to set port direction bcf TRISB & 0x07f, 0 ; Set bit 0 to output bcf STATUS, RP0 ; Go back to bank 0 Is the same to the PIC assembler as: bsf STATUS, RP0 ; Goto bank 1 to set port direction bcf PORTB, 0 ; Set bit 0 to output bcf STATUS, RP0 ; Go back to bank 0 But which is easier for the poor old Human to read and tells YOU exactly what the code is doing? BTW, We are only making bit-0 an output in the above example. The other Data direction Bits are not changed. Jim > >end > >Another thing I want to know is how can you clear PortB if you don't switch >banks first? I mean according to Mykes book, which is where I copied this >program from, the above code says it is ok to clear PortB, but to set the >I/O direction, you need to switch banks first. > >TIA, >Brian >******************************************** >Better Produce through Better Control >******************************************** > Regards, Jim Robertson NEWFOUND ELECTRONICS ________________________________________ Email: newfound@pipeline.com.au http://www.new-elect.com MPLAB compatible PIC programmers. ________________________________________