I am creating code and using a PIC16F1823 that will read an analog input, send it through the ADC, then display the result of just ADRESH in hex on a dual seven segment display.
I would like to set up a lookup table that I can give the most significant and least significant halves of ADRESH to and have it give me the according segments to turn on on the seven segment display.
I was wondering if anyone can point me in the right direction with this, thanks!
P.s. the dual seven segment display will have to be multiplexed and I am trying to figure that out also.
Here is what I have so far:
I would like to set up a lookup table that I can give the most significant and least significant halves of ADRESH to and have it give me the according segments to turn on on the seven segment display.
I was wondering if anyone can point me in the right direction with this, thanks!
P.s. the dual seven segment display will have to be multiplexed and I am trying to figure that out also.
Here is what I have so far:
Rich (BB code):
#include <htc.h>
unsigned char ad_convert(void);//function prototype
unsigned char hex(unsigned char);//converter function
__Config=0x09A4; //set up config 1
__Config=0x1CFF; //set up config 2
void main(void)
{
PORTA=0x00; //clear Port A
LATA=0x00; //Clear Lat A
PORTC=0x00; //Clear Port C
LATC=0x00; //Clear LAT C
ANSELA=0x01; //set RA0 as analog In, all other I/O)
ANSELC=0x00; //all port C I/)
TRISA=0x09; //RA0,RA3 inputs all others outputs
TRISC=0x00; //All port C output
OSCON=0x68; //set FOSC to 4MHz
TMR0=0;
T0IF=0;
while(1)// begin infinite while loop
{
unsigned char value; //variable to store 0-255 A-D conversion
unsigned char hex1, hex2; //hex values after conversion
value=ad_convert(); //call to function to read analog in and convert
hex1=value>>4;
THIS IS WHERE I WANT TO SENT THE BITS OF HEX1 TO A LOOKUP TABLE TO GET THE CORRECT SEGMENTS TO TURN ON.
}
}
unsigned char ad_convert(void) //unsigned char to return a value between 0-255
{
//unsigned char dig_value; //variable to store 0-255 value
PIE1=0x40; //enable ADIF
ANSELA=0x01; //set RA0 as analog In, all other I/O)
ADCON1=0x40; //set ADCS to FOSC/4, and Vref is VDD
ADCON0=0x01; //Turn on ADC, set analog in on RA0
__delay_us(25);
GO_nDONE=1; //start acquisition
__delay_us(25);
while(ADIF==0) //wait for AD converter flag to trip
{
ad_convert=ADRESH;
ADIF=0; //reset interrupt flag
ADCON=0x00; //turn off ADC
}
return(ad_convert)
}
Last edited by a moderator: