Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. /*
  2. * keyboard.c
  3. *
  4. * Created: 4/16/2019 4:59:58 PM
  5. * Author: dspuser
  6. */
  7.  
  8. #define F_CPU 14745600UL
  9. #include <avr/io.h>
  10. #include <avr/interrupt.h>
  11. #include <util/delay.h>
  12. #include "keyboard.h"
  13. #include "digit.h"
  14. #include <stdint.h>
  15.  
  16. void scan_key(){
  17. uint8_t row=0,column=0;
  18. DDRB=0x0F;
  19. PORTB=0x00;
  20.  
  21. while(1){
  22. do{
  23. PORTB=PORTB|0x0F;
  24. row=PORTB|0xF0;
  25. }while(row==0x00);
  26.  
  27. do{
  28. do{
  29. //_delay_ms(10);
  30. row=PORTB&0xF0;
  31. }while(row==0x00);
  32. //_delay_ms(20);
  33. row=PORTB&0xF0;
  34. }while(row==0x00);
  35. while(1){
  36. PORTB=PORTB&0xF0;
  37. PORTB=PORTB|0x01;
  38. row=PORTB&0xF0;
  39. if(row!=0x00){
  40. column=0;
  41. break;
  42. }
  43. PORTB=PORTB&0xF0;
  44. PORTB=PORTB|0x02;
  45. row=PORTB&0xF0;
  46. if(row!=0x00){
  47. column=1;
  48. break;
  49. }
  50. PORTB=PORTB&0xF0;
  51. PORTB=PORTB|0x04;
  52. row=PORTB&0xF0;
  53. if(row!=0x00){
  54. column=2;
  55. break;
  56. }
  57. PORTB=PORTB&0xF0;
  58. PORTB=PORTB|0x08;
  59. row=PORTB&0xF0;
  60. if(row!=0x00){
  61. column=3;
  62. break;
  63. }
  64. }
  65. if(row==0x10){
  66. display_digit(keyboard[0][column]);
  67. }
  68. if(row==0x20){
  69. display_digit(keyboard[1][column]);
  70. }
  71. if(row==0x40){
  72. display_digit(keyboard[2][column]);
  73. }
  74. if(row==0x80){
  75. display_digit(keyboard[3][column]);
  76. }
  77.  
  78. do{
  79. _delay_ms(20);
  80. PORTB=PORTB|0x0F;
  81. row=PORTB&0xF0;
  82. }while(row!=0x00);
  83. }
  84.  
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement