bas_90
Member level 1
- Joined
- Mar 21, 2013
- Messages
- 35
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,503
thnx Peter, but i compiled this code and don't make i want
or i don't understand it..
i need a simple code to change the words on LCD by push button
// Lcd module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_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;
void main()
{
Lcd_Init(); //LCD display initialization
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Cmd(_LCD_CURSOR_OFF); //Turn cursor Off for LCD
ANSELC.B0 = 0; //Configure RC0 pin as digital
ANSELC.B1 = 0; //Configure RC1 pin as digital
TRISC.B0 = 1; //Set RC0 pin as input
TRISC.B1 = 1; //Set RC1 pin as input
while (1)
{
if (PORTC.B0 = 1)
{
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1,1,"Main options");
Lcd_Out(2,1,"First, Second");
}
if (PORTC.B1 = 1)
{
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1,1,"Settings menu");
}
}
}
while (1)
{
if (PORTC.B0 = 1)
{
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1,1,"Main options");
Lcd_Out(2,1,"First, Second");
}
if (PORTC.B1 = 1)
{
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1,1,"Settings menu");
}
}
// Lcd module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_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;
char broj;
void main()
{
Lcd_Init(); //LCD display initialization
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Cmd(_LCD_CURSOR_OFF); //Turn cursor Off for LCD
ANSELC.B0 = 0; //Configure RC0 pin as digital
ANSELC.B1 = 0; //Configure RC1 pin as digital
TRISC.B0 = 1; //Set RC0 pin as input
TRISC.B1 = 1; //Set RC1 pin as input
broj = 0;
while (1)
{
if (PORTC.B0 = 1) broj++;
if (PORTC.B1 = 1) broj--;
Delay_ms(300); //Adjust this value if needed
switch(broj)
{
case 0:
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1,1,"Menu 1");
break;
case 1:
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1,1,"Menu 2");
break;
case 2:
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1,1,"Menu 3");
break;
case 3:
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1,1,"Menu 4");
break;
}
}
}
Hi bus_90,
Here is 2min example :
RC0 is for menu Up.
RC1 is for menu Down.
There is 4 menus in this example.
I try this on PIC18F45K22 at 32MHz and all is ok.
If you have slower clock adjust value in this row :
Delay_ms(300); //Adjust this value if needed
Code:// Lcd module connections sbit LCD_RS at LATB4_bit; sbit LCD_EN at LATB5_bit; sbit LCD_D4 at LATB0_bit; sbit LCD_D5 at LATB1_bit; sbit LCD_D6 at LATB2_bit; sbit LCD_D7 at LATB3_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; char broj; void main() { Lcd_Init(); //LCD display initialization Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen Lcd_Cmd(_LCD_CURSOR_OFF); //Turn cursor Off for LCD ANSELC.B0 = 0; //Configure RC0 pin as digital ANSELC.B1 = 0; //Configure RC1 pin as digital TRISC.B0 = 1; //Set RC0 pin as input TRISC.B1 = 1; //Set RC1 pin as input broj = 0; while (1) { if (PORTC.B0 = 1) broj++; if (PORTC.B1 = 1) broj--; Delay_ms(300); //Adjust this value if needed switch(broj) { case 0: Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen Lcd_Out(1,1,"Menu 1"); break; case 1: Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen Lcd_Out(1,1,"Menu 2"); break; case 2: Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen Lcd_Out(1,1,"Menu 3"); break; case 3: Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen Lcd_Out(1,1,"Menu 4"); break; } } }
I go to eat now.
Best regards,
Peter
Okay , Have a nice TIME
i will try it now
i working Ok but don't do what i want
because it working sequential command .. and i want to make for example 4 buttons
1 button go to Home (Main Menu)
1 button go to back (Cancel)
1 button go to "Choose 1"
1 button go to "Choose 2"
thnx about yr TIME ..
Its not problem, but we need additional two buttons.
I will write one example for that.
// Lcd module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_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;
int select, select_op, selection, submenu;
void main()
{
Lcd_Init(); //LCD display initialization
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Cmd(_LCD_CURSOR_OFF); //Turn cursor Off for LCD
ANSELC = 0; //Configure PortC pins as digital
TRISC.B0 = 1; //Set RC0 pin as input - Selection
TRISC.B1 = 1; //Set RC1 pin as input - Choose selection
TRISC.B2 = 1; //Set RC2 pin as input - Back to Main menu
select = 1;
selection = 1;
submenu = 0;
select_op = 1;
//Display main menu
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1, 2,"Menu1");
Lcd_Out(2, 2,"Menu2");
Lcd_Out(1,10,"Menu3");
Lcd_Out(2,10,"Menu4");
while (1)
{
if ((PORTC.B0 = 1) && (submenu == 0)) //When press RC0 '>' selecting display options
{
switch(selection)
{
case 1:
Lcd_Chr(1,1,'>');
selection = 2;
select = 1;
Lcd_Chr(2,9,' ');
break;
case 2:
Lcd_Chr(2,1,'>');
selection = 3;
select = 2;
Lcd_Chr(1,1,' ');
break;
case 3:
Lcd_Chr(1,9,'>');
selection = 4;
select = 3;
Lcd_Chr(2,1,' ');
break;
case 4:
Lcd_Chr(2,9,'>');
selection = 1;
select = 4;
Lcd_Chr(1,9,' ');
break;
}
}
if (PORTC.B1 = 1) //When press RC1 - choose selected option/menu
{
switch(select)
{
case 1:
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1, 1,"Menu 1");
Lcd_Out(1,10,"Option1");
Lcd_Out(2,10,"Option2");
submenu = 1;
break;
case 2:
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1, 1,"Menu 2");
Lcd_Out(1,10,"Option1");
Lcd_Out(2,10,"Option2");
submenu = 1;
break;
case 3:
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1, 1,"Menu 3");
Lcd_Out(1,10,"Option1");
Lcd_Out(2,10,"Option2");
submenu = 1;
break;
case 4:
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1, 1,"Menu 4");
Lcd_Out(1,10,"Option1");
Lcd_Out(2,10,"Option2");
submenu = 1;
break;
}
}
if ((PORTC.B0 = 1) && (submenu == 1))
{
switch(select_op)
{
case 1:
Lcd_Chr(1,9,'>');
select_op = 2;
Lcd_Chr(2,9,' ');
break;
case 2:
Lcd_Chr(2,9,'>');
select_op = 1;
Lcd_Chr(1,9,' ');
break;
}
}
//RETURN TO MAIN MENU IF RC2 is PRESSED
if (PORTC.B2 = 1)
{
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1, 2,"Menu1");
Lcd_Out(2, 2,"Menu2");
Lcd_Out(1,10,"Menu3");
Lcd_Out(2,10,"Menu4");
submenu = 0;
}
Delay_ms(300);
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?