-
Notifications
You must be signed in to change notification settings - Fork 1
/
MQ6812_int_table.c
executable file
·334 lines (315 loc) · 8.48 KB
/
MQ6812_int_table.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/*****************************************************************
;* Sample SFR/Vector File for TLCS-870/C1 Series *
;* Memory Style: Within 64K byte *
;*---------------------------------------------------------------*
;* (C)Copyright TOSHIBA CORPORATION 2008 All rights reserved *
;*****************************************************************/
//#define IO_MEM 1
#include "MQ6812.h"
#include "iApp.h"
#include "ExtINT.h"
extern uchar keySLIP, keyPUSH, keySLIP_down, keySLIP_up;
extern uchar cnt1_10ms, cnt2_10ms, cnt1_50ms, cnt2_50ms, cnt_1s;
extern uchar rec_done_flag, rec_start, rec_cnt, uart_flag;
extern uchar TX_DATA, RX_DATA;
char rx_data[10] = {0};
void startup(void); //defined by startup.asm
/*========================================================
[ Declare interrupt function ]
========================================================*/
void __interrupt Int2(void);
void __interrupt Int3(void);
void __interrupt Int4(void);
void __interrupt IntTC00(void);
void __interrupt IntTC01(void);
void __interrupt IntTC02(void);
void __interrupt IntTC03(void);
void __interrupt IntTC04(void);
void __interrupt IntTC05(void);
void __interrupt IntTCA0(void);
void __interrupt IntRTC(void);
void __interrupt IntADC(void);
void __interrupt IntVLTD(void);
void __interrupt IntRXD1(void);
void __interrupt IntTXD1(void);
void __interrupt IntSBI(void);
void __interrupt IntSIO0(void);
void __interrupt IntTBT(void);
void __interrupt IntWUC(void);
void __interrupt_n IntWDT(void);
void __interrupt_n IntSWI(void);
/*========================================================
[ Dummy function for interrupt ]
========================================================*/
void __interrupt Int_dummy(void){ }
void __interrupt_n Int_n_dummy(void){ }
/*========================================================
[ Implement interrupt function]
========================================================*/
void __interrupt Int2(void)
{
//if(1){D4 = 1;delay_times(t_1ms, 50);D4 = 0;return;}
d_ExtINT_02_Dis;
keyPUSH = 1;
// TCH3 // P7PRD.bit.b5
if( keySLIP >= 1 )
{
keySLIP_down = 1;
d_ExtINT_02_Dis;
d_ExtINT_03_Dis;
d_ExtINT_04_Dis;
}
else
{
delay_times(t_1ms, 20);
if( (TCH1 == 1) || (TCH2 == 1) )
{
keyPUSH = 100;
d_ExtINT_02_Dis;
d_ExtINT_03_Dis;
d_ExtINT_04_Dis;
}
else
{
keySLIP = 1;
d_ExtINT_03_Dis;
}
}
}
void __interrupt Int3(void)
{
//if(1){D2=D3 = 1;delay_times(t_1ms, 50);D2=D3 = 0;return;}
d_ExtINT_03_Dis;
keyPUSH = 1;
// TCH2 // P7PRD.bit.b6
if( keySLIP >= 1 )
{
// delay_times(t_1ms, 10);
}
else
{
delay_times(t_1ms, 20);
if( (TCH1 == 1) || (TCH3 == 1) )
{
keyPUSH = 100;
d_ExtINT_02_Dis;
d_ExtINT_03_Dis;
d_ExtINT_04_Dis;
}
else
{
keySLIP = 1;
}
}
}
void __interrupt Int4(void)
{
//if(1){D1 = 1;delay_times(t_1ms, 50);D1 = 0;return;}
d_ExtINT_04_Dis;
keyPUSH = 1;
// TCH1 // P7PRD.bit.b7
if( keySLIP >= 1 )
{
keySLIP_up = 1;
d_ExtINT_02_Dis;
d_ExtINT_03_Dis;
d_ExtINT_04_Dis;
}
else
{
delay_times(t_1ms, 20);
if( (TCH2 == 1) || (TCH3 == 1) )
{
keyPUSH = 100;
d_ExtINT_02_Dis;
d_ExtINT_03_Dis;
d_ExtINT_04_Dis;
}
else
{
keySLIP = 1;
d_ExtINT_03_Dis;
}
}
}
void __interrupt IntTC00(void)
{
//Add your interrupt handler code here
}
void __interrupt IntTC01(void)
{
//Add your interrupt handler code here
}
void __interrupt IntTC02(void)
{
//Add your interrupt handler code here
}
void __interrupt IntTC03(void)
{
//Add your interrupt handler code here
}
void __interrupt IntTC04(void)
{
//Add your interrupt handler code here
}
void __interrupt IntTC05(void)
{
//Add your interrupt handler code here
}
void __interrupt IntTCA0(void)
{
cnt1_10ms++;
cnt2_10ms++;
if( cnt1_10ms >= 5 )
{
cnt1_10ms = 0;
cnt1_50ms++;
cnt2_50ms++;
flag1_50ms = 1;
flag2_50ms = 1;
flag3_50ms = 1;
}
if( cnt2_50ms >= 4 )
{
cnt2_50ms = 0;
flag_200ms = 1;
}
if( cnt1_50ms >= 20 )
{
cnt1_50ms = 0;
cnt_1s++;
flag_1s = 1;
flag1_1s = 1;
flag2_1s = 1;
}
if( cnt_1s >= 3 )
{
cnt_1s = 0;
flag_3s = 1;
}
if( keyPUSH ) keyPUSH++;
//Add your interrupt handler code here
}
void __interrupt IntRTC(void)
{
//Add your interrupt handler code here
}
void __interrupt IntADC(void)
{
//Add your interrupt handler code here
}
void __interrupt IntVLTD(void)
{
//Add your interrupt handler code here
}
void __interrupt IntRXD1(void)
{
uart_flag = UART1SR.byte; //get flag data [PERR, FERR, OERR, -, RBSY, RBFL, TBSY, TBFL]
// PERR 奇偶校验错误标帜 0: 无奇偶校验错误
// 1: 发生奇偶校验错误
// RFERR 收发框错误标帜 0: 无收发框错误
// 1: 发生收发框错误
// OERR 溢出错误标帜 0: 无溢出错误
// 1: 发生溢出错误
// RBSY 接收忙碌标帜 0: 接收前或接收工作结束
// 1: 接收中
// RBFL 接收缓存器已满标帜 0: 接收缓存器为空
// 1: 接收缓存器已满
// TBSY 发送忙碌标帜 0: 发送前或发送工作结束
// 1: 发送中
// TBFL 发送缓存器已满标帜 0: 发送缓存器为空
// 1: 发送缓存器已满
RX_DATA = RD1BUF.byte; //get Rx data and clear flag
if( rec_start == 0x00 && RX_DATA == 0xaa)
{
rec_start = 0xaa;
rec_done_flag = 0;
rec_cnt=0;
rx_data[rec_cnt] = RX_DATA;
}
else if( rec_start == 0xaa )
{
rec_cnt++;
rx_data[rec_cnt] = RX_DATA;
if( RX_DATA==0XED)
{
rec_start = 0x00;
rec_cnt = 0;
rec_done_flag = 1;
}
}
//Add your interrupt handler code here
}
void __interrupt IntTXD1(void)
{
//Add your interrupt handler code here
}
void __interrupt IntSBI(void)
{
//Add your interrupt handler code here
}
void __interrupt IntSIO0(void)
{
//Add your interrupt handler code here
}
void __interrupt IntTBT(void)
{
//Add your interrupt handler code here
}
void __interrupt IntWUC(void)
{
//Add your interrupt handler code here
}
void __interrupt_n IntWDT(void)
{
//Add your interrupt handler code here
}
void __interrupt_n IntSWI(void)
{
//Add your interrupt handler code here
unsigned char tmp;
tmp =*(unsigned char*)(0xf000);
while(tmp != *(unsigned char*)(0xf000))
{
tmp =*(unsigned char*)(0xf000);
}
SYSCR2.byte=0x10; //system clock reset
}
/*============================================
[ Define interrupt table ]
This part must be rewrite.
============================================*/
#pragma section const INT_VECTOR1
void * const IntTbl1[] = {
IntTC05, /* 0xffc4 : IntTC05 */
IntTC04, /* 0xffc6 : IntTC04 */
(void *)0xffff, /* 0xffc8 : Reserved */
(void *)0xffff, /* 0xffca : Reserved */
IntTC03, /* 0xffcc : IntTC03 */
IntTC02, /* 0xffce : IntTC02 */
IntTXD1, /* 0xffd0 : IntTXD1 */
IntRXD1, /* 0xffd2 : IntRXD1 */
Int_dummy, /* 0xffd4 : Reserved */
Int4, /* 0xffd6 : Int4 */
Int3, /* 0xffd8 : Int3 */
Int2, /* 0xffda : Int2 */
Int_dummy, /* 0xffdc : Reserved */
Int_dummy, /* 0xffde : Reserved */
IntSBI, /* 0xffe0 : IntSBI */
IntTCA0, /* 0xffe2 : IntTCA0 */
IntTC01, /* 0xffe4 : IntTC01 */
IntTC00, /* 0xffe6 : IntTC00 */
IntRTC, /* 0xffe8 : IntRTC */
IntADC, /* 0xffea : IntADC */
IntVLTD, /* 0xffec : IntVLTD */
Int_dummy, /* 0xffee : Reserved */
Int_dummy, /* 0xfff0 : Reserved */
IntSIO0, /* 0xfff2 : IntSIO0 */
IntTBT, /* 0xfff4 : IntTBT */
IntWUC, /* 0xfff6 : IntWUC */
IntWDT, /* 0xfff8 : IntWDT */
(void *)0xffff, /* 0xfffa : Reserved */
IntSWI, /* 0xfffc : IntSWI/INTUNDEF */
startup /* 0xfffe : RESET */
};
#pragma section const /* return to default */