單片機(jī)程序之三,數(shù)碼管顯示0-9自檢
#include
#include
unsigned char data dis_digit;
unsigned char code dis_code[11] =
{0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0xFF}; //共陽(yáng)極數(shù)碼管
unsigned char data dis_buf[10];
unsigned char data dis_index;
unsigned char i = 0, j = 0;
void main(void)
{
unsigned char i;
P0 = 0xFF;
P2 = 0xFF;
TMOD = 1;
TH0 = 0xFC;
TL0 = 0x17;
IE = 0x82;
for(i=0;i<=9;i++)
{
dis_buf[i] = dis_code[i];
}
dis_digit = 0xFE;
dis_index = 0;
TR0 = 1;
while(1);
}
void timer0() interrupt 1
//定時(shí)器0中斷服務(wù)程序, 用于數(shù)碼管的動(dòng)態(tài)掃描
//dis_index--顯示索引, 用于標(biāo)識(shí)當(dāng)前顯示的數(shù)碼管和緩沖區(qū)的偏移量
//dis_gigit--位選通道, 傳送到P2口用于選通當(dāng)前數(shù)碼管的數(shù)值, 如為0xFE時(shí)選通P2.0口數(shù)碼管
//dis_buf--顯示緩沖區(qū)基地址
{
TH0 = 0xFC;
TL0 = 0x17;
P2 = 0xFF; //先關(guān)閉所有數(shù)碼管
P0 = dis_buf[dis_index];
P2 = dis_digit;
dis_digit = _crol_(dis_digit, 1); //位選通道左移, 下次中斷時(shí)選通下一位數(shù)碼管
i++;
if (i==100)
{
j++;
i = 0;
if (j == 5)
{
dis_index++;
if (dis_index == 10)
{
dis_index = 0;
}
i = 0;
j = 0;
}
}
//dis_index &= 0x07; //8個(gè)數(shù)碼管全部掃描完, 重新開(kāi)始
}
評(píng)論