Hello!
I need to schedule four buttons with the following functions "back" , " OK" , " up " and " down " . I have this code here but found it difficult to compile in mplab and also program along with the messages that I want to appear on my LCD (16x2) . I was trying to use vectors to display the phrases in the LCD , but it's getting so big that I'm losing myself easily. So I decided to delete that part of the code and only left the "skeleton" of it.
I appreciate if you could help me on this, the question of the buttons and how to put a menu to appear on the LCD with this code . I'm kind stuck and what I found on the Internet did not help much .
I'm using a pic18f4550.
Back -> RB1
OK -> RB0
UP-> RB2
Down-> RB3
I need to schedule four buttons with the following functions "back" , " OK" , " up " and " down " . I have this code here but found it difficult to compile in mplab and also program along with the messages that I want to appear on my LCD (16x2) . I was trying to use vectors to display the phrases in the LCD , but it's getting so big that I'm losing myself easily. So I decided to delete that part of the code and only left the "skeleton" of it.
I appreciate if you could help me on this, the question of the buttons and how to put a menu to appear on the LCD with this code . I'm kind stuck and what I found on the Internet did not help much .
I'm using a pic18f4550.
Back -> RB1
OK -> RB0
UP-> RB2
Down-> RB3
Code:
#include <xc.h>
#include <stdio.h>
#include "lcd.h"
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 16000000
#endif
//filter keyboard
#define MAX_FILTER_CNT 250
unsigned char Key1Cnt = 0;
unsigned char Key2Cnt = 0;
unsigned char Key3Cnt = 0;
unsigned char Key4Cnt = 0;
unsigned char Key1 = 0;
unsigned char Key2 = 0;
unsigned char Key3 = 0;
unsigned char Key4 = 0;
if (Key1 != RB0)
{
Key1Cnt++;
if(Key1Cnt > MAX_FILTER_CNT )
{
Key1Cnt = 0;
Key1 = RB0;
}
}
else
{
Key1Cnt = 0;
}
if (Key2 != RB1)
{
Key2Cnt++;
if(Key2Cnt > MAX_FILTER_CNT )
{
Key2Cnt = 0;
Key2 = RB1;
}
}
else
{
Key2Cnt = 0;
}
if (Key3 != RB2)
{
Key3Cnt++;
if(Key3Cnt > MAX_FILTER_CNT )
{
Key3Cnt = 0;
Key3 = RB2;
}
}
else
{
Key3Cnt = 0;
}
if (Key4 != RB3)
{
Key4Cnt++;
if(Key4Cnt > MAX_FILTER_CNT )
{
Key4Cnt = 0;
Key4 = RB3;
}
}
else
{
Key4Cnt = 0;
}
void inicio(){
lcd_clear();
printf("Control system");
printf("greenhouse");
}
void insistema(){
lcd_clear();
printf("1 \n");
printf("2 \n");
}
void informacoes(){ //shows a list of options
var=1;
}
//options
void cult0(){
lcd_clear();
printf("op1");
}
void cult1(){
lcd_clear();
printf("op2");
}
void cult2(){
lcd_clear();
printf("op3 ");
}
void cult3(){
lcd_clear();
printf("op4");
}
void cult4(){
lcd_clear();
printf("op5");
}
void cult5(){
lcd_clear();
printf("op6");
}
void cult6(){
lcd_clear();
printf("op7");
}
void cult7(){
lcd_clear();
printf("op8");
}
void cult8(){
lcd_clear();
printf("op9");
}
void cult9(){
lcd_clear();
printf("op10");
}
void cult10(){
lcd_clear();
printf("op11");
}
void cult11(){
lcd_clear();
printf("op12");
}
//information about each option
//(It needs more than four lines for each information option)
void inf0(){
lcd_clear();
printf("inf1 ....");
}
void inf1(){
lcd_clear();
printf("inf2 .....");
}
void inf2(){
lcd_clear();
printf("inf3 .....");
}
void inf3(){
lcd_clear();
printf("inf4 ......");
}
void inf4(){
lcd_clear();
printf("inf5 ......");
}
void inf5(){
lcd_clear();
printf("inf6 ......");
}
void inf6(){
lcd_clear();
printf("inf7 ......");
}
void inf7(){
lcd_clear();
printf("inf8 .....");
}
void inf8(){
lcd_clear();
printf("inf9 .....");
}
void inf9(){
lcd_clear();
printf("inf10 ......");
}
void inf10(){
lcd_clear();
printf("inf11 .....");
}
void inf11(){
lcd_clear();
printf("inf12 ......");
}
int main(void){
TRISD=0x00;
TRISB=0x0F;
ADCON1=0XFF;
CMCON=0X07;
PORTD=0;
for(aux=0; aux<200;aux++) __delay_ms(10);
lcd_init();
printf("Control system");
printf("greenhouse");
while(1)
{
}
}