Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********************************************************************************
- * Copyright 2013, Cypress Semiconductor Corporation. All rights reserved.
- * This software is owned by Cypress Semiconductor Corporation and is protected
- * by and subject to worldwide patent and copyright laws and treaties.
- * Therefore, you may use this software only as provided in the license agreement
- * accompanying the software package from which you obtained this software.
- * CYPRESS AND ITS SUPPLIERS MAKE NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * WITH REGARD TO THIS SOFTWARE, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT,
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- *******************************************************************************/
- #include <device.h>
- #include <upISR.h>
- #include <math.h>
- #include<stdio.h>
- #include <stdbool.h> //om boolean te kunnen gebruiken
- /* ========================================
- *
- * Enter the values to be returned from the
- * keypad in the required order in the
- * Key[4][4] character matrix
- *
- * ========================================
- */
- char UARTFlag=0;
- uint8 whichkey;
- uint8 run = 0;
- uint8 toggle = 0;
- 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};
- int currentStepA;
- int currentStepB;
- int currentStepC;
- int sineArraySize;
- int increment = 0;
- bool direct = 1; // richting true=voorwaarts, false=achterwaarts
- //CY_ISR_PROTO(upISR);
- /*
- CY_ISR(upISR){
- }*/
- /* button interrupt */
- CY_ISR_PROTO(button_interrupt_Handler);
- CY_ISR(button_interrupt_Handler){
- Bootloadable_Load();
- };
- /* UART interrupt */
- CY_ISR_PROTO(input_interrupt_Handler);
- CY_ISR(input_interrupt_Handler)
- {
- UARTFlag = UART_1_UartGetChar();//MSB has RxStatus Reg,and LSB has the data.
- uint32 source = 0;
- source = UART_1_GetRxInterruptSourceMasked();
- UART_1_ClearRxInterruptSource(source);
- /* `#END` */
- }
- /* externe button interrupt */
- CY_ISR_PROTO(upISR_Handler);
- CY_ISR(upISR_Handler)
- {
- upISR_Disable();
- SW1_Write(toggle);
- toggle = ~toggle;
- LCD_1_PutChar('c');
- upISR_Enable();
- };
- void interruptvlaggen(void){
- if(UARTFlag=='c'){
- LCD_1_ClearDisplay();
- }else if(UARTFlag=='t'){
- LCD_1_Position(0u,0u);
- }else if(UARTFlag=='b'){
- LCD_1_Position(1u,0u);
- }
- else if(UARTFlag=='a'){
- LCD_1_ClearDisplay();
- LCD_1_PrintNumber(36);
- }else if(UARTFlag=='v'){
- LCD_1_PrintString("dit is de spanning");
- }else
- {
- LCD_1_PrintString("inp:");
- LCD_1_PutChar(UARTFlag);
- }
- }
- //char8 Keypad_1_Key[4][4] = {
- // {'C','Y','P','R'}, //Row 0
- //
- // {'E','S','S','C'}, //Row 1
- //
- // {'O','M','P','O'}, //Row 2
- //
- // {'N','E','N','T'} //Row 3
- // };
- /*
- char8 Keypad_1_Key[4][4] = {
- {'1','2','3','A'}, //Row 0
- {'4','5','6','B'}, //Row 1
- {'7','8','9','C'}, //Row 2
- {'*','0','#','D'} //Row 3
- };
- */
- void rundisable(void){
- run=0;
- }
- int main(void)
- {
- uint8 swCounter;
- /* LCD */
- LCD_1_Start(); //Turns on the LCD module
- LCD_1_Position(0,0); //row, column
- /* Interrupt uart */
- CyGlobalIntDisable;
- UART_1_Start(); /* Start de UART*/
- input_interrupt_ClearPending();
- input_interrupt_StartEx(input_interrupt_Handler);
- upISR_ClearPending();
- upISR_StartEx(upISR_Handler);
- whichkey = 0;
- button_interrupt_ClearPending();
- button_interrupt_StartEx(button_interrupt_Handler);
- //upISR_StartEx(upISR_Interrupt);
- CyGlobalIntEnable; /* Enable global interrupts. */
- /* RTC */
- klok_Start();
- /* BLDC */
- sineArraySize = sizeof(pwmSin)/sizeof(int);
- int phaseShift = sineArraySize / 3; // Vind de faseverschuiving en initiële A,B,C fasewaarden
- currentStepA = 0;
- currentStepB = currentStepA + phaseShift;
- currentStepC = currentStepB + phaseShift;
- sineArraySize--; // Convert from array Size to last PWM array number
- while(1)
- {
- /* SW_1 bootloader */
- if(SW1_Read()) /* Reset the software counter if SW1 is not pressed (Pulled high)*/
- {
- swCounter = 0;
- } else
- {
- swCounter++; /* Increment the counter if SW1 is pressed (Shorted to GND) */
- CyDelay(10); /* Provide a 10 ms delay to make the counter approximately periodic every 10 ms */
- if(swCounter > 100)
- {
- Bootloadable_Load();
- }
- }
- if(UARTFlag!=0){
- interruptvlaggen();
- UARTFlag=0;
- }
- /*
- if(whichkey == 1){
- LCD_1_ClearDisplay();
- LCD_1_PutChar('b');
- whichkey = 0;
- } */
- /*
- if(!BT_Read()) //read a 1 when button is NOT pressed
- {
- LCD_1_ClearDisplay();
- LCD_1_PutChar('h');
- }
- else if(BT_Read()) //read a 0 when button is pressed
- {
- LCD_1_PutChar('w');
- } */
- }
- /* LCD */
- /*
- LCD_1_ClearDisplay(); //Clear Display
- LCD_1_Position(0,0); //Initial position
- uint32 d = klok_GetTime();
- char i;
- //LCD_1_PutChar((char) d%10+48);
- for(i=0; i < 32; i++)
- {
- //woord[16-i] = d%10;
- LCD_1_PutChar((char)d%10 + 48);
- d = d/10;
- }
- CyDelay(500);
- } */
- //char woord[16];
- //sprintf(woord,"%ld",d);
- //printf("%s \n \n \n", woord);
- /*while(1){
- LCD_1_ClearDisplay();
- LCD_1_PrintString("Test 1");
- CyDelay(1000);
- LCD_1_ClearDisplay();
- LCD_1_PrintString("Testjeu");
- }*/
- //LCD_1_PrintString(
- /* char woord2[5];
- for(i=0; i < 4; i++)
- {
- woord2[i] = woord[i];
- }
- LCD_1_PrintString(woord); */
- //LCD_1_Char_PrintString("");
- /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
- /*for(;;)
- {
- char8 i;
- i=Keypad_1_GetButton(); //Value recieved from Matrix
- LCD_1_ClearDisplay();
- LCD_1_PutChar(i); //Display
- }*/
- return 0;
- }
- /* [] END OF FILE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement