|
題目
平臺(tái)驗(yàn)證【3】:采用74HC573實(shí)現(xiàn)數(shù)
碼管顯示實(shí)驗(yàn)
用573鎖存器控制輸出段碼,用單片機(jī)PIN引
腳直接進(jìn)行位選,實(shí)現(xiàn)數(shù)碼管顯示
連接方法:P0與J12用8PIN排線連接,J16與P2用
8PIN排線連接,P1.0接到J21中柱
將8個(gè)數(shù)碼管分為兩組,同時(shí)顯示同一個(gè)數(shù),該數(shù)
從00.00到99.99,每次顯示完成后加0.01
0-9的段碼:
0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f
0.png (113.08 KB, 下載次數(shù): 80)
下載附件
2016-6-12 18:54 上傳
- #include "at89x51.h"
- #include <intrins.h>
- #define USE_573_LE
- #ifdef USE_573_LE
- sbit LE = P1^0; //定義輸出使能控制腳在P1.0上
- #endif
- //此表為 LED 的字模, 共陰數(shù)碼管 0-9
- unsigned char code Disp_Tab[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};
- //此表為8個(gè)數(shù)碼管位選控制, 共陰數(shù)碼管 1-8個(gè)
- unsigned char code dispbit[] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdF,0xbF,0x7F};
- unsigned int LedOut[8]; //變量定義
- void delay(unsigned int i);
- void setValue(unsigned int v)
- {
- LedOut[0] = Disp_Tab[(v % 10000) / 1000];
- LedOut[1] = Disp_Tab[(v % 1000) /100] | 0x80;
- LedOut[2] = Disp_Tab[(v % 100) / 10];
- LedOut[3] = Disp_Tab[v % 10];
-
- LedOut[4] = LedOut[0]; //千位
- LedOut[5] = LedOut[1]; //百位帶小數(shù)點(diǎn)
- LedOut[6] = LedOut[2]; //十位
- LedOut[7] = LedOut[3]; //個(gè)位
- }
- void dispBit(unsigned char i)
- {
- P0 = LedOut[i];
- #ifdef USE_573_LE
- LE = 1; //輸出使能,鎖存器將P0的8位數(shù)據(jù)全部接收
- LE = 0; //鎖存數(shù)據(jù), P0不再影響鎖存器的輸出
- #endif
- P2 = dispbit[i]; //使用查表法進(jìn)行位選
- }
- void main()
- {
- unsigned int DelayCNT, i, LedNumVal = 0; //變量定義
-
- DelayCNT = 0;
- setValue(LedNumVal);
- #ifdef USE_573_LE
- LE = 0;
- #else
- P1_0 = 1;
- #endif
- while(1)
- {
- if(++DelayCNT >= 20) //控制數(shù)字變化速度
- {
- DelayCNT = 0; //20個(gè)掃描周期清零一次
- ++LedNumVal; //每隔20個(gè)掃描周期加一次
- if(LedNumVal >= 10000)
- {
- LedNumVal = 0;
- }
- setValue(LedNumVal);
- }
- for(i = 0; i < 8; i++)
- {
- dispBit(i);
- delay(6); //掃描間隔時(shí)間太長(zhǎng),數(shù)碼管會(huì)有閃爍感. 注意晶振頻率。
- }
- }
- }
- void delay(unsigned int i)
- {
- unsigned char j;
- for(i; i > 0; i--)
- for(j = 200; j > 0; j--);
- }
復(fù)制代碼 |
-
-
c51-03.zip
2016-6-10 10:30 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
29.95 KB, 下載次數(shù): 17, 下載積分: 黑幣 -5
實(shí)驗(yàn)源代碼
|