国产精品无码一区二区三区A片_无码狠狠躁久久久久久久91_国产精品久久久久久久_国产99九九久久无码熟妇_国产人妻精品久久久久野外_久久夜色精品国产欧美乱极品_91精品国产色综合久久不卡98口_精品人妻系列无码人妻免费视频

技術(shù)熱線: 4007-888-234
設(shè)計(jì)開(kāi)發(fā)

專注差異化嵌入式產(chǎn)品解決方案 給智能產(chǎn)品定制注入靈魂給予生命

開(kāi)發(fā)工具

提供開(kāi)發(fā)工具、應(yīng)用測(cè)試 完善的開(kāi)發(fā)代碼案例庫(kù)分享

技術(shù)支持

從全面的產(chǎn)品導(dǎo)入到強(qiáng)大技術(shù)支援服務(wù) 全程貼心伴隨服務(wù),創(chuàng)造無(wú)限潛能!

新品推廣

提供新的芯片及解決方案,提升客戶產(chǎn)品競(jìng)爭(zhēng)力

新聞中心

提供最新的單片機(jī)資訊,行業(yè)消息以及公司新聞動(dòng)態(tài)

寫(xiě)了一個(gè)鬧鐘程序,24小時(shí)差12秒

更新時(shí)間: 2019-03-21
閱讀量:3131

 單片機(jī)方案開(kāi)發(fā)商深圳英銳恩分享寫(xiě)鬧鐘程序,24小時(shí)差12秒。

程序如下:

//////////////////////////////////////////////////
//  Author  : Toby
//  Date  : 2008/09/06
//      Function : 時(shí)間顯示與定時(shí)功能等
//  MCU   : PIC16F877A
//  C Compiler : PICC 8.05
//  IDE   : MPLAB IDE v8.10               
/////////////////////////////////////////////////

#include
__CONFIG(0x0f3a);
#define  ADD           RB0
#define  REDUCE        RB1
#define  LED           RC2
#define  SEC           RC1
void reset(void); 
void tmint(void);  
void interrupt clkint(void);                                
delay(unsigned char x);
const unsigned char TABLE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0X82,0XF8,0X80,0X90};    //0-9的數(shù)據(jù)段
void display(void);           
unsigned long QC=0,temp=0,n=1;
double bf=0,sc=0;

void main()                    //主函數(shù)
{
    reset();
  
    display();
}

void reset(void)
{
   ADCON1=0B0110;              //全做普通I/O
   TRISA=0x0;
   PORTA=0xff;
   TRISD=0x0;            
   PORTD=0xff;           
   TRISB=0xff;
   PORTB=0x0;
   TRISC=0x0;
   PORTC=0x0;
   tmint();
   GIE=1;
}


