一.硬件設(shè)計
本文引用地址:http://cafeforensic.com/article/201611/319912.htm說明:
選通一個數(shù)碼管分兩步,
第一步是位選,即選擇哪個數(shù)碼管亮,這里位選是通過鎖存器U2的WE1~WE6來選擇第一個數(shù)碼管到第六個數(shù)碼管,由于數(shù)碼管為共陰極(相對于8位數(shù)碼管),那么這里WE端為0代表位選選通,
第二步是段選,即選擇數(shù)碼管的哪位亮,這里段選是通過鎖存器U1的a~h來選擇數(shù)碼管的8位管子,這里DUAN端為1代表段選選通.
二.程序設(shè)計
1.程序功能
第一個數(shù)碼管循環(huán)顯示0~F
2. 程序源碼
#include
#define uchar unsigned char
#define uint unsigned int
sbit duan = P2 ^ 6;
sbit wela = P2 ^ 7;
uchar code led1[] = {
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
lenLed1 = sizeof(led1)/sizeof(led1[0]);
void delayms(uint xms);
void main()
{
uchar i;
wela = 1;
P0 = 0xfe;
wela = 0;
while (1)
{
for (i = 0; i < lenLed1; i++)
{
duan = 1;
P0 = led1[i];
duan = 0;
delayms(1000);
}
}
}
void delayms(uint xms)
{
uint i, j;
for (i = xms; i > 0; i--)
for (j = 110; j > 0; j--)
;
}
評論