lcd interface

Thread Starter

sryzdn

Joined Jun 1, 2014
27
Hi,

In the enclosed circuit, I have tried to interface ATmega32 to the lcd to show the temperature with the below code, but the lcd does not show anything. Would you please let me know where I'm wrong?

Rich (BB code):
#include <mega32.h>
#include <stdio.h>
#include <delay.h>
#include <alcd.h>

unsigned char d[20];
float v;
unsigned int adc_data;
#define ADC_VREF_TYPE 0x40

interrupt [ADC_INT] void adc_isr(void)
{
adc_data=ADCW;
}

unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);

delay_us(10);
#asm
    in   r30,mcucr
    cbr  r30,__sm_mask
    sbr  r30,__se_bit | __sm_adc_noise_red
    out  mcucr,r30
    sleep
    cbr  r30,__se_bit
    out  mcucr,r30
#endasm
return adc_data;
}
void main(void)
{
Func0=In 
State0=T 
PORTA=0x00;
DDRA=0x00;
Func0=In 
State0=T 
PORTB=0x00;
DDRB=0x00;

 Func0=In 
State0=T 
PORTC=0x00;
DDRC=0x00;
Func0=In 
State0=T 
PORTD=0x00;
DDRD=0x00;
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
MCUCR=0x00;
MCUCSR=0x00;
TIMSK=0x00;
UCSRB=0x00;
ACSR=0x80;
SFIOR=0x00;
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x8F;
SPCR=0x00;
TWCR=0x00;
lcd_init(16);
#asm("sei")

while (1)
      {
      v=read_adc(0);
      v=(v*500.0/1023.0);
      sprintf(d, "temp=%2.2fC",v);
      lcd_gotoxy(0,0);
      lcd_puts(d);
      }
}
 

Attachments

Brownout

Joined Jan 10, 2012
2,390
Have you got "Hello World" on your LCD yet? Did you connect a variable resistor for contrast? Sorry, I didn't try to unzip your file. If you can post a pfd or something, I will take a look.
 

Brownout

Joined Jan 10, 2012
2,390
Make sure you're using the correct LCD libraries for 4-bit mode. Make sure your libraries use the same I/O's as you've connected per your schematic. Are you running a simulation, or is this real hardware? Get a simple message to display on your LCD before going on to ADC and such. Try to debug one thing at a time.
 
Top