控制工程师论坛

教程与手册

定时计数器T0作定时应用技术(二)

xilinxue
xilinxue

2008-09-20

#include <AT89X51.H>
 
unsigned char tcount2s;
unsigned char tcount02s;
unsigned char ID;
 
void main(void)
{
  TMOD=0x01;
  TH0=(65536-50000)/256;
  TL0=(65536-50000)%256;
  TR0=1;
  ET0=1;
  EA=1;
 
  while(1);
}
 
void t0(void) interrupt 1 using 0
{
  tcount2s++;
  if(tcount2s==40)
    {
      tcount2s=0;
      ID++;
      if(ID==4)
        {
          ID=0;
        }
    }
  tcount02s++;
  if(tcount02s==4)
    {
      tcount02s=0;
      switch(ID)
        {
          case 0:
            P1_0=~P1_0;
            break;
          case 1:
            P1_1=~P1_1;
            break;
          case 2:
            P1_2=~P1_2;
            break;
          case 3:
            P1_3=~P1_3;
            break;
        }
    }
}

回帖

评论0

首页 | 登录 | 注册 | 返回顶部↑
手机版 | 电脑版
版权所有 Copyright(C) 2016 CE China