Ok, what Im trying to say is, I have my program take an ADC reading. This value gets stored to a varible, in my case I call it "RAW". Now, has the program (PIC), stored this ADC read value as a hex number, a binary number or a decimal number?
The F818 I am using has a 10 bit ADC therefore any reading will be 0 - 1023. So at a max reading, is the data stored as "1023" in the varible "RAW" or is the Hex, or binary equilvalent of 1023 stored in "RAW"
If its hex or binary, how do I convert it to decimal?
I wrote a small program that took an ADC reading and stored it in the eeprom. I can read the data back in my programmer and its read back as Hex. Hence the question, does the pic store data as a hex number, or is this just my programmer converting the stored data to Hex?
Here is the math I want to do with my ADC value: (All credit to Ingvar)
ADCIN 0, RAW 'READ ADC store value to RAW
millivolts = RAW */ 1250 'convert ADC to millivolts
psitimes100 = millivolts ** 47527 'convert millivolts to psi*100
psitimes100 = psitimes100 + 145 ' add sensor offset
I would like to display a decimal reading of psitimes100 on 3 seven segment displays.
I tried this following code just to experiment:
DEFINE OSC 20
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 10
TRISA = %11000001 'set portA
ADCON0 = %11000101 'read as analog
ADCON1 = %00001110
RAW VAR WORD 'Set ADC value to name of RAW
millivolts VAR WORD
psitimes100 var word
B0 VAR WORD
B1 VAR WORD
B2 VAR WORD
B3 VAR WORD
B4 VAR WORD
B5 VAR WORD
B6 VAR WORD
TRISB = %00000000 'set portB all outputs
PortA.2 = 1 'Blanks displays at startup
PortA.3 = 1
PortA.4 = 1
PortB.0 = 1 'A
PortB.1 = 1 'B
PortB.2 = 1 'C
PortB.3 = 1 'D
PortB.4 = 1 'E
PortB.5 = 1 'F
PortB.6 = 1 'G
PortB.7 = 1 'DP
loop:
ADCIN 0, RAW 'READ ADC store value to RAW
millivolts = RAW */ 1250 'convert ADC to millivolts
psitimes100 = millivolts ** 47527 'convert millivolts to psi*100
psitimes100 = psitimes100 + 145 ' add sensor offset
B2 = PSITIMES100 DIG 0 'TENTHS
B3 = PSITIMES100 DIG 1 'UNITS
B4 = PSITIMES100 DIG 2 'TENS
B0 = B2 ' Pass the count to the conversion subroutine
Gosub bin2seg ' Convert to segment value
PortB = B0 ' Put segment values out to LED
PortA.2 = 0 ' Turn on the digit
Pause 1 ' Display it for 1MS second
PortA.2 = 1
GOTO LOOP1
' Convert binary number in B0 to segments for LED
bin2seg: Lookup B0,[%11111001, %11000100, %11110000, %10011001, %10010010, %10000010, %11111000, %10000000, %10011000, %11000000],B0
Return
LOOP1
B5 = B3 ' Pass the count to the conversion subroutine
Gosub bin2seg2 ' Convert to segment value
PortB = B0 ' Put segment values out to LED
PortA.3 = 0 ' Turn on the digit
Pause 1 ' Display it for 1MS second
PortA.3 = 1
GOTO LOOP2
' Convert binary number in B0 to segments for LED
bin2seg2: Lookup B5,[%11111001, %11000100, %11110000, %10011001, %10010010, %10000010, %11111000, %10000000, %10011000, %11000000],B5
Return
LOOP2
B6 = B4 ' Pass the count to the conversion subroutine
Gosub bin2seg3 ' Convert to segment value
PortB = B0 ' Put segment values out to LED
PortA.4 = 0 ' Turn on the digit
Pause 1 ' Display it for 1MS second
PortA.4 = 1
Goto loop
' Convert binary number in B0 to segments for LED
bin2seg3: Lookup B6,[%11111001, %11000100, %11110000, %10011001, %10010010, %10000010, %11111000, %10000000, %10011000, %11000000],B6
Return
Goto loop
Im trying not to be a burden to the group, I apologise for all the questions.
Regards,
James.
Bookmarks