1 | /* Includes ------------------------------------------------------------------*/
|
2 | #include "stm8s.h"
|
3 | #include "stm8_tsl_rc_api.h"
|
4 | #include "stm8s_tim3.h"
|
5 | //#include "iostm8s105c6.h"
|
6 |
|
7 | /* Private typedef -----------------------------------------------------------*/
|
8 | /* Private define ------------------------------------------------------------*/
|
9 | #define MilliSec 1
|
10 | #define Sec 10
|
11 | /* Private macro -------------------------------------------------------------*/
|
12 | /* Private variables ---------------------------------------------------------*/
|
13 | /* Private function prototypes -----------------------------------------------*/
|
14 | void CLK_Configuration(void);
|
15 | void GPIO_Configuration(void);
|
16 | void ExtraCode_Init(void);
|
17 | void ExtraCode_StateMachine(void);
|
18 | void Delay(void action(void), int NumberofTIMCycles);
|
19 | void Toggle(void);
|
20 |
|
21 | #pragma vector = 0x12
|
22 | __interrupt void TIM3_Compare_vector(void);
|
23 | #pragma vector = 0x11
|
24 | __interrupt void TIM3_Update_vector(void);
|
25 |
|
26 | /* Private functions ---------------------------------------------------------*/
|
27 | /* Global variables ----------------------------------------------------------*/
|
28 | u8 BlinkSpeed = 6;
|
29 | u16 PWMvalue = 500;
|
30 | u16 nowCounterTim3;
|
31 | int NumberOfStart;
|
32 | int CheckFlag = 1;
|
33 |
|
34 | /* Public functions ----------------------------------------------------------*/
|
35 |
|
36 | /**
|
37 | ******************************************************************************
|
38 | * @brief Main function.
|
39 | * @par Parameters:
|
40 | * None
|
41 | * @retval void None
|
42 | * @par Required preconditions:
|
43 | * None
|
44 | ******************************************************************************
|
45 | */
|
46 | void main(void)
|
47 | {
|
48 | /* Configures clocks */
|
49 | CLK_Configuration();
|
50 |
|
51 | /* Configures GPIOs */
|
52 | GPIO_Configuration();
|
53 |
|
54 | /* Initialize Touch Sensing library */
|
55 | TSL_Init();
|
56 |
|
57 | /* Initialize all the Touch Sensing keys */
|
58 | ExtraCode_Init();
|
59 |
|
60 | /* Start the 100ms timebase Timer */
|
61 | TSL_Tick_Flags.b.User_Start_100ms = 1;
|
62 |
|
63 | /* Initialize Timer3 */
|
64 | TIM3_DeInit();
|
65 | TIM3_TimeBaseInit(TIM3_PRESCALER_1, 16535);
|
66 | TIM3_OC2Init(TIM3_OCMODE_PWM2, TIM3_OUTPUTSTATE_DISABLE, 999, TIM3_OCPOLARITY_LOW);
|
67 | TIM3_Cmd(ENABLE);
|
68 | TIM3_ITConfig(TIM3_IT_CC2,ENABLE);
|
69 | TIM3_ITConfig(TIM3_IT_UPDATE,ENABLE);
|
70 | enableInterrupts();
|
71 |
|
72 | for (;;)
|
73 | {
|
74 |
|
75 | /* User code */
|
76 | ExtraCode_StateMachine();
|
77 |
|
78 | /* Main function of the Touch Sensing library */
|
79 | TSL_Action();
|
80 |
|
81 | }
|
82 |
|
83 | }
|
84 |
|
85 | /* Interrupt functions */
|
86 | __interrupt void TIM3_Compare_vector(void)
|
87 | {
|
88 | TIM3_ClearITPendingBit(TIM3_IT_CC2);
|
89 | nowCounterTim3 = TIM3_GetCounter();
|
90 | GPIO_WriteHigh(GPIOD, GPIO_PIN_0);
|
91 | }
|
92 | __interrupt void TIM3_Update_vector(void)
|
93 | {
|
94 | TIM3_ClearITPendingBit(TIM3_IT_UPDATE);
|
95 | nowCounterTim3 = TIM3_GetCounter();
|
96 | GPIO_WriteLow(GPIOD, GPIO_PIN_0);
|
97 | }
|