Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. #include <stdint.h>
  2. #include "tm4c123gh6pm.h"
  3. //#include "emp_type.h"
  4. #include "string.h"
  5. #define SYSTICK_RELOAD_VALUE 80000 // 5 mS
  6. #define NVIC_INT_CTRL_PEND_SYST 0x04000000 // Pend a systick int
  7. #define NVIC_INT_CTRL_UNPEND_SYST 0x02000000 // Unpend a systick int
  8. #define SYSTICK_PRIORITY 0x7E
  9.  
  10. static int a,b;
  11. static int aa,or,sw,n,b,xd,i;
  12. void SysTick_Handler(void)
  13. {
  14. a++;
  15. //auto
  16.  
  17. if(a>=400)
  18. {
  19. aa=1;
  20. }
  21.  
  22. if(aa==1 && a>50)
  23. {
  24. if(n>=0)aa=0;
  25. a=0;
  26. switch (i)
  27. {
  28. case 0:
  29. GPIO_PORTF_DATA_R=0x00;
  30. i++;
  31. break;
  32.  
  33. case 1:
  34. GPIO_PORTF_DATA_R=0x02;
  35. break;
  36.  
  37. case 2:
  38. GPIO_PORTF_DATA_R=0x04;
  39. break;
  40.  
  41. case 3:
  42. GPIO_PORTF_DATA_R=0x06;
  43. break;
  44.  
  45. case 4:
  46. GPIO_PORTF_DATA_R=0x08;
  47. break;
  48.  
  49. case 5:
  50. GPIO_PORTF_DATA_R=0x0A;
  51. break;
  52.  
  53. case 6:
  54. GPIO_PORTF_DATA_R=0x0C;
  55. break;
  56.  
  57. case 7:
  58. GPIO_PORTF_DATA_R=0x0E;
  59. i=0;
  60. break;
  61. }
  62. if (i!=0)i++;
  63.  
  64. }
  65. if(0)
  66. {
  67. // counting buttons
  68. //if (a>30 && b==1)
  69. //{
  70. // n++;
  71. // xd=1;
  72. // a=0;
  73. //}
  74.  
  75. //activating switfh
  76. if(aa==0 && or==0)sw=1;
  77.  
  78. //activing order reverse
  79. if(n==2)or==1;
  80.  
  81. //switch
  82. if (sw==1 && b==1)
  83. {
  84. if(GPIO_PORTF_DATA_R!=0x0E) //if it is at the end, goes to 0x00;
  85. {
  86. GPIO_PORTF_DATA_R=0x00;
  87. }
  88. else
  89. {
  90. GPIO_PORTF_DATA_R++; //next diode
  91. }
  92. }
  93.  
  94. //reverse
  95. if (or==1 && b==1)
  96. {
  97. if(GPIO_PORTF_DATA_R!=0x00) //if it is at the end, goes to 0x0E;
  98. {
  99. GPIO_PORTF_DATA_R=0x0E;
  100. }
  101. else
  102. {
  103. GPIO_PORTF_DATA_R--; //next diode
  104. }
  105. }
  106. }
  107. }
  108.  
  109. void enable_global_int()
  110. {
  111. // enable interrupts.
  112. __asm("cpsie i");
  113. }
  114.  
  115. void disable_global_int()
  116. {
  117. // disable interrupts.
  118. __asm("cpsid i");
  119. }
  120.  
  121.  
  122. void SysTickInit()
  123. {
  124.  
  125. // Disable systick timer
  126. NVIC_ST_CTRL_R &= ~(NVIC_ST_CTRL_ENABLE);
  127.  
  128. // Set current systick counter to reload value
  129. NVIC_ST_CURRENT_R = SYSTICK_RELOAD_VALUE;
  130. // Set Reload value, Systick reload register
  131. NVIC_ST_RELOAD_R = SYSTICK_RELOAD_VALUE;
  132.  
  133. // NVIC systick setup, vector number 15
  134. // Clear pending systick interrupt request
  135. NVIC_INT_CTRL_R |= NVIC_INT_CTRL_UNPEND_SYST;
  136.  
  137. // Set systick priority to 0x10, first clear then set.
  138. NVIC_SYS_PRI3_R &= ~(NVIC_SYS_PRI3_TICK_M);
  139. NVIC_SYS_PRI3_R |= (NVIC_SYS_PRI3_TICK_M & (SYSTICK_PRIORITY<<NVIC_SYS_PRI3_TICK_S));
  140.  
  141. // Select systick clock source, Use core clock
  142. NVIC_ST_CTRL_R |= NVIC_ST_CTRL_CLK_SRC;
  143.  
  144. // Enable systick interrupt
  145. NVIC_ST_CTRL_R |= NVIC_ST_CTRL_INTEN;
  146.  
  147. // Enable and start timer
  148. NVIC_ST_CTRL_R |= NVIC_ST_CTRL_ENABLE;
  149. }
  150.  
  151. void Reset()
  152. {
  153. // Disable systick timer
  154. NVIC_ST_CTRL_R &= ~(NVIC_ST_CTRL_ENABLE);
  155. // Set current systick counter to reload value
  156. NVIC_ST_CURRENT_R = 0;
  157. NVIC_ST_RELOAD_R = SYSTICK_RELOAD_VALUE;
  158. NVIC_INT_CTRL_R |= NVIC_INT_CTRL_UNPEND_SYST;
  159. NVIC_ST_CTRL_R |= NVIC_ST_CTRL_ENABLE;
  160.  
  161. }
  162. void Off()
  163. {
  164. // Disable systick timer
  165. NVIC_ST_CTRL_R &= ~(NVIC_ST_CTRL_ENABLE);
  166.  
  167. }
  168.  
  169.  
  170.  
  171. int main(void)
  172. {
  173. enable_global_int();
  174. int dummy;
  175. SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF;
  176.  
  177. dummy = SYSCTL_RCGC2_R;
  178.  
  179. GPIO_PORTF_DIR_R=0x0E; //DDRA
  180.  
  181. GPIO_PORTF_DEN_R=0x1E; //like PORTA
  182.  
  183. GPIO_PORTF_LOCK_R = 0x4C4F434B; // Unlock the CR register
  184. GPIO_PORTF_CR_R = 0xFF; // Enable overwrite of PUR to FP0
  185.  
  186. GPIO_PORTF_PUR_R=0x10; //PULL UP HERE
  187. int i=0;
  188.  
  189. aa=or=sw=n=b=xd=i=a=0;
  190. GPIO_PORTF_DATA_R=0x00;
  191. sw=1;
  192. //GPIO_PORTF_DATA_R=0xFF;
  193. SysTickInit();
  194. Off();
  195.  
  196. while(1)
  197. {
  198. if (GPIO_PORTF_DATA_R & 0x10) //nie wciskam
  199. {
  200. if(aa==0)
  201. {
  202. Off();
  203. a=0;
  204. }
  205. b=0;
  206. }
  207. else //wciskam xd
  208. {
  209.  
  210. if(b==0)
  211. {
  212. //n++;
  213. b=1;
  214. Reset();
  215. }
  216. //if(a>399)GPIO_PORTF_DATA_R=0x0E;
  217. //else
  218. // GPIO_PORTF_DATA_R=0x02;
  219.  
  220.  
  221. // if(xd==0)
  222. // {
  223. // b=1;
  224. // }
  225.  
  226.  
  227. }
  228. }
  229. return(0);
  230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement