Programming of MUC

Discussion in 'Embedded Systems and Microcontrollers' started by rabhishek91, Apr 4, 2013.

  1. rabhishek91

    Thread Starter Member

    Feb 14, 2013
    51
    1
    Hi everyone. :)
    I am working on a code where i need to display messages on LCD depending on the input to MUC(Atmega32A).

    Below is the program where i need to display messages based on PortA input.

    First. i'll read the pin0 of PORTA (continously). Depending on the value of that pin i'll control LCD messages. I know i have made lot of mistakes in programming. This is my first program so i am unaware of what to use.:confused:
    Is this programming method correct ? or do i need to use some other method ?
    Please help me.


    Code ( (Unknown Language)):
    1.  
    2. int main()
    3. {
    4.     DDRA = 0x00;        [COLOR=YellowGreen]//configure portA as input[/COLOR]
    5.     while(1)                     /[COLOR=YellowGreen]/ To run the program continuously[/COLOR]
    6.     {
    7.     if(PORTA&=1<<PINA0)  /[COLOR=YellowGreen]/Check high on pin0 of portA[/COLOR]
    8.     {
    9.         DDRB=0xff;        [COLOR=YellowGreen]// Configure PORTB as output for data bus[/COLOR]
    10.         DDRD=0x07;        [COLOR=YellowGreen]//Configure PORTD as output for control lines[/COLOR]
    11.         init_LCD();        /[COLOR=YellowGreen]/ initialization of LCD[/COLOR]
    12.         _delay_ms(50);        [COLOR=YellowGreen]// delay of 50 mili seconds[/COLOR]
    13.         LCD_write_string("ABC");
    14.     }
    15.     else
    16.     {
    17.         DDRB=0xff;        
    18.         DDRD=0x07;          lines
    19.         init_LCD();        
    20.         _delay_ms(50);        
    21.         LCD_write_string("Thank you");
    22.     }
    23.        
    24.     }
    25.          
    26.     return 0;
    27. }
    28.  
     
    Last edited by a moderator: Apr 4, 2013
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    Three things:

    1 - USE CODE TAGS

    2 - Don't init DDRB, DDRD, and the LCD each time you run the loop. Do it once before you loop.

    3 - You need to clear the display before you write the new text so the new text goes in the same spot on the display.

    Code ( (Unknown Language)):
    1.  
    2. int main()
    3. {
    4.     DDRA = 0x00; //configure portA as input
    5.     DDRB=0xff; // Configure PORTB as output for data bus
    6.     DDRD=0x07; //Configure PORTD as output for control lines
    7.     init_LCD(); // initialization of LCD
    8.     _delay_ms(50); // delay of 50 mili seconds
    9.     while(1) // To run the program continuously
    10.     {
    11.         if(PORTA&=1<<PINA0) //Check high on pin0 of portA
    12.         {
    13.             LCD_Clear_Screen();         // <== I made this instruction up. Check your manual for the real instruction
    14.             LCD_write_string("ABC");
    15.         }
    16.         else
    17.         {
    18.             LCD_Clear_Screen();         // <== I made this instruction up. Check your manual for the real instruction
    19.             LCD_write_string("Thank you");
    20.         }
    21.     }
    22.     return 0;
    23. }
    Now there is one more problem for you to solve: the LCD will be weird with poor contrast. This is because the text is constantly being cleared and written over and over.

    You need to make a state variable to track which button was pressed and which message is on the display. If the button doesn't match the variable the variable is changed, and the display updated.

    A single bit is all the state information you need to do this.
     
    rabhishek91 likes this.
  3. rabhishek91

    Thread Starter Member

    Feb 14, 2013
    51
    1
    Thanks for your reply sir. I made all the changes but could not change the state variable part.
    "You need to make a state variable to track which button was pressed and which message is on the display. If the button doesn't match the variable the variable is changed, and the display updated."- Would you please elaborate this part ?
     
Loading...