找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2150|回复: 4
收起左侧

出现SEGMENT TOO LARGE !(用89c51单片机和lcd1602,做一个时钟)

[复制链接]
ID:752852 发表于 2020-5-18 00:53 | 显示全部楼层 |阅读模式
我是一个小白,刚学单片机,今天想用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,附上程序:(程序有点多)
  1. #include <reg51.h>
  2. //#include“ lcd.h”
  3. #include < intrins 。 h>

  4. //#include“ lcd.h”#定义




  5. LCD1602_DATAPINS P0位
  6. LCD1602_E = P2 ^ 2;
  7. 比特LCD1602_RW = P2 ^ 3;
  8. 比特LCD1602_RS = P2 ^ 4;





  9. 比特SCLK = P1 ^ 4;
  10. 比特RST = P1 ^ 5;
  11. 比特DSIO = P1 ^ 6;



  12. 比特SER = P2 ^ 0;
  13. 比特RCLK = P2 ^ 1;
  14. 比特SRCLK = P3 ^ 7;



  15. //位S1 = P2 ^ 2;
  16. //位S2 = P2 ^ 3;
  17. //位S3 = P2 ^ 4;

  18. 叮叮铃= P2 ^ 5;
  19. sbit SET = P3 ^ 3;
  20. 比特UP = P3 ^ 2;
  21. 比特DOWN = P3 ^ 0;
  22. sbit SHOW = P3 ^ 1;


  23. 设定的比特数= P2 ^ 7;
  24. sbit clkled = P2 ^ 6;

  25. //未签名的字符代码smgduan [11] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};
  26. //未签名的字符代码smgduan_dp [12] = {0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0x00,0x80};




  27. 无符号字符代码hcwei [8] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07};
  28. 无符号字符代码READ_RTC_ADDR [7] = {0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};
  29. 未签名的字符代码WRITE_RTC_ADDR [7] = {0x80,0x82,0x84,0x86,0x88,0x8a,0x8c};

  30. 无符号字符TIME [7] = {0,0x34,0x19,0x17,0x06,0x07,0x18};

  31. unsigned int time_trans [7] = {0,0,0,0,0,0,0};

  32. 无符号字符display_time [4] = {0,0,0,0};
  33. unsigned char display_monthday [4] = {1,1,1,1};
  34. unsigned char display_year [4] = {2,2,2,2};
  35. unsigned char display_second [2] = {0,0};
  36. unsigned char display_week = 0;
  37. 无符号字符时钟[4] = {0,8,3,0};

  38. 无符号字符ascii_display_time [8] = {0x30,0x30,0x30,0x30,0x30,'','',''};
  39. unsigned char ascii_display_monthday [8] = {0x30,0x30,0x30,0x30,0x30,'','',''};
  40. unsigned char ascii_display_year [8] = {0x30,0x30,0x30,0x30,'','','','};
  41. 无符号字符ascii_display_second [8] = {0x30,0x30,0x30,0x30,0x30,'','',''};
  42. // unsigned char ascii_week = 0x00;
  43. 无符号字符ascii_display_clock [8] = {0x30,0x30,0x30,0x30,0x30,'','',''};


  44. 无符号字符ascii_set_time [8] = {0x30,0x30,0x30,0x30,0x30,'','',''};

  45. unsigned char ascii_set_year [8] = {0x30,0x30,0x30,0x30,'','','','};
  46. 无符号字符ascii_set_second [8] = {0x30,0x30,0x30,0x30,0x30,'','','};
  47. 无符号字符ascii_set_clock [8] = {0x30,0x30,0x30,0x30,0x30,'','',''};






  48. unsigned char set_time [4] = {0,0,0,1};
  49. unsigned char set_monthday [4] = {0,0,0,2};
  50. unsigned char set_year [4] = {0,0,0,3};
  51. unsigned char set_clock [4] = {0,8,3,0};
  52. unsigned char set_write [7] = {0,0,0,0,0,0,0};

  53. 位flag_display = 1;
  54. 位flag_SET = 0;
  55. 位flag_clock = 0;
  56. 位flag_clock_arrive = 0;
  57. 位flag_exit = 0;

  58. 无符号字符display_mod = 0;
  59. 无符号字符set_mod = 0;
  60. 无符号字符flashbit = 0;


  61. 无符号字符t1_cnt = 0;



  62. 无符号字符t1_temp = 10;
  63. unsigned int year_temp;



  64. void Lcd1602_Delay1ms(unsigned int c)//误差0us
  65. {
  66.     unsigned char a,b;
  67.         for(; c> 0; c--)
  68.         {
  69.                  for(b = 199; b> 0; b--)
  70.                  {
  71.                           for(a = 1; a> 0; a--);
  72.                  }      
  73.         }
  74.            
  75. }


  76. void LcdWriteCom(unsigned char com)//         写入命令
  77. {
  78. LCD1602_E = 0; //使能
  79.         LCD1602_RS = 0; //选择发送命令
  80.         LCD1602_RW = 0; //选择
  81.       
  82.         写入LCD1602_DATAPINS = com; //加入命令
  83.         Lcd1602_Delay1ms(1); //等待数据稳定

  84.         LCD1602_E = 1; //写入预设
  85.         Lcd1602_Delay1ms(5); //保持时间
  86.         LCD1602_E = 0;
  87. }


  88. void LcdWriteData(unsigned char dat)//         写入数据
  89. {
  90. LCD1602_E = 0; //使能清零
  91.         LCD1602_RS = 1; //选择输入数据
  92.         LCD1602_RW = 0; //选择

  93.         写入LCD1602_DATAPINS = dat; //
  94.         写入数据Lcd1602_Delay1ms(1);

  95.         LCD1602_E = 1; //写入预设
  96.         Lcd1602_Delay1ms(5); //保持时间
  97.         LCD1602_E = 0;
  98. }

  99. void LcdInit()// LCD         初始化子程序
  100. {
  101. LcdWriteCom(0x38); //开显示
  102.         LcdWriteCom(0x0c); //开显示不显示光标
  103.         LcdWriteCom(0x06); //写一个指针加1
  104.         LcdWriteCom(0x01); //清屏
  105.         LcdWriteCom(0x80); //设置数据指针起点
  106. }


  107. void Ds1302Write(unsigned char addr,unsigned char dat)
  108. {
  109.     unsigned char n;
  110.         RST = 0;
  111.         _nop_();
  112.         SCLK = 0;
  113.         _nop_();
  114.         RST = 1;
  115.          _nop_();
  116.     对于(n = 0; n <8; n ++)
  117.         {
  118.          DSIO = addr&0x01;
  119.          地址>> = 1;
  120.          SCLK = 1;
  121.          _nop_();
  122.          SCLK = 0;
  123.          _nop_();
  124.         }
  125.     对于(n = 0; n <8; n ++)
  126.         {
  127.          DSIO = dat&0x01;
  128.          dat >> = 1;
  129.          SCLK = 1;
  130.          _nop_();
  131.          SCLK = 0;
  132.          _nop_();
  133.         }   
  134.         RST = 0;
  135.         _nop_();
  136. }

  137. unsigned char Ds1302Read(unsigned char addr)
  138. {
  139.     unsigned char n,dat,dat1;
  140.         RST = 0;
  141.         _nop_();
  142.         SCLK = 0;
  143.         _nop_();
  144.         RST = 1;
  145.         _nop_();
  146.     for(n = 0; n <8; n ++)
  147.         {
  148.         DSIO = addr&0x01;
  149.         地址>> = 1;
  150.         SCLK = 1;
  151.         _nop_();
  152.         SCLK = 0;
  153.         _nop_();
  154.         }
  155.         _nop_();
  156.     for(n = 0; n <8; n ++)
  157.         {
  158.          dat1 = DSIO;
  159.          dat =(dat >> 1)| (dat1 << 7);
  160.         SCLK = 1;
  161.         _nop_();
  162.         SCLK = 0;
  163.         _nop_();
  164.         }

  165.     RST = 0;
  166.         _nop_();  
  167.           SCLK = 1;
  168.           _nop_();
  169.           DSIO = 0;
  170.           _nop_();
  171.           DSIO = 1;
  172.           _nop_();
  173.           返回数据   
  174. }

  175. void Ds1302Init()
  176. {
  177. unsigned char n;
  178. Ds1302Write(0x8E,0X00);
  179. for(n = 0; n <7; n ++)
  180. {
  181. Ds1302Write(WRITE_RTC_ADDR [n],TIME [n]);
  182. }
  183. Ds1302Write(0x8E,0x80);
  184. }

  185. void Ds1302ReadTime()
  186. {
  187. unsigned char n;
  188. for(n = 0; n <7; n ++)
  189. {
  190. TIME [n] = Ds1302Read(READ_RTC_ADDR [n]);
  191. }

  192. }

  193. unsigned char week_calculation(unsigned char yearoo [],unsigned char monthdayoo [])
  194. {
  195.    unsigned int year = 0,month = 0,day = 0;
  196.    unsigned int week_temp = 0;
  197.    year = yearoo [0] * 1000 + yearoo [1] * 100 + yearoo [2] * 10 + yearoo [3];
  198.    month = monthdayoo [0] * 10 + monthdayoo [1];
  199.    天= monthdayoo [2] * 10 + monthdayoo [3];
  200.    if(month == 1 || month == 2)
  201.    {
  202.             month + = 12;
  203.          年 - ;
  204.    }
  205.    week_temp =(day + 2 * month + 3 *(month + 1)/ 5 + year + year / 4-year / 100 + year / 400)%7 + 1;

  206.    返回week_temp;


  207. }








  208. void TimeReset()
  209. {
  210.     unsigned char n;
  211.         TR0 = 0;
  212.     Ds1302Write(0x8E,0X00);
  213.         对于(n = 0; n <7; n ++)
  214.         {
  215.          Ds1302Write(WRITE_RTC_ADDR [n],set_write [n]);
  216.         }
  217.     Ds1302Write(0x8E,0x80);
  218.         for(n = 0; n <4; n ++)
  219.         {
  220.          clock [n] = set_clock [n];
  221.         }
  222.         TR0 = 1;
  223. }

  224. void delay(unsigned int cnt)
  225. {
  226. while(cnt--);
  227. }

  228. void time_transmission()
  229. {

  230.   set_write [1] =(set_time [2] << 4)| set_time [3];
  231.   set_write [2] =(set_time [0] << 4)| set_time [1];
  232.   set_write [3] =(set_monthday [2] << 4)| set_monthday [3];
  233.   set_write [4] =(set_monthday [0] << 4)| set_monthday [1];
  234.   set_write [5] = display_week;
  235.   set_write [6] =(set_year [2] << 4)| set_year [3];



  236. }

  237. void time_procressing()
  238. {
  239.   unsigned char i;
  240.   for(i = 0; i <7; i ++)
  241.   {
  242.   
  243.   
  244.             time_trans [i] = TIME [i] / 16 * 10 + TIME [i]%16;
  245.   
  246.   }



  247. }






  248. void hc595send(unsigned char dat)
  249. {
  250. unsigned char a;
  251. SRCLK = 0;
  252. RCLK = 0;
  253. for(a = 0; a <8; a ++)
  254. {
  255.   SER = dat >> 7;
  256.   dat << = 1;
  257.   SRCLK = 1;
  258.   _nop_();
  259.   _nop_();
  260.   SRCLK = 0;
  261. }
  262. RCLK = 1;
  263. _nop_();
  264. _nop_();
  265. RCLK = 0;


  266. }


  267. void time_assign()
  268. {
  269.     display_time [0] = time_trans [2] / 10;
  270.         display_time [1] = time_trans [2]%10;
  271.         display_time [2] = time_trans [1] / 10;
  272.         display_time [3] = time_trans [1]%10;

  273.     display_monthday [0] = time_trans [4] / 10;
  274.         display_monthday [1] = time_trans [4]%10;
  275.         display_monthday [2] = time_trans [3] / 10;
  276.         display_monthday [3] = time_trans [3]%10;

  277.     display_year [0] = 2;
  278.         display_year [1] = 0;
  279.         display_year [2] =(time_trans [6]%100)/ 10;
  280.         display_year [3] = time_trans [6]%10;

  281.     display_week = time_trans [5];

  282. // display_second [0] = 10;
  283. // display_second [1] = 11;
  284.         display_second [0] = time_trans [0] / 10;
  285.         display_second [1] = time_trans [0]%10;

  286.     if(flag_display)
  287.         {
  288.          hc595send(hcwei [display_week]);
  289.         }
  290.         其他
  291.         {
  292.          hc595send(0x00);
  293.         }
  294.     if(display_time [0] == clock [0] && display_time [1] == clock [1] && display_time [2] == clock [2] && display_time [3] == clock [3])
  295.         {
  296.          flag_clock_arrive = 1;
  297.         }
  298.         else
  299.         {
  300.          flag_clock_arrive = 0;
  301.         }
  302. }



  303. void ascii_display_assign()
  304.         {
  305.             unsigned char i;
  306. //
  307. // if(flag_SET == 0)
  308. // {
  309. // switch(display_mod)
  310. // {
  311. //情况0:


  312.                                                                                                   for(i = 0; i <2; i ++)
  313.                                                                                                    {
  314.                                                                                                            ascii_display_time [i] = display_time [i] + 0x30;
  315. // ascii_time [1] = asmg_temp [i] + 0x30;
  316.                                                                                                    }

  317.                                                                                                            ascii_display_time [2] = 0x3a;
  318.                                                                                                   for(i = 3; i <5; i ++)
  319.                                                                                                    {
  320.                                                                                                            ascii_display_time [i] = display_time [i] + 0x30;
  321. // ascii_time [4] = asmg_temp [i] + 0x30;
  322.                                                                                                    }
  323.                                                                                                   
  324. // break;
  325. //
  326. //情况1:


  327.                                                                                                   for(i = 0; i <2; i ++)
  328.                                                                                                    {
  329.                                                                                                            ascii_display_monthday [i] = display_monthday [i] + 0x30;
  330. // ascii_monthday [1] = asmg_temp [i] + 0x30;
  331.                                                                                                    }

  332.                                                                                                            ascii_display_monthday [2] = 0x3a;
  333.                                                                                                   for(i = 3; i <5; i ++)
  334.                                                                                                    {
  335.                                                                                                            ascii_display_monthday [i] = display_monthday [i] + 0x30;
  336. // ascii_monthday [4] = asmg_temp [i] + 0x30;
  337.                                                                                                    }
  338.                                                                                                   
  339. // break;
  340. //
  341. //
  342. //
  343. //情况2:


  344.                                                                                                   for(i = 0; i <4; i ++)
  345.                                                                                                    {
  346.                                                                                                ascii_display_year [i] = display_year [i] + 0x30;
  347. // ascii_year [1] = asmg_temp [i] + 0x30;
  348. // ascii_year [2] = asmg_temp [i] + 0x30;
  349. // ascii_year [3] = asmg_temp [i] + 0x30;
  350.                                                                                                    }
  351.                                                                                                   



  352. // break;
  353. //
  354. //
  355. //情况3:
  356. //               
  357.                
  358.                                                                                          
  359.                                                                                        ascii_display_second [0] ='';
  360.                                                                                                ascii_display_second [1] ='';
  361.                                                                                                    ascii_display_second [2] = 0x3a;

  362.                                                                                                    for(i = 0; i <2; i ++)
  363.                                                                                                         {

  364.                                                                                                    ascii_display_second [i + 3] = display_second [i] + 0x30;
  365. // ascii_second [] = asmg_temp [i] + 0x30;



  366.                                                                                                         }

  367. // break;
  368. //
  369. //情况4:

  370.                                                                                                    for(i = 0; i <2; i ++)
  371.                                                                                                    {
  372.                                                                                                            ascii_display_clock [i] = clock [i] + 0x30;
  373. // ascii_time [1] = asmg_temp [i] + 0x30;
  374.                                                                                                    }

  375.                                                                                                            ascii_display_clock [2] = 0x3a;
  376.                                                                                                    for(i = 3; i <5; i ++)
  377.                                                                                                    {
  378.                                                                                                            ascii_display_clock [i] = clock [i] + 0x30;
  379. // ascii_time [4] = asmg_temp [i] + 0x30;
  380.                                                                                                    }

  381. //
  382. //中断;
  383. // //





  384. //
  385. //}

  386.     }

  387. void ascii_set_assign()

  388.    {
  389.                   unsigned char i;

  390. // if(flag_SET == 1)
  391. // {
  392.                                            switch(set_mod)
  393.                                                   {
  394.                                                            case 0:

  395.                                                                                                  if(t1_temp == 10)
  396.                                                                                                  {
  397.                                                                                                   for(i = 0; i <2; i ++)
  398.                                                                                                    {
  399.                                                                                                            ascii_set_time [i] = set_time [i] + 0x30;
  400. // ascii_time [1] = asmg_temp [i] + 0x30;
  401.                                                                                                    }

  402.                                                                                                            ascii_set_time [2] = 0x3a;
  403.                                                                                                   for(i = 3; i <5; i ++)
  404.                                                                                                    {
  405.                                                                                                            ascii_set_time [i] = set_time [i] + 0x30;
  406. // ascii_time [4] = asmg_temp [i] + 0x30;
  407.                                                                                                    }
  408.                                                                                                  }
  409.                                                                                                  else
  410.                                                                                                  {
  411.                                                                                                             switch(flashbit)
  412.                                                                                                              {
  413.                                                                                                                          情况0:
  414.                                                                                                                                    ascii_set_time [0] = 0x5f;
  415.                                                                                                                         
  416.                                                                                                                       ascii_set_time [1] = set_time [1] + 0x30;
  417.                                                                                                                                   ascii_set_time [2] = 0x3a;
  418.                                                                                                                                    ascii_set_time [3] = set_time [2] + 0x30;
  419.                                                                                                                                   ascii_set_time [4] = set_time [3] + 0x30;
  420.                                                                                                                                  打破;
  421.                                                                                                                          情况1:
  422.                                                                                                                                    ascii_set_time [0] = set_time [0] + 0x30;
  423.                                                                                                                           ascii_set_time [1] = 0x5f;
  424.                                                                                                                                   ascii_set_time [2] = 0x3a;
  425.                                                                                                                                    ascii_set_time [3] = set_time [2] + 0x30;
  426.                                                                                                                                   ascii_set_time [4] = set_time [3] + 0x30;
  427.                                                                                                                                  打破;
  428.                                                                                                                          情况2:
  429.                                                                                                                                    ascii_set_time [0] = set_time [0] + 0x30;
  430.                                                                                                                           ascii_set_time [1] = set_time [1] + 0x30;
  431.                                                                                                                                   ascii_set_time [2] = 0x3a;
  432.                                                                                                                                    ascii_set_time [3] = 0x5f;
  433.                                                                                                                                   ascii_set_time [4] = set_time [3] + 0x30;
  434.                                                                                                                                  打破;
  435.                                                                                                                          情况3:
  436.                                                                                                                                    ascii_set_time [0] = set_time [0] + 0x30;
  437.                                                                                                                           ascii_set_time [1] = set_time [1] + 0x30;
  438.                                                                                                                                   ascii_set_time [2] = 0x3a;
  439.                                                                                                                                    ascii_set_time [3] = set_time [2] + 0x30;
  440.                                                                                                                                   ascii_set_time [4] = 0x5f;
  441.                                                                                                                                  打破;
  442.                                                                                                                  
  443.                                                                                                                  
  444.                                                                                                                  }
  445.                                                                                                 
  446.                                                                                                 
  447.                                                                                                  }
  448.                                                                                                 
  449.                                                                                                 
  450.                                                                                                 
  451.                                                                                                   
  452.                                                                          break;

  453.                                                            情况1:

  454.                                                                                                  if(t1_temp == 10)
  455.                                                                                                  {
  456.                                                                                                   for(i = 0; i <2; i ++)
  457.                                                                                                    {
  458.                                                                                                            ascii_set_monthday [i] = set_monthday [i] + 0x30;
  459. // ascii_time [1] = asmg_temp [i] + 0x30;
  460.                                                                                                    }

  461.                                                                                                            ascii_set_monthday [2] = 0x3a;
  462.                                                                                                   for(i = 3; i <5; i ++)
  463.                                                                                                    {
  464.                                                                                                            ascii_set_monthday [i] = set_monthday [i] + 0x30;
  465. // ascii_time [4] = asmg_temp [i] + 0x30;
  466.                                                                                                    }
  467.                                                                                                  }
  468.                                                                                                  其他
  469.                                                                                                  {
  470.                                                                                                             switch(flashbit)
  471.                                                                                                              {
  472.                                                                                                                          case 0:
  473.                                                                                                                                    ascii_set_monthday [0] = 0x5f;
  474.                                                                                                                         
  475.                                                                                                                       ascii_set_monthday [1] = set_monthday [1] + 0x30;
  476.                                                                                                                                   ascii_set_monthday [2] = 0x3a;
  477.                                                                                                                                    ascii_set_monthday [3] = set_monthday [2] + 0x30;
  478.                                                                                                                                   ascii_set_monthday [4] = set_monthday [3] + 0x30;
  479.                                                                                                                                  打破;
  480.                                                                                                                          情况1:
  481.                                                                                                                                    ascii_set_monthday [0] = set_monthday [0] + 0x30;
  482.                                                                                                                           ascii_set_monthday [1] = 0x5f;
  483.                                                                                                                                   ascii_set_monthday [2] = 0x3a;
  484.                                                                                                                                    ascii_set_monthday [3] = set_monthday [2] + 0x30;
  485.                                                                                                                                   ascii_set_monthday [4] = set_monthday [3] + 0x30;
  486.                                                                                                                                  打破;
  487.                                                                                                                          情况2:
  488.                                                                                                                                    ascii_set_monthday [0] = set_monthday [0] + 0x30;
  489.                                                                                                                           ascii_set_monthday [1] = set_monthday [1] + 0x30;
  490.                                                                                                                                   ascii_set_monthday [2] = 0x3a;
  491.                                                                                                                                    ascii_set_monthday [3] = 0x5f;
  492.                                                                                                                                   ascii_set_monthday [4] = set_monthday [3] + 0x30;
  493.                                                                                                                                  打破;
  494.                                                                                                                          情况3:
  495.                                                                                                                                    ascii_set_monthday [0] = set_monthday [0] + 0x30;
  496.                                                                                                                           ascii_set_monthday [1] = set_monthday [1] + 0x30;
  497.                                                                                                                                   ascii_set_monthday [2] = 0x3a;
  498.                                                                                                                                    ascii_set_monthday [3] = set_monthday [2] + 0x30;
  499.                                                                                                                                   ascii_set_monthday [4] = 0x5f;
  500.                                                                                                                                  打破;
  501.                                                                                                                  
  502.                                                                                                                  
  503.                                                                                                                  }
  504.                                                                                                 
  505.                                                                                                 
  506.                                                                                                  }
  507.                                                                                                 
  508.                                                                                                 
  509.                                                                                                 
  510.                                                                                                   
  511.                                                                          打破;




  512.                                                              情况2:
  513.                


  514.                                                                                                  if(t1_temp == 10)
  515.                                                                                                  {
  516.                                                                                                   
  517.                                                                                                   for(i = 0; i <4; i ++)
  518.                                                                                                    {
  519.                                                                                                            ascii_set_year [i] = set_year [i] + 0x30;
  520. //                                                                       
  521.                                                                                                    }
  522.                                                                                                  }
  523.                                                                                                  else
  524.                                                                                                  {
  525.                                                                                                             switch(flashbit)
  526.                                                                                                              {
  527.                                                                                                                          情况0:
  528.                                                                                                                                    ascii_set_year [0] = 0x5f;
  529.                                                                                                                         
  530.                                                                                                                       ascii_set_year [1] = set_year [1] + 0x30;
  531.                                                                                                                                  
  532.                                                                                                                                    ascii_set_year [2] = set_year [2] + 0x30;
  533.                                                                                                                                   ascii_set_year [3] = set_year [3] + 0x30;
  534.                                                                                                                                  打破;
  535.                                                                                                                          情况1:
  536.                                                                                                                                    ascii_set_year [0] = set_year [0] + 0x30;
  537.                                                                                                                           ascii_set_year [1] = 0x5f;
  538.                                                                                                                                  
  539.                                                                                                                                    ascii_set_year [2] = set_year [2] + 0x30;
  540.                                                                                                                                   ascii_set_year [3] = set_year [3] + 0x30;
  541.                                                                                                                                  打破;
  542.                                                                                                                          情况2:
  543.                                                                                                                                    ascii_set_year [0] = set_year [0] + 0x30;
  544.                                                                                                                           ascii_set_year [1] = set_year [1] + 0x30;
  545.                                                                                                                        
  546.                                                                                                                                    ascii_set_year [2] = 0x5f;
  547.                                                                                                                                   ascii_set_year [3] = set_year [3] + 0x30;
  548.                                                                                                                                  打破;
  549.                                                                                                                          情况3:
  550.                                                                                                                                    ascii_set_year [0] = set_year [0] + 0x30;
  551.                                                                                                                           ascii_set_year [1] = set_year [1] + 0x30;
  552.                                                                                                                                  
  553.                                                                                                                                    ascii_set_year [3] = set_year [2] + 0x30;
  554.                                                                                                                                   ascii_set_year [4] = 0x5f;
  555.                                                                                                                                  打破;
  556.                                                                                                                  
  557.                                                                                                                  
  558.                                                                                                                  }
  559.                                                                                                 
  560.                                                                                                 
  561.                                                                                                  }
  562.                                                                                                 
  563.                                                                                                 
  564.                                                                                                 
  565.                                                                                                   
  566.                                                                          打破;


  567.                                                            情况3:

  568.                                                                                  if(t1_temp == 10)
  569.                                                                                                  {
  570.                                                                                                   for(i = 0; i <2; i ++)
  571.                                                                                                    {
  572.                                                                                                            ascii_set_clock [i] = set_clock [i] + 0x30;
  573. // ascii_time [1] = asmg_temp [i] + 0x30;
  574.                                                                                                    }

  575.                                                                                                            ascii_set_clock [2] = 0x3a;
  576.                                                                                                   for(i = 3; i <5; i ++)
  577.                                                                                                    {
  578.                                                                                                            ascii_set_clock [i] = set_clock [i] + 0x30;
  579. // ascii_time [4] = asmg_temp [i] + 0x30;
  580.                                                                                                    }
  581.                                                                                                  }
  582.                                                                                                  else
  583.                                                                                                  {
  584.                                                                                                             switch(flashbit)
  585.                                                                                                              {
  586.                                                                                                                          情况0:
  587.                                                                                                                                    ascii_set_clock [0] = 0x5f;
  588.                                                                                                                         
  589.                                                                                                                       ascii_set_clock [1] = set_clock [1] + 0x30;
  590.                                                                                                                                   ascii_set_clock [2] = 0x3a;
  591.                                                                                                                                    ascii_set_clock [3] = set_clock [2] + 0x30;
  592.                                                                                                                                   ascii_set_clock [4] = set_clock [3] + 0x30;
  593.                                                                                                                                  打破;
  594.                                                                                                                          情况1:
  595.                                                                                                                                    ascii_set_clock [0] = set_clock [0] + 0x30;
  596.                                                                                                                           ascii_set_clock [1] = 0x5f;
  597.                                                                                                                                   ascii_set_clock [2] = 0x3a;
  598.                                                                                                                                    ascii_set_clock [3] = set_clock [2] + 0x30;
  599.                                                                                                                                   ascii_set_clock [4] = set_clock [3] + 0x30;
  600.                                                                                                                                  打破;
  601.                                                                                                                          情况2:
  602.                                                                                                                                    ascii_set_clock [0] = set_clock [0] + 0x30;
  603.                                                                                                                           ascii_set_clock [1] = set_clock [1] + 0x30;
  604.                                                                                                                                   ascii_set_clock [2] = 0x3a;
  605.                                                                                                                                    ascii_set_clock [3] = 0x5f;
  606.                                                                                                                                   ascii_set_clock [4] = set_clock [3] + 0x30;
  607.                                                                                                                                  打破;
  608.                                                                                                                          情况3:
  609.                                                                                                                                    ascii_set_clock [0] = set_clock [0] + 0x30;
  610.                                                                                                                           ascii_set_clock [1] = set_clock [1] + 0x30;
  611.                                                                                                                                   ascii_set_clock [2] = 0x3a;
  612.                                                                                                                                    ascii_set_clock [3] = set_clock [2] + 0x30;
  613.                                                                                                                                   ascii_set_clock [4] = 0x5f;
  614.                                                                                                                                  打破;
  615.                                                                                                                  
  616.                                                                                                                  
  617.                                                                                                                  }
  618.                                                                                                 
  619.                                                                                                 
  620.                                                                                                  }
  621.                                                                                                 
  622.                                                                                                 
  623.                                                                                                 
  624.                                                                                                   
  625.                                                                          break;




  626.                                                   }







  627.           } ////
  628.             


  629. void datapros()         
  630. // {
  631. //// Ds1302ReadTime();
  632. // time_procressing();
  633. // time_assign();
  634. // ascii_assign();
  635. // //
  636. //
  637. //
  638. //
  639. //
  640. //}









  641. void DigDisplay(unsigned char smg_temp [])
  642. {
  643.                                    unsigned char i;

  644.                                        LcdWriteCom(0x80);
  645.                
  646.                                    for(i = 0; i <8; i ++)
  647.                                                  {
  648.          
  649.                                                      LcdWriteData(smg_temp [i]);
  650.          
  651.                                                  }
  652.                                                          
  653.                                                            
  654.                                                                                      LcdWriteData('');
  655.                                                                                          LcdWriteData(0x73);
  656.                                                                                          LcdWriteData(0x70);
  657.                                                                                          LcdWriteData(0x65);
  658.                                                                                          LcdWriteData(0x65);
  659.                                                                                          LcdWriteData(0x64);
  660.                                                                                          LcdWriteData(0x3a);
  661.                                                                                          LcdWriteData(0x30);      





  662.         
  663.                               延迟(100);

  664.                        
  665. }
























  666. void clockoo()
  667. {
  668.     if(flag_clock && flag_clock_arrive && t0_cnt == 9)
  669.         {
  670.         bell = 〜bell ;
  671.         }
  672.         else
  673.         {
  674.         bell = 0;
  675.         }
  676. }

  677. unsigned char Leap(unsigned int year)
  678. {
  679.     if(year%100 == 0)
  680.         {
  681.            if(year%400 == 0)返回1;
  682.            否则返回0;
  683.         }
  684.         else
  685.         {
  686.            if(year%4 == 0)返回1;
  687.            否则返回0;
  688.         }
  689. }

  690. void sys_init()
  691. {
  692.     setled = 1;
  693.         clkled = 1;
  694.         钟= 0;
  695.         hc595send(0x00);

  696.         TMOD = 0x11;
  697.         TL0 =(65536-50000)/ 256;
  698.         TH0 =(65536-50000)%256;
  699.         ET0 = 1;
  700.         EA = 1;
  701.         TR0 = 1;


  702.     TL1 =(65536-50000)/ 256;
  703.         TH1 =(65536-50000)%256;
  704.         ET1 = 1;     
  705.         TR1 = 1;
  706.         Ds1302Init();
  707.     LcdInit();
  708. }

  709. void main()
  710. {
  711.     sys_init();
  712.     while(1)
  713.     {
  714.         if(flag_display)
  715.         {
  716.             switch(display_mod)
  717.             {
  718.                                 ascii_display_assign();
  719.                 案例0:DigDisplay(ascii_display_time); break;
  720.                 情况1:DigDisplay(ascii_display_monthday); break;
  721.                 情况2:DigDisplay(ascii_display_year); break;
  722.                 情况3:DigDisplay(ascii_display_second); break;
  723.                 情况4:DigDisplay(ascii_display_clock); break;
  724.                 默认:display_mod = 0; break;
  725.             }
  726.         }
  727.         if(SET == 0)
  728.                 {
  729.                  delay(1500);
  730.                    if(SET == 0)
  731.                    {
  732.                      flag_SET = 1;
  733.                          setled = 0;
  734.                    }
  735.                    while(!SET);
  736.             }
  737.         if(!flag_SET)
  738.         {
  739.             if(UP == 0)
  740.                         {
  741.                            delay(2000);
  742.                            if(UP == 0)
  743.                            {
  744.                                flag_display =〜flag_display;
  745.                            }
  746.                            while(!UP);
  747.                         }
  748.             if(DOWN == 0)
  749.                         {
  750.                            delay(2500);
  751.                            if(DOWN == 0)
  752.                               {flag_clock =!flag_clock;
  753.                                      clkled =!flag_clock;
  754.                               } while(!DOWN);
  755.                     }
  756.             if(SHOW == 0 && flag_display)
  757.                         {
  758.                           delay(2000);
  759.                           if(SHOW == 0)
  760.                           {
  761.                              display_mod ++;
  762.                                  if(display_mod> 4)
  763.                                     display_mod = 0;
  764.                           }
  765.                           while(!SHOW);
  766.                     }
  767.         }
  768.         else
  769.         {
  770.             while(flag_SET)
  771.             {
  772.                 switch(set_mod)
  773.                 {
  774.                     case 0:ascii_set_assign(); DigDisplay(ascii_set_time); break;
  775.                     情况1:ascii_set_assign(); DigDisplay(ascii_set_monthday); break;
  776.                     情况2:ascii_set_assign(); DigDisplay(ascii_set_year); break;
  777.                     情况3:ascii_set_assign(); DigDisplay(ascii_set_clock); break;
  778.                     默认值:set_mod = 0; break;
  779.                 }
  780.                 if(UP == 0)
  781.                 {
  782.                     delay(2000);
  783.                     if(UP == 0)
  784.                     {
  785.                         switch(set_mod)
  786.                         {
  787.                             case 0:if(t1_temp == 10){if(set_time [flashbit] <9)set_time [flashbit] ++;} else {if(t1_temp <9)t1_temp ++ ;}打破;
  788.                             情况1:if(t1_temp == 10){if(set_monthday [flashbit] <9)set_monthday [flashbit] ++;} else {if(t1_temp <9)t1_temp ++;} break;
  789.                             情况2:if(t1_temp == 10){if(set_year [flashbit] <9)set_year [flashbit] ++;} else {if(t1_temp <9)t1_temp ++;} break;
  790.                             情况3:if(t1_temp == 10){if(set_clock [flashbit] <9)set_clock [flashbit] ++;} else {if(t1_temp <9)t1_temp ++;} break;
  791.                         }
  792.                     } while(!UP);
  793.                 }
  794.                 if(DOWN == 0)
  795.                 {
  796.                     delay(2000);
  797.                     if(DOWN == 0)
  798.                     {
  799.                         switch(set_mod)
  800.                         {
  801.                             case 0:if(t1_temp == 10){if(set_time [flashbit]> 0)set_time [flashbit]-;} else {if(t1_temp> 0)t1_temp - ;}打破;
  802.                             情况1:if(t1_temp == 10){if(set_monthday [flashbit]> 0)set_monthday [flashbit]-;} else {if(t1_temp> 0)t1_temp-;} break;
  803.                             情况2:if(t1_temp == 10){if(set_year [flashbit]> 0)set_year [flashbit]-;}否则{if(t1_temp> 0)t1_temp-;} break;
  804.                             情况3:if(t1_temp == 10){if(set_clock [flashbit]> 0)set_clock [flashbit]-;} else {if(t1_temp> 0)t1_temp-;} break;
  805.                         }
  806.                     } while(!DOWN);
  807.                 }
  808.                 if(SHOW == 0)
  809.                 {
  810.                     delay(2000);
  811.                     if(SHOW == 0)
  812.                     {
  813.                         if(t1_temp!= 10)
  814.                         {
  815.                             switch(set_mod)
  816.                             {
  817.                                 case 0:set_time [flashbit] = t1_temp; t1_temp = 10; break;
  818.                                 情况1:set_monthday [flashbit] = t1_temp; t1_temp = 10; break;
  819.                                 情况2:set_year [flashbit] = t1_temp; t1_temp = 10; break;
  820.                                 情况3:set_clock [flashbit] = t1_temp; t1_temp = 10; break;
  821.                             }
  822.                         }
  823.                         flashbit ++;
  824.                         if(flashbit> 3)flashbit = 0;
  825.                     } while(!SHOW);
  826.                 }
  827.                 if(SET == 0)
  828.                 {
  829.                     delay(2000);
  830.                     if(SET == 0)
  831.                     {
  832.                         if(t1_temp!= 10)
  833.                         {
  834.                             switch(set_mod)
  835.                             {
  836.                                 case 0:set_time [flashbit] = t1_temp; t1_temp = 10; break;
  837.                                 情况1:set_monthday [flashbit] = t1_temp; t1_temp = 10; break;
  838.                                 情况2:set_year [flashbit] = t1_temp; t1_temp = 10; break;
  839.                                 情况3:set_clock [flashbit] = t1_temp; t1_temp = 10; break;
  840.                             }
  841.                         }
  842.                         开关(set_mod)
  843.                         {情况0:
  844.                             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;}}
  845.                             if((set_time [2] * 10 + set_time [3])> 60 || set_time [2]> 5){flag_exit = 1;} break;
  846.                         情况1:
  847.                             if((set_monthday [0] * 10 + set_monthday [1])> 12 || set_monthday [0]> 1){flag_exit = 1;}
  848.                             否则{if(set_monthday [0] == 1 && set_monthday [1]> 2){flag_exit = 1;} if(set_monthday [0] == 0 && set_monthday [1] == 0){flag_exit = 1;}}
  849.                             if((set_monthday [2] * 10 + set_monthday [3])> 31 || set_monthday [0]> 3){flag_exit = 1;}休息;
  850.                         情况2:
  851.                             if(set_year [0]!= 2 || set_year [1]!= 0){flag_exit = 1;}
  852.                             year_temp = set_year [0] * 1000 + set_year [1] * 100 + set_year [2] * 10 + set_year [ 3];
  853.                             if(!Leap(year_temp)){if(set_monthday [0] == 0 && set_monthday [1] == 2 && set_monthday [2] == 2 && set_monthday [3] == 9){flag_exit = 1;}}休息;
  854.                         情况3:
  855.                             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;}}
  856.                             if((set_clock [2] * 10 + set_clock [3])> 60 || set_clock [2]> 5){flag_exit = 1;} break;
  857.                         } set_mod ++; flashbit = 0;
  858.                     }
  859.                     while(!SET);
  860.                     if(flag_exit)
  861.                                         {
  862.                                           flag_exit = 0;
  863.                                           set_mod = 0;
  864.                                           flag_SET = 0;
  865.                                           set = 1;
  866.                                           flashbit = 0;
  867.                                           转到OUT;
  868.                                         }
  869.                                         else
  870.                                         {
  871.                                           if(set_mod == 4)
  872.                                           {
  873.                                              display_week = week_calculation(set_year,set_monthday);
  874.                                                  time_transmission();
  875.                                                  TimeReset();
  876.                                                  flag_exit = 0;
  877.                                                  set_mod = 0;
  878.                                                  flag_SET = 0;
  879.                                                  set = 1;
  880.                                                  flashbit = 0;
  881.                                                  转到OUT;
  882.                                           }
  883.                     }
  884.                 }
  885.             }
  886. OUT:_nop_();            
  887.         }
  888.                 clockoo();
  889.     }
  890. }

  891. 空隙GETTIME()中断1
  892. {
  893.     TL0 =(65536-50000)/ 256;
  894.         TH0 =(65536-50000)%256;
  895.         t0_cnt ++;
  896.     if(t0_cnt == 10)
  897.         {
  898.         Ds1302ReadTime();
  899.         time_procressing();
  900.         time_assign();
  901.         t0_cnt = 0;
  902.         }
  903. }

  904. void UpdataData()中断3
  905. {
  906. if(flag_SET)
  907.   {
  908.           TL1 =(65536-50000)/ 256;
  909.         TH1 =(65536-50000)%256;
  910.         t1_cnt ++;
  911.     if(t1_cnt == 20)
  912.         {
  913.           switch(set_mod)
  914.           {
  915.                    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;
  916.                    情况1:if(t1_temp == 10){t1_temp = set_monthday [flashbit]; set_monthday [flashbit] = 10;} else {set_monthday [flashbit] = t1_temp; t1_temp = 10;} break;
  917.                    情况2:if(t1_temp == 10){t1_temp = set_year [flashbit]; set_year [flashbit] = 10;} else {set_year [flashbit] = t1_temp; t1_temp = 10;} break;
  918.                    情况3:if(t1_temp == 10){t1_temp = set_clock [flashbit]; set_clock [flashbit] = 10;} else {set_clock [flashbit] = t1_temp; t1_temp = 10;} break;
  919.       
  920.          
  921.           }
  922.          t1_cnt = 0;

  923.         }
  924.   
  925.   }
  926. 其他
  927. {
  928.         TL1 =(65536-50000)/ 256;
  929.         TH1 =(65536-50000)%256;
  930.         t1_cnt ++;
  931.     if(t1_cnt == 20)
  932.          {
  933.                  unsigned char i;
  934.                 for(i = 0; i <4; i ++)
  935.                    {
  936.                            set_time [i] = display_time [i];
  937.                            set_monthday [i] = display_monthday [i];
  938.                            set_year [i] = display_year [i];
  939.                            set_clock [i] = clock [i];
  940.                   
  941.                   
  942.                   }
  943.          
  944.                    t1_cnt = 0;
  945.          
  946.          
  947.          }


  948. }


  949. }
