Hello.
I'm having trouble making a C language program with buttons, lcd (16x2) and a PIC18F4550.
Below, I've put the program description 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 I still have to implement it with the lcd options and everything else.
Do I really need to use multiple vectors? Do I need to use a character vector or what?
Description of the program:
The program starts with a simple menu with two options:
- Option (a) and,
- option (b)
If I press the "OK" button, option (a) will be selected and then it will open a screen with a two line sentence.
To select option (b) you must use the "down" button and then "OK". Then a menu with eleven options will open. Each option will occupy two LCD lines (LCD is 16x2).
Then, for example, to select option two (2) it is necessary to press the button "down" and then "OK".
Each of these eleven options, when selected, will open information of about five lines (a five line text, more or less).
And when, for example, the user wants to return options in the menu of the eleven options, just press the "back" button.
And if he needs to read the options or information he has already passed with the "down" button, just press "upload".
- (OK) - RB0;
- (Back) - RB1;
- (Up) - RB2;
- (Down) - 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
}