|
我是一个小白,刚学单片机,今天想用89c51和lcd1602,ds1302来做一个时钟,出现了SEGMENT TOO LARGE !!!,请大哥们帮忙看看问题在哪,蟹蟹
1,查百度给的提示是:
解决办法有二:
①在
复制前加码。②使用xdata数据空间(但是自己在写点阵屏显示程序时,将目标->内存模型中的值替换[Xarge:XDATA中的变量],不显示内容了,不知道为什么)。
2,按百度方法2操作,出现新错误:
构建目标'目标1'
编译main.c ...
C51致命错误-
ACTION:GOBAL优化
功能:_week_calculation
错误:无法优化功能
编译已终止。
使用以下解决方法:
#pragma OPTIMIZE(7)
/ *您的原始函数* /
_week_calculation(){
....
}
/ *原始功能的结尾* /
#pragma OPTIMIZE(8)
目标未创建
3,附上程序:(程序有点多)
- #include <reg51.h>
- //#include“ lcd.h”
- #include < intrins 。 h>
- //#include“ lcd.h”#定义
- LCD1602_DATAPINS P0位
- LCD1602_E = P2 ^ 2;
- 比特LCD1602_RW = P2 ^ 3;
- 比特LCD1602_RS = P2 ^ 4;
- 比特SCLK = P1 ^ 4;
- 比特RST = P1 ^ 5;
- 比特DSIO = P1 ^ 6;
- 比特SER = P2 ^ 0;
- 比特RCLK = P2 ^ 1;
- 比特SRCLK = P3 ^ 7;
- //位S1 = P2 ^ 2;
- //位S2 = P2 ^ 3;
- //位S3 = P2 ^ 4;
- 叮叮铃= P2 ^ 5;
- sbit SET = P3 ^ 3;
- 比特UP = P3 ^ 2;
- 比特DOWN = P3 ^ 0;
- sbit SHOW = P3 ^ 1;
- 设定的比特数= P2 ^ 7;
- sbit clkled = P2 ^ 6;
- //未签名的字符代码smgduan [11] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};
- //未签名的字符代码smgduan_dp [12] = {0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0x00,0x80};
- 无符号字符代码hcwei [8] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07};
- 无符号字符代码READ_RTC_ADDR [7] = {0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};
- 未签名的字符代码WRITE_RTC_ADDR [7] = {0x80,0x82,0x84,0x86,0x88,0x8a,0x8c};
- 无符号字符TIME [7] = {0,0x34,0x19,0x17,0x06,0x07,0x18};
- unsigned int time_trans [7] = {0,0,0,0,0,0,0};
- 无符号字符display_time [4] = {0,0,0,0};
- unsigned char display_monthday [4] = {1,1,1,1};
- unsigned char display_year [4] = {2,2,2,2};
- unsigned char display_second [2] = {0,0};
- unsigned char display_week = 0;
- 无符号字符时钟[4] = {0,8,3,0};
- 无符号字符ascii_display_time [8] = {0x30,0x30,0x30,0x30,0x30,'','',''};
- unsigned char ascii_display_monthday [8] = {0x30,0x30,0x30,0x30,0x30,'','',''};
- unsigned char ascii_display_year [8] = {0x30,0x30,0x30,0x30,'','','','};
- 无符号字符ascii_display_second [8] = {0x30,0x30,0x30,0x30,0x30,'','',''};
- // unsigned char ascii_week = 0x00;
- 无符号字符ascii_display_clock [8] = {0x30,0x30,0x30,0x30,0x30,'','',''};
- 无符号字符ascii_set_time [8] = {0x30,0x30,0x30,0x30,0x30,'','',''};
- unsigned char ascii_set_year [8] = {0x30,0x30,0x30,0x30,'','','','};
- 无符号字符ascii_set_second [8] = {0x30,0x30,0x30,0x30,0x30,'','','};
- 无符号字符ascii_set_clock [8] = {0x30,0x30,0x30,0x30,0x30,'','',''};
- unsigned char set_time [4] = {0,0,0,1};
- unsigned char set_monthday [4] = {0,0,0,2};
- unsigned char set_year [4] = {0,0,0,3};
- unsigned char set_clock [4] = {0,8,3,0};
- unsigned char set_write [7] = {0,0,0,0,0,0,0};
- 位flag_display = 1;
- 位flag_SET = 0;
- 位flag_clock = 0;
- 位flag_clock_arrive = 0;
- 位flag_exit = 0;
- 无符号字符display_mod = 0;
- 无符号字符set_mod = 0;
- 无符号字符flashbit = 0;
- 无符号字符t1_cnt = 0;
- 无符号字符t1_temp = 10;
- unsigned int year_temp;
- void Lcd1602_Delay1ms(unsigned int c)//误差0us
- {
- unsigned char a,b;
- for(; c> 0; c--)
- {
- for(b = 199; b> 0; b--)
- {
- for(a = 1; a> 0; a--);
- }
- }
-
- }
- void LcdWriteCom(unsigned char com)// 写入命令
- {
- LCD1602_E = 0; //使能
- LCD1602_RS = 0; //选择发送命令
- LCD1602_RW = 0; //选择
-
- 写入LCD1602_DATAPINS = com; //加入命令
- Lcd1602_Delay1ms(1); //等待数据稳定
- LCD1602_E = 1; //写入预设
- Lcd1602_Delay1ms(5); //保持时间
- LCD1602_E = 0;
- }
- void LcdWriteData(unsigned char dat)// 写入数据
- {
- LCD1602_E = 0; //使能清零
- LCD1602_RS = 1; //选择输入数据
- LCD1602_RW = 0; //选择
- 写入LCD1602_DATAPINS = dat; //
- 写入数据Lcd1602_Delay1ms(1);
- LCD1602_E = 1; //写入预设
- Lcd1602_Delay1ms(5); //保持时间
- LCD1602_E = 0;
- }
- void LcdInit()// LCD 初始化子程序
- {
- LcdWriteCom(0x38); //开显示
- LcdWriteCom(0x0c); //开显示不显示光标
- LcdWriteCom(0x06); //写一个指针加1
- LcdWriteCom(0x01); //清屏
- LcdWriteCom(0x80); //设置数据指针起点
- }
- void Ds1302Write(unsigned char addr,unsigned char dat)
- {
- unsigned char n;
- RST = 0;
- _nop_();
- SCLK = 0;
- _nop_();
- RST = 1;
- _nop_();
- 对于(n = 0; n <8; n ++)
- {
- DSIO = addr&0x01;
- 地址>> = 1;
- SCLK = 1;
- _nop_();
- SCLK = 0;
- _nop_();
- }
- 对于(n = 0; n <8; n ++)
- {
- DSIO = dat&0x01;
- dat >> = 1;
- SCLK = 1;
- _nop_();
- SCLK = 0;
- _nop_();
- }
- RST = 0;
- _nop_();
- }
- unsigned char Ds1302Read(unsigned char addr)
- {
- unsigned char n,dat,dat1;
- RST = 0;
- _nop_();
- SCLK = 0;
- _nop_();
- RST = 1;
- _nop_();
- for(n = 0; n <8; n ++)
- {
- DSIO = addr&0x01;
- 地址>> = 1;
- SCLK = 1;
- _nop_();
- SCLK = 0;
- _nop_();
- }
- _nop_();
- for(n = 0; n <8; n ++)
- {
- dat1 = DSIO;
- dat =(dat >> 1)| (dat1 << 7);
- SCLK = 1;
- _nop_();
- SCLK = 0;
- _nop_();
- }
- RST = 0;
- _nop_();
- SCLK = 1;
- _nop_();
- DSIO = 0;
- _nop_();
- DSIO = 1;
- _nop_();
- 返回数据
- }
- void Ds1302Init()
- {
- unsigned char n;
- Ds1302Write(0x8E,0X00);
- for(n = 0; n <7; n ++)
- {
- Ds1302Write(WRITE_RTC_ADDR [n],TIME [n]);
- }
- Ds1302Write(0x8E,0x80);
- }
- void Ds1302ReadTime()
- {
- unsigned char n;
- for(n = 0; n <7; n ++)
- {
- TIME [n] = Ds1302Read(READ_RTC_ADDR [n]);
- }
- }
- unsigned char week_calculation(unsigned char yearoo [],unsigned char monthdayoo [])
- {
- unsigned int year = 0,month = 0,day = 0;
- unsigned int week_temp = 0;
- year = yearoo [0] * 1000 + yearoo [1] * 100 + yearoo [2] * 10 + yearoo [3];
- month = monthdayoo [0] * 10 + monthdayoo [1];
- 天= monthdayoo [2] * 10 + monthdayoo [3];
- if(month == 1 || month == 2)
- {
- month + = 12;
- 年 - ;
- }
- week_temp =(day + 2 * month + 3 *(month + 1)/ 5 + year + year / 4-year / 100 + year / 400)%7 + 1;
- 返回week_temp;
- }
- void TimeReset()
- {
- unsigned char n;
- TR0 = 0;
- Ds1302Write(0x8E,0X00);
- 对于(n = 0; n <7; n ++)
- {
- Ds1302Write(WRITE_RTC_ADDR [n],set_write [n]);
- }
- Ds1302Write(0x8E,0x80);
- for(n = 0; n <4; n ++)
- {
- clock [n] = set_clock [n];
- }
- TR0 = 1;
- }
- void delay(unsigned int cnt)
- {
- while(cnt--);
- }
- void time_transmission()
- {
- set_write [1] =(set_time [2] << 4)| set_time [3];
- set_write [2] =(set_time [0] << 4)| set_time [1];
- set_write [3] =(set_monthday [2] << 4)| set_monthday [3];
- set_write [4] =(set_monthday [0] << 4)| set_monthday [1];
- set_write [5] = display_week;
- set_write [6] =(set_year [2] << 4)| set_year [3];
- }
- void time_procressing()
- {
- unsigned char i;
- for(i = 0; i <7; i ++)
- {
-
-
- time_trans [i] = TIME [i] / 16 * 10 + TIME [i]%16;
-
- }
- }
- void hc595send(unsigned char dat)
- {
- unsigned char a;
- SRCLK = 0;
- RCLK = 0;
- for(a = 0; a <8; a ++)
- {
- SER = dat >> 7;
- dat << = 1;
- SRCLK = 1;
- _nop_();
- _nop_();
- SRCLK = 0;
- }
- RCLK = 1;
- _nop_();
- _nop_();
- RCLK = 0;
- }
- void time_assign()
- {
- display_time [0] = time_trans [2] / 10;
- display_time [1] = time_trans [2]%10;
- display_time [2] = time_trans [1] / 10;
- display_time [3] = time_trans [1]%10;
- display_monthday [0] = time_trans [4] / 10;
- display_monthday [1] = time_trans [4]%10;
- display_monthday [2] = time_trans [3] / 10;
- display_monthday [3] = time_trans [3]%10;
- display_year [0] = 2;
- display_year [1] = 0;
- display_year [2] =(time_trans [6]%100)/ 10;
- display_year [3] = time_trans [6]%10;
- display_week = time_trans [5];
- // display_second [0] = 10;
- // display_second [1] = 11;
- display_second [0] = time_trans [0] / 10;
- display_second [1] = time_trans [0]%10;
- if(flag_display)
- {
- hc595send(hcwei [display_week]);
- }
- 其他
- {
- hc595send(0x00);
- }
- if(display_time [0] == clock [0] && display_time [1] == clock [1] && display_time [2] == clock [2] && display_time [3] == clock [3])
- {
- flag_clock_arrive = 1;
- }
- else
- {
- flag_clock_arrive = 0;
- }
- }
- void ascii_display_assign()
- {
- unsigned char i;
- //
- // if(flag_SET == 0)
- // {
- // switch(display_mod)
- // {
- //情况0:
- for(i = 0; i <2; i ++)
- {
- ascii_display_time [i] = display_time [i] + 0x30;
- // ascii_time [1] = asmg_temp [i] + 0x30;
- }
- ascii_display_time [2] = 0x3a;
- for(i = 3; i <5; i ++)
- {
- ascii_display_time [i] = display_time [i] + 0x30;
- // ascii_time [4] = asmg_temp [i] + 0x30;
- }
-
- // break;
- //
- //情况1:
- for(i = 0; i <2; i ++)
- {
- ascii_display_monthday [i] = display_monthday [i] + 0x30;
- // ascii_monthday [1] = asmg_temp [i] + 0x30;
- }
- ascii_display_monthday [2] = 0x3a;
- for(i = 3; i <5; i ++)
- {
- ascii_display_monthday [i] = display_monthday [i] + 0x30;
- // ascii_monthday [4] = asmg_temp [i] + 0x30;
- }
-
- // break;
- //
- //
- //
- //情况2:
- for(i = 0; i <4; i ++)
- {
- ascii_display_year [i] = display_year [i] + 0x30;
- // ascii_year [1] = asmg_temp [i] + 0x30;
- // ascii_year [2] = asmg_temp [i] + 0x30;
- // ascii_year [3] = asmg_temp [i] + 0x30;
- }
-
- // break;
- //
- //
- //情况3:
- //
-
-
- ascii_display_second [0] ='';
- ascii_display_second [1] ='';
- ascii_display_second [2] = 0x3a;
- for(i = 0; i <2; i ++)
- {
- ascii_display_second [i + 3] = display_second [i] + 0x30;
- // ascii_second [] = asmg_temp [i] + 0x30;
- }
- // break;
- //
- //情况4:
- for(i = 0; i <2; i ++)
- {
- ascii_display_clock [i] = clock [i] + 0x30;
- // ascii_time [1] = asmg_temp [i] + 0x30;
- }
- ascii_display_clock [2] = 0x3a;
- for(i = 3; i <5; i ++)
- {
- ascii_display_clock [i] = clock [i] + 0x30;
- // ascii_time [4] = asmg_temp [i] + 0x30;
- }
- //
- //中断;
- // //
- //
- //}
- }
- void ascii_set_assign()
- {
- unsigned char i;
- // if(flag_SET == 1)
- // {
- switch(set_mod)
- {
- case 0:
- if(t1_temp == 10)
- {
- for(i = 0; i <2; i ++)
- {
- ascii_set_time [i] = set_time [i] + 0x30;
- // ascii_time [1] = asmg_temp [i] + 0x30;
- }
- ascii_set_time [2] = 0x3a;
- for(i = 3; i <5; i ++)
- {
- ascii_set_time [i] = set_time [i] + 0x30;
- // ascii_time [4] = asmg_temp [i] + 0x30;
- }
- }
- else
- {
- switch(flashbit)
- {
- 情况0:
- ascii_set_time [0] = 0x5f;
-
- ascii_set_time [1] = set_time [1] + 0x30;
- ascii_set_time [2] = 0x3a;
- ascii_set_time [3] = set_time [2] + 0x30;
- ascii_set_time [4] = set_time [3] + 0x30;
- 打破;
- 情况1:
- ascii_set_time [0] = set_time [0] + 0x30;
- ascii_set_time [1] = 0x5f;
- ascii_set_time [2] = 0x3a;
- ascii_set_time [3] = set_time [2] + 0x30;
- ascii_set_time [4] = set_time [3] + 0x30;
- 打破;
- 情况2:
- ascii_set_time [0] = set_time [0] + 0x30;
- ascii_set_time [1] = set_time [1] + 0x30;
- ascii_set_time [2] = 0x3a;
- ascii_set_time [3] = 0x5f;
- ascii_set_time [4] = set_time [3] + 0x30;
- 打破;
- 情况3:
- ascii_set_time [0] = set_time [0] + 0x30;
- ascii_set_time [1] = set_time [1] + 0x30;
- ascii_set_time [2] = 0x3a;
- ascii_set_time [3] = set_time [2] + 0x30;
- ascii_set_time [4] = 0x5f;
- 打破;
-
-
- }
-
-
- }
-
-
-
-
- break;
- 情况1:
- if(t1_temp == 10)
- {
- for(i = 0; i <2; i ++)
- {
- ascii_set_monthday [i] = set_monthday [i] + 0x30;
- // ascii_time [1] = asmg_temp [i] + 0x30;
- }
- ascii_set_monthday [2] = 0x3a;
- for(i = 3; i <5; i ++)
- {
- ascii_set_monthday [i] = set_monthday [i] + 0x30;
- // ascii_time [4] = asmg_temp [i] + 0x30;
- }
- }
- 其他
- {
- switch(flashbit)
- {
- case 0:
- ascii_set_monthday [0] = 0x5f;
-
- ascii_set_monthday [1] = set_monthday [1] + 0x30;
- ascii_set_monthday [2] = 0x3a;
- ascii_set_monthday [3] = set_monthday [2] + 0x30;
- ascii_set_monthday [4] = set_monthday [3] + 0x30;
- 打破;
- 情况1:
- ascii_set_monthday [0] = set_monthday [0] + 0x30;
- ascii_set_monthday [1] = 0x5f;
- ascii_set_monthday [2] = 0x3a;
- ascii_set_monthday [3] = set_monthday [2] + 0x30;
- ascii_set_monthday [4] = set_monthday [3] + 0x30;
- 打破;
- 情况2:
- ascii_set_monthday [0] = set_monthday [0] + 0x30;
- ascii_set_monthday [1] = set_monthday [1] + 0x30;
- ascii_set_monthday [2] = 0x3a;
- ascii_set_monthday [3] = 0x5f;
- ascii_set_monthday [4] = set_monthday [3] + 0x30;
- 打破;
- 情况3:
- ascii_set_monthday [0] = set_monthday [0] + 0x30;
- ascii_set_monthday [1] = set_monthday [1] + 0x30;
- ascii_set_monthday [2] = 0x3a;
- ascii_set_monthday [3] = set_monthday [2] + 0x30;
- ascii_set_monthday [4] = 0x5f;
- 打破;
-
-
- }
-
-
- }
-
-
-
-
- 打破;
- 情况2:
-
- if(t1_temp == 10)
- {
-
- for(i = 0; i <4; i ++)
- {
- ascii_set_year [i] = set_year [i] + 0x30;
- //
- }
- }
- else
- {
- switch(flashbit)
- {
- 情况0:
- ascii_set_year [0] = 0x5f;
-
- ascii_set_year [1] = set_year [1] + 0x30;
-
- ascii_set_year [2] = set_year [2] + 0x30;
- ascii_set_year [3] = set_year [3] + 0x30;
- 打破;
- 情况1:
- ascii_set_year [0] = set_year [0] + 0x30;
- ascii_set_year [1] = 0x5f;
-
- ascii_set_year [2] = set_year [2] + 0x30;
- ascii_set_year [3] = set_year [3] + 0x30;
- 打破;
- 情况2:
- ascii_set_year [0] = set_year [0] + 0x30;
- ascii_set_year [1] = set_year [1] + 0x30;
-
- ascii_set_year [2] = 0x5f;
- ascii_set_year [3] = set_year [3] + 0x30;
- 打破;
- 情况3:
- ascii_set_year [0] = set_year [0] + 0x30;
- ascii_set_year [1] = set_year [1] + 0x30;
-
- ascii_set_year [3] = set_year [2] + 0x30;
- ascii_set_year [4] = 0x5f;
- 打破;
-
-
- }
-
-
- }
-
-
-
-
- 打破;
- 情况3:
- if(t1_temp == 10)
- {
- for(i = 0; i <2; i ++)
- {
- ascii_set_clock [i] = set_clock [i] + 0x30;
- // ascii_time [1] = asmg_temp [i] + 0x30;
- }
- ascii_set_clock [2] = 0x3a;
- for(i = 3; i <5; i ++)
- {
- ascii_set_clock [i] = set_clock [i] + 0x30;
- // ascii_time [4] = asmg_temp [i] + 0x30;
- }
- }
- else
- {
- switch(flashbit)
- {
- 情况0:
- ascii_set_clock [0] = 0x5f;
-
- ascii_set_clock [1] = set_clock [1] + 0x30;
- ascii_set_clock [2] = 0x3a;
- ascii_set_clock [3] = set_clock [2] + 0x30;
- ascii_set_clock [4] = set_clock [3] + 0x30;
- 打破;
- 情况1:
- ascii_set_clock [0] = set_clock [0] + 0x30;
- ascii_set_clock [1] = 0x5f;
- ascii_set_clock [2] = 0x3a;
- ascii_set_clock [3] = set_clock [2] + 0x30;
- ascii_set_clock [4] = set_clock [3] + 0x30;
- 打破;
- 情况2:
- ascii_set_clock [0] = set_clock [0] + 0x30;
- ascii_set_clock [1] = set_clock [1] + 0x30;
- ascii_set_clock [2] = 0x3a;
- ascii_set_clock [3] = 0x5f;
- ascii_set_clock [4] = set_clock [3] + 0x30;
- 打破;
- 情况3:
- ascii_set_clock [0] = set_clock [0] + 0x30;
- ascii_set_clock [1] = set_clock [1] + 0x30;
- ascii_set_clock [2] = 0x3a;
- ascii_set_clock [3] = set_clock [2] + 0x30;
- ascii_set_clock [4] = 0x5f;
- 打破;
-
-
- }
-
-
- }
-
-
-
-
- break;
- }
- } ////
-
- void datapros()
- // {
- //// Ds1302ReadTime();
- // time_procressing();
- // time_assign();
- // ascii_assign();
- // //
- //
- //
- //
- //
- //}
- void DigDisplay(unsigned char smg_temp [])
- {
- unsigned char i;
- LcdWriteCom(0x80);
-
- for(i = 0; i <8; i ++)
- {
-
- LcdWriteData(smg_temp [i]);
-
- }
-
-
- LcdWriteData('');
- LcdWriteData(0x73);
- LcdWriteData(0x70);
- LcdWriteData(0x65);
- LcdWriteData(0x65);
- LcdWriteData(0x64);
- LcdWriteData(0x3a);
- LcdWriteData(0x30);
-
- 延迟(100);
-
- }
- void clockoo()
- {
- if(flag_clock && flag_clock_arrive && t0_cnt == 9)
- {
- bell = 〜bell ;
- }
- else
- {
- bell = 0;
- }
- }
- unsigned char Leap(unsigned int year)
- {
- if(year%100 == 0)
- {
- if(year%400 == 0)返回1;
- 否则返回0;
- }
- else
- {
- if(year%4 == 0)返回1;
- 否则返回0;
- }
- }
- void sys_init()
- {
- setled = 1;
- clkled = 1;
- 钟= 0;
- hc595send(0x00);
- TMOD = 0x11;
- TL0 =(65536-50000)/ 256;
- TH0 =(65536-50000)%256;
- ET0 = 1;
- EA = 1;
- TR0 = 1;
- TL1 =(65536-50000)/ 256;
- TH1 =(65536-50000)%256;
- ET1 = 1;
- TR1 = 1;
- Ds1302Init();
- LcdInit();
- }
- void main()
- {
- sys_init();
- while(1)
- {
- if(flag_display)
- {
- switch(display_mod)
- {
- ascii_display_assign();
- 案例0:DigDisplay(ascii_display_time); break;
- 情况1:DigDisplay(ascii_display_monthday); break;
- 情况2:DigDisplay(ascii_display_year); break;
- 情况3:DigDisplay(ascii_display_second); break;
- 情况4:DigDisplay(ascii_display_clock); break;
- 默认:display_mod = 0; break;
- }
- }
- if(SET == 0)
- {
- delay(1500);
- if(SET == 0)
- {
- flag_SET = 1;
- setled = 0;
- }
- while(!SET);
- }
- if(!flag_SET)
- {
- if(UP == 0)
- {
- delay(2000);
- if(UP == 0)
- {
- flag_display =〜flag_display;
- }
- while(!UP);
- }
- if(DOWN == 0)
- {
- delay(2500);
- if(DOWN == 0)
- {flag_clock =!flag_clock;
- clkled =!flag_clock;
- } while(!DOWN);
- }
- if(SHOW == 0 && flag_display)
- {
- delay(2000);
- if(SHOW == 0)
- {
- display_mod ++;
- if(display_mod> 4)
- display_mod = 0;
- }
- while(!SHOW);
- }
- }
- else
- {
- while(flag_SET)
- {
- switch(set_mod)
- {
- case 0:ascii_set_assign(); DigDisplay(ascii_set_time); break;
- 情况1:ascii_set_assign(); DigDisplay(ascii_set_monthday); break;
- 情况2:ascii_set_assign(); DigDisplay(ascii_set_year); break;
- 情况3:ascii_set_assign(); DigDisplay(ascii_set_clock); break;
- 默认值:set_mod = 0; break;
- }
- if(UP == 0)
- {
- delay(2000);
- if(UP == 0)
- {
- switch(set_mod)
- {
- case 0:if(t1_temp == 10){if(set_time [flashbit] <9)set_time [flashbit] ++;} else {if(t1_temp <9)t1_temp ++ ;}打破;
- 情况1:if(t1_temp == 10){if(set_monthday [flashbit] <9)set_monthday [flashbit] ++;} else {if(t1_temp <9)t1_temp ++;} break;
- 情况2:if(t1_temp == 10){if(set_year [flashbit] <9)set_year [flashbit] ++;} else {if(t1_temp <9)t1_temp ++;} break;
- 情况3:if(t1_temp == 10){if(set_clock [flashbit] <9)set_clock [flashbit] ++;} else {if(t1_temp <9)t1_temp ++;} break;
- }
- } while(!UP);
- }
- if(DOWN == 0)
- {
- delay(2000);
- if(DOWN == 0)
- {
- switch(set_mod)
- {
- case 0:if(t1_temp == 10){if(set_time [flashbit]> 0)set_time [flashbit]-;} else {if(t1_temp> 0)t1_temp - ;}打破;
- 情况1:if(t1_temp == 10){if(set_monthday [flashbit]> 0)set_monthday [flashbit]-;} else {if(t1_temp> 0)t1_temp-;} break;
- 情况2:if(t1_temp == 10){if(set_year [flashbit]> 0)set_year [flashbit]-;}否则{if(t1_temp> 0)t1_temp-;} break;
- 情况3:if(t1_temp == 10){if(set_clock [flashbit]> 0)set_clock [flashbit]-;} else {if(t1_temp> 0)t1_temp-;} break;
- }
- } while(!DOWN);
- }
- if(SHOW == 0)
- {
- delay(2000);
- if(SHOW == 0)
- {
- if(t1_temp!= 10)
- {
- switch(set_mod)
- {
- case 0:set_time [flashbit] = t1_temp; t1_temp = 10; break;
- 情况1:set_monthday [flashbit] = t1_temp; t1_temp = 10; break;
- 情况2:set_year [flashbit] = t1_temp; t1_temp = 10; break;
- 情况3:set_clock [flashbit] = t1_temp; t1_temp = 10; break;
- }
- }
- flashbit ++;
- if(flashbit> 3)flashbit = 0;
- } while(!SHOW);
- }
- if(SET == 0)
- {
- delay(2000);
- if(SET == 0)
- {
- if(t1_temp!= 10)
- {
- switch(set_mod)
- {
- case 0:set_time [flashbit] = t1_temp; t1_temp = 10; break;
- 情况1:set_monthday [flashbit] = t1_temp; t1_temp = 10; break;
- 情况2:set_year [flashbit] = t1_temp; t1_temp = 10; break;
- 情况3:set_clock [flashbit] = t1_temp; t1_temp = 10; break;
- }
- }
- 开关(set_mod)
- {情况0:
- if((set_time [0] * 10 + set_time [1])> 24 || set_time [0]> 2){flag_exit = 1;}否则{if(set_time [0] == 2 && set_time [1] > 4){flag_exit = 1;}}
- if((set_time [2] * 10 + set_time [3])> 60 || set_time [2]> 5){flag_exit = 1;} break;
- 情况1:
- if((set_monthday [0] * 10 + set_monthday [1])> 12 || set_monthday [0]> 1){flag_exit = 1;}
- 否则{if(set_monthday [0] == 1 && set_monthday [1]> 2){flag_exit = 1;} if(set_monthday [0] == 0 && set_monthday [1] == 0){flag_exit = 1;}}
- if((set_monthday [2] * 10 + set_monthday [3])> 31 || set_monthday [0]> 3){flag_exit = 1;}休息;
- 情况2:
- if(set_year [0]!= 2 || set_year [1]!= 0){flag_exit = 1;}
- year_temp = set_year [0] * 1000 + set_year [1] * 100 + set_year [2] * 10 + set_year [ 3];
- if(!Leap(year_temp)){if(set_monthday [0] == 0 && set_monthday [1] == 2 && set_monthday [2] == 2 && set_monthday [3] == 9){flag_exit = 1;}}休息;
- 情况3:
- if((set_clock [0] * 10 + set_clock [1])> 24 || set_clock [0]> 2){flag_exit = 1;} else {if(set_clock [0] == 2 && set_clock [1]> 4){flag_exit = 1;}}
- if((set_clock [2] * 10 + set_clock [3])> 60 || set_clock [2]> 5){flag_exit = 1;} break;
- } set_mod ++; flashbit = 0;
- }
- while(!SET);
- if(flag_exit)
- {
- flag_exit = 0;
- set_mod = 0;
- flag_SET = 0;
- set = 1;
- flashbit = 0;
- 转到OUT;
- }
- else
- {
- if(set_mod == 4)
- {
- display_week = week_calculation(set_year,set_monthday);
- time_transmission();
- TimeReset();
- flag_exit = 0;
- set_mod = 0;
- flag_SET = 0;
- set = 1;
- flashbit = 0;
- 转到OUT;
- }
- }
- }
- }
- OUT:_nop_();
- }
- clockoo();
- }
- }
- 空隙GETTIME()中断1
- {
- TL0 =(65536-50000)/ 256;
- TH0 =(65536-50000)%256;
- t0_cnt ++;
- if(t0_cnt == 10)
- {
- Ds1302ReadTime();
- time_procressing();
- time_assign();
- t0_cnt = 0;
- }
- }
- void UpdataData()中断3
- {
- if(flag_SET)
- {
- TL1 =(65536-50000)/ 256;
- TH1 =(65536-50000)%256;
- t1_cnt ++;
- if(t1_cnt == 20)
- {
- switch(set_mod)
- {
- case 0:if(t1_temp == 10){t1_temp = set_time [flashbit]; set_time [flashbit] = 10;} else {set_time [flashbit] = t1_temp; t1_temp = 10;} break;
- 情况1:if(t1_temp == 10){t1_temp = set_monthday [flashbit]; set_monthday [flashbit] = 10;} else {set_monthday [flashbit] = t1_temp; t1_temp = 10;} break;
- 情况2:if(t1_temp == 10){t1_temp = set_year [flashbit]; set_year [flashbit] = 10;} else {set_year [flashbit] = t1_temp; t1_temp = 10;} break;
- 情况3:if(t1_temp == 10){t1_temp = set_clock [flashbit]; set_clock [flashbit] = 10;} else {set_clock [flashbit] = t1_temp; t1_temp = 10;} break;
-
-
- }
- t1_cnt = 0;
- }
-
- }
- 其他
- {
- TL1 =(65536-50000)/ 256;
- TH1 =(65536-50000)%256;
- t1_cnt ++;
- if(t1_cnt == 20)
- {
- unsigned char i;
- for(i = 0; i <4; i ++)
- {
- set_time [i] = display_time [i];
- set_monthday [i] = display_monthday [i];
- set_year [i] = display_year [i];
- set_clock [i] = clock [i];
-
-
- }
-
- t1_cnt = 0;
-
-
- }
- }
- }
复制代码 |
|