Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Numeric Voltmeter with Lcd Display (help)

Status
Not open for further replies.

geo2007

Newbie level 2
Joined
Jan 11, 2010
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Romania
Activity points
1,289
Hi all,

I want to make a numeric voltmeter, with atmega16 processor and an LCD display 2X16 (with 14 pins). I tried to make a program but it didnt worked. It only displays:
Volts = 3fV

Can anyone please help me with this.

Many thanks.


Code:
/*****************************************************
This program was produced by the
CodeWizardAVR V1.24.7d Professional
Automatic Program Generator
© Copyright 1998-2005 Pavel Haiduc, HP InfoTech s.r.l.
[url]http://www.hpinfotech.com[/url]
e-mail:office@hpinfotech.com


Chip type           : ATmega16
Program type        : Application
Clock frequency     : 13.500000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
*****************************************************/

#include <mega16.h>
#include<stdio.h>
#include<delay.h>
#include<math.h>
// Alphanumeric LCD Module functions
#asm
  .equ __lcd_port=0x15;PORTC
#endasm
#include <lcd.h>
#define ADC_VREF_TYPE 0xC0

char lcd_buffer[33];
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{  

ADMUX=adc_input|ADC_VREF_TYPE;
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}

// Declare your global variables here


void main(void)
{
float adc,volts;
//#asm("cli")


PORTA=0x20;
DDRA=0x20;

PORTB=0x00;
DDRB=0x00;

PORTC=0x00;
DDRC=0x00;  

PORTD=0x00;
DDRD=0x40;


// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 105.469 kHz
// ADC Voltage Reference: Int., cap. on AREF
// ADC Auto Trigger Source: None
ADMUX=ADC_VREF_TYPE;
ADCSRA=0x87;
delay_ms(22);
// LCD module initialization
lcd_init(16);
 
 //lcd_gotoxy(0,1);
 //lcd_putsf("    [0-20V]    ");
 
while (1)   {  
     
      adc = read_adc(1);
      if (adc>830)
      { PORTD.6=1;
     lcd_gotoxy(0,1);
     lcd_putsf("Schimbati scala");
     delay_ms(500);
     lcd_clear();
      }
     else  
       PORTD.6=0;
      if(PINA.5==1){
            volts = (((adc *2.56)/1024)*10);
      }
       else  
              volts = (((adc *2.56)/1024));
     lcd_gotoxy(0,0);
     sprintf(lcd_buffer," Volts = %3.3fV ",volts);
     lcd_clear();
     lcd_puts(lcd_buffer);
     delay_ms(100);
       
     
}    

   }
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top