×
单片机 > 单片机程序设计 > 详情

c51中断计数器

发布时间:2022-09-29 发布时间:
|

#include

#define uchar unsigned char

#define uint unsigned int

#define ulong unsigned long

uint tc;

static uint i;

uchar ledbuff[8];

uchar ledchar[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};

void init_en()

{

EA = 1;

ET1=1;

ET0=1;

TMOD = 0X51;

TH0 = 0XFC;

TL0 = 0X67;

TR0=1;

TR1=1;

}


void clac(ulong num)

{

static uchar j;

uchar buff[8];

buff[6] = num%10;

buff[5] = num/10%10;

buff[4] = num/100%10;

buff[3] = num/1000%10;

buff[2] = num/10000%10;

buff[1] = num/100000%10;

buff[0] = num/1000000%10;

buff[7] = num/10000000%10;

for(j=0;j<8;j++)

ledbuff[j]=ledchar[buff[j]];

}

void display()

{

static uchar j=0;

j++;

j %= 8;

P2 = j;

P1 = ledbuff[j];

}


void main()

{

static ulong count;

init_en();

while(1)

{

if(i == 1000)

{

i=0;

TR0=TR1 = 0;

count = (tc*65536+TH1*256 +TL1);

count =count*12/11059.2;

clac(count);

count = tc = TH1 =TL1 = 0;

TR0=TR1 = 1;

}

}

}


void t0() interrupt 1

{

TH0 = 0XFC;

TL0 = 0X66;

i++;

display();

}


void t1() interrupt 3

{

tc++;

}



『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
C51 特殊功能寄存器SFR的名称和地址