欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: 第一次發帖,自學中斷后寫的一個模擬電子手表的秒表 [打印本頁]

作者: 薯片0321    時間: 2017-10-26 10:03
標題: 第一次發帖,自學中斷后寫的一個模擬電子手表的秒表
/**************************************************************************************
*                                  秒表計時                                                                                                                                                                  
***************************************************************************************/

#include "reg52.h"                         //此文件中定義了單片機的一些特殊功能寄存器

typedef unsigned int u16;          //對數據類型進行聲明定義
typedef unsigned char u8;
#define GPIO_DIG   P0
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;

u8 code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
                                        0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//顯示0~F的值
u8 Second;
u8 Second1;
u8 DisplayData[8];
/*******************************************************************************
* 函 數 名         : delay
* 函數功能                   : 延時函數,i=1時,大約延時10us
*******************************************************************************/
void delay(u16 i)
{
        while(i--);       
}

/*******************************************************************************
* 函 數 名         : DigDisplay
* 函數功能                   : 數碼管動態掃描函數,循環掃描8個數碼管顯示
*******************************************************************************/
void DigDisplay()
{
        u8 i;
        for(i=0;i<8;i++)
        {
                switch(i)         //位選,選擇點亮的數碼管,
                {
                        case(0):
                                LSA=0;LSB=0;LSC=0; break;//顯示第0位
                        case(1):
                                LSA=1;LSB=0;LSC=0; break;//顯示第1位
                        case(2):
                                LSA=0;LSB=1;LSC=0; break;//顯示第2位
                        case(3):
                                LSA=1;LSB=1;LSC=0; break;//顯示第3位
                        case(4):
                                LSA=0;LSB=0;LSC=1; break;//顯示第4位
                        case(5):
                                LSA=1;LSB=0;LSC=1; break;//顯示第5位
                        case(6):
                                LSA=0;LSB=1;LSC=1; break;//顯示第6位
                        case(7):
                                LSA=1;LSB=1;LSC=1; break;//顯示第7位       
                }
                GPIO_DIG=DisplayData[i];//發送段碼
                delay(100); //間隔一段時間掃描       
                GPIO_DIG=0x00;//消隱
        }
}
/*******************************************************************************
* 函 數 名         : Timer0Init
* 函數功能                   : 定時器1定義
*******************************************************************************/
void Timer0Init()
{
        TMOD|=0X01;//選擇為定時器0模式,工作方式1,僅用TR0打開啟動。

        TH0=0XFC;        //給定時器賦初值,定時1ms
        TL0=0X18;       
        ET0=1;//打開定時器0中斷允許
        EA=1;//打開總中斷
        TR0=1;//打開定時器                       
}
/*******************************************************************************
* 函 數 名         : Timer1Init
* 函數功能                   : 定時器1定義
*******************************************************************************/
void Timer1Init()
{
        TMOD|=0X01;//選擇為定時器0模式,工作方式1,僅用TR0打開啟動。

        TH1=0XFC;        //給定時器賦初值,定時1ms
        TL1=0X18;       
        ET1=1;//打開定時器0中斷允許
        EA=1;//打開總中斷
        TR1=1;//打開定時器                       
}
/*******************************************************************************
* 函 數 名       : main
* 函數功能                 : 主函數
* 輸    入       : 無
* 輸    出             : 無
*******************************************************************************/
void main()
{         Timer0Init();
        Second = 1;
        while(1)
        {       
                        if(Second == 100)
                 {
                        Second = 1;
                 }
                        if(Second1 == 100)
                 {
                        Second1 = 1;
                 }       
                                if(Second < 100||Second1 < 100)
                        {        DisplayData[0] = 0x00;
                                DisplayData[1] = 0x00;
                                DisplayData[2] = smgduan[Second1 % 100 / 10];
                                DisplayData[3] = smgduan[Second1%10];
                                DisplayData[4] = 0x00;
                                DisplayData[5] = 0x00;
                                DisplayData[6] = smgduan[Second % 100 / 10];
                                DisplayData[7] = smgduan[Second%10];
                                DigDisplay();  //數碼管顯示函數
                               
                        }
               
                        /*if(Second1 < 100)
                        {       
                                DisplayData[0] = 0x00;
                                DisplayData[1] = 0x00;
                                DisplayData[2] = smgduan[Second1 % 100 / 10];
                                DisplayData[3] = smgduan[Second1%10];
                                DigDisplay();  //數碼管顯示函數
                               
                        }*/       
               
                }
                                       
}
/*******************************************************************************
* 函 數 名         : void Timer0() interrupt 1
* 函數功能                   : 定時器0中斷函數
* 輸    入         : 無
* 輸    出         : 無
*******************************************************************************/
void Timer0() interrupt 1
{
static u16 i;
static u16 j;
        TH0=0XFC;        //給定時器賦初值,定時1ms
        TL0=0X18;
        i++;
        j++;
        if(i==10)
        {
                i=0;
                Second ++;       
        }
        if(j==1000)
        {
                j=0;
                Second1 ++;       
        }
}







歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1