C51 定时器

#include <reg52.h>
typedef unsigned int uint;
typedef unsigned char uchar;


sbit led =  P1^1;
uint tt=0;
uint i =0;
void main(){
//    led =0;
    TMOD = 0x01;   // 设置定时器0为工作方式1
    EA=1;       // 开总中断
    ET0=1;      //  开定时器0中断
    TR0=1;      // 启动定时器 0
    TH0=(65536-50000)/256;
    TL0=(65536-50000)%256;
    while(1){
    
        if(tt==20){
            tt=0;
            led=0;
        }else if(tt==10){
            led=1;
        }
    }
}

void enter0() interrupt 1{
    tt++;
    TH0=(65536-50000)/256;
    TL0=(65536-50000)%256;
}

此图 为 TMOD取值 ,若取值方式1,为0x01,和下图联合看,因为对T0,控制,高4位为 T1的控制,因为本案例不对T1操作,所以取值00.

原文地址:https://www.cnblogs.com/sdgtxuyong/p/14867718.html