当前位置:三九宝宝网 → 宝宝成长 → 宝宝手工 → 正文

如何用单片机制作24秒计时器

更新:01-06 整理:39baobao.com
字体:

#include

#define uchar unsigned char

#define uint unsigned int

uchar tt=0,flag;

uint i=0;

uchar code table[10] = {0x03, 0x9f, 0x25, 0x0d, 0x99, 0x49, 0x41, 0x1f, 0x01, 0x09};

void display(uint i);

void delay(uint del)

{

uchar i, j;

for(i=0; i

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

}

main()

{

TMOD=0X01;

TR0=1; //启动定时器

ET0=1; //开定时器

TH0=0X40;

TL0=0X00;

EA=1; //开总中断

while(1)

{

if(tt==20)

{

tt=0;

i++;

if(i==24)

i=0;

}

display(i);

}

}

void display(uint k)

{

P2=0X04;

P0=table[k/100];

delay(5);

P2=0X02;

P0=table[k%100/10];

delay(5);

P2=0X01;

P0=table[k%10];

delay(5);

}

void timer0() interrupt 1

{

TH0=0X40;

TL0=0X00;

tt++;

}

本文地址:https://www.39baobao.com/show/15_5315.html

以上内容来自互联网,请自行判断内容的正确性。若本站收录的信息无意侵犯了贵司版权,请联系我们,我们会及时处理和回复,谢谢.