Hi Guru's
Here I have a scenario in which I need to read specific BYTE's from an external LED&Keyscan matrix chip (Holtek - HT16K33), make alterations to individual BITS of the read BYTE and then write the BYTE back to the HT16K33. For understanding, there are parts of two different BYTES making up a row of 6 LED's.
The following CODE does work flawlessly, however each SETBIT line burns 3 BYTES of program space and CLEARBIT lines burn 7 BYTES. Is there a more program space efficient way I can do this?
It'd be nice if I could essentially say:
setbit Temp_Byte,{1st BIT},{2nd BIT},{3rd BIT},etc..
or better yet,
setbit Temp_Byte,(%10101010) in the hope of combining SETBIT and CLEARBIT in one command line, but obviously this does not work.
Any ideas spring to mind?
Thanks in advance.
Regards,
Mort.
Here I have a scenario in which I need to read specific BYTE's from an external LED&Keyscan matrix chip (Holtek - HT16K33), make alterations to individual BITS of the read BYTE and then write the BYTE back to the HT16K33. For understanding, there are parts of two different BYTES making up a row of 6 LED's.
The following CODE does work flawlessly, however each SETBIT line burns 3 BYTES of program space and CLEARBIT lines burn 7 BYTES. Is there a more program space efficient way I can do this?
It'd be nice if I could essentially say:
setbit Temp_Byte,{1st BIT},{2nd BIT},{3rd BIT},etc..
or better yet,
setbit Temp_Byte,(%10101010) in the hope of combining SETBIT and CLEARBIT in one command line, but obviously this does not work.
Any ideas spring to mind?
Code:
HI2cSetup I2CMASTER, $E0, I2CFAST, I2CBYTE 'I2C Communication for HT16K33 - I2C Address $E0
'Initialize and setup HT16K33
hi2cout [$E0],($21) 'Turn on Oscillator
pause 2
hi2cout [$E0],($EF) 'Set LED's Brightness ($E0 = min), ($EF = max)
pause 2
hi2cout [$E0],($81) 'Turn on Display with no blinking
Symbol Temp_Byte = b0
Symbol ADC_Read = b1
Symbol ADC_In = C.2
readadc ADC_In, ADC_Read
if ADC_Read>=206 then
HI2CIN [$E0],$01,(Temp_Byte)
setbit Temp_Byte,6
setbit Temp_Byte,5
HI2COUT [$E0],$01,(Temp_Byte)
pause 2
HI2CIN [$E0],$08,(Temp_Byte)
setbit Temp_Byte,3
setbit Temp_Byte,2
setbit Temp_Byte,1
setbit Temp_Byte,0
HI2COUT [$E0],$08,(Temp_Byte)
elseif ADC_Read<206 and b9>=192 then
HI2CIN [$E0],$01,(Temp_Byte)
setbit Temp_Byte,6
setbit Temp_Byte,5
HI2COUT [$E0],$01,(Temp_Byte)
pause 2
HI2CIN [$E0],$08,(Temp_Byte)
clearbit Temp_Byte,3
setbit Temp_Byte,2
setbit Temp_Byte,1
setbit Temp_Byte,0
HI2COUT [$E0],$08,(Temp_Byte)
elseif ADC_Read<192 and b9>=177 then
HI2CIN [$E0],$01,(Temp_Byte)
setbit Temp_Byte,6
setbit Temp_Byte,5
HI2COUT [$E0],$01,(Temp_Byte)
pause 2
HI2CIN [$E0],$08,(Temp_Byte)
clearbit Temp_Byte,3
clearbit Temp_Byte,2
setbit Temp_Byte,1
setbit Temp_Byte,0
HI2COUT [$E0],$08,(Temp_Byte)
elseif ADC_Read<177 and b9>=163 then
HI2CIN [$E0],$01,(Temp_Byte)
setbit Temp_Byte,6
setbit Temp_Byte,5
HI2COUT [$E0],$01,(Temp_Byte)
pause 2
HI2CIN [$E0],$08,(Temp_Byte)
clearbit Temp_Byte,3
clearbit Temp_Byte,2
clearbit Temp_Byte,1
setbit Temp_Byte,0
HI2COUT [$E0],$08,(Temp_Byte)
elseif ADC_Read<163 and b9>=156 then
HI2CIN [$E0],$01,(Temp_Byte)
setbit Temp_Byte,6
setbit Temp_Byte,5
HI2COUT [$E0],$01,(Temp_Byte)
pause 2
HI2CIN [$E0],$08,(Temp_Byte)
clearbit Temp_Byte,3
clearbit Temp_Byte,2
clearbit Temp_Byte,1
clearbit Temp_Byte,0
HI2COUT [$E0],$08,(Temp_Byte)
elseif ADC_Read<156 then
HI2CIN [$E0],$01,(Temp_Byte)
clearbit Temp_Byte,6
setbit Temp_Byte,5
HI2COUT [$E0],$01,(Temp_Byte)
pause 2
HI2CIN [$E0],$08,(Temp_Byte)
clearbit Temp_Byte,3
clearbit Temp_Byte,2
clearbit Temp_Byte,1
clearbit Temp_Byte,0
HI2COUT [$E0],$08,(Temp_Byte)
endif
Thanks in advance.
Regards,
Mort.