Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #include "at91sam3x8.h"
  2. #include <stdlib.h>
  3. #include "system_sam3x.h"
  4.  
  5. #define PIOC_PER (unsigned int *)(0x400E1200)
  6. #define PIOC_ODR (unsigned int *)(0x400E1214)
  7. #define PIOC_PDSR (unsigned int *)(0x400E123C)
  8. #define PIOC_OER (unsigned int *)(0x400E1210)
  9. #define PIOC_PDR (unsigned int *)(0x400E1204)
  10. #define PMC_PCER0 (unsigned int *)(0x400E0610)
  11. #define PMC_PCER1 (unsigned int *)(0x400E0700)
  12. #define PIOD_CODR (unsigned int *)(0x400E1434)
  13. #define PIOD_SODR (unsigned int *)(0x400E1430)
  14. #define PIOC_CODR (unsigned int *)(0x400E1234)
  15. #define PIOC_SODR (unsigned int *)(0x400E1230)
  16. #define PIOC_PUDR (unsigned int *)(0x400E1260)
  17. #define PIOD_PUDR (unsigned int *)(0x400E1460)
  18.  
  19. void pins_int();
  20. int counter=0;
  21.  
  22. unsigned int rows[4];
  23. unsigned int columns[3];
  24. int value=0;
  25.  
  26.  
  27. int col=0;// increase variabel för kolumnerna
  28. int row=0; // increase variabel för raderna
  29.  
  30. void pins_int(){
  31.  
  32. *PIOD_PER = 0xE;
  33. //*PMC_PCER1= (1<<13);// Ställer in Peripheral clock.
  34. *PIOC_PER= 0x3BC;// Enablar alla pins som raderna och kolumnerna.
  35. *PIOC_ODR= 0x3BC;//Disablar alla pins för raderna till output.
  36. *PIOC_OER= 0x380;
  37.  
  38. *PIOD_CODR= 0x4;
  39. *PIOC_PUDR=0x380;
  40. *PIOD_PUDR=0xC;
  41.  
  42. }
  43.  
  44. int func(void){
  45.  
  46. columns[0]=0x80;
  47. columns[1]=0x100;
  48. columns[2]=0x200;
  49.  
  50. rows[0] = 0x4;
  51. rows[1] = 0x8;
  52. rows[2] = 0x10;
  53. rows[3] = 0x20;
  54.  
  55.  
  56. for(col=0;col<3 && value==0 ;col++){
  57. *PIOC_CODR=columns[col];
  58. for(row=0; row<4 && value==0;row++){
  59. if((*PIOC_PDSR & rows[row-1])==0){
  60. value=3*row+col+1;
  61. }
  62. *PIOC_SODR=columns[col];
  63. }
  64. }
  65. return(value);
  66. }
  67.  
  68. /*Value = 0=Check
  69. Clear OE KEY BUS (Active Low)= Check
  70. Make all Column pin as output= Check
  71. Set all Column pin as high= Check
  72. Loop Column=Check
  73. Clear one column at the time=Check
  74. Loop Row=Check
  75. Read row and check if bit is zero=Check
  76. Value = Row*3+Col+1;=Check
  77. end loop Row=Check
  78. Set the column again=Check
  79. End loop Column=Check
  80. Make all Column pin as input=Check
  81. Return Value. =Check.*/
  82.  
  83.  
  84.  
  85. int main()
  86. {
  87. pins_int();
  88. SystemInit();
  89. SysTick_Config(84000);
  90. while(1){
  91. func();
  92.  
  93. }
  94. }
  95.  
  96. void Systick_Handler(){
  97. counter++;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement