Re: Hex values to decimal
Output the data serially on the UART or bit bang it out of a pin?
Why involve a pickit3 at all, for just reading the stored data?
Re: Hex values to decimal
a small board sending data to the PC " Hyperterminal " .... when the chip is placed on a ZIF socket ??? ( see "Debug" PBP command i.e. )
Alain
Re: Hex values to decimal
Is there an another way to make it work ? Such as viewing the hex on EXCEL ? or an another software ?
Re: Hex values to decimal
Have to agree with the others, use serial and either cable or use a HC-05 bluetooth module and read the values or HEX stored via a terminal application, or write your own app using something like VB or Liberty Basic.
You risk damage to the PIC constantly removing it and then re-inserting it into your PCB
Re: Hex values to decimal
Of course you can do the conversions in Excel; but again, how would you get the data into Excel in the first place? And if you do that, (using something like StampDaq or some such), then why not let the pic/PBP itself do the conversion(s)?
Re: Hex values to decimal
Ok thanks to everyone for the answers ..
Re: Hex values to decimal
Hi All,
How to convert a HEX value to DEC value. For example: Var mai = $2B and I want to store the decimal value of this (which is 43 in decimal) in other variable.
On LCD is all ok, shows the right dec value, but how to store this in decimal in other variable that's my problem.
I do some search on the forum but no success. Can me to someone explain how to do?
Thanks.
Code:
#CONFIG
cfg = _INTRC_OSC_NOCLKOUT
cfg&= _WDT_ON
cfg&= _PWRTE_OFF
cfg&= _MCLRE_OFF
cfg&= _CP_OFF
cfg&= _CPD_OFF
cfg&= _BOD_ON
cfg&= _IESO_ON
cfg&= _FCMEN_ON
__CONFIG cfg
#ENDCONFIG
DEFINE OSC 8 ; Use a 8 MHZ internal clock
OSCCON = %01110000
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_BAUD 38400
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
Define LCD_DREG PORTC
Define LCD_DBIT 0
Define LCD_RSREG PORTC
define LCD_RSBIT 4
define LCD_EREG PORTC
define LCD_EBIT 5
define LCD_BITS 4
define LCD_LINES 2
define LCD_COMMANDUS 2000
define LCD_DATAUS 50
ANSELH = 0 ; Set RB6 (TX) pin to digital
ANSEL = 0 ; Set all digital
TRISA = %011100 ; Set RA5,RA4,RA3 input ; RA2,RA1,RA0 output
TRISB = %0011 ; Set RB4,RB5 input ; RB6,RB7 output
TRISC = %00000000 ; Set RC0,RC3,RC4,RC5,RC6, RC1,RC2,RC7 output
CM1CON0 = 0 ; Disable comparator 1
CM2CON0 = 0 ; Disable comparator 2
OPTION_REG.7=1 ; Disable weak pull ups
mai var byte[2]
decvalue var byte
Lcdout $fe, 1
pause 1000
main:
hserout ["01 05",13,10]
pauseus 1
HSerin 1000,main, [wait ("41 05"), skip 1, hex mai]
Lcdout $fe, 1
lcdout dec mai
let decvalue = mai
pause 1000
goto main
Re: Hex values to decimal
to start with
Quote:
mai var byte[2]
HSerin 1000,main, [wait ("41 05"), skip 1, hex mai]
probably does not work as you intend
input
41 05xC , mai[0]=$C or 12 or %00001100
41 05x2C , mai[0]=$2C or 44 or %00101100
41 05x42C , mai[0]=$2C or 44 or %00101100
41 05x552C , mai[0]=$2C or 44 or %00101100
41 05x3FED2C , mai[0]=$2C or 44 or %00101100
mai[1] takes no part in this
secondly
the data is always binary once "parsed" by the HEX modifier in hserin ,it just depends on how you display/interpret the data
Re: Hex values to decimal
Quote:
Originally Posted by
richard
to start with
probably does not work as you intend
input
41 05xC , mai[0]=$C or 12 or %00001100
41 05x2C , mai[0]=$2C or 44 or %00101100
41 05x42C , mai[0]=$2C or 44 or %00101100
41 05x552C , mai[0]=$2C or 44 or %00101100
41 05x3FED2C , mai[0]=$2C or 44 or %00101100
mai[1] takes no part in this
secondly
the data is always binary once "parsed" by the HEX modifier in hserin ,it just depends on how you display/interpret the data
Thanks Richard for answer, but still not clear for me. The serin input data is a string like:
41 05 2B The "41 05" part represent the identificator and the "2B" is the value in hex which is changing and this part I want store in variable in dec format.
Re: Hex values to decimal
You don't get to choose in what format the number is stored, it doesn't work like that.
2B in hex
43 in decimal
00101011 in binary
+ in ASCII
These are all the same thing and stored exactly the same in a variable.
Code:
mai = $2B
mai = %00101011
mai = 43
mai = "+"
Exactly the same result. It's just how we choose to interpret the information.
If you want to receive a number expressed in a "human readable" format (ie represented as an ASCII string) you use the available DEC/HEX/BIN modifiers (as you are).
The code, as it runs, will then interpret ASCII characters and convert to an actual number so that the ASCII string '2B' becomes the decimal value 43. There's no need to use an array in the HSERIN statement because you're not storing the '2' and the 'B', you're storing the decimal value 43 that the ASCII string '2B' represents.
Then, when you do the LCDOUT you, again, use the DEC (or HEX or BIN) modifier to convert the decimal value 43 back into the ASCII characters '4' and '3' which are displayed on the LCD.
Since your LCD shows 43 when you send '41 05 2B' everything is working exactly as expected and when you do decvalue = mai you'll copy the content of mai to decvalue so it TOO contains 43.
I don't get what the problem is......
/Henrik.
Re: Hex values to decimal
Quote:
Originally Posted by
HenrikOlsson
You don't get to choose in what format the number is
stored, it doesn't work like that.
2B in hex
43 in decimal
00101011 in binary
+ in ASCII
These are all the same thing and stored exactly the same in a variable.
Code:
mai = $2B
mai = %00101011
mai = 43
mai = "+"
Exactly the same result. It's just how we choose to
interpret the information.
If you want to receive a number expressed in a "human readable" format (ie represented as an ASCII string) you use the available DEC/HEX/BIN modifiers (as you are).
The code, as it runs, will then
interpret ASCII characters and convert to an actual number so that the ASCII string '2B' becomes the decimal value 43. There's no need to use an array in the HSERIN statement because you're not storing the '2' and the 'B', you're storing the decimal value 43 that the ASCII string '2B' represents.
Then, when you do the LCDOUT you, again, use the DEC (or HEX or BIN) modifier to convert the decimal value 43 back into the ASCII characters '4' and '3' which are displayed on the LCD.
Since your LCD shows 43 when you send '41 05 2B' everything is working exactly as expected and when you do
decvalue = mai you'll copy the content of
mai to
decvalue so it TOO contains 43.
I don't get what the problem is......
/Henrik.
Hi Henrik, yes right the LCD shows the value in dec that is what I want, but next in the code I want to do some math or comparsion with decimal value of this number.
Re: Hex values to decimal
And what's stopping you?
Either I don't get it or you don't :-) No offense.
Code:
mai VAR BYTE
value VAR BYTE
mai = $2B 'assign value to variable, in this case the value 43 represented as HEX.
mai = mai + 10
LCDOUT $FE, 1, DEC mai ' will show 53
PAUSE 2000
value = mai * 4
LCDOUT $FE, 1, DEC value ' will show 212
PAUSE 2000
value = value / 5
LCDOUT $FE, 1, DEC value ' will show 42
PAUSE 2000
IF mai < $3A THEN
LCDOUT $FE, 1, "mai is smaller than 58"
ENDIF
PAUSE 2000
IF mai > value THEN
LCDOUT $FE, 1, "Yes, mai is bigger than value"
ENDIF
PAUSE 2000
LCDOUT $FE, 1, DEC mai, " ", HEX mai
PAUSE 2000
Show us the math or comparison you're wanting to do and tell us wha the problem you're having actually is.
/Henrik.
Re: Hex values to decimal
ahaaa, I thought that in PBP not work and I don't try this all the time. Now it's
more clear. Thanks guys for the patience with me, I'm just an old beginner (63) and I try to learn about these (new for me) things.