單片機(jī)左右流水燈與數(shù)碼管動(dòng)態(tài)顯示C程序
//定時(shí)器初始化程序
void init()
{
//定時(shí)器0和定時(shí)器1初始化函數(shù)
TMOD = 0x11;//定義定時(shí)器1和0在工作方式1下
TH0 = 0xB8; //定時(shí)器0定時(shí)20毫秒
TL0 = 0x00;
TH1 = 0xFC; //定時(shí)器1定時(shí)20毫秒
TL1 = 0x67;
TR0 = 1; //打開(kāi)定時(shí)器0
TR1 = 1; //打開(kāi)定時(shí)器1
EA = 1; //打開(kāi)總中斷
ET0 = 1; //打開(kāi)定時(shí)器0中斷
ET1 = 1; //打開(kāi)定時(shí)器1中斷
}
//數(shù)碼管顯示子程序
void display()
{
dula = 1;
P0 = table_du[num];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = table_we[num1];
wela = 0;
dula = 1;
P0 = table_du[num];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = table_we[num1];
wela = 0;
dula = 1;
P0 = table_du[num];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = table_we[num1];
wela = 0;
dula = 1;
P0 = table_du[num];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = table_we[num1];
wela = 0;
dula = 1;
P0 = table_du[num];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = table_we[num1];
wela = 0;
dula = 1;
P0 = table_du[num];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = table_we[num1];
wela = 0;
}
//中斷定時(shí)器0
void int_time0() interrupt 1
{
TH0 = 0xB8;
TL0 = 0x00;
counter++;
if(flag == 0)
{
if(counter % 10 == 0)//定時(shí)200毫秒
{
P1 = ~(1 << j++);//流水燈左移流動(dòng)
if(j == 8)
{
j = 0;
}
}
}
else
{
if(counter % 5 == 0)
{
//counter = 0;
//流水燈右移流動(dòng)
P1 = ~(0x80 >> j++);
FM = ~FM;
if(j == 8)
j = 0;
}
}
}
//中斷定時(shí)器1
void int_time1() interrupt 3
{
TH1 = 0xFC;
TL1 = 0x67;
counter1++;
}本文引用地址:http://www.ex-cimer.com/article/201612/324624.htm
評(píng)論