Forum Replies Created
Viewing 1 post (of 1 total)
-
AuthorPosts
-
March 10, 2013 at 7:12 pm in reply to: Temperature Sensor : Interfacing LM35 and LCD Display to PIC18F4550 #9289himanshu singhParticipant
help me rectifying error in this code for ADC
// program to read analog input from TEMPERATURE SENSOR AND PRODUCE EQUIVALENT OUTPUT AND PRINT IT ON LCD
#include <avr/io.h>#include<util/delay.h>#include “lcd.h”#include “lcd.c”#define F_CPU 1000000ULvoid main(){char ch; // declaring ch as character variable of length 4, used to select 1 channel out of 7unsigned long int adc_result; // declaring adc_result variable as unsigned integer used to to store adc result which willbe passed onto lcdlcd_init (LCD_DISP_ON);lcd_clrscr() ;initADC (); // initialise adc funtionlcd_gotoxy(0,0);lcd_puts(“ADC TEST”);lcd_gotoxy(0,1);lcd_puts(“ADC= “);while (1){adc_result= ReadADC(); // store adc result in adc_result variablesprintf(ch,”%4d”,adc_result); // to print this result in lcd, first store it in ch variablelcd_gotoxy(4,1);lcd_puts(ch); // display the result on lcd_delay_ms(100);}}void initADC() // ADC INITIALISATION FUNCTION{ADMUX=(1<<REFS0)|(1<<REFS1); // VOLTAGE REFERENCE AS 2.56ADCSRA= (1<<ADEN)|(1<<ADPS1)|(1<<ADPS0);// ENABLING ADC AND SELECTING PRESCALING OF 8}unsigned long int ReadADC(void) // ADC READING FUNCTION, RETURN VALUE IS OF 16 BITS SO UINT16_T AND CHANNEL LENGTH AS INPUT ARGUMENT{// enabling 0to 7 channelsADMUX|= (1<<MUX0);ADCSRA |= (1<<ADSC); // start adc conversionwhile (!(ADCSRA & (1<<ADIF))); // wait until conversion is completeADCSRA|= (1<<ADIF); // clear adif flag after completion, yes its 1 to clear itreturn (ADC); // return the digital output} -
AuthorPosts
Viewing 1 post (of 1 total)