fantabulous68
Member
I recently got a pikit 2, its the 1st time that im using push button switches.
im using 4 pushbuttons. when i power the circuit The LCD displays "infrared liquid level detector" permanently, so the lcd code and initialising is working.
All i want for now is:
when i press ENTER/Settings button....i want "enter/settings" to display on the LCD. And that is not happening when i press the button. Please help me solve this problem....i attached a picture of how i connect the switch to the pic.
im using 4 pushbuttons. when i power the circuit The LCD displays "infrared liquid level detector" permanently, so the lcd code and initialising is working.
All i want for now is:
when i press ENTER/Settings button....i want "enter/settings" to display on the LCD. And that is not happening when i press the button. Please help me solve this problem....i attached a picture of how i connect the switch to the pic.
Code:
#include <pic.h>
#include "pic.h"
#include "delay.h"
#include "math.h"
#include <stdio.h>
#include <stdlib.h>
char input_sw;
#define HOME_SW RC2 //HOME switch
#define INCREASE_SW RC3 //INCREASE switch
#define DECREASE_SW RC4 //DECREASE switch
#define ENTERSETTINGS_SW RA4 //ENTERSETTINGS switch
void init(void)
{
OSCCON|=0x60; //set fosc to 4Mhz
TRISB=0x00;
TRISC=0xFC;
TRISA = 0b10000010; // RA7 high imp, RA3 is serial out,
ANSEL=0x02; //set RA1 as analog input for GP2 sensor
ANSELH=0x00;
lcd_init(); //call LCD initialisation
}
void read_input_sw(void)
{
char input_sw2;
input_sw = ((HOME_SW*8)+(INCREASE_SW*4)+(DECREASE_SW*2)+(ENTERSETTINGS_SW*1)); //create a binary combination of the input switches
if (input_sw != 0) //check if any of the switches are pressed
{
DelayMs(20); //switch debouncing
input_sw2 = ((HOME_SW*8)+(INCREASE_SW*4)+(DECREASE_SW*2)+(ENTERSETTINGS_SW*1));
while (input_sw2 != 0) //if a switch is pressed wait for release
{
input_sw2 = ((HOME_SW*8)+(INCREASE_SW*4)+(DECREASE_SW*2)+(ENTERSETTINGS_SW*1));
DelayMs(20); //switch debouncing
}
}
}
[COLOR="Red"]void home_screen(void)[/COLOR]
{
lcd_clear();
lcd_goto_L1();
[COLOR="Red"]lcd_puts("INFRARED LIQUID"); //home screen message (line 1)[/COLOR]
lcd_goto_L2();
[COLOR="Red"] lcd_puts("LEVEL DETECTOR"); //home screen message (line 2)[/COLOR]
read_input_sw();
while(input_sw == 0)
read_input_sw();
switch(input_sw)
{
case 8: break;
// ENTER/SETTINGS button pressed
case 1: { lcd_clear();
lcd_goto_L1();
[COLOR="Red"] lcd_puts(" ENTER/SETTINGS ");[/COLOR]
DelayS(1);
lcd_clear();
break;
}
default : break; //should any abnormalties occur
}
return;
}
void main(void)
{
init(); // initialise I/O ports, LCD
while (1)
{
home_screen();
}
}
Attachments
Last edited: