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);
- }
- }
- /////////////////////////////////////////
- /*
- * keyboard.h
- *
- * Created: 4/16/2019 4:53:50 PM
- * Author: dspuser
- */
- #ifndef KEYBOARD_H_
- #define KEYBOARD_H_
- #include <stdint.h>
- static const uint8_t keyboard[4][4]={ {1,2,3,10},
- {4,5,6,11},
- {7,8,9,12},
- {14,0,15,13}
- };
- void scan_key();
- #endif
- //////////////////////
- /*
- * GccApplication8.c
- *
- * Created: 3/26/2019 4:24:12 PM
- * Author : dspuser
- */
- #define F_CPU 14745600UL
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
- #include "timer.h"
- #include "digit.h"
- #include "keyboard.h"
- uint8_t i;
- int main(void)
- {
- //uint8_t n=0;
- /*sei();
- timer_init();
- init_digit();
- while(1)
- {
- _delay_ms(1000);
- display_digit(i);
- if(i>15)
- {i=0;
- clear_digit();}
- else
- i++;*/
- /*if(flag==1){
- toggle_led();
- flag=0;
- }*/
- scan_key();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement