ผู้เขียน หัวข้อ: งานครั้งที่ 20 เขียนโปรแกรมแสดงผลตัวเลขบน 7 Segment MAX7219 & UART (install Lib)  (อ่าน 6583 ครั้ง)

admin

  • Administrator
  • Hero Member
  • *****
  • กระทู้: 706
    • ดูรายละเอียด
    • อีเมล์
เขียนโปรแกรมแสดงผลตัวเลขบน 7 Segment MAX7219 และ UART
ฟังก์ชั่นอยู่ในกลุ่ม Serial http://arduino.cc/en/Reference/Serial
-Serial.begin() http://arduino.cc/en/Serial/Begin
-if (Serial) http://arduino.cc/en/Serial/IfSerial
-Serial.available() http://arduino.cc/en/Serial/Available
-Serial.read() http://arduino.cc/en/Serial/Read
-Serial.print() http://arduino.cc/en/Serial/Print
-Serial.println() http://arduino.cc/en/Serial/Println
-Serial.flush() http://arduino.cc/en/Serial/Flush

ฟังก์ชั่นทั่วไป
-delay() http://arduino.cc/en/Reference/Delay
-millis()http://arduino.cc/en/Reference/Millis

ไลบารี่เพิ่มเติม
-LedControl.h https://github.com/wayoda/LedControl/releases

การเพิ่มไลบารี่ลงในโปรแกรม Arduino IDE จากไฟล์ Zip
1. ดาวน์โหลดไฟล์ Zip ดังรูป


2. ทำการเพิ่มไลบรารี่ลงในโปรแกรม Arduino IDE โดยการเพิ่มจากไฟล์ zip แล้วทำการหาไฟล์ zip ที่ได้จากการดาวน์โหลดในข้อ 1



ฟังก์ชั่นในไลบารี่ LedControl.h
-LedControl lc=LedControl(dataPin,clkPin,csPin,numDevices);
-lc.shutdown(addr,false);         // Enable display
-lc.setIntensity(addr,value);     // Set brightness level (0 is min, 15 is max)
-lc.clearDisplay(addr);             // Clear display register
-lc.setDigit(addr, digit, value, point_decimal)  //display number 0-9
-lc.setChar(addr, digit, character, false)          //display character etc. A,b,c,d,E,F,H,L,P,-,_
-lc.setRow(addr, digit,value)                          //display part of segment

รายละเอียดเพิ่มเติมของไลบารี่ http://playground.arduino.cc/Main/LedControl

โจทย์โปรแกรม
-แสดงตัวเลขเวลาตั้งแต่โปรแกรมเริ่มทำงาน (1/10 วินาที) ที่ 7 segment MAX7219 และแสดงผลผ่าน UART
-โปรแกรมรายละเอียดพิเศษรายกลุ่ม (แจ้งให้ทราบเมื่อถึงชั่วโมงเรียน)


วงจรที่ใช้ในการทดลองสำหรับผู้ที่ใช้บอร์ด Arduino


วงจรที่ใช้ในการทดลองสำหรับผู้ที่ใช้ไอซี ATmega328 (ที่มี Boot Loader Arduino)


บริเวณใช้งานบอร์ดทดลอง

โมดูลสำเร็จรูปเพิ่มเติม
MAX7219 7 Segment

http://www.arduinoall.com (คลิก)

ตัวอย่างการใช้งานฟังก์ชั่น setRow


ตัวอย่างโปรแกรม
โค๊ด: [Select]
#include "LedControl.h"
LedControl lc=LedControl(11,13,12,1); // Pin 11->DIN, 13->CLK, 12->CS, 1 = No.of devices
void setup()
{
  lc.shutdown(0,false);    // Enable display
  lc.setIntensity(0,10);   // Set brightness level (0 is min, 15 is max)
  lc.clearDisplay(0);      // Clear display register
}
void loop()
{
   lc.setDigit(0,7,2,false);   
   lc.setDigit(0,6,3,true);
   lc.setDigit(0,5,4,false);
   lc.setRow(0,4,B00110111);
   lc.setRow(0,3,B01001111);
   lc.setRow(0,2,B00001110);     
   lc.setRow(0,1,B00001110);
   lc.setRow(0,0,B01111110);   
  delay(1000);
}
« แก้ไขครั้งสุดท้าย: มิถุนายน 27, 2017, 07:59:52 PM โดย admin »