Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. #include "system_sam3x.h"
  2. #include "at91sam3x8.h"
  3. #include <stdio.h>
  4.  
  5. int func()
  6. {
  7. unsigned int value = 0; //Return value
  8. *AT91C_PIOD_SODR = (0 << 2); //Enable/Clear OE pin
  9.  
  10. //Make col pins as output
  11. *AT91C_PIOC_PER = (3 << 8);
  12. *AT91C_PIOC_PER = (1 << 12);
  13. *AT91C_PIOC_OER = (3 << 8);
  14. *AT91C_PIOC_OER = (1 << 12);
  15.  
  16. *AT91C_PIOC_SODR = (3 << 8); //Set Colum pins all to 1
  17. *AT91C_PIOC_SODR = (1 << 12);
  18.  
  19. for (int i = 0; i < 3; i++) //Col loop
  20. {
  21. if (i == 2)
  22. *AT91C_PIOC_CODR = (1 << 12); //Clear one col at a time/ Set it to zero
  23.  
  24. else
  25. *AT91C_PIOC_CODR = (1 << 8+i); //Clear one col at a time/ Set it to zero
  26.  
  27. for (int j = 0; j < 4; j++) //Row Loop
  28. {
  29. if (*AT91C_PIOC_PDSR & (1 << j+4) == 0) //Check if the bit is 0 if it is set the value equal to that button
  30. {
  31. value = (3*j+ i+1);
  32. }
  33. }
  34.  
  35. *AT91C_PIOC_SODR = (3 << 8); //Make col pins high again
  36. *AT91C_PIOC_SODR = (1 << 12);
  37. }
  38.  
  39. *AT91C_PIOC_CODR = (3 << 8); //Clear all pins and make them as input
  40. *AT91C_PIOC_CODR = (1 << 12);
  41. *AT91C_PIOC_ODR = (3 << 8);
  42. *AT91C_PIOC_ODR = (1 << 12);
  43.  
  44.  
  45. *AT91C_PIOD_SODR = (1 << 2); //Disable/Clear OE pin
  46. return value;
  47.  
  48. }
  49.  
  50. //Delay Function
  51. void Delay(int val)
  52. {
  53. for (int i = 0; i < val; i++)
  54. {
  55. asm("nop");
  56. }
  57. }
  58.  
  59. //Read Status
  60. unsigned char Read_Status_Display(void)
  61. {
  62. unsigned char temp;
  63.  
  64.  
  65.  
  66. }
  67.  
  68. //Write command
  69. void Write_Command_2_Display_(unsigned char command)
  70. {
  71.  
  72. }
  73.  
  74. //Write Data
  75. void Write_data_2_Display(unsigned char data)
  76. {
  77.  
  78. }
  79.  
  80.  
  81. //Display function
  82. int Display(void)
  83. {
  84.  
  85. }
  86.  
  87. int main()
  88. {
  89. SystemInit();
  90.  
  91. //Enable Periphial Main Clock
  92. *AT91C_PMC_PCER = (3 << 13);
  93.  
  94. //Set up the pins as correct output and inputs
  95. *AT91C_PIOC_PER = (0xF << 4);
  96. *AT91C_PIOC_ODR = (0xF << 4);
  97.  
  98. *AT91C_PIOD_PER = (1 << 2);
  99. *AT91C_PIOD_PPUDR = (1 << 2);
  100. *AT91C_PIOD_OER = (1 << 2);
  101.  
  102. while(1)
  103. {
  104. // ReadButton(&i);
  105. int val = func();
  106.  
  107. if (val != 0)
  108. {
  109. asm("nop");
  110. }
  111. }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement