回覆列表
  • 1 # 使用者7063786766555

    #include <reg52.h>

    #define uchar unsigned char

    #define uint unsigned int

    unsigned char code table[]={0x3f,0x06,0x5b,0x4f,

    0x66,0x6d,0x7d,0x07,

    0x7f,0x6f,0x77,0x7c,

    0x39,0x5e,0x79,0x71,0x00};

    uchar intnum;

    uchar sec;

    void init()

    {

    TMOD=0x01; // 定時器模式選擇,選擇T0定時器,方式1

    TR0=1; //1 開啟定時器0

    ET0=1; //定時器0中斷使能位

    EA=1; //使能全域性中斷

    TH0=(65536-50000)/256;

    TL0=(65536-50000)%256;

    }

    void time0() interrupt 1 //50ms

    {

    //TF0=0; //定時器0溢位 ,清楚中斷

    TH0=(65536-50000)/256;

    TL0=(65536-50000)%256;

    intnum++;//溢位值加1

    if(intnum==20)

    {

    intnum=0;

    sec++;

    if(sec==100)

    {

    sec=0;

    }

    }

    }

    void disp(uchar num1,uchar num2)

    {

    P0=table[num1];

    P2=table[num2];

    }

    void main()

    {

    init();

    while(1)

    {

    uchar a,b;

    a=sec/10;

    b=sec%10;

    disp(a,b);

    }

  • 中秋節和大豐收的關聯?
  • 親密距離有多遠?