AVR Development Board – AVR-DK20A User Manual
42
A.12 Experiment 6 – Keypad scanning to LEDs Display
//Experiment 6
//Title : Keypad scanning and output to 8-bits LEDs Display
//Jumper for LEDs : LK9 to LK16
//Jumper Setting: L0-B0, L1-B1, L2-B2, L3-B3, L4-B4,L5-B5, L6-B6, L7-B7
//Jumper for Keypad : LK17-LK19, LK21-LK24
//Jumper Setting: C0-CL1,C1-CL2,C2-CL3,C4-RW1,C5-RW2,C6-RW3,C7-RW4
void main(){
DDRB = 0xff; //PortB for Output
PORTB = 0;
DDRC = 0X0F; //PORTC0-C2 FOR COLUMN AS OUTPUT ;
//PORTC4-C7 FOR ROW AS INPUT
PORTC = 0X00;
do{
PORTC = 0x01; //1st column
if ((PINC4_bit = 1)) {
PORTB=0x00;
delay_ms(100);
}
if (PINC5_bit = 1){
PORTB = 0x03;
delay_ms(100);
}
if (PINC6_bit = 1){
PORTB=0x06;
delay_ms(100);
}
if (PINC7_bit = 1){
PORTB=0x09;
delay_ms(100);
}
PORTC = 0x02; //2nd column
if (PINC4_bit =1) {
PORTB = 0x01;
delay_ms(100);
}
if (PINC5_bit = 1){
PORTB = 0x04;
delay_ms(100);
}
if (PINC6_bit = 1){
PORTB = 0x07;
delay_ms(100);
}
if (PINC7_bit = 1){
PORTB = 0x0a;
delay_ms(100);
}
PORTC = 0x04; //3rd column
if (PINC4_bit =1) {
PORTB = 0x02;
delay_ms(100);
}
if (PINC5_bit = 1){