Programming of MUC

Thread Starter

rabhishek91

Joined Feb 14, 2013
51
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.


Rich (BB code):
int main()
{
    DDRA = 0x00;        //configure portA as input
    while(1)                     // To run the program continuously
    {
    if(PORTA&=1<<PINA0)  //Check high on pin0 of portA
    {
        DDRB=0xff;        // Configure PORTB as output for data bus
        DDRD=0x07;        //Configure PORTD as output for control lines
        init_LCD();        // initialization of LCD
        _delay_ms(50);        // delay of 50 mili seconds
        LCD_write_string("ABC");
    }
    else
    {
        DDRB=0xff;         
        DDRD=0x07;          lines
        init_LCD();         
        _delay_ms(50);         
        LCD_write_string("Thank you");
    }
        
    }
         
    return 0;
}
 
Last edited by a moderator:

ErnieM

Joined Apr 24, 2011
8,377
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.

Rich (BB code):
int main()
{
    DDRA = 0x00; //configure portA as input
    DDRB=0xff; // Configure PORTB as output for data bus
    DDRD=0x07; //Configure PORTD as output for control lines
    init_LCD(); // initialization of LCD
    _delay_ms(50); // delay of 50 mili seconds
    while(1) // To run the program continuously
    {
        if(PORTA&=1<<PINA0) //Check high on pin0 of portA
        {
            LCD_Clear_Screen();         // <== I made this instruction up. Check your manual for the real instruction
            LCD_write_string("ABC");
        }
        else
        {
            LCD_Clear_Screen();         // <== I made this instruction up. Check your manual for the real instruction
            LCD_write_string("Thank you");
        }
    }
    return 0;
}
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.
 

Thread Starter

rabhishek91

Joined Feb 14, 2013
51
Three things:

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.
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 ?
 
Top