Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
kate said:hi! ive seen your code about 16f84a working with ADC. can u please translate it in english so i can understand your code because your comments are written in a different language.
#define AD_CK pin_A2 // Clock
#define AD_DO pin_A3 // Data Out
#define AD_DI pin_A4 // Data In (MUX Channel Selector). Use a PULL-UP resistor
#define AD_CS pin_A7 // Chip Select
int adc_result;
int MUX;
void Clock() {
output_high(AD_CK);
output_low(AD_CK);
}
void set_adc(short ch, short mode) { //SGL:1/0 ==>Single-Ended/Differential Mode
int i;
if(mode==1 & ch==0) {
MUX=2;
}
if(mode==1 & ch==1) {
MUX=3;
}
if(mode==0 & ch==0) {
MUX=0;
}
if(mode==0 & ch==1) {
MUX=1;
}
output_high(AD_CS); //CS=1, disable ADC0832
output_low(AD_CS); //CS=0, enable ADC0832
output_high(AD_DI); //Start BIT
Clock();
for (i=0;i<2;i++) { //Send MUX word
if((MUX & 0x2)==0) { //
output_low(AD_DI); //
}
else { //
output_high(AD_DI); //
}
MUX<<= 1;
Clock();
}
}
void read_adc() {
int i;
for (i=0;i<8;i++) {
Clock();
shift_left(&adc_result, 1, input(AD_DO));
}
output_high(AD_CS);
}
//use following code to read ADC0832
set_adc(0,1); //set channel 0, in Single_Ended mode. I can be Differential mode too.
read_adc();
lcd_init();
lcd_gotoxy(1,1);
printf(lcd_putc,"Tempe:");
lcd_gotoxy(12,1);
printf(lcd_putc,"°C");
while(true) {
float T;
set_adc(0,1); // Choice CH & Single_Ended mode
read_adc();
T=(adc_result/1.02)+2; //Vref is 5 Volts
lcd_gotoxy(7,1);
printf(lcd_putc,"%3.2f",T);
delay_ms(100);
}