Mimuwhen
Junior Member level 3
- Joined
- Oct 7, 2014
- Messages
- 29
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 284
Hi,
I'm trying to use an if else statement in microC to toggle an LCD screen between two states.
Unfortunately I cannot get this to work,
The code under the if statement cycles between 3 different messages and when the button tied to RB7 makes RB7 go low, it's supposed to make the screen display the string "Screen Toggled".
What is happening instead is that the 3 different messages keep cycling as if the button isn't being pushed and the code never goes into the else part of the code.
Attached is the mikroC project as well as the proteous project.
I'd appreciate any help, thank you.View attachment LCDtoggle.rar
This is what the code looks like,
I'm trying to use an if else statement in microC to toggle an LCD screen between two states.
Unfortunately I cannot get this to work,
The code under the if statement cycles between 3 different messages and when the button tied to RB7 makes RB7 go low, it's supposed to make the screen display the string "Screen Toggled".
What is happening instead is that the 3 different messages keep cycling as if the button isn't being pushed and the code never goes into the else part of the code.
Attached is the mikroC project as well as the proteous project.
I'd appreciate any help, thank you.View attachment LCDtoggle.rar
This is what the code looks like,
Code:
// Lcd module connections
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;
// End Lcd module connections
void main(){
TRISA = 0xFF;
PORTA = 0x00;
TRISB = 0b10000000;
PORTB = 0b00000000;
TRISD = 0X00;
PORTD = 0X00;
Lcd_Init(); // Initialize Lcd
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
if(PORTB.F7=1) // If button is not pushed
{
while(1){ // Repeat sequence
Lcd_Out(1,6,"Message 1");
Delay_ms(500);
Lcd_Out(1,6,"Message 2");
Delay_ms(500);
Lcd_Out(1,6,"Message 3");
Delay_ms(500);
}
}
else{ // If button is pressed
Delay_ms(100); // Debounce
if(PORTB.F7=0){ // If button is still pressed
Lcd_Out(1,2,"Screen Toggled");
}
}
}