-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLV1main
289 lines (259 loc) · 8.43 KB
/
LV1main
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
/******************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only
* intended for use with Renesas products. No other uses are authorized.
* This software is owned by Renesas Electronics Corporation and is protected under
* all applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES
* REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY,
* INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY
* DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
* FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS
* AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this
* software and to discontinue the availability of this software.
* By using this software, you agree to the additional terms and
* conditions found by accessing the following link:
* http://www.renesas.com/disclaimer
******************************************************************************/
/* Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved. */
/******************************************************************************
* File Name : main.c
* Version : 1.00
* Device(s) :
* Tool-Chain :
* H/W Platform :
* Description :
******************************************************************************
* History : DD.MM.YYYY Version Description
* : 03.07.2015 1.00 First Release
******************************************************************************/
/******************************************************************************
Includes <System Includes> , "Project Includes"
******************************************************************************/
#include "r_macro.h" /* System macro and standard type definition */
#include "r_spi_if.h" /* SPI driver interface */
#include "lcd.h" /* LCD driver interface */
#include "Port.h"
#include <string.h>
#include "ChatDel.h"
/******************************************************************************
Typedef definitions
******************************************************************************/
volatile int G_elapsedTime = 0; // Timer Counter
/******************************************************************************
Macro definitions
******************************************************************************/
/******************************************************************************
Imported global variables and functions (from other files)
******************************************************************************/
/******************************************************************************
Exported global variables and functions (to be accessed by other files)
******************************************************************************/
unsigned int second = 50;
unsigned int minute = 0;
unsigned int match = 0;
unsigned int prev = 0x70;
unsigned int read = 0x70;
unsigned int final = 0;
unsigned int prevfinal = 0;
/******************************************************************************
Private global variables and functions
******************************************************************************/
void r_main_userinit(void);
char * string_shown_on_lcd[10];
volatile unsigned int swt1 = 0;
volatile unsigned int swt2 = 0;
volatile unsigned int swt3 = 0;
volatile unsigned int state = 3;
unsigned int button = 0;
/******************************************************************************
* Function Name: main
* Description : Main program
* Arguments : none
* Return Value : none
******************************************************************************/
void main(void)
{
/* Initialize user system */
r_main_userinit();
/* Clear LCD display */
ClearLCD();
/* Print message to the first line of LCD */
//DisplayLCD(LCD_LINE1, (uint8_t *)"Hello World!");
sprintf(string_shown_on_lcd, "%2d:%2d", minute, second);
DisplayLCD(LCD_LINE3, string_shown_on_lcd);
/* Main loop - Infinite loop */
while (1)
{
button = ChatDel();
//A button is pressed;
if((button != 0) && (button != 0x70)){
/* Check if 1st button is pressed */
if (button == 0x40 && 1 != swt1)
{
swt1 = 1;
DisplayLCD(LCD_LINE5, "B1");
}
/* Check if 2nd button is pressed */
if (button == 0x10 && 1 != swt2)
{
swt2 = 1;
DisplayLCD(LCD_LINE5, "B2_1");
}
/* Check if 3rd button is pressed */
if (button == 0x20 && 1 != swt3)
{
swt3 = 1;
DisplayLCD(LCD_LINE5, "B3_1");
}
else if (button == 0x20 && 1 == swt3)
{
swt3 = 0;
DisplayLCD(LCD_LINE5, "B3_0");
}
button=0;
}
// /* Check if 1st button are pressed */
// if ((P7&0x40) != 0x40 && 1 != swt1)
// {
// swt1 = 1;
// DisplayLCD(LCD_LINE5, "B1");
// }
//
// /* Check if 2nd button are pressed */
// if ((P7&0x10) != 0x10 && 1 != swt2)
// {
// swt2= 1;
// DisplayLCD(LCD_LINE5, "B2");
// }
// else if ((P7&0x10) != 0x10 && 1 == swt2)
// {
// swt2= 0;
// DisplayLCD(LCD_LINE5, "B2");
// }
//
// /* Check if 3rd button are pressed */
// if ((P7&0x20) != 0x20 && 1 != swt3)
// {
// swt3 = 1;
// DisplayLCD(LCD_LINE5, "B3");
// }
// else if ((P7&0x20) != 0x20 && 1 == swt3)
// {
// swt3 = 0;
// DisplayLCD(LCD_LINE5, "B3");
//
// }
switch (swt1)
{
case 0:
break;
case 1:
second++;
swt1 = 0;
sprintf(string_shown_on_lcd, "%2d:%2d", minute, second);
DisplayLCD(LCD_LINE3, string_shown_on_lcd);
break;
}
switch (swt2)
{
case 0:
break;
case 1:
switch (swt3)
{
case 0:
minute = 0;
second = 0;
swt2 = 0;
state = 3; //Setting
sprintf(string_shown_on_lcd, "%2d:%2d", minute, second);
DisplayLCD(LCD_LINE3, string_shown_on_lcd);
break;
case 1:
minute++;
swt2 = 0;
sprintf(string_shown_on_lcd, "%2d:%2d", minute, second);
DisplayLCD(LCD_LINE3, string_shown_on_lcd);
break;
}
break;
}
switch (swt3)
{
case 0:
swt3 = 0;
state = 1; //Pausing
//DisplayLCD(LCD_LINE1, "Setting...");
break;
case 1:
state = 2; //Counting
//DisplayLCD(LCD_LINE1, "Counting...");
if (second > 0 && 1 == swt3)
{
Wait1MiliSecond();
G_elapsedTime++;
if (G_elapsedTime >= 1000)
{
second--;
G_elapsedTime = G_elapsedTime - 1000;
sprintf(string_shown_on_lcd, "%2d:%2d", minute, second);
DisplayLCD(LCD_LINE3, string_shown_on_lcd);
}
}
else if (0 == second && 0 == minute)
{
state = 3; //Setting
//DisplayLCD(LCD_LINE1, "Setting...");
}
break;
}
}
}
/******************************************************************************
* Function Name: r_main_userinit
* Description : User initialization routine
* Arguments : none
* Return Value : none
******************************************************************************/
void r_main_userinit(void)
{
uint16_t i;
/* Enable interrupt */
EI();
/* Output a logic LOW level to external reset pin*/
P13_bit.no0 = 0;
for (i = 0; i < 1000; i++)
{
NOP();
}
/* Generate a raising edge by ouput HIGH logic level to external reset pin */
P13_bit.no0 = 1;
for (i = 0; i < 1000; i++)
{
NOP();
}
/* Output a logic LOW level to external reset pin, the reset is completed */
P13_bit.no0 = 0;
/* Initialize SPI channel used for LCD */
R_SPI_Init(SPI_LCD_CHANNEL);
/* Initialize Chip-Select pin for LCD-SPI: P145 (Port 14, pin 5) */
R_SPI_SslInit(
SPI_SSL_LCD, /* SPI_SSL_LCD is the index defined in lcd.h */
(unsigned char *)&P14, /* Select Port register */
(unsigned char *)&PM14, /* Select Port mode register */
5, /* Select pin index in the port */
0, /* Configure CS pin active state, 0 means active LOW level */
0 /* Configure CS pin active mode, 0 means active per transfer */
);
/* Initialize LCD driver */
InitialiseLCD();
}
/******************************************************************************
End of file
******************************************************************************/