新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 單片機左右流水燈與數(shù)碼管動態(tài)顯示C程序

單片機左右流水燈與數(shù)碼管動態(tài)顯示C程序

作者: 時間:2016-12-02 來源:網絡 收藏

//定時器初始化程序
void init()
{
//定時器0和定時器1初始化函數(shù)
TMOD = 0x11;//定義定時器1和0在工作方式1下
TH0 = 0xB8; //定時器0定時20毫秒
TL0 = 0x00;
TH1 = 0xFC; //定時器1定時20毫秒
TL1 = 0x67;
TR0 = 1; //打開定時器0
TR1 = 1; //打開定時器1
EA = 1; //打開總中斷
ET0 = 1; //打開定時器0中斷
ET1 = 1; //打開定時器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;

}
//中斷定時器0
void int_time0() interrupt 1
{
TH0 = 0xB8;
TL0 = 0x00;
counter++;
if(flag == 0)
{
if(counter % 10 == 0)//定時200毫秒
{
P1 = ~(1 << j++);//流水燈左移流動
if(j == 8)
{
j = 0;
}
}
}
else
{
if(counter % 5 == 0)
{
//counter = 0;
//流水燈右移流動
P1 = ~(0x80 >> j++);
FM = ~FM;
if(j == 8)
j = 0;
}
}


}
//中斷定時器1
void int_time1() interrupt 3
{
TH1 = 0xFC;
TL1 = 0x67;
counter1++;

}

本文引用地址:http://butianyuan.cn/article/201612/324624.htm

上一頁 1 2 下一頁

評論


技術專區(qū)

關閉