OK, I’m not TK, but I’ll take a shot at this.
This may not be the best way, but it will work.
So I’m guessing you have about twelve choices.
The first step is to convert your 0-127 input into 0-11 for your twelve choices.
We take your original value and divide by about 10.66. Since division is
not easy, we’ll multiply by 24, then divide by 256.(both easy to do)
movf yourvalue,W ;get your starting value
mullw d’24’
movf PRODH,W ;now you have 0-11 in W
call channame ;selects the right name
call MIOS_LCD_PrintString ;and prints it
Next up is to choose your label. I’m SURE there are better ways, but
this works for me.
;this will select the proper name for a given channel (in W)
channame
movwf NameScan ;store our channel target
TABLE_ADDR TEXT_CHAN_0 ;point to first name
movf NameScan,F
btfsc STATUS,Z ;if the channel number is Zero,
return
TABLE_ADDR TEXT_CHAN_1 ;point to second name
dcfsnz ChanScan ;decrement the channel number. If the result is zero,
return
TABLE_ADDR TEXT_CHAN_2 ;point to the third name
dcfsnz ChanScan ;dec the channel number. If the result is zero,
return
TABLE_ADDR TEXT_CHAN_3 ;point to the fourth name
dcfsnz ChanScan ;dec the channel number. If the result is Zero,
return
TABLE_ADDR TEXT_CHAN_4
dcfsnz ChanScan ;repeat until a name is found
return
TABLE_ADDR TEXT_CHAN_5
dcfsnz ChanScan
return
TABLE_ADDR TEXT_CHAN_6
dcfsnz ChanScan
return
TABLE_ADDR TEXT_CHAN_7
dcfsnz ChanScan
return
TABLE_ADDR TEXT_CHAN_8
dcfsnz ChanScan
return
TABLE_ADDR TEXT_CHAN_9
dcfsnz ChanScan
return
TABLE_ADDR TEXT_CHAN_10
dcfsnz ChanScan
return
TABLE_ADDR TEXT_CHAN_11
return
Finally, define the names with the string macro
;Name your channels here
;remember to change the number to the length of the new name
;the 0x04 tells where to put the text on the display
TEXT_CHAN_0 STRING 8,0x04,“Whatever”
TEXT_CHAN_1 STRING 3,0x04,“XVQ”
TEXT_CHAN_2 STRING 3,0x04,“FU2”
TEXT_CHAN_3 STRING 9,0x04,“Channel 4”
TEXT_CHAN_4 STRING 9,0x04,“Channel 5”
TEXT_CHAN_5 STRING 9,0x04,“Channel 6”
TEXT_CHAN_6 STRING 9,0x04,“Channel 7”
TEXT_CHAN_7 STRING 9,0x04,“Channel 8”
TEXT_CHAN_8 STRING 9,0x04,“Channel 9”
TEXT_CHAN_9 STRING 10,0x04,“Channel 10”
TEXT_CHAN_10 STRING 10,0x04,“Channel 11”
TEXT_CHAN_11 STRING 10,0x04,“Channel 12”
Hope that helps,
LyleHaze
[edit] cleaned up the code just a little bit