I use a look up table to convert binary to seven seg e.g:
Lookuptable:
retlw b'00111111' ; = 0 on 7 seg display
Then I send the data to the display:
movwf display
All this works fine! However the seven seg data is only seven bits (obviously) and I want to use the 'spare' bit7 on portC for another output function. Is there an easy way to make my label/definition only apply to bits 0 to 6 on portC and my look up table only return bits 0 to 6?
I use a look up table to convert binary to seven seg e.g:
Lookuptable:
retlw b'00111111' ; = 0 on 7 seg display
Then I send the data to the display:
movwf display
All this works fine! However the seven seg data is only seven bits (obviously) and I want to use the 'spare' bit7 on portC for another output function. Is there an easy way to make my label/definition only apply to bits 0 to 6 on portC and my look up table only return bits 0 to 6?
[You could OR the status of bit7 [from a image reg] with the segment pattern.]
erm, not really sure what your on about there! Sounds a bit over my head in programming terms!
It's just that in both my definition and the data I send to portC I wish to exclude the msb (without having to add lots of lines of code) so that I can use it for an output function not associated with the display. If the solution is complex I'd sooner leave things as they are and use an output pin other than RC7. Sorry if I'm not articulating my point properly
hi AB,
As you have LED's being segment driven and multiplexed.?
You may want to change the state of PORT bit 7 at other times than when you want to refresh the display.
Use BSF PORTx.7 or BCF PORTx.7 for those.
If you only want to change PORTx.7 at the refresh times, save the state you want bit7 to be in say, reg1 bit7.
Then when you refresh, get the segment pattern from the table and OR it with reg1, then output it.
Geko's code will work but it is not obvious what it is doing. If you want an easier to understand piece of code, try,
Code:
; enter with bits for 7 segment display in Wreg bits 6-0
btfsc PORTC,7 ;is bit 7 set
iorlw 128 ;yes, so set bit 7 of W
movwf PORTC ;write it to the port
Geko's code will work but it is not obvious what it is doing. If you want an easier to understand piece of code, try,
Code:
; enter with bits for 7 segment display in Wreg bits 6-0
[FONT=Courier New] btfsc PORTC,7 ;is bit 7 set
iorlw 128 ;yes, so set bit 7 of W
movwf PORTC ;write it to the port[/FONT]
Worth mentioning that with Pommie's codeit's important that bit 7 of the data in W is always 0, otherwise you may unintentionally set bit 7 of PORTC. If you know it will always be 0 the code above is okay, otherwise adding an andlw instruction will ensure that it works in all circumstances.
Code:
[I]; enter with bits for 7 segment display in Wreg bits 6-0 [/I]
[FONT=Courier New] andlw 0x7F ;ensure bit 7 of W reg is clear
btfsc PORTC,7 ;is bit 7 of PORTC set?
iorlw 128 ;yes, so set bit 7 of W
movwf PORTC ;write it to the port[/FONT]