winky4110
Joined: 05 Nov 2010 Posts: 1
|
CVD mtouch by using 16f877a |
Posted: Fri Nov 05, 2010 12:53 pm |
|
|
I am trying to make a capacitive push button by using 16f877a. According to the Microchip application note (AN1298), most of the devices which have adc can be used. I used lcd to show the value of adc but the result was randomly jump between 0 to 5v (abnormal).
Here is my coding:
Code: |
#include <16F877A.H>
#device adc=10
#fuses XT, NOWDT, NOPROTECT, NOBROWNOUT, NOPUT, NOLVP
#use delay(clock=4000000)
#include "flex_lcd.c"
#byte adcon0=01F
//============================
void main()
{
int16 adc_value;
float volts;
lcd_init();
output_low(pin_a0);
delay_us(100);
set_tris_a(0b11111111);
setup_adc_ports(AN0_AN1_AN3);
setup_adc(ADC_CLOCK_DIV_32);
while(true)
{
adcon0=0b10001001;
delay_us(100);
adcon0=0b10000001;
delay_us(20);
adc_value = read_adc();
volts = (float)(adc_value * 5)/1023.0;
printf(lcd_putc, "\f%3.2f", volts);
delay_ms(50);
}
} |
Pin AN1 was connected to Vdd.
Pls help....Thx!!! |
|