Microcontroller › AVR › to display analog value of potentiometr on lcd using atmega 32
- This topic has 2 replies, 3 voices, and was last updated 12 years, 2 months ago by AJISH ALFRED.
-
AuthorPosts
-
August 22, 2012 at 7:09 am #1924aParticipant
cn any one help me regarding this topic if we using code vision avr. this is the code bt i am facing problem with dis. how to remove the errors . my code is here.
#define F_CPU 16000000UL#include<mega32.h>#include<delay.h>#include<stdio.h>#include “LCD.h”#define ADC_VREF_TYPE 0x00char volts[50];void ADC_init(void){ADMUX=ADC_VREF_TYPE & 0xff;ADCSRA=0x85;}unsigned int read_adc(unsigned char adc_input){ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);delay_us(10);ADCSRA|=0x40;while ((ADCSRA & 0x10)==0);ADCSRA|=0x10;return ADCW;}void main(){int adcD=0;double adcA=0.0;DDRB = 0xff;PORTB = 0x00;ADC_init();lcd_init(16);lcd_string_array(“Volts: “);while(1){adcD = read_adc(0);adcA = (int)(adcD*5.0)/1024.0;sprintf(volts,”%0.2f”,adcA);lcd_string_array(volts);delay_ms(50);lcd_gotoxy(0,7);delay_us(10);}}errors are:Error: C:cvavr2binankitarec.c(35): undefined symbol ‘lcd_string_array’Warning: C:cvavr2binankitarec.c(30): the ‘double’ data type will be supported only in the ‘Professional’ version, defaulting to ‘float’some body please help me . as i m begginer so facings alot many problems.August 24, 2012 at 11:45 am #8505AmrithParticipantHi Frnd,
Try this code:
//***********************************************************************
//*********** PROGRAM FOR DISPLAYING ADC VALUE ON LCD ************
//***********************************************************************
//Controller: ATmega8535 (Crystal: 8 Mhz)
//Compiler: CodeVisionAVR
//Author: Amrith Thakur
//********************************************************#include <mega8535.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <delay.h>void port_init(void)
{DDRB = 0x0F;
PORTB = 0x00;
DDRC = 0xFF;
PORTC = 0x00;
DDRD = 0xFF;
PORTD = 0x00;
}// ************* LCD.h : Header file *************
void LCD_init(void);
void LCD_WriteData (unsigned char Data);
void LCD_DisplayString_F(char row, char column, const unsigned char *string);
void LCD_Cursor(char row, char column);
void LCD_WriteCommand (unsigned char Command);void Display_PinStatus();
void LCD_DisplayFloat (char row, char column ,int value,char fp);
int Get_Voltage_fp2(char channel);void Init_UART();
void USART_Transmit( unsigned char data);
void Send_String(char flash *str);
void Send_floatvalue(int value, char dp);
void Init_ADC();
unsigned int Read_ADC_Channel(unsigned char adc_pin);#define ENABLE_LCD PORTB |= 0x04
#define DISABLE_LCD PORTB &= ~0x04
#define SET_LCD_DATA PORTB |= 0x01
#define SET_LCD_CMD PORTB &= ~0x01
#define pushButton1_PRESSED !(PINB & 0x80)
#define pushButton1_OPEN (PINB & 0x80)#define Enable_ADC(x) (x) ? (ADCSRA |= 0x80) : (ADCSRA &= (~0x80))
#define Start_ADC_Convertion(x) (x) ? (ADCSRA |= 0x40) :(ADCSRA &= (~0x40))
#define ADC_CHANNEL_0 0x00
#define ADC_CHANNEL_1 0x01
#define ADC_CHANNEL_2 0x02#define G_Calib 46.900
//call this routine to initialize all peripherals
void init_devices(void)
{
port_init();
LCD_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
}
//******************* MAIN FUNCTION *******************
void LCD_init(void)
{
delay_ms(100); // wait for 100ms
LCD_WriteCommand (0x38); // 8 data lines
//LCD_WriteCommand (0x06); // cursor setting
LCD_WriteCommand (0x0f); // display ON
LCD_WriteCommand (0x01); // clear LCD memory
delay_ms (10); // 10ms delay after clearing LCD
}// **********************************************
// *** Write a command instruction to the LCD ***
// **********************************************
void LCD_WriteCommand (unsigned char Command)
{
SET_LCD_CMD; // Set LCD in command mode
PORTC = Command; // Load data to port
ENABLE_LCD; // Write data to LCD
delay_ms(1);
DISABLE_LCD; // Disable LCD
delay_ms(1); // wait for 1ms
}// *****************************************
// *** Write one byte of data to the LCD ***
// *****************************************
void LCD_WriteData (unsigned char Data)
{
SET_LCD_DATA; // Set LCD in data mode
PORTC = Data; // Load data to port
ENABLE_LCD; // Write data to LCD
delay_ms(1);
DISABLE_LCD; // Disable LCD
delay_ms(1); // wait for 1ms
}// ************************************************************
// Display a string at the specified row and column, from FLASH
//*************************************************************
void LCD_DisplayString_F (char row, char column ,const unsigned char *string)
{
LCD_Cursor (row, column);
while (*string)
LCD_WriteData(*string++);
}// ***************************************************
// *** Position the LCD cursor at “row”, “column”. ***
// ***************************************************
void LCD_Cursor (char row, char column)
{
switch (row)
{
case 1: LCD_WriteCommand (0x80 + column – 1); break;
case 2: LCD_WriteCommand (0xc0 + column – 1); break;
default: break;
}
}void LCD_DisplayFloat (char row, char column ,int value,char fp)
{
int i=0;
unsigned char buffer[10];LCD_Cursor (row, column);
if(value < 0)
LCD_WriteData(‘-‘);
value = abs(value);
do
{
buffer[i++] = (value % 10)+0x30;
value /= 10;
if(i==fp)
{
buffer[i++] = ‘.’;
if(value == 0)
buffer[i++] = ‘0’;
}
}while(value);while(i>=0)
LCD_WriteData(buffer);
}int Get_Voltage_fp2(char channel)
{
float Calib = G_Calib;
unsigned long ADC_Value;
unsigned int voltage = 0;//read Adc channel
ADC_Value = Read_ADC_Channel(channel);
voltage = ((float)ADC_Value/Calib)*100;
return voltage;
}void Init_UART()
{
UCSRA = 0x00;
UCSRB = 0x98;
UCSRC = 0x06;
UBRRH = 0x00;
UBRRL = 0x33;
SREG = 0x80;
}void USART_Transmit( unsigned char data )
{
UDR = data;
while((UCSRA & 0x40) == 0);
UCSRA = 0;
delay_ms(10);
}void Send_String(char flash *str)
{
while(*str != ‘