Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.74 KB | None | 0 0
  1. /********************************************************************************
  2. * Copyright 2013, Cypress Semiconductor Corporation. All rights reserved.
  3. * This software is owned by Cypress Semiconductor Corporation and is protected
  4. * by and subject to worldwide patent and copyright laws and treaties.
  5. * Therefore, you may use this software only as provided in the license agreement
  6. * accompanying the software package from which you obtained this software.
  7. * CYPRESS AND ITS SUPPLIERS MAKE NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  8. * WITH REGARD TO THIS SOFTWARE, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT,
  9. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  10. *******************************************************************************/
  11.  
  12. #include <device.h>
  13. #include <upISR.h>
  14. #include <math.h>
  15. #include<stdio.h>
  16. #include <stdbool.h> //om boolean te kunnen gebruiken
  17.  
  18. /* ========================================
  19. *
  20. * Enter the values to be returned from the
  21. * keypad in the required order in the
  22. * Key[4][4] character matrix
  23. *
  24. * ========================================
  25. */
  26.  
  27. char UARTFlag=0;
  28. uint8 whichkey;
  29. uint8 run = 0;
  30. uint8 toggle = 0;
  31.  
  32. const int pwmSin[] = {128, 132, 136, 140, 143, 147, 151, 155, 159, 162, 166, 170, 174, 178, 181, 185, 189, 192, 196, 200, 203, 207, 211, 214, 218, 221, 225, 228, 232, 235, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 253, 253, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 253, 253, 253, 252, 252, 251, 250, 250, 249, 248, 248, 247, 246, 245, 244, 243, 242, 241, 240, 239, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 253, 253, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 253, 253, 253, 252, 252, 251, 250, 250, 249, 248, 248, 247, 246, 245, 244, 243, 242, 241, 240, 239, 238, 235, 232, 228, 225, 221, 218, 214, 211, 207, 203, 200, 196, 192, 189, 185, 181, 178, 174, 170, 166, 162, 159, 155, 151, 147, 143, 140, 136, 132, 128, 124, 120, 116, 113, 109, 105, 101, 97, 94, 90, 86, 82, 78, 75, 71, 67, 64, 60, 56, 53, 49, 45, 42, 38, 35, 31, 28, 24, 21, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 8, 7, 6, 6, 5, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 8, 7, 6, 6, 5, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 21, 24, 28, 31, 35, 38, 42, 45, 49, 53, 56, 60, 64, 67, 71, 75, 78, 82, 86, 90, 94, 97, 101, 105, 109, 113, 116, 120, 124};
  33. int currentStepA;
  34. int currentStepB;
  35. int currentStepC;
  36. int sineArraySize;
  37. int increment = 0;
  38. bool direct = 1; // richting true=voorwaarts, false=achterwaarts
  39.  
  40.  
  41.  
  42. //CY_ISR_PROTO(upISR);
  43. /*
  44. CY_ISR(upISR){
  45.  
  46. }*/
  47.  
  48. /* button interrupt */
  49. CY_ISR_PROTO(button_interrupt_Handler);
  50. CY_ISR(button_interrupt_Handler){
  51. Bootloadable_Load();
  52. };
  53.  
  54. /* UART interrupt */
  55. CY_ISR_PROTO(input_interrupt_Handler);
  56. CY_ISR(input_interrupt_Handler)
  57. {
  58. UARTFlag = UART_1_UartGetChar();//MSB has RxStatus Reg,and LSB has the data.
  59. uint32 source = 0;
  60. source = UART_1_GetRxInterruptSourceMasked();
  61. UART_1_ClearRxInterruptSource(source);
  62. /* `#END` */
  63. }
  64.  
  65. /* externe button interrupt */
  66. CY_ISR_PROTO(upISR_Handler);
  67. CY_ISR(upISR_Handler)
  68. {
  69. upISR_Disable();
  70. SW1_Write(toggle);
  71. toggle = ~toggle;
  72. LCD_1_PutChar('c');
  73. upISR_Enable();
  74. };
  75.  
  76. void interruptvlaggen(void){
  77. if(UARTFlag=='c'){
  78. LCD_1_ClearDisplay();
  79. }else if(UARTFlag=='t'){
  80. LCD_1_Position(0u,0u);
  81. }else if(UARTFlag=='b'){
  82. LCD_1_Position(1u,0u);
  83.  
  84. }
  85. else if(UARTFlag=='a'){
  86. LCD_1_ClearDisplay();
  87. LCD_1_PrintNumber(36);
  88.  
  89. }else if(UARTFlag=='v'){
  90. LCD_1_PrintString("dit is de spanning");
  91. }else
  92. {
  93. LCD_1_PrintString("inp:");
  94. LCD_1_PutChar(UARTFlag);
  95. }
  96.  
  97. }
  98.  
  99. //char8 Keypad_1_Key[4][4] = {
  100. // {'C','Y','P','R'}, //Row 0
  101. //
  102. // {'E','S','S','C'}, //Row 1
  103. //
  104. // {'O','M','P','O'}, //Row 2
  105. //
  106. // {'N','E','N','T'} //Row 3
  107. // };
  108. /*
  109. char8 Keypad_1_Key[4][4] = {
  110. {'1','2','3','A'}, //Row 0
  111.  
  112. {'4','5','6','B'}, //Row 1
  113.  
  114. {'7','8','9','C'}, //Row 2
  115.  
  116. {'*','0','#','D'} //Row 3
  117. };
  118. */
  119.  
  120. void rundisable(void){
  121. run=0;
  122. }
  123.  
  124.  
  125.  
  126.  
  127. int main(void)
  128. {
  129. uint8 swCounter;
  130.  
  131. /* LCD */
  132. LCD_1_Start(); //Turns on the LCD module
  133. LCD_1_Position(0,0); //row, column
  134.  
  135. /* Interrupt uart */
  136. CyGlobalIntDisable;
  137. UART_1_Start(); /* Start de UART*/
  138. input_interrupt_ClearPending();
  139. input_interrupt_StartEx(input_interrupt_Handler);
  140.  
  141. upISR_ClearPending();
  142. upISR_StartEx(upISR_Handler);
  143. whichkey = 0;
  144.  
  145. button_interrupt_ClearPending();
  146. button_interrupt_StartEx(button_interrupt_Handler);
  147.  
  148. //upISR_StartEx(upISR_Interrupt);
  149. CyGlobalIntEnable; /* Enable global interrupts. */
  150.  
  151. /* RTC */
  152. klok_Start();
  153.  
  154. /* BLDC */
  155. sineArraySize = sizeof(pwmSin)/sizeof(int);
  156. int phaseShift = sineArraySize / 3; // Vind de faseverschuiving en initiële A,B,C fasewaarden
  157. currentStepA = 0;
  158. currentStepB = currentStepA + phaseShift;
  159. currentStepC = currentStepB + phaseShift;
  160. sineArraySize--; // Convert from array Size to last PWM array number
  161.  
  162.  
  163. while(1)
  164. {
  165. /* SW_1 bootloader */
  166. if(SW1_Read()) /* Reset the software counter if SW1 is not pressed (Pulled high)*/
  167. {
  168. swCounter = 0;
  169. } else
  170. {
  171. swCounter++; /* Increment the counter if SW1 is pressed (Shorted to GND) */
  172. CyDelay(10); /* Provide a 10 ms delay to make the counter approximately periodic every 10 ms */
  173. if(swCounter > 100)
  174. {
  175. Bootloadable_Load();
  176. }
  177. }
  178.  
  179. if(UARTFlag!=0){
  180. interruptvlaggen();
  181. UARTFlag=0;
  182. }
  183. /*
  184. if(whichkey == 1){
  185. LCD_1_ClearDisplay();
  186. LCD_1_PutChar('b');
  187.  
  188. whichkey = 0;
  189. } */
  190. /*
  191. if(!BT_Read()) //read a 1 when button is NOT pressed
  192. {
  193. LCD_1_ClearDisplay();
  194. LCD_1_PutChar('h');
  195. }
  196. else if(BT_Read()) //read a 0 when button is pressed
  197. {
  198. LCD_1_PutChar('w');
  199. } */
  200. }
  201.  
  202. /* LCD */
  203. /*
  204. LCD_1_ClearDisplay(); //Clear Display
  205. LCD_1_Position(0,0); //Initial position
  206. uint32 d = klok_GetTime();
  207. char i;
  208. //LCD_1_PutChar((char) d%10+48);
  209. for(i=0; i < 32; i++)
  210. {
  211. //woord[16-i] = d%10;
  212. LCD_1_PutChar((char)d%10 + 48);
  213. d = d/10;
  214. }
  215. CyDelay(500);
  216. } */
  217.  
  218. //char woord[16];
  219. //sprintf(woord,"%ld",d);
  220. //printf("%s \n \n \n", woord);
  221.  
  222. /*while(1){
  223. LCD_1_ClearDisplay();
  224. LCD_1_PrintString("Test 1");
  225. CyDelay(1000);
  226. LCD_1_ClearDisplay();
  227. LCD_1_PrintString("Testjeu");
  228. }*/
  229. //LCD_1_PrintString(
  230.  
  231. /* char woord2[5];
  232. for(i=0; i < 4; i++)
  233. {
  234. woord2[i] = woord[i];
  235. }
  236. LCD_1_PrintString(woord); */
  237. //LCD_1_Char_PrintString("");
  238.  
  239.  
  240. /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
  241.  
  242. /*for(;;)
  243. {
  244. char8 i;
  245.  
  246. i=Keypad_1_GetButton(); //Value recieved from Matrix
  247.  
  248. LCD_1_ClearDisplay();
  249.  
  250. LCD_1_PutChar(i); //Display
  251.  
  252. }*/
  253. return 0;
  254. }
  255.  
  256. /* [] END OF FILE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement