-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.c
224 lines (211 loc) · 6.26 KB
/
display.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
#pragma once
#include "display.h"
#define GET_BIT(val,n) ( ( (val) & (1<<(n)) )?1:0 )
#define TEMP_30C *((unsigned int *)0x1A1A) //温度传感器校准后 1.5V,30C时 数据的地址
#define TEMP_85C *((unsigned int *)0x1A1C)
void date_to_str(char* str)
{
str[0]=date/10000000+'0';
str[1]=date%10000000/1000000+'0';
str[2]=date%1000000/100000+'0';
str[3]=date%100000/10000+'0';
str[5]=date%10000/1000+'0';
str[6]=date%1000/100+'0';
str[8]=date%100/10+'0';
str[9]=date%10+'0';
str[4]=str[7]='.';str[10]='\0';
update=0;
}
void time_to_str(long t,char* str)//将时间转化为字符
{
char hour=t/3600,minute=t%3600/60,second=t%60;
if(hour==24)hour=0;
str[0]=hour/10+'0';str[1]=hour%10+'0';
str[2]=':';
str[3]=minute/10+'0';str[4]=minute%10+'0';
str[5]=':';
str[6]=second/10+'0';str[7]=second%10+'0';
str[8]='\0';
}
void show_homepage()
{
static char _date[11],_week;
char _time[9],_temp[6];
if(GET_BIT(alarmctl,5))
{ time_to_str(time,_time);
OLED_ShowString(0*8, 2, _time);//时间
}
else {
if(time<43200){
time_to_str(time,_time);
OLED_ShowString(0*8, 2, _time);
OLED_ShowString(9*8, 2, "AM");
}
else if(time<46800){
time_to_str(time,_time);
OLED_ShowString(0*8, 2, _time);
OLED_ShowString(9*8, 2, "PM");
}
else {
time_to_str(time-43200,_time);
OLED_ShowString(0*8, 2, _time);
OLED_ShowString(9*8, 2, "PM");
}
}
if(update){date_to_str(_date);_week=week();}
OLED_ShowString(0*8,0, _date);//日期
OLED_ShowCHinese(12*8,2,17);
OLED_ShowCHinese(14*8,2,_week+18);//星期
get_temp(_temp);
OLED_ShowString(11*8,0, _temp);
OLED_ShowCHinese(0,6,14);
OLED_ShowCHinese(16,6,15);
OLED_ShowCHinese(32,6,16);
}
void show_menu()
{
OLED_Clear();
OLED_ShowString(0, 0,"1.");//1.设置时间
OLED_ShowCHinese(2*8, 0, 3);
OLED_ShowCHinese(4*8, 0, 4);
OLED_ShowCHinese(6*8, 0, 5);
OLED_ShowCHinese(8*8, 0, 6);
OLED_ShowString(0, 2,"2.");//2.闹钟
OLED_ShowCHinese(2*8, 2, 7);
OLED_ShowCHinese(4*8, 2, 8);
OLED_ShowString(0, 4,"3.");//3.秒表
OLED_ShowCHinese(2*8, 4, 9);
OLED_ShowCHinese(4*8, 4, 10);
OLED_ShowString(0, 6,"4.");//4.倒计时
OLED_ShowCHinese(2*8, 6, 11);
OLED_ShowCHinese(4*8, 6, 12);
OLED_ShowCHinese(6*8, 6, 13);
char ch;
do{
ch=getnum();
if(mode!=1){OLED_Clear();return;}
}while(ch<0||ch>4);
//if(ch=='#')mode/=10;
mode=10*mode+ch;
OLED_Clear();
}
void choose_alarm()
{
char i=0;
char ala[11];ala[1]='.';
for(i=0;i<4;i++)
{
ala[0]='1'+i;
time_to_str(alarm[i],ala+2);
OLED_ShowString(0*8, i*2, ala);
OLED_ShowCHinese(14*8,i*2,GET_BIT(alarmctl,i)+27);
}
do{
i=getch();
if(i>='A'&&i<='D')
{alarmctl ^= 1<<(i-'A');
OLED_ShowCHinese(14*8,(i-'A')*2,GET_BIT(alarmctl,i-'A')+27);}
if(i>='0'&&i<='9')
mode=10*mode+i-'0';
}while(mode==12);
flash_erase(0x1900);
save_alarm();
flash_write_long((long*)0x1910,alarmctl);
}
char second_10=0,_timer[12];//0.1s
void show_timer()
{
//static char _time[12];
if(timer==-1)
{
time_to_str(0,_timer);
_timer[8]='\0',_timer[9]='0',_timer[10]='\0';
OLED_ShowString(0*8, 2, _timer);
OLED_ShowCHinese(8*12,0,28);OLED_ShowCHinese(8*14,0,29);//开始
do{
_timer[11]=getch();
if(mode!=13){OLED_Clear();return;}
}while(_timer[11]!='A');
timer=0;
}
if(timer<99999){OLED_ShowCHinese(8*12,2,30);OLED_ShowCHinese(8*14,2,31);}//暂停
else {OLED_ShowCHinese(8*12,2,34);OLED_ShowCHinese(8*14,2,35);
OLED_ShowCHinese(8*12,4,32);OLED_ShowCHinese(8*14,4,33);}
if(getchar()=='B')//暂停、继续
{
if(timer<99999)timer+=100000;
else timer-=100000;
}
if(getchar()=='C')//清零
{timer=-1;OLED_Clear();return;}
if(timer<99999)
{
//time_to_str(timer,_timer);
_timer[8]='.';_timer[9]=second_10+'0';//_timer[10]='\0';
OLED_ShowString(0*8, 2, _timer);
}
}
//中断只使0.1s位+1,但不再刷新屏幕;刷新屏幕放到了main的while(1)里
//否则若将OLED_SHOW放在该中断中,会花屏,猜测原因是上一次刷新屏幕未结束又触发了中断,死嵌套
#pragma vector=TIMERB0_VECTOR
__interrupt void TIMERB0_ISR (void)
{
if(timer>=0&&timer<99999)
{ second_10 = second_10 + 1;
if (second_10 == 10)
{ second_10 = 0;
time_to_str(timer, _timer);
}
}
}
/*
#pragma vector=TIMER2_A0_VECTOR
__interrupt void TIMER_ISR(void)
{
second_10=second_10+1;
if(second_10==10){
second_10=0;timer++;
time_to_str(timer,_timer);
}
if(mode==13){
_timer[9]=second_10+'0';
OLED_ShowString(0*8, 2, _timer);
}
}*/
void show_counter()
{
//OLED_Clear();
//OLED_ShowCHinese(8*0,6,25);OLED_ShowCHinese(8*2,6,26);//确认
//OLED_ShowCHinese(8*12,0,28);OLED_ShowCHinese(8*14,0,29);//开始
if(counter<99999)
{OLED_ShowCHinese(8*12,2,30);OLED_ShowCHinese(8*14,2,31);}//暂停
else {OLED_ShowCHinese(8*12,2,34);OLED_ShowCHinese(8*14,2,35);}
OLED_ShowCHinese(8*12,4,32);OLED_ShowCHinese(8*14,4,33);//清零
//counter--;
static char _time[9];
if(getchar()=='B')
{if(counter<99999)counter+=100000;
else counter-=100000;}
else if(getchar()=='C')
counter=-1;
if(counter<99999)
time_to_str(counter,_time);
OLED_ShowString(0*8, 2, _time);
if(counter==0)
{belling=10;bell_on();led_on();return;}
}
int temp;
void get_temp(char* _temp)
{
//temp=( 30+(temp-TEMP_30C)*55.0/(TEMP_85C-TEMP_30C) )*10;
temp=(30+(temp-2225)*11.0/69.0)*10;
_temp[5]='\0';_temp[4]='C';
_temp[0]=temp/100+'0';_temp[1]=temp%100/10+'0';
_temp[2]='.';_temp[3]=temp%10+'0';
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
if(__even_in_range(ADC12IV,34)==6)
temp=ADC12MEM0;
}