EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies / help me rectifying error in

help me rectifying error in

|

Microcontroller › PIC › Temperature Sensor : Interfacing LM35 and LCD Display to PIC18F4550 › help me rectifying error in

March 10, 2013 at 7:12 pm #9289
himanshu singh
Participant

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 1000000UL
void main()
{
 
char ch; // declaring ch as character variable of length 4, used to select 1 channel out of 7
unsigned long int adc_result; // declaring adc_result variable as unsigned integer used to to store adc result which willbe passed onto lcd
 
lcd_init (LCD_DISP_ON);
lcd_clrscr() ;
 
initADC (); // initialise adc funtion
 
 
lcd_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 variable
sprintf(ch,”%4d”,adc_result); // to print this result in lcd, first store it in ch variable
lcd_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.56
ADCSRA= (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 channels
ADMUX|= (1<<MUX0);
 
ADCSRA |= (1<<ADSC); // start adc conversion
 
while (!(ADCSRA & (1<<ADIF))); // wait until conversion is complete
ADCSRA|= (1<<ADIF); // clear adif flag after completion, yes its 1 to clear it
return (ADC); // return the digital output
}
 

RSS Recent Posts

  • How to repair this plug in connector where wires came loose May 17, 2025
  • Lightbox circuit May 17, 2025
  • Fuel Auto Shutoff May 17, 2025
  • Kawai KDP 80 Electronic Piano Dead May 17, 2025
  • Python help with keystroke entries May 17, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise