回覆列表
  • 1 # 使用者2458114238191884

    先看看下面程式,看懂了,就知道咋編了

    #include

    #define uchar unsigned char

    #define uint unsigned int

    uchar a , b=0;

    sbit wei1=P1.0;

    sbit wei2=P1.1;

    //共陰數碼管七段碼

    uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,0x7f,0x6f,0x77};

    void Delay1ms(uint i) //1ms延時程式

    {

    uint j;

    for(;i>0;i--)

    {

    for(j=0;j

    {;}

    }

    }

    void display( uchar a)) /顯示子程式

    {

    P0= table[a/10];//十位

    wei1=1;

    Delay1ms(2) ;

    wei1=0;

    P0= table[a%10];//個位

    wei2=1;

    Delay1ms(2) ;

    wei2=0;

    }

    void main(void )//主程式

    {

    TMOD=0x01;// 定時器1工作方式一

    ET0=1;

    EA=1;

    TH0=(65536-50000)/256;//定時50ms

    TL0=(65536-50000)%256;

    TR0=1;

    while(1)

    {

    display(b);

    }

    }

    //中斷子程式

    void Timer0(void) interrupt 1

    {

    TH0=(65536-50000)/256;

    TL0=(65536-50000)%256;

    a++;

    if(a==20)//20次是1 秒

    { a=0;b++;}

    if(b==60)

    { b=0;}

    }

  • 中秋節和大豐收的關聯?
  • 落葉留住秋天的句子?