I am programming a PIC16F877a with 3 toggle switches and a 20 x 4 LCD. The 3 switches are soldered to pins B0 - B2 on the PIC. The other end of the switches is connected to +5v (PortsB have internal pull up resistors). I am programming using CCS and the problem I've met is that for some reason, ports B0 - B2 always read true and ignores the buttons. The problem might be a software issue so here's my program:
#include <16f877a.h>
#fuses XT,NOWDT,BROWNOUT,PUT,NOLVP
#use delay (crystal=4000000)
#include <Flex_LCD420.c>
#include <7segDisp.c>
#define btn_A PIN_B0
#define btn_B PIN_B1
#define btn_C PIN_B2
int i;
void main() {
output_low(LCD_RW);
lcd_init();
printf(lcd_putc, "\fPress Any Button");
while(1){
if(input(btn_A) == 0 || input(btn_B) == 1 || input(btn_C) == 1) {
break;
}
}
printf(lcd_putc, "\fChecking Btns..A");
while(1){
if(input(btn_A) == 1) {
break;
}
}
printf(lcd_putc, "\fChecking Btns..B");
while(1){
if(input(btn_B) == 1) {
break;
}
}
printf(lcd_putc, "\fChecking Btns..C");
while(1){
if(input(btn_C) == 1) {
break;
}
}
printf(lcd_putc, "\f\nEnd Check");
while(1);
}
I need help urgently as this is for a project that is due today.
Thanks in advance.
output_low();
and such, you should add a directive, something like fast i/o. \$\endgroup\$