lcd interface

Discussion in 'General Electronics Chat' started by sryzdn, Aug 10, 2014.

  1. sryzdn

    Thread Starter New Member

    Jun 1, 2014
    23
    0
    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?

    Code ( (Unknown Language)):
    1. #include <mega32.h>
    2. #include <stdio.h>
    3. #include <delay.h>
    4. #include <alcd.h>
    5.  
    6. unsigned char d[20];
    7. float v;
    8. unsigned int adc_data;
    9. #define ADC_VREF_TYPE 0x40
    10.  
    11. interrupt [ADC_INT] void adc_isr(void)
    12. {
    13. adc_data=ADCW;
    14. }
    15.  
    16. unsigned int read_adc(unsigned char adc_input)
    17. {
    18. ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
    19.  
    20. delay_us(10);
    21. #asm
    22.     in   r30,mcucr
    23.     cbr  r30,__sm_mask
    24.     sbr  r30,__se_bit | __sm_adc_noise_red
    25.     out  mcucr,r30
    26.     sleep
    27.     cbr  r30,__se_bit
    28.     out  mcucr,r30
    29. #endasm
    30. return adc_data;
    31. }
    32. void main(void)
    33. {
    34. Func0=In
    35. State0=T
    36. PORTA=0x00;
    37. DDRA=0x00;
    38. Func0=In
    39. State0=T
    40. PORTB=0x00;
    41. DDRB=0x00;
    42.  
    43.  Func0=In
    44. State0=T
    45. PORTC=0x00;
    46. DDRC=0x00;
    47. Func0=In
    48. State0=T
    49. PORTD=0x00;
    50. DDRD=0x00;
    51. TCCR0=0x00;
    52. TCNT0=0x00;
    53. OCR0=0x00;
    54. TCCR1A=0x00;
    55. TCCR1B=0x00;
    56. TCNT1H=0x00;
    57. TCNT1L=0x00;
    58. ICR1H=0x00;
    59. ICR1L=0x00;
    60. OCR1AH=0x00;
    61. OCR1AL=0x00;
    62. OCR1BH=0x00;
    63. OCR1BL=0x00;
    64. ASSR=0x00;
    65. TCCR2=0x00;
    66. TCNT2=0x00;
    67. OCR2=0x00;
    68. MCUCR=0x00;
    69. MCUCSR=0x00;
    70. TIMSK=0x00;
    71. UCSRB=0x00;
    72. ACSR=0x80;
    73. SFIOR=0x00;
    74. ADMUX=ADC_VREF_TYPE & 0xff;
    75. ADCSRA=0x8F;
    76. SPCR=0x00;
    77. TWCR=0x00;
    78. lcd_init(16);
    79. #asm("sei")
    80.  
    81. while (1)
    82.       {
    83.       v=read_adc(0);
    84.       v=(v*500.0/1023.0);
    85.       sprintf(d, "temp=%2.2fC",v);
    86.       lcd_gotoxy(0,0);
    87.       lcd_puts(d);
    88.       }
    89. }
     
  2. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    Hi.

    It's better to attach your circuit as an image file. Instead of zipping it. Not everyone has your program installed.
     
  3. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,383
    495
  4. Brownout

    Well-Known Member

    Jan 10, 2012
    2,375
    998
    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.
     
  5. sryzdn

    Thread Starter New Member

    Jun 1, 2014
    23
    0
    Sincere apologies for attaching the wrong file in the first post.
     
  6. Brownout

    Well-Known Member

    Jan 10, 2012
    2,375
    998
    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.
     
Loading...