|
|
View previous topic :: View next topic |
Author |
Message |
iedchan
Joined: 01 Jun 2007 Posts: 2
|
keypad driver..coding from port d to port c |
Posted: Sat Jun 02, 2007 2:16 am |
|
|
anyone knows how to change this keypad driver..so that i could used port c instead of port d?
Code: |
//#byte port_d = 0x08
char get_key(void)
{
char t;
while (1) {
output_d (input_d() | 0xFF);
output_bit(PIN_D4,0);
if (input (PIN_D0) ==0);{
delay_ms(10);
return 'A';
}
if (input (PIN_D1) ==0){
delay_ms(10);
return '7';
}
if (input (PIN_D2) ==0){
delay_ms(10);
return '4';
}
if (input (PIN_D3) ==0){
delay_ms(10);
return '1';
}
output_d (input_d() | 0xFF);
output_bit(PIN_D5,0);
if (input (PIN_D0) ==0);{
delay_ms(10);
return '0';
}
if (input (PIN_D1) ==0){
delay_ms(10);
return '8';
}
if (input (PIN_D2) ==0){
delay_ms(10);
return '5';
}
if (input (PIN_D3) ==0){
delay_ms(10);
return '2';
}
output_d (input_d() | 0xFF);
output_bit(PIN_D6,0);
if (input (PIN_D0) ==0);{
delay_ms(10);
return 'B';
}
if (input (PIN_D1) ==0){
delay_ms(10);
return '9';
}
if (input (PIN_D2) ==0){
delay_ms(10);
return '6';
}
if (input (PIN_D3) ==0){
delay_ms(10);
return '3';
}
output_d (input_d() | 0xFF);
output_bit(PIN_D7,0);
if (input (PIN_D0) ==0);{
delay_ms(10);
return 'C';
}
if (input (PIN_D1) ==0){
delay_ms(10);
return 'D';
}
if (input (PIN_D2) ==0){
delay_ms(10);
return 'E';
}
if (input (PIN_D3) ==0){
delay_ms(10);
return 'F';
}
else return '<';
}
}
|
|
|
|
inservi
Joined: 13 May 2007 Posts: 128
|
|
Posted: Sat Jun 02, 2007 6:44 am |
|
|
Hello,
You can try this code !
Code: | #byte port_c = 0xF83 // depending on the microcontroleur 0xF83 is for a 18F452
#define keyboard port_c
#define keyboard_line0 PIN_C0
#define keyboard_line1 PIN_C1
#define keyboard_line2 PIN_C2
#define keyboard_line3 PIN_C3
#define keyboard_row0 PIN_C4
#define keyboard_row1 PIN_C5
#define keyboard_row2 PIN_C6
#define keyboard_row3 PIN_C7
#define setPort output_c (keyboard | 0xFF);
char get_key(void){
while (true) {
setPort
output_bit(keyboard_row0,0);
if (input (keyboard_line0) ==0);{
delay_ms(10);
return 'A';
}
if (input (keyboard_line1) ==0){
delay_ms(10);
return '7';
}
if (input (keyboard_line2) ==0){
delay_ms(10);
return '4';
}
if (input (keyboard_line3) ==0){
delay_ms(10);
return '1';
}
setPort
output_bit(keyboard_row1,0);
if (input (keyboard_line0) ==0);{
delay_ms(10);
return '0';
}
if (input (keyboard_line1) ==0){
delay_ms(10);
return '8';
}
if (input (keyboard_line2) ==0){
delay_ms(10);
return '5';
}
if (input (keyboard_line3) ==0){
delay_ms(10);
return '2';
}
setPort
output_bit(keyboard_row2,0);
if (input (keyboard_line0) ==0);{
delay_ms(10);
return 'B';
}
if (input (keyboard_line1) ==0){
delay_ms(10);
return '9';
}
if (input (keyboard_line2) ==0){
delay_ms(10);
return '6';
}
if (input (keyboard_line3) ==0){
delay_ms(10);
return '3';
}
setPort
output_bit(keyboard_row3,0);
if (input (keyboard_line0) ==0);{
delay_ms(10);
return 'C';
}
if (input (keyboard_line1) ==0){
delay_ms(10);
return 'D';
}
if (input (keyboard_line2) ==0){
delay_ms(10);
return 'E';
}
if (input (keyboard_line3) ==0){
delay_ms(10);
return 'F';
}
else return '<';
}
}
|
I'm not try it but it is compiled without error.
Normaly, you need to change the #byte and the #define for use an other port.
dro _________________ in médio virtus |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|