RT-USB-9AXIS-00
UserInterface.c
[詳解]
1 
8 #include "LPC13xx.h"
9 #include "core_cm3.h"
10 #include "timer.h"
11 #include "type.h"
12 #include "pwm.h"
13 #include "debug.h"
14 #include "UserInterface.h"
15 #include "ad.h"
16 
17 //LEDが点滅状態か常時点灯状態かのフラグ 1:点滅  0:常時点灯(消灯も含む)
18 volatile static uint8_t flag_flash_green_LED = 0;
19 volatile static uint8_t flag_flash_red_LED = 0;
20 
21 //SWの押下状態のカウント
22 volatile static uint16_t SW_count = 0;
23 //LEDの点滅用カウント
24 volatile static uint16_t green_LED_count = 0;
25 volatile static uint16_t red_LED_count = 0;
26 //経過時間のカウント
27 volatile static uint32_t elapsed_time_count = 0;
28 //LEDの点滅時間のon/off時間のカウント
29 volatile static uint16_t on_count_green_LED = 0;
30 volatile static uint16_t off_count_green_LED = 1;
31 
32 volatile static uint16_t on_count_red_LED = 0;
33 volatile static uint16_t off_count_red_LED = 1;
34 
35 
53 void initUI(void)
54 {
55  startTimer32_0();
56 }
57 
64 uint8_t getStateSW(void)
65 {
66  uint32_t state;
67  state = (LPC_GPIO0->DATA & 0x2)>>1;
68  state = 1 - state;
69  return state;
70 }
71 
78 uint16_t getSWcount(void)
79 {
80  return SW_count;
81 }
82 
90 uint32_t getElapsedTime(void)
91 {
92  return elapsed_time_count;
93 }
94 
102 {
103  elapsed_time_count = 0;
104 }
105 
112 static void setStateGreenLED(uint8_t state)
113 {
114  if(state == 1)
115  {
116  LPC_GPIO1->DATA |= 0x0004; //LED on
117  }
118  else
119  {
120  LPC_GPIO1->DATA &= ~0x0004; //LED off
121  }
122 }
123 
130 static void setStateRedLED(uint8_t state)
131 {
132  if(state == 1)
133  {
134  LPC_GPIO1->DATA |= 0x0002; //LED on
135  }
136  else
137  {
138  LPC_GPIO1->DATA &= ~0x0002; //LED off
139  }
140 }
141 
142 
150 void turnGreenLED(uint8_t state)
151 {
152  flag_flash_green_LED = 0;
153  setStateGreenLED(state);
154 }
155 
163 void turnRedLED(uint8_t state)
164 {
165  flag_flash_red_LED = 0;
166  setStateRedLED(state);
167 }
168 
169 
183 void flashGreenLED(uint16_t on_count, uint16_t off_count)
184 {
185  flag_flash_green_LED = 1;
186  on_count_green_LED = on_count;
187  off_count_green_LED = off_count;
188 }
189 
203 void flashRedLED(uint16_t on_count, uint16_t off_count)
204 {
205  flag_flash_red_LED = 1;
206  on_count_red_LED = on_count;
207  off_count_red_LED = off_count;
208 }
209 
210 
219 {
220  LPC_TMR32B0->IR=0x08; //clear interrupt flag
221 
222  //緑LEDの点滅処理
223  if(flag_flash_green_LED == 1)
224  {
225  //LEDの点滅
226  if(green_LED_count < on_count_green_LED ) setStateGreenLED(1);
227  else setStateGreenLED(0);
228  if( (on_count_green_LED + off_count_green_LED) < green_LED_count ) green_LED_count = 0;
229  green_LED_count ++;
230  }
231 
232  //赤LEDの点滅処理
233  if(flag_flash_red_LED == 1)
234  {
235  //LEDの点滅
236  if(red_LED_count < on_count_red_LED ) setStateRedLED(1);
237  else setStateRedLED(0);
238  if( (on_count_red_LED + off_count_red_LED) < red_LED_count ) red_LED_count = 0;
239  red_LED_count ++;
240  }
241 
242  //時間経過
243  elapsed_time_count ++;
244 
245  //スイッチの押下
246  if(getStateSW() == 1) SW_count ++;
247  else SW_count = 0;
248 
249 }
250 
257 void debugUI(void)
258 {
259  myPrintfUSB("#######debug UI####### \n");
260  myPrintfUSB("SW state %d \n", getStateSW());
261  myPrintfUSB("SW count %d msec \n", getSWcount());
262  myPrintfUSB("Elap Time %d msec \n", getElapsedTime());
263 }
264 
265 /******************************************************************************
266 ** End Of File
267 ******************************************************************************/
void resetElapsedTime(void)
uint16_t getSWcount(void)
Definition: UserInterface.c:78
uint8_t getStateSW(void)
Definition: UserInterface.c:64
void flashGreenLED(uint16_t on_count, uint16_t off_count)
CMSIS Cortex-M3 Core Peripheral Access Layer Header File.
void turnRedLED(uint8_t state)
void turnGreenLED(uint8_t state)
void TIMER32_0_IRQHandler(void)
void flashRedLED(uint16_t on_count, uint16_t off_count)
uint32_t getElapsedTime(void)
Definition: UserInterface.c:90
LED,SW,電源電圧の監視等の機能の実装
void initUI(void)
Definition: UserInterface.c:53
void debugUI(void)