📄 a.txt
字号:
if(DEC_VALUE != 0)
{
item = DS1302_read_byte(0x87) ;
item=(item/16)*10+item%16;
item--;
if(item == 0)item=31;
item=(item/10)*16+item%10;
DS1302_write_byte(0x8e,0x00);//允许写操作
DS1302_write_byte(0x86,item);
DEC_VALUE = 0 ;
}
}
else if(MODE_ON == 4)
{
uint8 item ;
LCD1602_write_cmd(0x8f) ;
if(INC_VALUE !=0 )
{
item = DS1302_read_byte(0x8b) ;
item=(item/16)*10+item%16;
item++;
if(item==8)item=1;
item=(item/10)*16+item%10;
DS1302_write_byte(0x8e,0x00);//允许写操作
DS1302_write_byte(0x8a,item);
INC_VALUE = 0 ;
}
if(DEC_VALUE != 0)
{
item = DS1302_read_byte(0x8b) ;
item=(item/16)*10+item%16;
item--;
if(item == 0)item=7;
item=(item/10)*16+item%10;
DS1302_write_byte(0x8e,0x00);//允许写操作
DS1302_write_byte(0x8a,item);
DEC_VALUE = 0 ;
}
}
else if(MODE_ON == 5)
{
uint8 item ;
LCD1602_write_cmd(0xc5) ;
if(INC_VALUE !=0 )
{
item = DS1302_read_byte(0x85) ;
item=(item/16)*10+item%16;
item++;
if(item==24)item=0;
item=(item/10)*16+item%10;
DS1302_write_byte(0x8e,0x00);//允许写操作
DS1302_write_byte(0x84,item);
INC_VALUE = 0 ;
}
if(DEC_VALUE != 0)
{
item = DS1302_read_byte(0x85) ;
item=(item/16)*10+item%16;
item--;
if(item == -1)item=23;
item=(item/10)*16+item%10;
DS1302_write_byte(0x8e,0x00);//允许写操作
DS1302_write_byte(0x84,item);
DEC_VALUE = 0 ;
}
}
else if(MODE_ON == 6)
{
uint8 item ;
LCD1602_write_cmd(0xc8) ;
if(INC_VALUE !=0 )
{
item = DS1302_read_byte(0x83) ;
item=(item/16)*10+item%16;
item++;
if(item==60)item=0;
item=(item/10)*16+item%10;
DS1302_write_byte(0x8e,0x00);//允许写操作
DS1302_write_byte(0x82,item);
INC_VALUE = 0 ;
}
if(DEC_VALUE != 0)
{
item = DS1302_read_byte(0x83) ;
item=(item/16)*10+item%16;
item--;
if(item == -1)item=59;
item=(item/10)*16+item%10;
DS1302_write_byte(0x8e,0x00);//允许写操作
DS1302_write_byte(0x82,item);
DEC_VALUE = 0 ;
}
}
else if(MODE_ON == 7)
{
uint8 item ;
LCD1602_write_cmd(0xcb) ;
if(INC_VALUE !=0 )
{
item = DS1302_read_byte(0x81) ;
item=(item/16)*10+item%16;
item++;
if(item==60)item=0;
item=(item/10)*16+item%10;
DS1302_write_byte(0x8e,0x00);//允许写操作
DS1302_write_byte(0x80,item);
INC_VALUE = 0 ;
}
if(DEC_VALUE != 0)
{
item = DS1302_read_byte(0x81) ;
item=(item/16)*10+item%16;
item--;
if(item == -1)item=59;
item=(item/10)*16+item%10;
DS1302_write_byte(0x8e,0x00);//允许写操作
DS1302_write_byte(0x80,item);
DEC_VALUE = 0 ;
}
}
else
{
LCD1602_write_cmd(0x86);
MODE_ON = 1 ;
}
if(OK_VALUE == 2 )
{
MODE_ON = 1 ;
OK_VALUE = 0 ;
LCD1602_write_cmd(0x01) ;
LCD1602_write_cmd(0x0c) ;
}
}
if(self_pos == 1 || self_pos == -2)
{ //uint8 alarm_temp ;
LCD1602_write_cmd(0x80);
LCD1602_write_string(0,1,"Alarm time ") ;
LCD1602_write_data(DS1302_read_byte(0xc1)/16+0x30);
LCD1602_write_data(DS1302_read_byte(0xc1)%16+0x30);
LCD1602_write_data(':');
LCD1602_write_data(DS1302_read_byte(0xc3)/16+0x30);
LCD1602_write_data(DS1302_read_byte(0xc3)%16+0x30);
if(ALARM_VALUE == 1)
LCD1602_write_string(2,0," ON") ;
else
LCD1602_write_string(2,0,"OFF") ;
LCD1602_write_cmd(0xcb) ;
LCD1602_write_data(DS1302_read_byte(0xc5)/16+0x30);
LCD1602_write_data(DS1302_read_byte(0xc5)%16+0x30);
LCD1602_write_data(':');
LCD1602_write_data(DS1302_read_byte(0xc7)/16+0x30);
LCD1602_write_data(DS1302_read_byte(0xc7)%16+0x30);
LCD1602_write_cmd(0x8c) ;
if(MODE_ON == 1)
{
uint8 item ;
if(INC_VALUE !=0 )
{
item = DS1302_read_byte(0xc1) ;
item=(item/16)*10+item%16;
item++;
if(item==24)item=0;
item=(item/10)*16+item%10;
DS1302_write_byte(0x8e,0x00);//允许写操作
DS1302_write_byte(0xc0,item);
INC_VALUE = 0 ;
}
if(DEC_VALUE != 0)
{
item = DS1302_read_byte(0xc1) ;
item=(item/16)*10+item%16;
item--;
if(item == -1)item=23;
item=(item/10)*16+item%10;
DS1302_write_byte(0x8e,0x00);//允许写操作
DS1302_write_byte(0xc0,item);
DEC_VALUE = 0 ;
}
}
else if(MODE_ON == 2)
{
uint8 item ;
LCD1602_write_cmd(0x8f) ;
if(INC_VALUE !=0 )
{
item = DS1302_read_byte(0xc3) ;
item=(item/16)*10+item%16;
item++;
if(item==60)item=0;
item=(item/10)*16+item%10;
DS1302_write_byte(0x8e,0x00);//允许写操作
DS1302_write_byte(0xc2,item);
INC_VALUE = 0 ;
}
if(DEC_VALUE != 0)
{
item = DS1302_read_byte(0xc3) ;
item=(item/16)*10+item%16;
item--;
if(item == -1)item=59;
item=(item/10)*16+item%10;
DS1302_write_byte(0x8e,0x00);//允许写操作
DS1302_write_byte(0xc2,item);
DEC_VALUE = 0 ;
}
}
else if(MODE_ON == 3)
{
LCD1602_write_cmd(0xc4);
if(INC_VALUE != 0 || DEC_VALUE !=0 )
{
INC_VALUE = 0 ;
DEC_VALUE = 0 ;
ALARM_VALUE^=1 ; //取反
}
}
else if(MODE_ON == 4)
{
uint8 item ;
LCD1602_write_cmd(0xcc) ;
if(INC_VALUE !=0 )
{
item = DS1302_read_byte(0xc5) ;
item=(item/16)*10+item%16;
item++;
if(item==24)item=0;
item=(item/10)*16+item%10;
DS1302_write_byte(0x8e,0x00);//允许写操作
DS1302_write_byte(0xc4,item);
INC_VALUE = 0 ;
}
if(DEC_VALUE != 0)
{
item = DS1302_read_byte(0xc5) ;
item=(item/16)*10+item%16;
item--;
if(item == -1)item=23;
item=(item/10)*16+item%10;
DS1302_write_byte(0x8e,0x00);//允许写操作
DS1302_write_byte(0xc4,item);
DEC_VALUE = 0 ;
}
}
else if(MODE_ON == 5)
{
uint8 item ;
LCD1602_write_cmd(0xcf) ;
if(INC_VALUE !=0 )
{
item = DS1302_read_byte(0xc7) ;
item=(item/16)*10+item%16;
item++;
if(item==60)item=0;
item=(item/10)*16+item%10;
DS1302_write_byte(0x8e,0x00);//允许写操作
DS1302_write_byte(0xc6,item);
INC_VALUE = 0 ;
}
if(DEC_VALUE != 0)
{
item = DS1302_read_byte(0xc7) ;
item=(item/16)*10+item%16;
item--;
if(item == -1)item=59;
item=(item/10)*16+item%10;
DS1302_write_byte(0x8e,0x00);//允许写操作
DS1302_write_byte(0xc6,item);
DEC_VALUE = 0 ;
}
}
else
{
LCD1602_write_cmd(0x8c);
MODE_ON = 1 ;
}
if(OK_VALUE == 2 )
{
MODE_ON = 1 ;
OK_VALUE = 0 ;
LCD1602_write_cmd(0x01) ;
LCD1602_write_cmd(0x0c) ;
}
}
if(self_pos == 2 || self_pos == -1)
{
if(DEC_VALUE != 0)
{
TR0 = 0;
DEC_VALUE = 0 ;
}
if(INC_VALUE != 0 )
{
TR0= 1 ;
INC_VALUE = 0 ;
}
LCD1602_write_cmd(0x0c) ;
LCD1602_write_string(4,1,"stopwatch") ;
LCD1602_write_char(5,0,stopwatch_minute/10+0x30) ;
LCD1602_write_char(6,0,stopwatch_minute%10+0x30) ;
LCD1602_write_char(7,0,':') ;
LCD1602_write_char(8,0,stopwatch_second/10+0x30) ;
LCD1602_write_char(9,0,stopwatch_second%10+0x30) ;
LCD1602_write_char(10,0,':') ;
LCD1602_write_char(11,0,stopwatch_count/10+0x30) ;
LCD1602_write_char(12,0,stopwatch_count%10+0x30) ;
if(OK_VALUE == 2 )
{
TR0 = 0 ;
stopwatch_minute = 0;
stopwatch_second = 0;
stopwatch_count = 0;
}
if(OK_VALUE == 3)
{
TR0 = 0 ;
MODE_ON = 1 ;
OK_VALUE = 0 ;
stopwatch_minute = 0;
stopwatch_second = 0;
stopwatch_count = 0;
LCD1602_write_cmd(0x01) ;
}
}
}
}
/***********************************************************
闹钟初始化
************************************************************/
void alarm_init(void)
{
DS1302_write_byte(0x8e,0x00) ;//允许写操作
DS1302_write_byte(0xc0,0x12) ;//第一个闹钟的时
DS1302_write_byte(0xc2,0x00) ;//第一个闹钟的分
DS1302_write_byte(0xc4,0x12) ;//第二个闹钟的时
DS1302_write_byte(0xc6,0x00) ;//第二个闹钟的分
DS1302_write_byte(0x8e,0x80) ;//禁止写操作
}
/***********************************************************
检测闹钟是否到了定时时间
************************************************************/
void alarm_check(void)
{
if(ALARM_VALUE ==1 && ALARM_ON == 1)
{
read_1 = DS1302_read_byte(0x85) ;
read_1 ^= DS1302_read_byte(0xc1);
read_2 = DS1302_read_byte(0x83) ;
read_2 ^= DS1302_read_byte(0xc3);
read_3 = DS1302_read_byte(0x85) ;
read_3 ^= DS1302_read_byte(0xc5);
read_4 = DS1302_read_byte(0x83) ;
read_4 ^= DS1302_read_byte(0xc7);
}
if((read_1 == 0) && (read_2 == 0) || (read_3 == 0) && (read_4 == 0))
{
if(ALARM_VALUE == 1)
{
speakers(100) ;
delay_ms(10);
speakers(10);
delay_ms(5);
ALARM_ON = 0 ;
}
}
}
/***********************************************************
主函数
************************************************************/
void main(void)
{
TMOD = 0x01 ;
TH0 = 0xd8 ;
TL0 = 0xf0 ;
EA = 1 ;
ET0 = 1 ;
TR0 = 0 ;
LCD1602_init() ;
alarm_init() ;
DS1302_init() ;
speakers(20) ;
while(1)
{
key_scan() ;
menu_display_1() ;
menu_display_2() ;
if(STOPWATCH_START == 0)
{
alarm_check();
DS1302_read_time();
tdat=rd_temperature(); //温度读取
tem_conv(); //温度转换
updata_buffer();
if(DIS_ON == 1)
{
display_buffer();
}
}
}
}
void t0_server(void) interrupt 1 using 1
{
TH0 = 0xd8 ;
TL0 = 0xf0 ;
stopwatch_count++ ;
if(stopwatch_count == 100)
{
stopwatch_second++ ;
stopwatch_count = 0 ;
}
if(stopwatch_second == 60)
{
stopwatch_second = 0 ;
stopwatch_minute++ ;
}
if(stopwatch_minute == 60)
{stopwatch_minute = 0 ;}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -