PDA

View Full Version : hex dec ascii



l_gaminde
- 11th February 2015, 16:45
Below is code to make porta.5 led come on, the "If V1>100 then high porta.5" does not work. I have basically the same code where I send out 28 receive data in hex shift it and then display it on an lcd screen which works fine.
The lcd allows me to use dec modifier to display to the lcd but the code below v1 without the dec modifier gives me d (tested on lcd screen) which is ascii for 100 but the light will not turn on what would be my best approach here.




TH:
SEROUT2 PORTB.2,16468,40,["28"]
GOSUB SOUT
GOSUB SINV1
GOSUB SHIFTV1
V1 = V1 */$0065
DISPLAY_TH:
If V1>100 then high porta.5

HenrikOlsson
- 11th February 2015, 17:48
The value is 100 but your IF statements says IF Value is more than 100....

/Henrik.

l_gaminde
- 11th February 2015, 19:10
I was just using that as an example to show I was getting ascii rather than dec, I have tried 50 and many other numbers along with = and => but without the dec modifier it just does not work guess I will input in dec and shift and try that

Tabsoft
- 11th February 2015, 19:22
Can you provide us the values as you step through the routine?
1. Initial value of V1 from the "GOSUB SINV1"
2. What the details of SHIFTV1 does
3. What the value of V1 is before you perform this "V1 = V1 */$0065"

A little more clarity might help us help you get pointed to the issue.

l_gaminde
- 11th February 2015, 19:32
its an old program and not sure of the values, the value is correct from them but its in ascii rather than dec when outputed to lcd if I output to lcd dec3 v1 its fine I can put them on the screen side by side one reads d the other 100

100 dec is d ascii

HenrikOlsson
- 11th February 2015, 19:54
Look, a byte variable can hold values from 0 to 255, that's it.
All this DEC, HEX, BIN and ASCII stuff is just us humans expressing the same thing in different ways, 100=64=d=01100100.

A character LCD is used to display stuff for humans to read so it "understands" ASCII. If a variable contains the value 100 and you send that to the LCD you'll get 'd' since 100 is the ASCII code for 'd' (exactly as you say). If you want to display the numeric value of the variable AS ASCII then you use the DEC modifier. The DEC modifier does in no way change the value.

If you do LCDOUT $FE, 1, DEC V1 and the display shows a value of more than 100 then If V1>100 then High PortA.5 statement WILL evalute true and the problem is with controling PortA.5.

l_gaminde
- 11th February 2015, 21:11
OK after HenrikOlsson spanking I started checking from his line of thinking putting in a fast blink between steps and it was hanging at a serin command and not getting value into V! also found I was missing an ADCON1 = %1111
statement so it is working, guess I needed a slap