Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

Project Request

Return
iverson nair
iverson

posted on 2013/05/14 09:57:56 AM CEST

Graphics & LCD

displaying different messages on 16x2 lcd with pic16f628a

hi
im trying to display different messages when push button is depressed. the program buids in mikro c but when connected
the message to be displayed when switch is depressed comes up even if the swith is off can any one helpsource code is below

//HEADER*******************************************************************************

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections



// Define Messages
char text1[] = "test 1";
char text2[] = "lcd on";
char text3[] = "test 2";
char text4[] = "good";
char text5[] = "test 3 ";
char text6[] = "fine";
char text7[] = "test5";
char text8[] = "good";
char text9[] = "test 7";
char text10[] = "good";
char text11[] = "test 8";
char text12[] = "good";
char text13[] = "test9";




void main() {
CMCON |= 7; // Disable Comparators
TRISB = 0;
PORTB = 0;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
PORTA = 255;
TRISA = 255;




Lcd_Init(); // Initialize LCD
do {
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,text1); // Write message1 in 1st row
Lcd_Out(2,1,text2); // Write message1 in 2nd row
Delay_ms(1000); // delay 3s
Lcd_Cmd(_LCD_CLEAR); // Clear display
Delay_ms(1000); // delay 1s
Lcd_Out(1,1,text1); // Write message3 in 1st row
Lcd_Out(2,1,text4);
Delay_ms(8000); // delay 15S
} while(0);

if(Button(&PORTA,3,1,1))

Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,text5); // Write message1 in 1st row
Lcd_Out(2,1,text6); // Write message1 in 2nd row
Delay_ms(3000); // WAIT 3 SEC
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,text1); // Write message1 in 1st row
Lcd_Out(2,1,text7); // Write message1 in 2nd row
Delay_ms(15000);

while(1);

}