找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5057|回复: 0
打印 上一主题 下一主题
收起左侧

51单片机时钟DS1302+AT24C02 仿真+源码

[复制链接]
跳转到指定楼层
楼主
单片机时钟的仿真图电路图:


单片机时钟仿真工程文件以及源码打包下载:
1.zip (83.04 KB, 下载次数: 112)

功能相对完善,具有整点报时,闹钟等等功能 ,绝对的好东西,正在完善。加我,可以相互交流

程序源码:
  1. #include<reg52.h>
  2. #define uchar  unsigned char
  3. #define uint unsigned int

  4. sbit clk=P3^3;                 //  时钟控制引脚
  5. sbit io=P3^4;                 //   数据输入输出引脚
  6. sbit rst=P3^5;

  7. sbit k1=P2^3;//状态键
  8. sbit k2=P2^2;//加
  9. sbit k3=P2^1;//减
  10. sbit k4=P2^0;//查看键
  11. sbit beep=P3^2;//蜂鸣器

  12. sbit scl = P3^6;
  13. sbit sda = P3^7;

  14. sbit m1 = P2^4;
  15. sbit m2 = P2^5;//闪烁灯

  16. sbit m3 = P2^7;//标志灯

  17. bit anflg = 1;//查看标志
  18. bit write = 0;//写标志

  19. static uchar set = 0;
  20. static uint js = 0;
  21. static uint num = 0;

  22. void initTimer();
  23. void key();               
  24. void ShowTwinkle();
  25. uchar code wu[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
  26. uchar code du[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff,0xbf,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xc7,0x7f};
  27. uchar time_buf1[]={20,15,9,5,11,26,50,5};                //初值
  28. uchar  buf[]={0,0,0,0,0,0};
  29. uchar clockh=8,clockm=0,clocks=0;
  30. void clock();

  31. void delay(int z)//延时
  32. {
  33.         int x;
  34.         for(;z>0;z--)
  35.         for(x=110;x>0;x--);
  36. }

  37. void write_1302dat(uchar add,uchar dat)//写地址和数据
  38. {
  39.    uchar i;
  40.    clk=0;
  41.    rst=1;
  42.    for(i=0;i<8;i++)                          //写地址
  43.    {
  44.           clk=0;
  45.           io=add&0x01;
  46.                 clk=1;
  47.                 add>>=1;
  48.          }
  49.    for(i=0;i<8;i++)                         //写数据
  50.    {
  51.           clk=0;
  52.           io=dat&0x01;
  53.                 clk=1;
  54.                 dat>>=1;
  55.          }
  56.    clk=0;
  57.    rst=0;
  58. }

  59. uchar read_1302dat(uchar add)//写  读数据
  60. {
  61.    uchar i,dat;
  62.    clk=0;
  63.    rst=1;
  64.    for(i=0;i<8;i++)                //   写地址
  65.      {
  66.             clk=0;
  67.             io=add&0x01;
  68.                         clk=1;
  69.                         add>>=1;
  70.                  }
  71.    
  72.    for(i=0;i<8;i++)                         //读数据
  73.      {
  74.             clk=0;
  75.                         dat>>=1;
  76.             if(io==1)
  77.                   dat|=0x80;
  78.                         clk=1;
  79.                  }
  80.    rst=0;
  81.    clk=0;
  82.    return dat;
  83. }

  84. void Ds1302_Write_Time(void)//将数据写入相对应的地址
  85. {
  86.      
  87.   unsigned char i,tmp;
  88.         for(i=0;i<8;i++)
  89.          {                  //BCD处理
  90.                         tmp=time_buf1[i]/10;
  91.                         time_buf1[i]=time_buf1[i]%10;
  92.                         time_buf1[i]=time_buf1[i]+tmp*16;
  93.          }
  94.                         rst=0;
  95.                         clk=0;
  96.                         rst=1;   //启动
  97.             write_1302dat(0x8e,0x00);                                                //关闭写保护
  98.             write_1302dat(0x80,0x80);                                                //暂停
  99.             write_1302dat(0x90,0xa9);                                                //涓流充电
  100.             write_1302dat(0x8c,time_buf1[1]);                //年
  101.             write_1302dat(0x88,time_buf1[2]);                //月
  102.             write_1302dat(0x86,time_buf1[3]);                //日
  103. //    write_1302dat(ds1302_day_add,time_buf[7]);                //周
  104.             write_1302dat(0x84,time_buf1[4]);                //时
  105.             write_1302dat(0x82,time_buf1[5]);                //分
  106.             write_1302dat(0x80,time_buf1[6]);                //秒
  107.             write_1302dat(0x8a,time_buf1[7]);                //周
  108.             write_1302dat(0x8e,0x80);                                                //打开写保护

  109. }

  110. void Ds1302_Read_Time(void) //转换
  111. {
  112.   unsigned char i,tmp;
  113.         io=0;
  114.         time_buf1[1]=read_1302dat(0x8d); io=0;                //年  
  115.         time_buf1[2]=read_1302dat(0x89); io=0;                //月  
  116.         time_buf1[3]=read_1302dat(0x87); io=0;                //日  
  117.         time_buf1[4]=read_1302dat(0x85); io=0;                //时  
  118.         time_buf1[5]=read_1302dat(0x83); io=0;                //分  
  119.         time_buf1[6]=read_1302dat(0x81); io=0;                //秒  
  120.         time_buf1[7]=read_1302dat(0x8b); io=0;                //周  
  121.          

  122.         for(i=0;i<8;i++)
  123.         {           //BCD处理
  124.                 tmp=time_buf1[i]/16;
  125.                 time_buf1[i]=time_buf1[i]%16;
  126.                 time_buf1[i]=time_buf1[i]+tmp*10;
  127.         }
  128. }

  129. void clock()//闹钟函数,在一分钟之内只叫两次,一次15秒
  130. {
  131.         if(time_buf1[4]==clockh&&time_buf1[5]==clockm&&(time_buf1[6]>30&&time_buf1[6]<45||time_buf1[6]<15))
  132.         {
  133.                 num++;
  134.                
  135.                 if(num<40||num>80&&num<120||num>160&&num<200||num>240&&num<280)
  136.                 {
  137.                         beep=0;
  138.                         m3 =~ m3;
  139.                 }
  140.                 else
  141.                 beep=1;
  142.                 if(num>300)
  143.                 num=0;
  144.                 return;
  145.         }
  146.         else if(time_buf1[6]<=1&&time_buf1[5]==0&&set==0)
  147.         {
  148.                 m3 = 0;
  149.                 beep=0;
  150.         }
  151.         else
  152.         {
  153.                 m3 = 1;
  154.                 beep=1;
  155.         }        
  156. }


  157. void start()                            //启始信号
  158. {
  159.    sda=1;
  160.    scl=1;
  161.    sda=0;
  162. }
  163. void stop()                                   //结束信号
  164. {
  165.   sda=0;
  166.   scl=1;
  167.   sda=1;
  168. }
  169. void ack()                                  //检测应答
  170. {
  171.    uchar i;
  172.    sda=1;
  173.    scl=1;
  174.    while((sda==1)&(i<100)) i++;
  175.    scl=0;
  176. }
  177. void write_byte(uchar dat)                   //写一个字节
  178. {
  179.   uchar i;
  180.   for(i=0;i<8;i++)                 //循环移入八位数据,高位在前
  181.     {
  182.            dat<<=1;
  183.            scl=0;
  184.            sda=CY;
  185.            scl=1;
  186.         }
  187.         scl=0;
  188. }
  189. uchar read_byte()                                //读一个字节
  190. {
  191.   uchar i,dat;
  192.   for(i=0;i<8;i++)                           //循环读入八位数据,高位在前
  193.     {
  194.           dat<<=1;
  195.           scl=1;
  196.           if(sda==1)
  197.             dat|=0x01;
  198.           scl=0;
  199.         }
  200.         return dat;
  201. }
  202. void write_dat2402(uchar add,uchar dat)          //向24C02写一个字节进去
  203. {
  204.    start();
  205.    write_byte(0xa0);                                          // 器件地址以及写入操作
  206.    ack();
  207.    write_byte(add);                                                  // 写入数据的地址
  208.    ack();
  209.    write_byte(dat);                                                  // 写入的数据
  210.    ack();
  211.    stop();
  212. }
  213. uchar read_dat2402(uchar add)                //从24C02读一个字节进去
  214. {
  215.    uchar dat;
  216.    start();
  217.    write_byte(0xa0);                                // 器件地址以及写入操作
  218.    ack();
  219.    write_byte(add);                                        // 读出数据的地址
  220.    ack();
  221.    start();
  222.    write_byte(0xa1);                                // 器件地址以及读取操作
  223.    ack();
  224.    dat=read_byte();  
  225.    stop();
  226.    return dat;         
  227. }

  228. void init24c02()//初始化24c02
  229. {
  230.         sda=1;
  231.         scl=1;
  232. }


  233. void cunchu()//将数据存入24c02,加判断防止数据出错
  234. {
  235.         time_buf1[4] = read_dat2402(4);        //时
  236.                 if(time_buf1[4] > 23)
  237.                         time_buf1[4] = 0;
  238.                 delay(5);               
  239.         time_buf1[5] = read_dat2402(5);        //分
  240.                 if(time_buf1[5] > 59)
  241.                         time_buf1[5] = 0;
  242.                 delay(5);               
  243.         time_buf1[6] = read_dat2402(6);        //秒
  244.                 if(time_buf1[6] > 59)
  245.                         time_buf1[6] = 0;
  246.                 delay(5);               
  247. }


  248. void xie()//将数据写入24c02
  249. {
  250.         if(write == 1)
  251.         {
  252.                 write = 0;
  253.                 write_dat2402(4,time_buf1[4]);    //时
  254.                 write_dat2402(5,time_buf1[5]);    //分
  255.                 write_dat2402(6,time_buf1[6]);    //秒                                                                  
  256.         }                                                  
  257. }


  258. void main()//主函数
  259. {
  260.         rst=0;
  261.         clk=0;
  262.         write_1302dat(0x80,0x00);
  263.         initTimer();
  264.         init24c02();
  265.         cunchu();
  266.         
  267.         beep = 0;
  268.         m3 = 0;
  269.         delay(1000);
  270.         m3 = 1;
  271.         beep = 1;//开机响一次
  272.         
  273.         while(1)
  274.         {
  275.                 key();        //按键
  276.                 clock();
  277.                 Ds1302_Read_Time();
  278.                 ShowTwinkle();                //显示函数
  279.                 xie();
  280.         }        
  281. }                                               
  282. void time0() interrupt 1                        
  283. {                                               
  284.         static uchar cnt = 0;                          
  285.         TH0=(65536-1000)/256;                        
  286.         TL0=(65536-1000)%256;                        
  287.         js++;                                         
  288.         if(js>1000)                                    
  289.         {         
  290.                 write = 1; //每一秒向24c02写一次                                 
  291.                 js=0;                                       
  292.         }         
  293.         if(++cnt>5) cnt=0;                           
  294.         P0=0xff;                                      
  295.         P1=wu[cnt];                                   
  296.         P0=du[buf[cnt]];                              
  297. }

  298. void initTimer()//定时器初始化函数
  299. {
  300.         TMOD=0x01;
  301.         TH0=(65536-1000)/256;
  302.         TL0=(65536-1000)%256;
  303.         EA=1;
  304.         ET0=1;                                                                                 
  305.         TR0=1;
  306. }

  307. void key()//按键函数
  308. {
  309.         static uchar flg=0;
  310.         static uchar j = 0;
  311.         if(k1==0)
  312.         {
  313.                 if(flg==0)
  314.                 {
  315.                         flg=1;
  316.                         set++;
  317.                         if(set>9) set=0;
  318.                 }
  319.         }        
  320.         
  321.         else if(k2==0)
  322.         {
  323.                         if(flg==0)
  324.                         {
  325.                                 flg=1;
  326.                                 switch(set)
  327.                                         {        
  328.                                                 case 9 :        clockh++;//clockh
  329.                                                                                         if(clockh>23)
  330.                                                                                         clockh=0;
  331.                                                                                                                                                                                 break;
  332.                                                 
  333.                                                 case 8 :        clockm++;//clockm
  334.                                                                                         if(clockm>59)
  335.                                                                                         clockm=0;
  336.                                                                                                                                                                                 break;
  337.                                                 
  338.                                                 case 7 :        time_buf1[1]++;//年
  339.                                                                                         if(time_buf1[1]>99)
  340.                                                                                         time_buf1[1]=0;
  341.                                                                                         Ds1302_Write_Time();  break;
  342.                                                 
  343.                                                 case 6 :  time_buf1[2]++; //月
  344.                                                                                         if(time_buf1[2]>12)
  345.                                                                                   time_buf1[2]=1;
  346.                                                                                         Ds1302_Write_Time();  break;
  347.                                                 
  348.                                                 case 5 :         time_buf1[3]++; //日
  349.                                                                                         if(time_buf1[3]>31)
  350.                                                                                         time_buf1[3]=1;
  351.                                                                                         Ds1302_Write_Time();  break;

  352.                                                 case 4 :        time_buf1[7]++; //星期
  353.                                                                                         if(time_buf1[7]>7)
  354.                                                                                         time_buf1[7]=1;
  355.                                                                                         Ds1302_Write_Time();  break;
  356.                                                                                        
  357.                                                 case 3 :        time_buf1[4]++; //时
  358.                                                                                         if(time_buf1[4]>23)
  359.                                                                                         time_buf1[4]=0;
  360.                                                                                         Ds1302_Write_Time();  break;
  361.                                                 
  362.                                                 case 2 :  time_buf1[5]++; //分
  363.                                                                                         if(time_buf1[5]>59)
  364.                                                                                   time_buf1[5]=0;
  365.                                                                                         Ds1302_Write_Time();  break;
  366.                                                 
  367.                                                 case 1 :         time_buf1[6]++; //秒
  368.                                                                                         if(time_buf1[6]>59)
  369.                                                                                         time_buf1[6]=0;
  370.                                                                                         Ds1302_Write_Time();  break;
  371.                                         }
  372.                         }
  373.         }
  374.         
  375.         else if(k3==0)
  376.         {
  377.                         if(flg==0)
  378.                         {
  379.                                 flg=1;
  380.                                 switch(set)
  381.                                         {
  382.                                                 case 9 :  clockh--;                                                        //clockh
  383.                                                                                         if(clockh>100)
  384.                                                                                                 clockh=23;
  385.                                                                                         if(clockh<0)
  386.                                                                                                 clockh=23;
  387.                                                                                                                                                                                 break;

  388.                                                 case 8 :  clockm--;                                                        //clockm
  389.                                                                                         if(clockm>100)
  390.                                                                                                 clockm=59;
  391.                                                                                         if(clockm<0)
  392.                                                                                                 clockm=59;
  393.                                                                                                                                                                                 break;
  394.                                                 
  395.                                                 case 7 :  time_buf1[1]--;                                                        //年
  396.                                                                                         if(time_buf1[1]>100)
  397.                                                                                                 time_buf1[1]=99;
  398.                                                                                         if(time_buf1[1]<0)
  399.                                                                                                 time_buf1[1]=99;
  400.                                                                                         Ds1302_Write_Time();  break;
  401.                                                 
  402.                                                 case 6 :         time_buf1[2]--;                                                 //月
  403.                                                                                         if(time_buf1[2]>100)
  404.                                                                                                 time_buf1[2]=12;
  405.                                                                                         if(time_buf1[2] < 1)
  406.                                                                                                 time_buf1[2] = 12;
  407.                                                                                         Ds1302_Write_Time();  break;

  408.                                                 case 5 :        time_buf1[3]--;                                                        //日
  409.                                                                                         if(time_buf1[3]>100)
  410.                                                                                                 time_buf1[3]=31;
  411.                                                                                         if(time_buf1[3]<1)
  412.                                                                                                 time_buf1[3]=31;
  413.                                                                                         Ds1302_Write_Time();  break;

  414.                                                 case 4 :        time_buf1[7]--;                                                        //周
  415.                                                                                         if(time_buf1[7]>100)
  416.                                                                                                 time_buf1[7]=7;  
  417.                                                                                         if(time_buf1[7]<1)
  418.                                                                                                 time_buf1[7]=1;
  419.                                                                                         Ds1302_Write_Time();  break;
  420.                                                                                        
  421.                                                 case 3 :  time_buf1[4]--;                                                 //时
  422.                                                                                         if(time_buf1[4]>100)
  423.                                                                                                 time_buf1[4]=23;
  424.                                                                                         if(time_buf1[4]<0)
  425.                                                                                                 time_buf1[4]=23;
  426.                                                                                         Ds1302_Write_Time();  break;
  427.                                                 
  428.                                                 case 2 :         time_buf1[5]--;                                                 //分
  429.                                                                                         if(time_buf1[5]>100)
  430.                                                                                                 time_buf1[5]=59;
  431.                                                                                         if(time_buf1[5]<0)
  432.                                                                                                 time_buf1[5]=59;
  433.                                                                                         Ds1302_Write_Time();  break;
  434.                                                 
  435.                                                 case 1 :        time_buf1[6]--;                                                 //秒
  436.                                                                                         if(time_buf1[6]>100)
  437.                                                                                                 time_buf1[6]=59;  
  438.                                                                                         if(time_buf1[6]<0)
  439.                                                                                                 time_buf1[6]=59;
  440.                                                                                         Ds1302_Write_Time();  break;
  441.                                         }
  442.                         }
  443.         }                 
  444.         else if(k4 == 0)
  445.         {
  446.                 if(flg == 0)
  447.                 {
  448.                         flg =1;
  449.                         anflg = anflg*0;
  450.                         j++;
  451.                         if(j == 1)
  452.                                 set = 6;
  453.                         else if(j == 2)
  454.                                 set = 7;
  455.                         else if(j == 3)
  456.                                 set = 9;
  457.                         else
  458.                                 set = 0;
  459.                         
  460.                         if(j > 4)
  461.                                 j = 0;
  462.                 }
  463.         }
  464.         else
  465.                 flg=0;
  466. }

  467. void ShowTwinkle()//状态显示函数
  468. {
  469.         if(set==0)
  470.         {
  471.                
  472.                 buf[0]=time_buf1[4]/10;
  473.                 buf[1]=time_buf1[4]%10;
  474.         
  475.         
  476.         
  477.                 buf[2]=time_buf1[5]/10;
  478.                 buf[3]=time_buf1[5]%10;
  479.         
  480.         
  481.         
  482.                 buf[4]=time_buf1[6]/10;
  483.                 buf[5]=time_buf1[6]%10;
  484.                
  485.                 if(js<500)
  486.                 {
  487.                         m1 = 0;
  488.                         m2 = 0;
  489.                 }
  490.                 if(js>500)
  491.                 {
  492.                         m1 = 1;
  493.                         m2 = 1;
  494.                 }
  495.         }
  496.         
  497.         if(set==1)
  498.         {
  499.                 buf[0]=time_buf1[4]/10;
  500.                 buf[1]=time_buf1[4]%10;
  501.         
  502.                 buf[2]=time_buf1[5]/10;
  503.                 buf[3]=time_buf1[5]%10;
  504.                
  505.                 if(anflg == 1)
  506.                 {
  507.                         if(js<500)
  508.                         {
  509.                                 buf[4]=time_buf1[6]/10;
  510.                                 buf[5]=time_buf1[6]%10;               
  511.                                        
  512.                                 m1 = 0;m2 = 0;
  513.                         }
  514.                         if(js>500)
  515.                         {        
  516.                                 buf[4]=10;buf[5]=10;

  517.                                 m1 = 1;m2 = 1;                                
  518.                         }
  519.                 }
  520.                 else
  521.                 {
  522.                                 buf[4]=time_buf1[6]/10;
  523.                                 buf[5]=time_buf1[6]%10;               
  524.                                        
  525.                                 m1 = 0;m2 = 0;
  526.                 }
  527.         }

  528.         if(set==2)
  529.         {
  530.                 buf[0]=time_buf1[4]/10;
  531.                 buf[1]=time_buf1[4]%10;
  532.                 buf[4]=time_buf1[6]/10;
  533.                 buf[5]=time_buf1[6]%10;        
  534.                
  535.                 if(anflg == 1)
  536.                 {
  537.                         if(js<500)
  538.                         {
  539.                                 buf[2]=time_buf1[5]/10;
  540.                                 buf[3]=time_buf1[5]%10;
  541.                         
  542.                                 m1 = 0;m2 = 0;                                
  543.                         }
  544.                         if(js>500)
  545.                         {
  546.                                 buf[2]=10;buf[3]=10;        
  547.                                 m1 = 1;m2 = 1;                                                               
  548.                         }
  549.                 }
  550.                 else
  551.                 {
  552.                         buf[2]=time_buf1[5]/10;
  553.                         buf[3]=time_buf1[5]%10;
  554.                         
  555.                         m1 = 0;m2 = 0;                                
  556.                 }
  557.         }
  558.         
  559.         if(set==3)
  560.         {
  561.                 buf[2]=time_buf1[5]/10;
  562.                 buf[3]=time_buf1[5]%10;
  563.         
  564.                 buf[4]=time_buf1[6]/10;
  565.                 buf[5]=time_buf1[6]%10;        
  566.                
  567.                 if(anflg == 1)
  568.                 {
  569.                         if(js<500)
  570.                         {
  571.                                 buf[0]=time_buf1[4]/10;
  572.                                 buf[1]=time_buf1[4]%10;
  573.         
  574.                                 m1 = 0;m2 = 0;                                                               
  575.                         }
  576.                         if(js>500)
  577.                         {
  578.                                 buf[0]=10;buf[1]=10;
  579.         
  580.                                 m1 = 1;m2 = 1;                                                                                                
  581.                         }
  582.                 }
  583.                 else
  584.                 {
  585.                                 buf[0]=time_buf1[4]/10;
  586.                                 buf[1]=time_buf1[4]%10;
  587.         
  588.                                 m1 = 0;m2 = 0;                                                               
  589.                 }
  590.         }
  591.         if(set==4)
  592.         {
  593.                 buf[0]=time_buf1[2]/10;
  594.                 buf[1]=time_buf1[2]%10;
  595.         
  596.                 buf[2]=time_buf1[3]/10;
  597.                 buf[3]=time_buf1[3]%10;
  598.                
  599.                 buf[4]=10;        
  600.                         
  601.                 if(anflg == 1)
  602.                 {
  603.                         if(js<500)
  604.                         {
  605.                                 buf[5]=time_buf1[7];

  606.                                 m1 = 0;m2 = 0;                                                               
  607.                         }
  608.                         if(js>500)
  609.                         {               
  610.                                 buf[5]=10;        
  611.                                 m1 = 1;m2 = 1;                                                                                                                                
  612.                         }
  613.                 }
  614.                 else
  615.                 {
  616.                                 buf[5]=time_buf1[7];

  617.                                 m1 = 0;m2 = 0;                                                               
  618.                 }
  619.         }

  620.         if(set==5)
  621.         {
  622.                 buf[0]=time_buf1[2]/10;
  623.                 buf[1]=time_buf1[2]%10;
  624.                 buf[4]=10;
  625.                 buf[5]=time_buf1[7];        
  626.                
  627.                 if(anflg == 1)
  628.                 {
  629.                         if(js<500)
  630.                         {
  631.         
  632.                                 buf[2]=time_buf1[3]/10;
  633.                                 buf[3]=time_buf1[3]%10;
  634.         

  635.                                 m1 = 0;m2 = 0;                                                               
  636.                         }
  637.                         if(js>500)
  638.                         {               
  639.                                 buf[2]=10;buf[3]=10;

  640.                                 m1 = 1;m2 = 1;                                                                                                                                                        
  641.                         }
  642.                 }
  643.                 else
  644.                 {
  645.                         buf[2]=time_buf1[3]/10;
  646.                         buf[3]=time_buf1[3]%10;
  647.         
  648.                         m1 = 0;m2 = 0;                                                               
  649.                 }
  650.         }
  651.         
  652.         if(set==6)
  653.         {
  654.                 buf[2]=time_buf1[3]/10;
  655.                 buf[3]=time_buf1[3]%10;
  656.                
  657.                 buf[4]=10;
  658.                 buf[5]=time_buf1[7];        
  659.                
  660.                 if(anflg == 1)
  661.                 {

  662.                         if(js<500)
  663.                                 {
  664.                                         buf[0]=time_buf1[2]/10;
  665.                                         buf[1]=time_buf1[2]%10;
  666.                         
  667.                                         m1 = 0;m2 = 0;                                                                                                
  668.                                 }
  669.                         if(js>500)
  670.                                 {
  671.                                         buf[0]=10;
  672.                                         buf[1]=10;
  673.                         
  674.                                         m1 = 1;m2 = 1;                                                                                                                                                                                       
  675.                                 }
  676.                 }
  677.                 else
  678.                 {
  679.                                 buf[0]=time_buf1[2]/10;
  680.                                 buf[1]=time_buf1[2]%10;
  681.                         
  682.                                 m1 = 0;m2 = 0;                                                                                                        
  683.                 }
  684.         }
  685.         
  686.         if(set==7)
  687.         {
  688.                 buf[0]=2;
  689.                 buf[1]=0;
  690.                 buf[4]=10;buf[5]=10;
  691.                
  692.                 if(anflg == 1)
  693.                 {
  694.                         if(js<500)
  695.                         {                                
  696.                                 buf[2]=time_buf1[1]/10;        
  697.                                 buf[3]=time_buf1[1]%10;
  698.                                 
  699.                                 m1 = 0;m2 = 0;                                                                                                
  700.                         }
  701.                                 
  702.                         if(js>500)
  703.                         {        
  704.                                 buf[2]=10;buf[3]=10;                                                               
  705.                                 m1 = 1;m2 = 1;                                                                                                                                                                                       
  706.                         }
  707.                 }
  708.                 else
  709.                 {
  710.                         buf[2]=time_buf1[1]/10;        
  711.                         buf[3]=time_buf1[1]%10;
  712.                                 
  713.                         m1 = 0;m2 = 0;                                                                                                
  714.                 }
  715.         }
  716.         
  717.         if(set==8)
  718.         {
  719.                 buf[0]=clockh/10;
  720.                 buf[1]=clockh%10;
  721.                 buf[4]=clocks/10;
  722.                 buf[5]=clocks%10;
  723.                
  724.                 if(anflg == 1)
  725.                 {
  726.                         if(js<500)
  727.                         {
  728.                                 buf[2]=clockm/10;
  729.                                 buf[3]=clockm%10;

  730.                                 m1 = 0;m2 = 0;                                                                                                
  731.                         }
  732.                         if(js>500)
  733.                         {        
  734.                                 buf[2]=10;buf[3]=10;
  735.                                                 
  736.                                 m1 = 1;m2 = 1;                                                                                                                                                                                       
  737.                         }
  738.                 }
  739.                 else
  740.                 {
  741.                         buf[2]=clockm/10;
  742.                         buf[3]=clockm%10;
  743.                         
  744.                         m1 = 0;m2 = 0;                                                                                                
  745.                 }
  746.         }
  747.         
  748.         if(set==9)
  749.         {
  750.                 buf[2]=clockm/10;
  751.                 buf[3]=clockm%10;               
  752.                
  753.                 buf[4]=clocks/10;
  754.                 buf[5]=clocks%10;
  755.                
  756.                 if(anflg == 1)
  757.                 {
  758.                         if(js<500)
  759.                         {
  760.                                 buf[0]=clockh/10;
  761.                                 buf[1]=clockh%10;
  762.                                                 
  763.                                 m1 = 0;m2 = 0;                                                                                                
  764.                         }
  765.                         if(js>500)
  766.                         {
  767.                                 buf[0]=10;buf[1]=10;
  768.                                 
  769.                                 m1 = 1;m2 = 1;                                                                                                                                                                                       
  770.                         }
  771.                 }
  772.                 else
  773.                 {
  774.                         buf[0]=clockh/10;
  775.                         buf[1]=clockh%10;
  776.                                                 
  777.                         m1 = 0;m2 = 0;                                                                                                
  778.                 }
  779.         }        
  780. }
复制代码


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享淘帖 顶 踩
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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