update on this thread: we are able to transmit data between MCU(pic16f877a) and Desktop Computer via D9 cable
toolsuite compiler: Hi-tech C compiler
program compiler/debuuger : MPLAB IDE
problems: how can i get the LED to lit when there's an element inside an array?
scenario on KEYPRESS:
upon pressing 1st KEY 1st led will light ON, pressing 2nd KEY 2nd led will light On......
scenario on INPUT CLEARING:
clearing DATA as a whole for example.. the keypad was pressed twice which was not done by the user, it must be clear before entering his 6 digit key using "asterisk key". and "#" serve as ENTER
im using a 3x4 keypad
1 2 3
4 5 6
7 8 9
* 0 #
can anyone help? my current code is this:
#include <pic.h>
//configuration fuses
__CONFIG(HS & WDTDIS & PWRTDIS & UNPROTECT);
unsigned char scanned_key = 0x00;
unsigned char decoded_key = 0x00;
void init_LED(void)
{
PORTB &= ~0x0F;
TRISB &= ~0x0F;
}
void init_KEYPAD(void)
{
TRISD |= 0x70; //PORTD<6:4> input, COLUMNS
TRISD &= ~0x0F; //PORTD<3:0> output, ROWS
PORTD |= 0x0F; //PORTD<3:0> initially high
}
unsigned char decode_key(unsigned char val)
{
unsigned char key;
switch(val)
{
case 0x60: //1
//key = 0x01;
break;
case 0x50: //2
//key = 0x02;
break;
case 0x30: //3
//key = 0x03;
break;
case 0x61: //4
//key = 0x04;
break;
case 0x51: //5
//key = 0x05;
break;
case 0x31: //6
//key = 0x06;
break;
case 0x62: //7
//key = 0x07;
break;
case 0x52: //8
//key = 0x08;
break;
case 0x32: //9
//key = 0x09;
break;
case 0x63: //*
//key = 0x00;
break;
case 0x53: //0
//key = 0x0B;
break;
case 0x33: //#
//key = 0x0C;
break;
default:
//key = decoded_key;
break;
}
return key;
}
void display_key(unsigned char key)
{
PORTB = key;
}
unsigned char scan_keypad()
{
unsigned char val_1 = 0x00;
unsigned char val_2 = 0x00;
unsigned char count1;
for(count1=0;count1 < 4;count1++)
{
PORTD = ~(0x01 << count1); //scan row
val_1 = PORTD & 0x70; //read column, RD<6:4>
//while clearing RD<7> &
//RD<3:0>
if (val_1 != 0x70) //if a column is pressed
{
val_2 = (val_1 | count1); //column (high-nibble) and count (low-nibble)
return val_2; //return value
}
}
return 0xFF; //return any value
}
void main()
{
init_LED(); //initialize PORTB<3:0>, 4 LEDS connected
init_KEYPAD(); //initialize PORTD;
//PORTD<3:0> as output
//PORTD<6:4> as input
while(1)
{
scanned_key = scan_keypad();
decoded_key = decode_key(scanned_key);
display_key(decoded_key);
}
}
///
/*
1 0x60
2 0x50
3 0x30
4 0x61
5 0x51
6 0x31
7 0x62
8 0x52
9 0x32
asterisk 0x63
0 0x53
hash 0x33
*/
for now all it do was everytime i press the key. its corresponding hex value will lit the LED. and another problem... i cant seems to get the HEX value of 8. the 4th led doesnt light ON. and goes to other combination
thank you...