C中LED的实时时钟,增量和显示

时间:2013-12-15 06:13:29

标签: c embedded clock

我的时钟循环,如果键盘发送x值为30,我试图增加30秒。然后显示在LED显示屏上。它有效,但我似乎遇到了添加30秒和超过59秒的问题。它最初的工作方式是它不断增加30到60到90 + 120等等。但是我希望它每隔60秒滚动一次,当我加30秒时。如果我应该重写代码,我就是游戏,但任何线索都会有所帮助。知道此代码适用于嵌入式项目,并且只是一个片段。在设置循环之前添加初始设置时间,并保持为测试值。

n=test;
for(i=0;i<n;i++){

        q = test %100;    /*q makes real time clock work in 60 sec decriments*/

         if(q==0){
            test = test - 40;
         }  
         key = KeypadReadPort();
         x = keys[key];
         if(x==30){           /*add 30 seconds during count*/
              n = n + 30;
              sec1=(test+30)%90;
              if(sec1>=60){
                min=q; 
                sec2=(test+30)%60;
                test=sec2+(100+q);
              } else if (sec1<60){
                test=test+30;
              }
           SevenSegWrite(test);/* display result on LED*/


         }
         test = test - 1;       /*count down tick*/
         SevenSegWrite(test);
         OSTimeDlyHMSM(0, 0, 1, 0);/*1 second tick*/
         if(test==0){

           for(i=0;i<750;i++){               /*buzzer*/
             PTT = PTT | 0x20;
             OSTimeDlyHMSM(0,0,0,1);
             PTT = PTT & 0xDF;
             OSTimeDlyHMSM(0,0,0,1);  
           }
         }
       }
      test=0;

1 个答案:

答案 0 :(得分:1)

我会这样做。这个对我有用。你有一个好的开始!你只需要稍微分解你的时钟数字。

 if(start<15){
        min=0;                                                               /*microwave keypad numeric input method*/
       n = test;
       for(i=0;i<n;i++){
        q = test %100;               /*q makes real time clock work in 60 sec decriments*/

         if(q==0){
            test = test - 40;
         }  
         key = KeypadReadPort();
         x = keys[key];
         if(x==30){           /*add 30 seconds during count*/

              d4 = test % 10;
              d3 = (test / 10) % 10;
              d2 = (test / 100) % 10;
              d1 = (test / 1000) % 10;
              min=(d1*1000)+(d2*100);
              sec1=(d3*10)+d4;
              n = n + 30;
              sec2=(sec1+30)%90;

              if(sec2>=60){
                min=min+100; 
                sec1=(sec1+30)%60;
                test=sec1+(min);
              } else if (sec2<60){
                test=test+30;
              }
           SevenSegWrite(test);


         }
         test = test - 1;       /*count down tick*/
         SevenSegWrite(test);
         OSTimeDlyHMSM(0, 0, 1, 0);
         if(test==0){

           for(i=0;i<750;i++){               /*buzzer*/
             PTT = PTT | 0x20;
             OSTimeDlyHMSM(0,0,0,1);
             PTT = PTT & 0xDF;
             OSTimeDlyHMSM(0,0,0,1);  
           }
         }