Dspic Dev
Dspic Dev
Dspic Dev
If the data read is all 1s, no key in that row is activated and the
process is moved to the next row. It grounds the next row, reads the
columns, and checks for any zero. This process continues until the row
is identified. After identification of the row in which the key has been
pressed, the next task is to find out which column the pressed key
belongs to.
Fig. 1 Interfacing keypad to Microcontroller
Interfacing keypad with dsPIC30F4011
We now want to scan a keypad in DsPIC30F4011 Development
Board. In case of 4X4 matrix Keypad both the ends of switches are
connected to the port pin i.e. four rows and four columns. So in all
sixteen switches have been interfaced using just eight lines.
Source Code
The Interfacing keypad with dsPIC30F4011 program is very simple
and straight forward, that scan a keypad rows and columns. When
the rows and columns are detected then it will display in PC
through UART1. The C program is developed in Mplab software &
compiled with Microchip C30 C Compiler.
C Program to 4 X 4 matrix keypad using dsPIC
*******************************************************************************
********
*******************************************************************************
********
#include
#include "p30f4011.h"
#include "delay.c"
_FWDT(WDT_OFF);
_FGS(CODE_PROT_OFF);
Delay_ms10M(50);
TRISB = 0x0000;
ADPCFG = 0xffff;
SerialInit();
Delay_ms10M(50);
putch(0x0c);
while(1)
LATB = 0x000f;k=0;k++;
TRISB = 0x000f;
ScanRow();
LATB = 0x00f0;
k=0;
k++;
TRISB = 0x00f0;
ScanCol();
Delay_ms10M(40);
Count[Row][Col]++;
Delay_ms10M(200);
void ScanRow()
break;
break;
break;
break;
}
}
void ScanCol()
switch(temp)
break;
break;
break;
break;
void SerialInit()
{
U1MODE = 0x8000;
U1STA = 0x8400;
U1BRG = BRGVAL;
IFS0bits.U1TXIF=1;
while(IFS0bits.U1TXIF==0);
U1TXREG=SendDat;
IFS0bits.U1TXIF=0;
To compile the above C code you need the Mplab software &
Microchip C30 C Compiler. They must be properly set up and a project
with correct settings must be created in order to compile the code. To
compile the above code, the C file must be added to the project.
If you want to see more details about debugging just see the videos in
below link.