|
实现一个数码管从0到9再到0再到9的循环,每隔1S循环一次(附件为原理图)P1接J16,P0接J12
#include "reg51.h"
#define uchar unsigned char
#define uint unsigned int
uchar code table_numberP[] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar code table[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uint n;
uint ge;
void main()
{
ge = 0;
TMOD = 0x01;
TH0 = (65536-45872)/256;
TL0 = (65536-45872)%256;
EA = 1;
ET0 = 1;
TR0 = 1;
while(1);
}
void T0_time()interrupt 1
{
TH0 = (65536-45872)/256;
TL0 = (65536-45872)%256;
n++;
if(n%20 == 0)
{
if(ge<=9){
P1 = table_numberP[0];
P0 = table[ge];
ge++;
if(ge == 10){
ge = 0;
}
}
}
}
|
|