内容发布更新时间 : 2024/11/16 22:38:28星期一 下面是文章的全部内容请认真阅读。
#include
#define uint unsigned int #define uchar unsigned char
#define first_line 0x80 #define second_line 0x90 #define third_line 0x88 #define forth_line 0x98
#define sec_addr_pos 0x04 #define min_addr_pos 0x02 #define hor_addr_pos 0x00 #define day_addr_pos 0x05 #define mon_addr_pos 0x03 #define yer_addr_pos 0x01 #define wek_addr_pos 0x02 #define sbl_addr_pos 0x04 #define Tep_addr_pos 0x05 #define Tmp_addr_pos 0x06
uchar code line_one[]=\年10月31日 %uchar code line_two[]=\:22:45 %uchar code line_three[]=\星期五 - 23℃ %uchar str_wek[]=\一二三四五六日℃\
char second,minute,hour,day,week,month,year; uchar key_flag,mode_cnt;
uint temperature,symbol;//用于存储DS18B20采集的整个数据 uchar DS18B20_H;//用于存储DS18B20数据采集的整数部分 uchar DS18B20_L;//用于存储DS18B20数据采集的小数部分 uchar init_18B20_fail;
sfr LCD_DATA=0x80; sbit LCD_EN=P2^7; sbit LCD_RS=P2^6; sbit LCD_RW=P2^5; sbit DS_CLK=P3^6; sbit DS_RST=P3^5; sbit DS_IO=P3^4; sbit ACC0=ACC^0;
sbit ACC7=ACC^7; sbit key_1=P2^4; sbit key_2=P2^3; sbit key_3=P2^2; sbit DQ=P3^7;
void delay_ms(uint ms); void delay_us(uint us); bit busy(void);
void write_command(uchar command); void write_data(uchar dat); void lcd_pos(uchar x,uchar y); void LCD_init(void);
void Input_1byte(uchar TD); uchar Output_1byte(void);
uchar Read_DS1302(uchar DS_ADD);
void write_DS1302(uchar DS_ADD,uchar DS_DATE); void write_time(uchar addr,uchar num); uchar BCD_to_Dec(uchar num); void write_week(uchar num);
void write_date(uchar addr,uchar num); uchar readsecond(void); uchar readminute(void); uchar readhour(void); uchar readday(void); uchar readmonth(void); uchar readweek(void); uchar readyear(void); void readtime(void); void DS1302_init(void); void key_scan(void);
uchar DS18B20_read_byte(void);
void DS18B20_write_byte(uchar byte); uchar DS18B20_Init(void); uint read_temperature(void); void write_temp(uchar temp_h);
void write_symbol(uchar addr,uchar symbol); void display_18B20_err(void);
void main(void)
{
key_flag=0; second=20; minute=30; hour=10; day=31; week=3; month=12; year=16;
LCD_init();
/*while(1){
write_date(day_addr_pos,day); write_date(mon_addr_pos,month); write_date(yer_addr_pos,year); write_time(sec_addr_pos,second); write_time(min_addr_pos,minute); write_time(hor_addr_pos,hour); write_week(week); }*/
if(!(Read_DS1302(0x8E)&0x80)){ DS1302_init(); }
while(1){
key_scan();
if(key_flag==0){
second=Read_DS1302(0x81);
write_time(sec_addr_pos,BCD_to_Dec(second));
minute=Read_DS1302(0x83);
write_time(min_addr_pos,BCD_to_Dec(minute));
hour=Read_DS1302(0x85);