冰楓論壇

 找回密碼
 立即註冊
搜索
查看: 596|回覆: 0
打印 上一主題 下一主題

[討論] Padauk PMS150C製作六位數字時鐘

[複製鏈接]

2609

主題

0

好友

1010

積分

金牌會員

Rank: 6Rank: 6

UID
373967
帖子
9061
主題
2609
精華
0
積分
1010
楓幣
0
威望
987
存款
36233
贊助金額
0
推廣
0
GP
1205
閱讀權限
70
在線時間
462 小時
註冊時間
2023-1-12
最後登入
2024-12-30

2023端午節紀念勳章 2023中秋節紀念勳章 2023聖誕節紀念勳章

跳轉到指定樓層
1
發表於 2023-4-2 11:53:52 |只看該作者 |倒序瀏覽
製作六位數字時鐘所需材料:

Padauk PMS150C 微控制器
6 位共陰極 7 段 LED 數字顯示器
6 顆 220Ω 電阻
2 個按鈕作為時間校正用
電路板、麵包板或其他適當的電路搭建工具
杜邦線等連接線材
一個 5V 直流電源
程式碼範例,使用 Padauk PMS150C 控制 LED 顯示器顯示時間:


#include <PMS150C.h>

// Pin definitions
#define CLOCK_PIN   0
#define DATA_PIN    1
#define LATCH_PIN   2
#define BUTTON1_PIN 3
#define BUTTON2_PIN 4

// Global variables
unsigned int timer = 0;   // Timer counter
unsigned int seconds = 0; // Current time in seconds
unsigned int minutes = 0; // Current time in minutes
unsigned int hours = 0;   // Current time in hours
unsigned int mode = 0;    // Current mode (normal or setting)

void setup() {
  // Set pin modes
  pinMode(CLOCK_PIN, OUTPUT);
  pinMode(DATA_PIN, OUTPUT);
  pinMode(LATCH_PIN, OUTPUT);
  pinMode(BUTTON1_PIN, INPUT_PULLUP);
  pinMode(BUTTON2_PIN, INPUT_PULLUP);

  // Initialize timer
  TMR0 = 6;    // Prescale = 1:64, TMR0 = 6 (256-6)*64/1000000 = 10.24us
  OPTION = 0b00000111; // Prescale = 1:64, timer is on

  // Set initial time
  seconds = 0;
  minutes = 0;
  hours = 0;
}

void loop() {
  // Read buttons
  if (digitalRead(BUTTON1_PIN) == LOW) {
    mode = 1;
  } else if (digitalRead(BUTTON2_PIN) == LOW) {
    mode = 2;
  } else {
    mode = 0;
  }

  // Update time
  if (timer >= 976) {  // 976 * 10.24us = 10ms
    timer = 0;
    seconds++;
    if (seconds >= 60) {
      seconds = 0;
      minutes++;
      if (minutes >= 60) {
        minutes = 0;
        hours++;
        if (hours >= 24) {
          hours = 0;
        }
      }
    }
  }

  // Display time
  if (mode == 0) {
    // Display time normally
    displayDigit(0, hours / 10);
    displayDigit(1, hours % 10);
    displayDigit(2, minutes / 10);
    displayDigit(3, minutes % 10);
    displayDigit(4, seconds / 10);
    displayDigit(5, seconds % 10);
  } else if (mode == 1) {
    // Set hours
    if (digitalRead(BUTTON2_PIN) == LOW) {
      hours++;
      if (hours >= 24) {
        hours = 0;
      }
     
#include <PMS150C.h>

// Pin definitions
#define CLOCK_PIN   0
#define DATA_PIN    1
#define LATCH_PIN   2
#define BUTTON1_PIN 3
#define BUTTON2_PIN 4

// Global variables
unsigned int timer = 0;   // Timer counter
unsigned int seconds = 0; // Current time in seconds
unsigned int minutes = 0; // Current time in minutes
unsigned int hours = 0;   // Current time in hours
unsigned int mode = 0;    // Current mode (normal or setting)

void setup() {
  // Set pin modes
  pinMode(CLOCK_PIN, OUTPUT);
  pinMode(DATA_PIN, OUTPUT);
  pinMode(LATCH_PIN, OUTPUT);
  pinMode(BUTTON1_PIN, INPUT_PULLUP);
  pinMode(BUTTON2_PIN, INPUT_PULLUP);

  // Initialize timer
  TMR0 = 6;    // Prescale = 1:64, TMR0 = 6 (256-6)*64/1000000 = 10.24us
  OPTION = 0b00000111; // Prescale = 1:64, timer is on

  // Set initial time
  seconds = 0;
  minutes = 0;
  hours = 0;
}

void loop() {
  // Read buttons
  if (digitalRead(BUTTON1_PIN) == LOW) {
    mode = 1;
  } else if (digitalRead(BUTTON2_PIN) == LOW) {
    mode = 2;
  } else {
    mode = 0;
  }

  // Update time
  if (timer >= 976) {  // 976 * 10.24us = 10ms
    timer = 0;
    seconds++;
    if (seconds >= 60) {
      seconds = 0;
      minutes++;
      if (minutes >= 60) {
        minutes = 0;
        hours++;
        if (hours >= 24) {
          hours = 0;
        }
      }
    }
  }

  // Display time
  if (mode == 0) {
    // Display time normally
    displayDigit(0, hours / 10);
    displayDigit(1, hours % 10);
    displayDigit(2, minutes / 10);
    displayDigit(3, minutes % 10);
    displayDigit(4, seconds / 10);
    displayDigit(5, seconds % 10);
  } else if (mode == 1) {
    // Set hours
    if (digitalRead(BUTTON2_PIN) == LOW) {
      hours++;
      if (hours >= 24) {
        hours = 0;
      }
      delay(100); // debounce
    }
    displayDigit(0, hours / 10);
    displayDigit(1, hours % 10);
    displayDigit(2, 0);
    displayDigit(3, 0);
    displayDigit(4, 0);
    displayDigit(5, 0);
  } else if (mode == 2) {
    // Set minutes
    if (digitalRead(BUTTON2_PIN) == LOW) {
      minutes++;
      if (minutes >= 60) {
        minutes = 0;
      }
      delay(100); // debounce
    }
    displayDigit(0, 0);
   
#include <PMS150C.h>

// Pin definitions
#define CLOCK_PIN   0
#define DATA_PIN    1
#define LATCH_PIN   2
#define BUTTON1_PIN 3
#define BUTTON2_PIN 4

// Global variables
unsigned int timer = 0;   // Timer counter
unsigned int seconds = 0; // Current time in seconds
unsigned int minutes = 0; // Current time in minutes
unsigned int hours = 0;   // Current time in hours
unsigned int mode = 0;    // Current mode (normal or setting)

void setup() {
  // Set pin modes
  pinMode(CLOCK_PIN, OUTPUT);
  pinMode(DATA_PIN, OUTPUT);
  pinMode(LATCH_PIN, OUTPUT);
  pinMode(BUTTON1_PIN, INPUT_PULLUP);
  pinMode(BUTTON2_PIN, INPUT_PULLUP);

  // Initialize timer
  TMR0 = 6;    // Prescale = 1:64, TMR0 = 6 (256-6)*64/1000000 = 10.24us
  OPTION = 0b00000111; // Prescale = 1:64, timer is on

  // Set initial time
  seconds = 0;
  minutes = 0;
  hours = 0;
}

void loop() {
  // Read buttons
  if (digitalRead(BUTTON1_PIN) == LOW) {
    mode = 1;
  } else if (digitalRead(BUTTON2_PIN) == LOW) {
    mode = 2;
  } else {
    mode = 0;
  }

  // Update time
  if (timer >= 976) {  // 976 * 10.24us = 10ms
    timer = 0;
    seconds++;
    if (seconds >= 60) {
      seconds = 0;
      minutes++;
      if (minutes >= 60) {
        minutes = 0;
        hours++;
        if (hours >= 24) {
          hours = 0;
        }
      }
    }
  }

  // Display time
  if (mode == 0) {
    // Display time normally
    displayDigit(0, hours / 10);
    displayDigit(1, hours % 10);
    displayDigit(2, minutes / 10);
    displayDigit(3, minutes % 10);
    displayDigit(4, seconds / 10);
    displayDigit(5, seconds % 10);
  } else if (mode == 1) {
    // Set hours
    if (digitalRead(BUTTON2_PIN) == LOW) {
      hours++;
      if (hours >= 24) {
        hours = 0;
      }
      delay(100); // debounce
    }
    displayDigit(0, hours / 10);
    displayDigit(1, hours % 10);
    displayDigit(2, 0);
    displayDigit(3, 0);
    displayDigit(4, 0);
    displayDigit(5, 0);
  } else if (mode == 2) {
    // Set minutes
    if (digitalRead(BUTTON2_PIN) == LOW) {
      minutes++;
      if (minutes >= 60) {
        minutes = 0;
      }
      delay(100); // debounce
    }
    displayDigit(0, 0);
    displayDigit(1, 0);
    displayDigit(2, minutes / 10);
    displayDigit(3, minutes % 10);
    display

#include <PMS150C.h>

// Pin definitions
#define CLOCK_PIN   0
#define DATA_PIN    1
#define LATCH_PIN   2
#define BUTTON1_PIN 3
#define BUTTON2_PIN 4

// Global variables
unsigned int timer = 0;   // Timer counter
unsigned int seconds = 0; // Current time in seconds
unsigned int minutes = 0; // Current time in minutes
unsigned int hours = 0;   // Current time in hours
unsigned int mode = 0;    // Current mode (normal or setting)

void setup() {
  // Set pin modes
  pinMode(CLOCK_PIN, OUTPUT);
  pinMode(DATA_PIN, OUTPUT);
  pinMode(LATCH_PIN, OUTPUT);
  pinMode(BUTTON1_PIN, INPUT_PULLUP);
  pinMode(BUTTON2_PIN, INPUT_PULLUP);

  // Initialize timer
  TMR0 = 6;    // Prescale = 1:64, TMR0 = 6 (256-6)*64/1000000 = 10.24us
  OPTION = 0b00000111; // Prescale = 1:64, timer is on

  // Set initial time
  seconds = 0;
  minutes = 0;
  hours = 0;
}

void loop() {
  // Read buttons
  if (digitalRead(BUTTON1_PIN) == LOW) {
    mode = 1;
  } else if (digitalRead(BUTTON2_PIN) == LOW) {
    mode = 2;
  } else {
    mode = 0;
  }

  // Update time
  if (timer >= 976) {  // 976 * 10.24us = 10ms
    timer = 0;
    seconds++;
    if (seconds >= 60) {
      seconds = 0;
      minutes++;
      if (minutes >= 60) {
        minutes = 0;
        hours++;
        if (hours >= 24) {
          hours = 0;
        }
      }
    }
  }

  // Display time
  if (mode == 0) {
    // Display time normally
    displayDigit(0, hours / 10);
    displayDigit(1, hours % 10);
    displayDigit(2, minutes / 10);
    displayDigit(3, minutes % 10);
    displayDigit(4, seconds / 10);
    displayDigit(5, seconds % 10);
  } else if (mode == 1) {
    // Set hours
    if (digitalRead(BUTTON2_PIN) == LOW) {
      hours++;
      if (hours >= 24) {
        hours = 0;
      }
      delay(100); // debounce
    }
    displayDigit(0, hours / 10);
    displayDigit(1, hours % 10);
    displayDigit(2, 0);
    displayDigit(3, 0);
    displayDigit(4, 0);
    displayDigit(5, 0);
  } else if (mode == 2) {
    // Set minutes
    if (digitalRead(BUTTON2_PIN) == LOW) {
      minutes++;
      if (minutes >= 60) {
        minutes = 0;
      }
      delay(100); // debounce
    }
    displayDigit(0, 0);
    displayDigit(1, 0);
    displayDigit(2, minutes / 10);
    displayDigit(3, minutes % 10);
    displayDigit

#include <PMS150C.h>

// Pin definitions
#define CLOCK_PIN   0
#define DATA_PIN    1
#define LATCH_PIN   2
#define BUTTON1_PIN 3
#define BUTTON2_PIN 4

// Global variables
unsigned int timer = 0;   // Timer counter
unsigned int seconds = 0; // Current time in seconds
unsigned int minutes = 0; // Current time in minutes
unsigned int hours = 0;   // Current time in hours
unsigned int mode = 0;    // Current mode (normal or setting)

void setup() {
  // Set pin modes
  pinMode(CLOCK_PIN, OUTPUT);
  pinMode(DATA_PIN, OUTPUT);
  pinMode(LATCH_PIN, OUTPUT);
  pinMode(BUTTON1_PIN, INPUT_PULLUP);
  pinMode(BUTTON2_PIN, INPUT_PULLUP);

  // Initialize timer
  TMR0 = 6;    // Prescale = 1:64, TMR0 = 6 (256-6)*64/1000000 = 10.24us
  OPTION = 0b00000111; // Prescale = 1:64, timer is on

  // Set initial time
  seconds = 0;
  minutes = 0;
  hours = 0;
}

void loop() {
  // Read buttons
  if (digitalRead(BUTTON1_PIN) == LOW) {
    mode = 1;
  } else if (digitalRead(BUTTON2_PIN) == LOW) {
    mode = 2;
  } else {
    mode = 0;
  }

  // Update time
  if (timer >= 976) {  // 976 * 10.24us = 10ms
    timer = 0;
    seconds++;
    if (seconds >= 60) {
      seconds = 0;
      minutes++;
      if (minutes >= 60) {
        minutes = 0;
        hours++;
        if (hours >= 24) {
          hours = 0;
        }
      }
    }
  }

  // Display time
  if (mode == 0) {
    // Display time normally
    displayDigit(0, hours / 10);
    displayDigit(1, hours % 10);
    displayDigit(2, minutes / 10);
    displayDigit(3, minutes % 10);
    displayDigit(4, seconds / 10);
    displayDigit(5, seconds % 10);
  } else if (mode == 1) {
    // Set hours
    if (digitalRead(BUTTON2_PIN) == LOW) {
      hours++;
      if (hours >= 24) {
        hours = 0;
      }
      delay(100); // debounce
    }
    displayDigit(0, hours / 10);
    displayDigit(1, hours % 10);
    displayDigit(2, 0);
    displayDigit(3, 0);
    displayDigit(4, 0);
    displayDigit(5, 0);
  } else if (mode == 2) {
    // Set minutes
    if (digitalRead(BUTTON2_PIN) == LOW) {
      minutes++;
      if (minutes >= 60) {
        minutes = 0;
      }
      delay(100); // debounce
    }
    displayDigit(0, 0);
    displayDigit(1, 0);
    displayDigit(2, minutes / 10);
    displayDigit(3, minutes % 10);

#include <PMS150C.h>

// Pin definitions
#define CLOCK_PIN   0
#define DATA_PIN    1
#define LATCH_PIN   2
#define BUTTON1_PIN 3
#define BUTTON2_PIN 4

// Global variables
unsigned int timer = 0;   // Timer counter
unsigned int seconds = 0; // Current time in seconds
unsigned int minutes = 0; // Current time in minutes
unsigned int hours = 0;   // Current time in hours
unsigned int mode = 0;    // Current mode (normal or setting)

void setup() {
  // Set pin modes
  pinMode(CLOCK_PIN, OUTPUT);
  pinMode(DATA_PIN, OUTPUT);
  pinMode(LATCH_PIN, OUTPUT);
  pinMode(BUTTON1_PIN, INPUT_PULLUP);
  pinMode(BUTTON2_PIN, INPUT_PULLUP);

  // Initialize timer
  TMR0 = 6;    // Prescale = 1:64, TMR0 = 6 (256-6)*64/1000000 = 10.24us
  OPTION = 0b00000111; // Prescale = 1:64, timer is on

  // Set initial time
  seconds = 0;
  minutes = 0;
  hours = 0;
}

void loop() {
  // Read buttons
  if (digitalRead(BUTTON1_PIN) == LOW) {
    mode = 1;
  } else if (digitalRead(BUTTON2_PIN) == LOW) {
    mode = 2;
  } else {
    mode = 0;
  }

  // Update time
  if (timer >= 976) {  // 976 * 10.24us = 10ms
    timer = 0;
    seconds++;
    if (seconds >= 60) {
      seconds = 0;
      minutes++;
      if (minutes >= 60) {
        minutes = 0;
        hours++;
        if (hours >= 24) {
          hours = 0;
        }
      }
    }
  }

  // Display time
  if (mode == 0) {
    // Display time normally
    displayDigit(0, hours / 10);
    displayDigit(1, hours % 10);
    displayDigit(2, minutes / 10);
    displayDigit(3, minutes % 10);
    displayDigit(4, seconds / 10);
    displayDigit(5, seconds % 10);
  } else if (mode == 1) {
    // Set hours
    if (digitalRead(BUTTON2_PIN) == LOW) {
      hours++;
      if (hours >= 24) {
        hours = 0;
      }
      delay(100); // debounce
    }
    displayDigit(0, hours / 10);
    displayDigit(1, hours % 10);
    displayDigit(2, 0);
    displayDigit(3, 0);
    displayDigit(4, 0);
    displayDigit(5, 0);
  } else if (mode == 2) {
    // Set minutes
    if (digitalRead(BUTTON2_PIN) == LOW) {
      minutes++;
      if (minutes >= 60) {
        minutes = 0;
      }
      delay(100); // debounce
    }
    displayDigit(0, 0);
    displayDigit(1, 0);
    displayDigit(2, minutes / 10);
    displayDigit(3, minutes % 10);
    display
收藏收藏0 推0 噓0


把本文推薦給朋友或其他網站上,每次被點擊增加您在本站積分: 1鑰匙
複製連結並發給好友,以賺取推廣點數
簡單兩步驟,註冊、分享網址,即可獲得獎勵! 一起推廣文章換商品、賺$$
高級模式
B Color Image Link Quote Code Smilies |上傳

廣告刊登意見回饋關於我們管群招募本站規範DMCA隱私權政策

Copyright © 2011-2024 冰楓論壇, All rights reserved

免責聲明:本網站是以即時上載留言的方式運作,本站對所有留言的真實性、完整性及立場等,不負任何法律責任。

而一切留言之言論只代表留言者個人意見,並非本網站之立場,用戶不應信賴內容,並應自行判斷內容之真實性。

小黑屋|手機版|冰楓論壇

GMT+8, 2024-12-30 20:38

回頂部