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

標題: 51單片機第三課中斷控制一位數碼管顯示 [打印本頁]

作者: Max_zhang    時間: 2021-2-20 23:44
標題: 51單片機第三課中斷控制一位數碼管顯示
/********************51單片機第三課*******************/
/********************一位數碼管顯示*******************/
/******************** 運用中斷控制 *******************/
/********************By Max.Zhang  *******************/

#include <reg52.h>

typedef unsigned char uint8;             //定義參數類型,規范書寫格式
typedef unsigned int uint16;
uint16 i;
uint8  cnt;
uint8  num;

/******** 38譯碼器引腳對應P1位置*********/

sbit ADDR0  =P1^0;
sbit ADDR1  =P1^1;
sbit ADDR2  =P1^2;
sbit ADDR3  =P1^3;
sbit ENLED  =P1^4;

/********     數碼管真值表     *********/
uint8 code DS[16]={            //code 表示把數據存到flash,不占用內部存儲
    0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8,
    0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E};
void main()
{   
/************** 38譯碼器設置*************/
        ADDR0 =0;               //打開數碼管DS0,也即LEDS0
        ADDR1 =0;
        ADDR2 =0;
        ADDR3 =1;
        ENLED =0;
/************** 中斷初始化 *************/
        TMOD = 01;
        TH0         =0xB8;              //計算20ms的計數初值
        TL0  =0x09;
        TR0  =1;       
        EA  =1;
        ET0 =1;
        P0   = 0xFF;
        while(1);
}

void timer0_interrupt() interrupt 1
{               
        static cnt =0;
        static num =0;
        TH0         =0xB8;              //計算20ms的計數初值
        TL0  =0x09;
        TF0  =0;
        cnt++;
         if(cnt>=50)               //計數50次,延時1s
                {
                 cnt=0;P0=DS[num];num++;//每一秒數組內部標號+1
                        if(num>=16)
                                {
                                        num=0;
                                }
                }

}






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