void display(void)  //顯示函數(shù)
   {   
     unsigned long qian_1,bai_1,shi_1,shiwan,wan_1,wan,qian,bai,shi,ge;   //定義臨時(shí)變量
                   
                    while(1)
                    {
                          bf=QC;
                          if(ADD==0)                    QC+=2;                /(秒)調(diào)整加 
                          if(REDUCE==0)                 QC-=2;                /(秒)調(diào)整減
                          if((ADD==0)&&(REDUCE==0))     QC+=2500;             //兩個(gè)按鍵同時(shí)按下,時(shí)間快速增加
                          if(bf>=1318359.375)           QC=0;                 //24小時(shí)到,重新開(kāi)始計(jì)時(shí),如果24小時(shí)時(shí)間有
                          誤差可以在這修正。
                          if(((bf>430297.8515625)&&(bf<439453.125))||((bf>549316.40625)&&(bf<558471.6796875))||((bf>659179.6875)&&(bf<668334.9609375))||((bf>704956.0546875)&&(bf<714111.328125))||((bf>823974.609375)&&(bf<833129.8828125))||((bf>933837.890625)&&(bf<942993.1640625))) LED=1; else LED=0;
                          //----------7:50---8:00-------------     ----------------10;00---10:10-----------    ----------12:00---12:100------------    --------------12:50---13:00----------       -------------15:00---15:10---------      ---------17:00---17:10-------------
                          
                          temp=bf/15.2587890625;
                          shiwan=temp/36000;          //求小時(shí)的十位

                          wan_1=temp/3600;            //求小時(shí)的個(gè)位
                          wan=wan_1%10;

                          qian_1=temp%3600;           //求分鐘的十位
                          qian=qian_1/600;

                          bai_1=qian_1%600;           //求分鐘的個(gè)位
                          bai=bai_1/60; 
    
                          shi_1=bai_1%60;             //求秒的十位
                          shi=shi_1/10; 
 
                          ge=shi_1%10;                //求秒的個(gè)位

                          PORTD=TABLE[shiwan];        //查表得小時(shí)的十位數(shù),
                          PORTA=0B111110;             //RA0輸出低電平,點(diǎn)亮小時(shí)的十位數(shù)
                          delay(5);                   //延時(shí)一定時(shí)間,保證顯示亮度  

                          PORTD=TABLE[wan];           // 小時(shí)個(gè)位顯示
                          PORTA=0B111101;            
                           delay(5);                

                          PORTD=TABLE[qian];          //分鐘十位顯示  
                          PORTA=0B1111011;         
                          delay(5);                 

                          PORTD=TABLE[bai];           //分鐘個(gè)位顯示          
                          PORTA=0x37;               
                          delay(5);                

                          PORTD=TABLE[shi];           //秒的十位顯示     
                          PORTA=0x2F;               
                          delay(5);                 

                          PORTD=TABLE[ge];            //查表得秒的個(gè)位位數(shù),         
                          PORTA=0x1F;                 //RA5輸出低電平,點(diǎn)亮秒的個(gè)位數(shù)             
                          delay(5);                  //延時(shí)一定時(shí)間,保證顯示亮度              
                          PORTD=0xff;
                    }
    }

           
  delay(unsigned char x)       //延時(shí)函數(shù)
    {
        unsigned char a=x,b;
        for(a;a--;)
        for(b=50;b>=1;b--)
        asm("nop");      
    } 

void tmint(void)               //定時(shí)初始化函數(shù)               
{
        T0CS=0;                //T0CS是TMR0的時(shí)鐘源選擇位,當(dāng)其=1時(shí)是用RA4(T0CKI)的外部輸入時(shí)鐘,當(dāng)其=0時(shí)是用內(nèi)部指令周期時(shí)鐘(CLKOUT)
        PSA=0;                 //PSA是預(yù)分頻器分配位,當(dāng)其=1預(yù)分頻器分配給WDT,當(dāng)其=0時(shí)預(yù)分頻器分配給Timer0 模塊
        PS2=1;                 //PS2:PS1:PS0:預(yù)分頻比選擇位  1 1 1是256分頻
        PS1=1;
        PS0=1;
        T0IF=0;                //T0IF是TMR0溢出中斷標(biāo)志位,當(dāng)其=1時(shí)TMR0 寄存器已經(jīng)溢出(必須用軟件清零),當(dāng)其=0時(shí)寄存器尚未發(fā)生溢出
        T0IE=1;                //T0IE是TMR0 溢出中斷允許位當(dāng)其=1時(shí)允許TMR0 溢出中斷,當(dāng)其=0時(shí)禁止TMR0 溢出中斷
}

 void interrupt clkint(void)   //定時(shí)器中斷函數(shù)
{  
           TMR0=0x0;
           QC++;
           T0IF=0x0;
}

單片機(jī)代理商英銳恩現(xiàn)提供服務(wù)產(chǎn)品涉及主控芯片:8位單片機(jī)、16位單片機(jī)、32位單片機(jī)及各類運(yùn)算放大器等,支持需求定制單片機(jī)方案開(kāi)發(fā),同時(shí)提供增值服務(wù),包括樣品申請(qǐng),芯片編程等。