A problem in running character LCD via ATMEGA32A

Discussion in 'Homework Help' started by eric_s88, Nov 13, 2011.

  1. eric_s88

    Thread Starter Member

    Apr 20, 2011
    157
    1
    Hi everyone!
    I just wanted to show 2 statement (with a delay time between them) in a 2X16 character LCD via ATMEGA32A .. I use C language and Codvision compiler..
    but when I run the circuit all of sections in line one in LCD get lighted (as shown in pic)
    In order to test if the chip get programmed properly or not I used an LED in bit 0 at port A :) and I see LED works.. but LCD does not :(
    where is the problem :( ??

    [​IMG]

    and my codes:

    Code ( (Unknown Language)):
    1.  
    2. /*****************************************************
    3. This program was produced by the
    4. CodeWizardAVR V2.05.0 Advanced
    5. Automatic Program Generator
    6. © Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.
    7. http://www.hpinfotech.com
    8.  
    9. Project :
    10. Version :
    11. Date    : 2011/10/14
    12. Author  : www.Eca.ir *** www.Webkade.ir
    13. Company :
    14. Comments:
    15.  
    16.  
    17. Chip type               : ATmega32A
    18. Program type            : Application
    19. AVR Core Clock frequency: 4.000000 MHz
    20. Memory model            : Small
    21. External RAM size       : 0
    22. Data Stack size         : 512
    23. *****************************************************/
    24.  
    25. #include <mega32a.h>
    26. #include <delay.h>
    27.  
    28. // Alphanumeric LCD Module functions
    29. #include <alcd.h>
    30.  
    31. // Declare your global variables here
    32.  
    33. void main(void)
    34. {
    35. int i;
    36.     for(i=0;i<=9;i++)
    37.     {
    38.     PORTA.0=1;
    39.     delay_ms(350);
    40.     PORTA.0=0;
    41.     delay_ms(350);
    42.     }
    43. // Declare your local variables here
    44.  
    45. // Input/Output Ports initialization
    46. // Port A initialization
    47. // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
    48. // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
    49. PORTA=0x00;
    50. DDRA=0x00;
    51.  
    52. // Port B initialization
    53. // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
    54. // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
    55. PORTB=0x00;
    56. DDRB=0x00;
    57.  
    58. // Port C initialization
    59. // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
    60. // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
    61. PORTC=0x00;
    62. DDRC=0x00;
    63.  
    64. // Port D initialization
    65. // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
    66. // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
    67. PORTD=0x00;
    68. DDRD=0x00;
    69.  
    70. // Alphanumeric LCD initialization
    71. // Connections specified in the
    72. // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
    73. // RS - PORTC Bit 0
    74. // RD - PORTC Bit 1
    75. // EN - PORTC Bit 2
    76. // D4 - PORTC Bit 4
    77. // D5 - PORTC Bit 5
    78. // D6 - PORTC Bit 6
    79. // D7 - PORTC Bit 7
    80. // Characters/line: 16
    81. lcd_init(16);
    82.  
    83. while (1)
    84.       {
    85.       lcd_clear();
    86.       lcd_gotoxy(0,0);
    87.       lcd_putsf("state1");
    88.       delay_ms(1000);
    89.       lcd_putsf(" state2");
    90.       delay_ms(1000);
    91.  
    92.       }
    93. }
    94.  
    95.  
    96.  
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,418
    3,355
    A lot has to do with lcd_init( ).
    I have not used that particular library.
    How does the library know which ports are connected to the LCD interface?
    How does it know you are using PORTC?
    Shouldn't PORTC be output? DDRC = 0xFF
     
  3. eric_s88

    Thread Starter Member

    Apr 20, 2011
    157
    1
    I use Codevision , wich has a software , CodeWizard. in this software we can do a lots of micro settings..see the photo
    [​IMG]


    do you think if I make that change > DDRC=0xFF.. the problem will be solved?
     
  4. MrChips

    Moderator

    Oct 2, 2009
    12,418
    3,355
    No. I believe the library will init DDRC for you.
    Try testing if it can find the LCD.

    Code ( (Unknown Language)):
    1.  
    2. // LCD module initialization
    3. if (lcd_init(LCD_CHARS_LINE)!=0)
    4.    {
    5.    // The LCD is present
    6.    }
    7. else
    8.    {
    9.    // The LCD is not present
    10.    };
    11.  
    12.  
    Can you post a schematic of your circuit?
    and what is the model number of your LCD?
     
    Last edited: Nov 13, 2011
  5. eric_s88

    Thread Starter Member

    Apr 20, 2011
    157
    1
    I have tested this code in Proteus simulator, and there, everything was OK..
    but in practical test, I cant get the statement in LCD :(
     
  6. MrChips

    Moderator

    Oct 2, 2009
    12,418
    3,355
    Forget the simulator. This is the real world!
     
    eric_s88 likes this.
  7. eric_s88

    Thread Starter Member

    Apr 20, 2011
    157
    1
    [​IMG]
    this is my schematic... is it OK?
     
  8. bertus

    Administrator

    Apr 5, 2008
    15,645
    2,344
    Hello,

    Are you really using 2 X 22 nF at the crystal?
    I think they should be 22 pF.

    Bertus
     
    eric_s88 likes this.
  9. eric_s88

    Thread Starter Member

    Apr 20, 2011
    157
    1
    yes it was a mistake sry I am usuing 22pF caps, I now find the probolem.. :D It was sth wrong with fusebits programming:D now I have the statements on LCD , thank you
     
  10. MrChips

    Moderator

    Oct 2, 2009
    12,418
    3,355
    Now the next step is to double check the wiring on your breadboard.
    Can you write code to make an LED flash? Have you done this and verified that it works?
    You will need this to trouble shoot the circuit, unless you have an online debugger.
    I do not see your ISP connections.

    edit: Congrats! Now that you have it working, tell us what you had before and what changes you made to get it working. This forum works both ways. We help you, you help us.
     
  11. eric_s88

    Thread Starter Member

    Apr 20, 2011
    157
    1
    thank you :)
    yeaaah... in codvision software in section of programming FuseBits , fusebit called JTAGEN=0 was set as a default, that was wrong, I set SUT0=0 and CKOPT=0 fusebits on.. they are the fusebits that program my external oscillator ... that was all the problem :)
     
  12. eric_s88

    Thread Starter Member

    Apr 20, 2011
    157
    1
    the photo

    [​IMG]
     
Loading...