复制代码

出现新问题

出现新问题

按百度操作

按百度操作

百度

百度

出现了SEGMENT TOO LARGE !!!

出现了SEGMENT TOO LARGE !!!
回复

使用道具 举报

ID:213173 发表于 2020-5-18 09:03 | 显示全部楼层
楼主可能用的是所谓汉字编程软件,其实就是把关键字汉化,没有多少实际意义。反倒因为用汉字输入造成夹杂大量汉字字符导致错误从而无法通过编译。
回复

使用道具 举报

ID:752852 发表于 2020-5-18 09:30 | 显示全部楼层
wulin 发表于 2020-5-18 09:03
楼主可能用的是所谓汉字编程软件,其实就是把关键字汉化,没有多少实际意义。反倒因为用汉字输入造成夹杂大 ...

应该不是的,程序里面的汉字,是复制程序到帖子时,谷歌浏览器插件给自动翻译的,keil uvision4里面程序全是英文哦,
回复

使用道具 举报

ID:282850 发表于 2020-5-18 10:36 | 显示全部楼层
            switch(display_mod)
            {
                 案例0:DigDisplay(ascii_display_time); break;
                情况1:DigDisplay(ascii_display_monthday); break;
google直是醉了。

89C51的flash实在太小了,换89C52或58试试,这个不难。
回复

使用道具 举报

ID:584814 发表于 2020-5-19 11:17 | 显示全部楼层
1602怎么又和595干上了 ?这个程序是做什么的 ?
不如打包工程上传,或坛内找现成的1602时钟做参考。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表