Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * keyboard.c
- *
- * Created: 4/16/2019 4:59:58 PM
- * Author: dspuser
- */
- #define F_CPU 14745600UL
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
- #include "keyboard.h"
- #include "digit.h"
- #include <stdint.h>
- void scan_key(){
- uint8_t row=0,column=0;
- DDRB=0x0F;
- PORTB=0x00;
- while(1){
- do{
- PORTB=PORTB|0x0F;
- row=PORTB|0xF0;
- }while(row==0x00);
- do{
- do{
- //_delay_ms(10);
- row=PORTB&0xF0;
- }while(row==0x00);
- //_delay_ms(20);
- row=PORTB&0xF0;
- }while(row==0x00);
- while(1){
- PORTB=PORTB&0xF0;
- PORTB=PORTB|0x01;
- row=PORTB&0xF0;
- if(row!=0x00){
- column=0;
- break;
- }
- PORTB=PORTB&0xF0;
- PORTB=PORTB|0x02;
- row=PORTB&0xF0;
- if(row!=0x00){
- column=1;
- break;
- }
- PORTB=PORTB&0xF0;
- PORTB=PORTB|0x04;
- row=PORTB&0xF0;
- if(row!=0x00){
- column=2;
- break;
- }
- PORTB=PORTB&0xF0;
- PORTB=PORTB|0x08;
- row=PORTB&0xF0;
- if(row!=0x00){
- column=3;
- break;
- }
- }
- if(row==0x10){
- display_digit(keyboard[0][column]);
- }
- if(row==0x20){
- display_digit(keyboard[1][column]);
- }
- if(row==0x40){
- display_digit(keyboard[2][column]);
- }
- if(row==0x80){
- display_digit(keyboard[3][column]);
- }
- do{
- _delay_ms(20);
- PORTB=PORTB|0x0F;
- row=PORTB&0xF0;
- }while(row!=0x00);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement