Your code isn't too bad. You could eliminate the BCF STATUS,C instruction and change the ANDLW to ANDLW 0Eh. This is a bit shorter: ; Call this with the bit number in W set_bit_in_portb: call getmask iorwf portb,f return getmask: andlw 7 ; extract bit number addwf pcl,f ; assumes page bits/pclath set properly and table fits in page retlw 1 retlw 2 retlw 4 retlw 8 retlw 16 retlw 32 retlw 64 retlw 128 What is real cool is you can also create: clr_bit_in_port_b: call getmask xorlw 0FFh andwf portb,f return and: toggle_bit_in_port_b: call getmask xorwf portb,f return Bob Ammerman RAm Systems ----- Original Message ----- From: "Daryl Sayers" To: Sent: Wednesday, January 16, 2002 1:16 PM Subject: Re: Beginners 16C84 programming question > Sorry for not explaining my question correctly. What I REALLY wanted was > to express the data between 0-7 as bit location to turn on. > > eg: if the data was 0x03 then I would turn on bit 3 of port B. > > The code snippet I gave showed this but my question was incorrect. I have > since tried a few ideas and have come up with the following. I hope its not > too repulsive. > > ... > CALL Setport > RETURN > > Setport > BCF STATUS, C > RLF DataByte, w > ANDLW 0fh > addwf PCL,f > bsf PORTB,0 > RETURN > bsf PORTB,1 > RETURN > bsf PORTB,2 > RETURN > bsf PORTB,3 > RETURN > bsf PORTB,4 > RETURN > bsf PORTB,5 > RETURN > bsf PORTB,6 > RETURN > bsf PORTB,7 > RETURN > > > > Do you mean: > > movf TmpByte,w > > movwf PORTB > > > Al Williams > > AWC > > * Floating point math for the Stamp, PIC, SX, or any microcontroller > > http://www.al-williams.com/awce/pak1.htm > > > > >> -----Original Message----- > >> From: pic microcontroller discussion list > >> [mailto:PICLIST@MITVMA.MIT.EDU] On Behalf Of Daryl Sayers > >> Sent: Monday, January 14, 2002 5:50 PM > >> To: PICLIST@MITVMA.MIT.EDU > >> Subject: Beginners 16C84 programming question > >> > >> > >> I had a play with a 16C84 several years ago and I now need to > >> make it do something. I am a real PIC beginner. My simple > >> programming question is how do I represent a byte out to the > >> RB port. It seems my restriction is using a variable in the > >> bsf op code. I manually did it by doing each bit but I am > >> sure there is a more elegant way of doing it through a loop. > >> I am using gpasm-0.9.14 alpha to assemble code. > >> > >> movlw 0x01 > >> subwf TmpByte,w > >> btfsc STATUS, Z > >> bsf PORTB,0 > >> > >> movlw 0x02 > >> subwf TmpByte,w > >> btfsc STATUS, Z > >> bsf PORTB,1 > >> > >> ...... > >> > >> movlw 0x80 > >> subwf TmpByte,w > >> btfsc STATUS, Z > >> bsf PORTB,7 > >> > > -- > http://www.piclist.com hint: To leave the PICList > mailto:piclist-unsubscribe-request@mitvma.mit.edu > > -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu