- UID
- 373967
- 帖子
- 9013
- 主題
- 2609
- 精華
- 0
- 積分
- 1004
- 楓幣
- 0
- 威望
- 981
- 存款
- 35926
- 贊助金額
- 0
- 推廣
- 0
- GP
- 1205
- 閱讀權限
- 70
- 在線時間
- 460 小時
- 註冊時間
- 2023-1-12
- 最後登入
- 2024-12-23
|
這裡提供的程式碼示例是使用C語言編寫
#include <STC8.H>
// Define the pins for the 18 LEDs
#define LED_PIN_1 P10
#define LED_PIN_2 P11
#define LED_PIN_3 P12
#define LED_PIN_4 P13
#define LED_PIN_5 P14
#define LED_PIN_6 P15
#define LED_PIN_7 P16
#define LED_PIN_8 P17
#define LED_PIN_9 P30
#define LED_PIN_10 P31
#define LED_PIN_11 P32
#define LED_PIN_12 P33
#define LED_PIN_13 P34
#define LED_PIN_14 P35
#define LED_PIN_15 P36
#define LED_PIN_16 P37
#define LED_PIN_17 P06
#define LED_PIN_18 P07
void main(void)
{
// Configure the pins for the LEDs as output
LED_PIN_1 = 0;
LED_PIN_2 = 0;
LED_PIN_3 = 0;
LED_PIN_4 = 0;
LED_PIN_5 = 0;
LED_PIN_6 = 0;
LED_PIN_7 = 0;
LED_PIN_8 = 0;
LED_PIN_9 = 0;
LED_PIN_10 = 0;
LED_PIN_11 = 0;
LED_PIN_12 = 0;
LED_PIN_13 = 0;
LED_PIN_14 = 0;
LED_PIN_15 = 0;
LED_PIN_16 = 0;
LED_PIN_17 = 0;
LED_PIN_18 = 0;
// Loop forever
while (1)
{
// Turn on each LED in sequence for a short period of time
LED_PIN_1 = 1;
DelayMs(100);
LED_PIN_1 = 0;
LED_PIN_2 = 1;
DelayMs(100);
LED_PIN_2 = 0;
LED_PIN_3 = 1;
DelayMs(100);
LED_PIN_3 = 0;
LED_PIN_4 = 1;
DelayMs(100);
LED_PIN_4 = 0;
LED_PIN_5 = 1;
DelayMs(100);
LED_PIN_5 = 0;
LED_PIN_6 = 1;
DelayMs(100);
LED_PIN_6 = 0;
LED_PIN_7 = 1;
DelayMs(100);
LED_PIN_7 = 0;
LED_PIN_8 = 1;
DelayMs(100);
LED_PIN_8 = 0;
LED_PIN_9 = 1;
DelayMs(100);
LED_PIN_9 = 0;
LED_PIN_10 = 1;
DelayMs(100);
LED_PIN_10 = 0;
LED_PIN_11 = 1;
DelayMs(100);
LED_PIN_11 = 0;
LED_PIN_12 = 1;
DelayMs(100
LED_PIN_12 = 0;
LED_PIN_13 = 1;
DelayMs(100);
LED_PIN_13 = 0;
LED_PIN_14 = 1;
DelayMs(100);
LED_PIN_14 = 0;
LED_PIN_15 = 1;
DelayMs(100);
LED_PIN_15 = 0;
LED_PIN_16 = 1;
DelayMs(100);
LED_PIN_16 = 0;
LED_PIN_17 = 1;
DelayMs(100);
LED_PIN_17 = 0;
LED_PIN_18 = 1;
DelayMs(100);
LED_PIN_18 = 0;
}
}
這個示例程式中,我們先定義了每個LED的輸出引腳,然後在主函數中設置了這些引腳為輸出模式。在一個無限循環中,我們逐個點亮每個LED,每個LED亮100毫秒,然後熄滅。這樣就可以讓所有LED依次閃爍。 |
|