Milenia
Newbie level 4
Hi guys.
I am beginner in microcontroller. Current I’m doing my assignment. My assignment has one push button and lcd by using pic16f877a. When my push button is press, I want the LCD is dispIay “AVAILABLE 2” and LED ‘1’. I have try my coding. But it seems not works correctly same as my expected. Its only display “AVAILABE 2” and LED ‘1’ without I press the push button. Same when I press the push button. It will display the same thing. How to make it correctly?Maybe there is some mistaken that I did.
I am beginner in microcontroller. Current I’m doing my assignment. My assignment has one push button and lcd by using pic16f877a. When my push button is press, I want the LCD is dispIay “AVAILABLE 2” and LED ‘1’. I have try my coding. But it seems not works correctly same as my expected. Its only display “AVAILABE 2” and LED ‘1’ without I press the push button. Same when I press the push button. It will display the same thing. How to make it correctly?Maybe there is some mistaken that I did.
Code:
Coding
[syntax=c]// LCD module connections
sbit LCD_RS at RC2_bit;
sbit LCD_EN at RC3_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISC2_bit;
sbit LCD_EN_Direction at TRISC3_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
// End LCD module connections
void main()
{
TRISA.F0 = 1; //PortA bit 1 input
TRISD.F0 = 0; //Port D pada bit 0,1,2 output
while (1)
{
if(PORTA.F0 == 0) //If the switch is pressed
{
Delay_ms(1000); //Switch Debounce
PORTD.F0 = 0; //LED port 0 ON
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"FULL ");
}
else
{
Delay_ms(1000); //Switch Debounce
PORTD.F0 = 1; //LED port 0 ON
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"AVAILABLE 2");
} // Write text'Hello World' in first row
}
}[/syntax]
Last edited by a moderator: