Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

help me in AVR ADC

Status
Not open for further replies.
If you like WinAVR compiler tools you can use AVRLIB library. Then code looks really simple:
Code:
//----- Include Files ---------------------------------------------------------
#include <avr/io.h>		// include I/O definitions (port names, pin names, etc)
#include <avr/signal.h>	// include "signal" names (interrupt names)
#include <avr/interrupt.h>	// include interrupt support
#include <avr/iom8.h>
#include <avr/delay.h>
#include "global.h"		// include our global settings
//#include "uart.h"		// include uart function library
#include "rprintf.h"	// include printf function library
#include "a2d.h"		// include A/D converter function library
#include "timer.h"		// include timer function library (timing, PWM, etc)
#include "lcd.h"

//----- Begin Code ------------------------------------------------------------
int main(void)
{
	u08 a=0;
	u08 Pressure;

	a2dInit();
	
	// initialize LCD
	lcdInit();
	// direct printf output to LCD
	rprintfInit(lcdDataWrite);

	// print message on LCD
	rprintf("Welcome");

	DDRC = 0x00;
	PORTC = 0x00;
lcdClear();
	// display a bargraph of the analog voltages on a2d channels 0,1
	while(1)
	{
	
		lcdGotoXY(0,0);
		lcdProgressBar(a2dConvert8bit(0), 255, 20);
		lcdGotoXY(0,1);
		Pressure=(int)((((a2dConvert8bit(0)+0.3)/255)-0.04)/0.009);
		rprintf("Pressure:%d  kPa", Pressure);
	}

	return 0;
}
Full ready to compile project files you can find here
Reading Pressure sensor with Atmega8
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top