基于普中开发版的多功能闹钟
立即下载
资源介绍:
这里面底层驱动用的普中开发版的(有修改),其他的自己写的,矩阵键盘这些也是自己写的消抖比较好,另外我把u8,u16的定义直接放reg52.h里面了
#include "ired.h"
#include "key.h"
#include "ds1302.h"
#include "24c02.h"
#include "stdio.h"
#include "lcd1602.h"
#include "xpt2046.h"
#include "findnumber.h"
sbit motor=P3^1;
sbit buzzer=P2^5;
sbit sour=P3^3;
u8 keynow=0;
u8 jel=0,df=1;
u8 temp=0,light=0,uu=0;
u8 fond4_anas=0,fond4_addre=0;
//u8 gsmg_code[37] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71, 0x61};
u8 number_str[17]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71, 0x61};
u8 nuber_second[17]={0};
u8 smg_find(u8 k)
{
u8 y;
switch(k)
{
case 0:
y=0x3f;
break;
case 1:
y=0x06;
break;
case 2:
y=0x5b;
break;
case 3:
y=0x4f;
break;
case 4:
y=0x66;
break;
case 5:
y=0x6d;
break;
case 6:
y=0x7d;
break;
case 7:
y=0x07;
break;
case 8:
y=0x7f;
break;
case 9:
y=0x6f;
break;
case 10:
y=0x77;
break;
case 11:
y=0x7c;
break;
case 12:
y=0x39;
break;
case 13:
y=0x5e;
break;
case 14:
y=0x79;
break;
case 15:
y=0x71;
break;
case 16:
y=0x61;
break;
}
return y;
}
void lcdword(u8 k)
{
if(k<=4)
{
switch(k)
{
case 0:
strcpy(number_str,"1:close 2:sen ");
strcpy(nuber_second,"3:exe 4:TIM ");
break;
case 1:
strcpy(number_str,"if you want to ");
strcpy(nuber_second,"10:enter ");
break;
case 2:
sprintf(number_str, "TP:%4d rev:5", (int)temp); // ������ i ת��Ϊ�ַ������洢�� number_str ��
sprintf(nuber_second, "lg:%4d rev:6", (int)light); // ������ i ת��Ϊ�ַ������洢�� number_str ��
break;
case 3:
strcpy(number_str,"B: M: C: 9");
// ��� uu �ĵ�3λ����0��ʼ������ң�ؿ���
if (uu & 4) {
number_str[12] = 'O'; // J��ס"K"��Ҫ��
number_str[13] = 'K';
} else {
number_str[12] = 'N';
number_str[13] = 'O';
}
// ��� uu �����λ ������
if (uu & 1) {
number_str[2] = 'O';
number_str[3] = 'K';
} else {
number_str[2] = 'N';
number_str[3] = 'O';
}
// ��� uu �ĵ�2λ ���
if (uu & 2) {
number_str[7] = 'O';
number_str[8] = 'K';
} else {
number_str[7] = 'N';
number_str[8] = 'O';
}
strcpy(nuber_second,"re:5 re:6 re:7 R");
break;
case 4:
strcpy(number_str,"5:cl 6:rev 7:at ");
switch(fond4_addre++)
{
case 1:
fond4_anas=ds1302_read_byte(6)%10;
nuber_second[0]=fond4_anas+'0';
nuber_second[1]='-';
break;
case 2:
fond4_anas=ds1302_read_byte(4)%100;
nuber_second[2]=fond4_anas/10+'0';
nuber_second[3]=fond4_anas%10+'0';
nuber_second[4]='-';
break;
case 3:
fond4_anas=ds1302_read_byte(3)%100;
nuber_second[5]=fond4_anas/10+'0';
nuber_second[6]=fond4_anas%10+'0';
nuber_second[7]='-';
break;
case 4:
//ds1302_read_time(2);
fond4_anas=ds1302_read_byte(2)%100;
nuber_second[8]=fond4_anas/10+'0';
nuber_second[9]=fond4_anas%10+'0';
nuber_second[10]='-';
break;
case 5:
fond4_anas=ds1302_read_byte(1)%100;
nuber_second[11]=fond4_anas/10+'0';
nuber_second[12]=fond4_anas%10+'0';
nuber_second[13]='-';
break;
case 6:
fond4_anas=ds1302_read_byte(0)%100;
nuber_second[14]=fond4_anas/10+'0';
nuber_second[15]=fond4_anas%10+'0';
break;
}
fond4_addre%=7;
break;
}
}
else if(k<7)
{
strcpy(number_str,"5:+ 6:- 7:cl ");
if(k==5)
{
if(temp)
sprintf(nuber_second, "TP:%4d 9:return", (int)temp);
else
strcpy(nuber_second, "TP:clos 9:return");
}
else
{
if(light)
sprintf(nuber_second, "lg:%4d 9:return", (int)light);
else
strcpy(nuber_second,"lg:clos 9:return");
}
}
else if(k==7)
{
strcpy(number_str,"TB: rev:5 9:RE");
if ((uu & 8) != 0) {
number_str[3] = 'O';
number_str[4] = 'K';
} else {
number_str[3] = 'N';
number_str[4] = 'O';
}
strcpy(nuber_second,"LM: rev:6 TURN");
if ((uu & 16) != 0) {
nuber_second[3] = 'O';
nuber_second[4] = 'K';
} else {
nuber_second[3] = 'N';
nuber_second[4] = 'O';
}
}
else if(k<15)
{
strcpy(number_str,"5:+ 6:- 7:L 8:R");
//ds1302_read_time(14-k);
fond4_anas=ds1302_read_byte(14-k);
switch(k)
{
case 8:
sprintf(nuber_second, "year:%4d 9:re", (int)fond4_anas);
break;
case 9:
sprintf(nuber_second, "week:%4d 9:re", (int)fond4_anas);
break;
case 10:
sprintf(nuber_second, "month:%3d 9:re", (int)fond4_anas);
break;
case 11:
sprintf(nuber_second, "day:%3d 9:re", (int)fond4_anas);
break;
case 12:
sprintf(nuber_second, "hour:%3d 9:re", (int)fond4_anas);
break;
case 13:
sprintf(nuber_second, "min:%3d 9:re", (int)fond4_anas);
break;
case 14:
sprintf(nuber_second, "second:%3d 9:re", (int)fond4_anas);
break;
}
}
else if(k==15)
{
fond4_addre%=8;
strcpy(number_str,"5:t 6:+ 7:L 8:R");
fond4_anas=at24c02_read_byte(58);
if(fond4_addre==7)
sprintf(nuber_second+7,"%4d 9:re", (int) (week+1));
else
nuber_second[fond4_addre]=(fond4_anas & (1<timeset && timenow<(timeset+30))
uu^=1;
else if(timenow>(timeset+30) && timenow<(timeset+35));
uu &= 0xfe;
}
}
}
void main()
{
u8 message=0;
u8 save=0;
sour=1;
ds1302_init();//��ʼ��DS1302
lcd1602_init();//LCD1602��ʼ��
lcd1602_clear();
//at24c02_read_byte(1);
ired_init();
while(1)
{
keynow=keynumber();
switch (message++)
{
case 1:
time(0);
if(asd)
{
lcdword(find1(asd,& uu));
}
else
{
lcdword(find1(gired_data[3],& uu));
gired_data[3]=0;
}
time(1);
while(uu & 32)//������uu����Ϊ������0���������������������д��==1��!=0��==1��һ��
{
keynow=keynumber();
if(asd==0)
{
asd=gired_data[3];
gired_data[3]=0;
}
find1(asd, & uu);
}
break;
case 2:
if(save/8<30)
save += 8;
else
{
clockset();
save= save&0x07;
}
break;
case 3:
ds1302_read_time(sa