回覆列表
  • 1 # 使用者8852944140293

    #include

    sbit key =P1^1;

    sbit led1=P1^2;

    sbit led2=P1^3;

    sbit led3=P1^4;

    bit key_flag;

    bit flag_500ms;

    void InitTimer0(void)

    {

    TMOD |= 0x01;

    TH0 = 0x3C;

    TL0 = 0x0B0;

    EA = 1;

    ET0 = 1;

    TR0 = 1;

    }

    unsigned char stat;

    void main(void)

    {

    InitTimer0();

    key_flag=0;

    stat=0;

    while (1)

    {

    if (key_flag) stat++;

    stat%=3;

    switch (stat)

    {

    case 0:

    led3=led2=1;

    led1=flag_500ms;

    break;

    case 1:

    led1=led3=1;

    led2=flag_500ms;

    break;

    case 2:

    led1=led2=1;

    led3=flag_500ms;

    break;

    default :break;

    }

    }

    }

    unsigned char key_time,time_500;

    void Timer0Interrupt(void) interrupt 1 //50ms

    {

    TH0 = 0x3C;

    TL0 = 0x0B0;

    //add your code here!

    key=1;

    if (!key) key_time++;

    else key_time=0;

    if (key_time>5)

    {

    key_time=5;

    }

    if (key_time==4)key_flag=1;

    if (time_500)time_500--;

    else

    {flag_500ms=1;time_500=10;}

    }

  • 中秋節和大豐收的關聯?
  • 天氣預報裡的雨量毫米是什麼意思?