用89c51单片机

核心提示#include<reg51.h>#define uchar unsigned charuchar code ledtab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40}

#include<reg51.h>

#define uchar unsigned char

uchar code ledtab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};//0-9

uchar ledtab[]={0x66,0x79,0x68,0x68,0x5c, //HELLo

0x00,0x39,0x6d,0x00,0x3f,0x66}; // C51 04

0x66,0x79,0x68,0x68,0x5c} //HELLo

uchar disdat[6],num;

void dischg()

{

disdat[0]=num;

disdat[1]=num+1;

disdat[2]=num+2;

disdat[3]=num+3;

disdat[4]=num+4;

disdat[5]=num+5;

}

void t0isr() interrupt 1 //秒计时

{

TH0=0x3c;

TL0=0xb0;

time++;

if(time>=20)

{

time=0;

dischg();

num++;

num%=10;

}

}

void t1isr() interrupt 3 //显示

{

TH1=0xec;

TL1=0x78;

P2=0x01<<scanled;

P0=disdat[scanled];

scanled++;

scanled%=6;

}

main()

{

TMOD=0x11;

TH0=0x3c;

TL0=0xb0;

TH1=0xec;

TL1=0x78;

TR1=1;

TR0=1;

ET0=1;

ET1=1;

EA=1;

while(1);

}

 
友情链接
鄂ICP备19019357号-22