在此提供 單晶片微電腦 MCU,使用的是 ATMEL AT89S52
控制 8x8 LED display 輪流顯示 0 1 2 3 4 5 6 7 8 9
完整程式碼 如下:- #include <reg52.h>
- #include <intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar code Table_OF_Digits[]={ // 將要顯示的字形,存於 Flash ROM
- 0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00,
- 0x00,0x00,0x00,0x21,0x7f,0x01,0x00,0x00,
- 0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00,
- 0x00,0x22,0x49,0x49,0x49,0x36,0x00,0x00,
- 0x00,0x0c,0x14,0x24,0x7f,0x04,0x00,0x00,
- 0x00,0x72,0x51,0x51,0x51,0x4e,0x00,0x00,
- 0x00,0x3e,0x49,0x49,0x49,0x26,0x00,0x00,
- 0x00,0x40,0x40,0x40,0x4f,0x70,0x00,0x00,
- 0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00,
- 0x00,0x32,0x49,0x49,0x49,0x3e,0x00,0x00,};
-
- uchar i=0,t=0,Num_Index = 0;
- void main() // 主程式
- {
- P3 = 0x80;
- TMOD = 0x00;
- TH0 = (8192-2000)/32; // 設定 T0 初值,2mS 中斷一次
- TL0 = (8192-2000)%32;
- TR0 = 1; // 啟動 T0 開始計時
- IE = 0x82; // 啟動 Timer 0 中斷功能
- Num_Index = 0;
- while(1); // 無窮迴圈,等待 Timer 0 每間隔 2mS 執行中斷服務程式
- }
- void LED_Screen_Display() interrupt 1 // 每間隔 2mS T0 中斷一次,中斷服務程式
- {
- TH0 = (8192-2000)/32; // T0 reload 新值,設定於 2mS 後,再中斷一次
- TL0 = (8192-2000)%32;
- P3 = _crol_(P3,1); // Port 3 左移位 1 bit
- P0 = ~Table_OF_Digits[Num_Index * 8 +i];
- if(++i == 8)
- i = 0;
- if(++t == 250)
- {
- t = 0x00;
- if(++Num_Index == 10)
- Num_Index = 0;
- }
- }
複製代碼 電路圖 如下:
|