I have a problem with the "button" mikroC.
When I press my button I 5V when I break, I'm 20 mV. So I have my levels correct.
When I press my button, the text of the LCD has to change. Mons LCD working properly!
Now when I push on the button, my text does not change!
Here is my code.
Code: Select all
void button_menu(void)
{
char oldstate_menu = 0;
if (Button(&PORTD, 0, 1, 1)) // Detect logical one
oldstate_menu = 1; // Update flag
if (oldstate_menu == 1 && Button(&PORTD, 0, 1, 0)) )
{ // Detect one-to-zero transition
menu_principal += 1;
if (menu_principal == nb_total_menu)
menu_principal = 1;
oldstate_menu = 0; // Update flag
}
}
Code: Select all
#include "button.c"
// 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
char txt1[] = "OPEN - FIRE";
char txt2[] = "MSTK CORPORATION";
char txt3[] = "MODE ON";
char txt4[] = "MODE OFF";
char txt5[] = "MODE TIMING";
char txt6[] = "Allume";
char txt7[] = "Eteind";
char txt8[] = "Temporise";
char txt9[] = "Arret";
char txt10[]= "Tourne";
char txt11[]= "OK pour demarrer";
char txt12[]= "OK pour arreter";
char menu_principal = 1;
char nb_total_menu = 4;
void main()
{
ANSELA = 0; // Configure AN pins as digital I/O
ANSELB = 0;
ANSELD = 0;
TRISD0_bit = 1; // set RD0 pin as input
Lcd_Init(); // Initialize LCD
Sound_Init(&PORTE, 2); // Initialize Sound
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,4,txt1); // Write text in first row
Lcd_Out(2,1,txt2); // Write text in second row
Delay_ms(3000);
button_menu();
switch(menu_principal)
{
case 1 : // mode OFF
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,4,txt4); // MODE OFF
Lcd_Out(2,4,txt12); // OK pour arreter
break;
case 2 :
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,4,txt5); // MODE OFF
Lcd_Out(2,4,txt12); // OK pour arreter
break;
case 3 :
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,4,txt6); // MODE OFF
Lcd_Out(2,4,txt12); // OK pour arreter
break;
}
} // fin du programme
Thank you