PDA

View Full Version : How to read data 4 bit



chai98a
- 10th December 2006, 04:26
I would to read last 4 bit of data.
Ex:
Data = FA ' hex

4bit.low = 10 'Dec
4bit.high = 15 'Dec

paul borgmeier
- 10th December 2006, 05:25
4BitLo = Data & $0F ' = 10
4BitHi = Data >> 4 ' = 15

(See manual or online for & and >> details)

chai98a
- 10th December 2006, 14:47
Thank you paul borgmeier
I have 1 question...
How to convert Hex to Dec?

we try to do 7seg display time.
If we need to show minute 10 , sec 20

n = Value Dig i ' Get digit to display

So, how to store data minute and sec in to Value = 2010 (dec)

mister_e
- 10th December 2006, 17:36
where the data comes from?

anyways, the following should work


'
' HEX to DEC
' ----------
Decimal=((Hexadecimal>>4)*10)+(Hexadecimal & $0F)

'
' DEC to HEX
' ----------
Hexadecimal=((Decimal/10)<<4)+(Decimal // 10)

paul borgmeier
- 11th December 2006, 05:07
Chai98a,

If you have enough RAM, it is easier to keep the seconds, minutes, hours, etc., all in their own variable. This saves building and unbuilding combined variables each time a second passes. I have posted two examples of clocks here

http://www.picbasic.co.uk/forum/showthread.php?t=2129

that uses separate variables for each “item”. The code sections of interest for you are at the very end of the programs. The first only has minutes and hours but seconds could easily be added. The second has all three. Check them out and see if they might help.