K.S.S
Newbie level 2
Hi All
I have been working on a project involving a handheld controller controlling a bank of resistors. The 877A in the controller is responsible for taking in the values according to the keys pressed and displaying these values on LCD screen. IT works fine initially but after incrementing or decrementing the values by few KWatt values the 877A freezes due to which the display freezes and the keys do not function.
Why does this happen???? Please povide a solution to this problem. I was wondering if the PIC is freezing due to debouncing. I tried making some changes in the kepad driver software but it still freezes. Please let me know where did I go wong in the coding. I am using the CCS compiler
kb_direct.c
In the main program, the function int16 get_key(void) is called to get the value of the key pressed.
It is also showing the error "A #device is required before this line"
I have been working on a project involving a handheld controller controlling a bank of resistors. The 877A in the controller is responsible for taking in the values according to the keys pressed and displaying these values on LCD screen. IT works fine initially but after incrementing or decrementing the values by few KWatt values the 877A freezes due to which the display freezes and the keys do not function.
Why does this happen???? Please povide a solution to this problem. I was wondering if the PIC is freezing due to debouncing. I tried making some changes in the kepad driver software but it still freezes. Please let me know where did I go wong in the coding. I am using the CCS compiler
kb_direct.c
Code:
//Button assignments
#define button_adjd PIN_A0
#define button_adju PIN_A1
#define button_accept PIN_A2
#define button_100s PIN_A3
#define button_10s PIN_A4
#define button_1s PIN_A5
#define button_qstop PIN_E0
#define button_sstop PIN_E1
#define button_revert PIN_E2
// prototypes
int16 get_key(void);
int16 get_keyX(void);
int16 keytemp=0;
int8 dbcounter=0;
int8 T_valid=0;
// implementations
void kb_init(void)
{
keytemp=0;
}
int16 get_key(void)
{
int16 a=0;
int8 T_valid=100;
int i=0;
if ((input(button_adjd)==1))
{
dbcounter=0;
for ( i=0;i<255;i++)
{
dbcounter= dbcounter+1;
}
if (dbcounter>T_valid)
{
a+=1;
}
}
if ((input(button_adju)==1))
{
dbcounter=0;
for ( i=0;i<255;i++)
{
dbcounter= dbcounter+1;
}
if (dbcounter>T_valid)
{
a+=2;
}
}
//if (input(button_adjd)==1) a+=1;
//if (input(button_adju)==1) a+=2;
if (input(button_accept)==1) a+=4;
if (input(button_100s)==1) a+=8;
if (input(button_10s)==1) a+=16;
if (input(button_1s)==1) a+=32;
if (input(button_qstop)==1) a+=64;
if (input(button_sstop)==1) a+=128;
if (input(button_revert)==1) a+=256;
// 1 = adjd
// 2 = adju
// 4 = accept
// 8 = 100s
// 16 = 10s
// 32 = 1s
// 64 = qstop
// 128 = sstop
// 256 = revert
if (keytemp==a)
{
return(0);
}
else
{
if (a>keytemp)
{
keytemp=a;
return(a);
}
if (a==0)
{
keytemp=0;
return(0);
}
}
}
int16 get_keyX(void)
{
int16 a=0;
if (input(button_adjd)==1) a=1;
if (input(button_adju)==1) a=2;
if (input(button_100s)==1) a=4;
if (input(button_10s)==1) a=5;
if (input(button_1s)==1) a=6;
if (input(button_accept)==1) a=3;
if (input(button_revert)==1) a=9;
if (input(button_sstop)==1) a=8;
if (input(button_qstop)==1) a=7;
// 1 = adjd
// 2 = adju
// 3 = accept
// 4 = 100s
// 5 = 10s
// 6 = 1s
// 7 = qstop
// 8 = sstop
// 9 = revert
if (keytemp==a)
{
return(0);
}
else
{
keytemp=a;
return(a);
}
}
In the main program, the function int16 get_key(void) is called to get the value of the key pressed.
It is also showing the error "A #device is required before this line"
Last edited by a moderator: