2
Hello.
I’m having trouble making a program in C language with buttons, lcd (16x2) and a PIC18F4550.
Below, I put the description of the program and the code I have so far, a keyboard filter and some basic pic settings.
I was trying to use multiple vectors to display the two initial options and then functions for each line, but it was getting too big and confusing. And besides, when I pressed other sequences of buttons the program understood as something else and went to another screen that was not what I wanted.
So I thought of this keyboard filter, but it remains to implement it with the lcd options and everything else.
Is it really necessary to use multiple vectors? I need to use a character vector or what?
Program description:
The program starts with a simple menu with two options:
- Option (a) and,
- option (b)
If I press the "OK" button, the option (a) will be selected and then will open a screen with a two-line phrase.
To select the option (b) it is necessary to use the button "go down" and then "OK". Then a menu with eleven options will be opened. Each option will occupy two LCD lines (the LCD is 16x2).
So, for example, to select option two (2) you need to press the "down" button and then "OK".
Each of these eleven options, when selected, will open information of about five lines (a text of five lines, more or less).
And when, for example, the user wants to return options in the menu of selections of the eleven options just press the button "back".
And if he needs to read the options or information that he has already passed with the "down" button, just press "up".
- (OK) - RB0;
- (Back) - RB1;
- (Up) - RB2;
- (Descend) - RB3.
Code:
#include <xc.h>
#include <stdio.h>
#include "lcd.h"
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 16000000
#endif
//filtro teclado
#define MAX_FILTER_CNT 250
unsigned char Tecla1Cnt = 0;
unsigned char Tecla2Cnt = 0;
unsigned char Tecla3Cnt = 0;
unsigned char Tecla4Cnt = 0;
unsigned char Tecla1 = 0;
unsigned char Tecla2 = 0;
unsigned char Tecla3 = 0;
unsigned char Tecla4 = 0;
if (Tecla1 != RB0)
{
Tecla1Cnt++;
if (Tecla1Cnt > MAX_FILTER_CNT)
{
Tecla1Cnt = 0;
Tecla1 = RB0;
}
}
else
{
Tecla1Cnt = 0;
}
if (Tecla2 != RB1)
{
Tecla2Cnt++;
if (Tecla2Cnt > MAX_FILTER_CNT )
{
Tecla2Cnt = 0;
Tecla2 = RB1;
}
}
else
{
Tecla2Cnt = 0;
}
if (Tecla3 != RB2)
{
Tecla3Cnt++;
if (Tecla3Cnt > MAX_FILTER_CNT )
{
Tecla3Cnt = 0;
Tecla3 = RB2;
}
}
else
{
Tecla3Cnt = 0;
}
if (Tecla4 != RB3)
{
Tecla4Cnt++;
if(Tecla4Cnt > MAX_FILTER_CNT )
{
Tecla4Cnt = 0;
Tecla4 = RB3;
}
}
else
{
Tecla4Cnt = 0;
}
int main(void){
TRISD = 0x00;
TRISB = 0x0F;
ADCON1 = 0XFF;
CMCON = 0X07;
T1CON = 0b11111001;
PORTD = 0;
for(aux = 0; aux < 100; aux++)
__delay_ms(10);
lcd_init();
while(1)
{
//manipulação dos botões e opções
}
Hard to answer because your question is confused and so is the code.
– Daniel Grillo