📄 main.c
字号:
#include<reg51.h>
#include "time_ds1302_51.h"
#define uchar unsigned char
#define uint unsigned int
sbit DS = P2^3;
sbit OE = P2^4;
sbit RCK = P2^5;
sbit SCK = P2^6;
sbit SCLR = P2^7;
sbit Key1 = P1^0;
sbit Key2 = P1^1;
sbit Sel17 = P1^2;
sbit Sel18 = P1^3;
void Send_data(uint DAT);
code uint LED17[4][10]={
{0,0,0x06,0,0,0,0,0,0,0},
{0x68,0,0x38,0x30,0x50,0x70,0x78,0,0x78,0x70},
{0x380,0x300,0x180,0x380,0x300,0x280,0x280,0x380,0x380,0x380},
{0x3400,0,0x1c00,0x1800,0x2800,0x3800,0x3c00,0,0x3c00,0x3800},
};
code uint LED18[4][10]={
{0,0x0c,0x06,0,0,0,0,0,0,0},
{0x70,0x30,0x50,0x70,0x30,0x60,0x60,0x70,0x70,0x70},
{0x680,0,0x700,0x300,0x180,0x380,0x780,0,0x780,0x380},
{0x3800,0x1800,0x2800,0x3800,0x1800,0x3000,0x3000,0x3800,0x3800,0x3800},
};
uchar Time_get[7]={0x02,0x15,0x16,0x17,0x08,0x01,0x08};
uchar Time_set[7]={0x02,0x15,0x16,0x17,0x08,0x01,0x08};
uint Led17ram = 0x0000;
uint Led18ram = 0x0000;
void delay(uint t)
{
while(t--);
}
//功能:595传送数据函数
//参数:整型数据,高位在前,低位在后
void Send_data(uint DAT)
{
uchar i;
SCLR = 0;
SCLR = 1;
SCK = 0;
for(i = 16;i > 0;i--)
{
SCK = 0;
if(DAT & (1 << (i-1)))
DS = 1;
else
DS = 0;
SCK = 1;
}
OE = 1;
RCK = 1;
RCK = 0;
OE = 0;
}
void display(uchar t)
{
Send_data(Led17ram);
Sel17 = 0;
delay(t);
Sel17 = 1;
Send_data(Led18ram);
Sel18 = 0;
delay(t);
Sel18 = 1;
}
void change_dis(uchar LED_left,uchar LED_right)
{
Led17ram &= 0xc001;
Led18ram &= 0xc001;
Led17ram |= LED17[0][LED_left/16]+LED17[1][LED_left%16]+LED17[2][LED_right/16]+LED17[3][LED_right%16];
Led18ram |= LED18[0][LED_left/16]+LED18[1][LED_left%16]+LED18[2][LED_right/16]+LED18[3][LED_right%16];
}
uchar Key_scan(void)
{
if(Key1==0)
{
return 1;
}
else if(Key2==0)
{
return 2;
}
else
return 0;
}
/*
void initTimer(void)
{
TMOD=0x1;
TH0=0xb1;
TL0=0xe0;
}
void timer0(void) interrupt 1
{
TH0=0xb1;
TL0=0xe0;
//add your code here.
}
*/
void main(void)
{
uint count=0;
uint count1 = 50000;
uchar count2 = 50;
uint count3=0;
uchar temp;
uchar a=0;
/*initTimer();
TR0=1;
ET0=1;*/
init_ds1302();
//Set1302(Time_set);
//EA = 1;
while(1)
{
display(100);
count ++;
if(count>110)
{
count = 0;
count2++;
if(count2>50)
{
count2=0;
Get1302(Time_get);
change_dis(Time_get[2],Time_get[1]);
}
Led17ram ^= 0x4000;
if(Key_scan() != 0)
{
count1 = 500;
while(count1--)
{
display(100);
if(Key_scan() == 1)
{
count1 = 550;
temp = (Time_get[2]/16)*10+Time_get[2]%16;
count3++;
if(count3>50)
{
temp++;
count3=0;
}
if(temp > 23)
temp = 0;
Time_get[2] = (temp/10)*16+temp%10;
Set1302(Time_get);
change_dis(Time_get[2],Time_get[1]);
}
else if(Key_scan() == 2)
{
count1 = 550;
temp = (Time_get[1]/16)*10+Time_get[1]%16;
count3++;
if(count3>10)
{
temp++;
count3=0;
}
if(temp > 59)
temp = 0;
Time_get[1] = (temp/10)*16+temp%10;
Set1302(Time_get);
change_dis(Time_get[2],Time_get[1]);
}
}
}
else{;}
}
else{;}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -