The output it is reading is 0.00. Not able to figure out y? posting the code below [code] #include"lpc214x.h" #include<stdio.h>
#define LED (0x00000001<<7) #define BIT16 (0X00000001<<16) #define BIT18 (0X00000001<<18) #define BIT24 (0X00000001<<24) //po.28 adc0.1
unsigned char key_press[]="key press"; void PrintonVGA(unsigned char *); void adc_init(void); void UART_Init (void); void adc_read(void); int main() { unsigned int i; UART_Init() ; PINSEL1=BIT24; //ADC0.1
IODIR0=LED; IODIR0|=~KEY; adc_init();
PrintonVGA( key_press); adc_read(); IOSET0=LED; for(i=0;i<40000;i++); IOCLR0=LED;
}
void adc_read(void) {
float res=0; unsigned char buf[20]; AD0CR|=0X01000000; PrintonVGA(" Start conversion"); while(!(AD0DR1 & 0x80000000)); // checking for done bit PrintonVGA("converted");
res=((AD0DR1>>6)&(0x000003ff)); // extracting the converted value
sprintf(buf,"%f",res); PrintonVGA(buf); AD0CR|=0x00200302; // stop adc
} void adc_init(void) { PCONP |= 0x0100;
AD0CR=0x00200302; //channel 1 adc 0 }
void UART_Init (void) {
PINSEL0 |= BIT16 + BIT18;
U1LCR = 0x83; U1DLM = 0x00; U1DLL = 0x62; U1LCR = 0x03;
U1FCR = 0x07; }
void SendUARTByte (int ch) { while (!(U1LSR & 0x20)); U1THR = ch; }
void PrintonVGA(unsigned char *ptrBuf) {
while(*ptrBuf != '\0') { SendUARTByte(*ptrBuf); ptrBuf++; } } [/code]