Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 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. }
  87. /////////////////////////////////////////
  88. /*
  89. * keyboard.h
  90. *
  91. * Created: 4/16/2019 4:53:50 PM
  92. * Author: dspuser
  93. */
  94.  
  95. #ifndef KEYBOARD_H_
  96. #define KEYBOARD_H_
  97.  
  98. #include <stdint.h>
  99. static const uint8_t keyboard[4][4]={ {1,2,3,10},
  100. {4,5,6,11},
  101. {7,8,9,12},
  102. {14,0,15,13}
  103. };
  104. void scan_key();
  105.  
  106. #endif
  107. //////////////////////
  108. /*
  109. * GccApplication8.c
  110. *
  111. * Created: 3/26/2019 4:24:12 PM
  112. * Author : dspuser
  113. */
  114. #define F_CPU 14745600UL
  115. #include <avr/io.h>
  116. #include <avr/interrupt.h>
  117. #include <util/delay.h>
  118. #include "timer.h"
  119. #include "digit.h"
  120. #include "keyboard.h"
  121.  
  122.  
  123. uint8_t i;
  124.  
  125. int main(void)
  126. {
  127. //uint8_t n=0;
  128.  
  129. /*sei();
  130. timer_init();
  131. init_digit();
  132.  
  133. while(1)
  134. {
  135. _delay_ms(1000);
  136. display_digit(i);
  137. if(i>15)
  138. {i=0;
  139. clear_digit();}
  140. else
  141. i++;*/
  142.  
  143. /*if(flag==1){
  144. toggle_led();
  145. flag=0;
  146. }*/
  147. scan_key();
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement