痞酷網_PIGOO

 找回密碼
 立即註冊
!!! [系統偵測到廣告阻擋軟體] !!!

如果您覺得痞酷網對您有些許幫助,或者您認同痞酷網的理想,

那麼希望您將痞酷網設定為白名單.

並請在上論壇的時候,動動您的手指,用行動支持我們.

謝謝!
查看: 6945|回復: 0

測試 lgc12002 初步ok

[複製鏈接]
發表於 2016-7-23 14:02:18 | 顯示全部樓層 |閱讀模式
收到了L大送來的禮物. 很潦草地隨便測試一下, 準備繼續改良做玩具, 目的是測試在單電池供電可否運作, 結果是OK. 20mA-40mA, 比較耗電, 不過3.5V-4.2還是正常運作. ARDUINO 已經拆除 5V 穩壓IC, 不需要, 不然更耗電, 原因不詳. 要自行控制寫特殊符號, 例如 r, 口, 等字符, 還沒研究出來. 有空再來.


test lgc12002

test lgc12002




接線圖

test lgc12002

test lgc12002


接線圖再放大一點, 這樣接, 麵包板最有條理

test lgc12002

test lgc12002





測試碼, 抄來的

Arduino skectch
  1. #include <PT6961.h>

  2. // Pin 4 = CS
  3. // Pin 3 = CLK
  4. // Pin 2 = DIN
  5. PT6961 LED(2, 3, 4);
  6. void setup()
  7. {
  8.      LED.initDisplay();
  9. LED.sendCmd(0x8a); // (_DISPLAY_4_16); // dim LED display 1/4
  10.      Serial.begin(9600);
  11. }

  12. void loop()
  13. {
  14.      //count through 0-9,a-f
  15.      for(int i=0; i<16; i++)
  16.      {
  17.           LED.sendDigits(0,0,0,i,0);
  18.           Serial.println(i);
  19.           delay(1000);
  20.      }
  21. }
複製代碼




PT6961.cpp
  1. /*
  2.   PT6961.cpp - Library for communicating with PT6961 LED driver.
  3.   Created by Garrett Blanton January, 16, 2013.
  4.   Released into the public domain.
  5. */

  6. //0 - A
  7. //1 - B
  8. //2 - C
  9. //3 - D
  10. //4 - E
  11. //5 - F
  12. //6 - G
  13. //7 - Colon

  14. #include "Arduino.h"
  15. #include "PT6961.h"

  16. PT6961::PT6961(int DIN, int CLK, int CS)
  17. {
  18.   pinMode(DIN, OUTPUT);
  19.   pinMode(CLK, OUTPUT);
  20.   pinMode(CS, OUTPUT);
  21.   _DIN = DIN;
  22.   _CLK = CLK;
  23.   _CS = CS;
  24. }

  25. void PT6961::initDisplay()
  26. {
  27.   sendCmd(_DISPLAY_6X12);
  28.   sendCmd(_AUTO_INCREMENT);
  29.   initRAM();
  30.   sendCmd(_DISPLAY_14_16);
  31. }

  32. // Initializes RAM to all zeros
  33. void PT6961::initRAM()
  34. {
  35.   //first clear 8 bytes of the display RAM
  36.   digitalWrite(_CS,LOW);
  37.   shiftOut(_DIN, _CLK, LSBFIRST, 0xC0);
  38.   for(int i=0; i<8; i++){
  39.     shiftOut(_DIN, _CLK, LSBFIRST, 0x00);
  40.   }
  41.   digitalWrite(_CS,HIGH);
  42. }

  43. // Use to send command based on enumeration
  44. void PT6961::sendCmd(char cmd)
  45. {
  46.   digitalWrite(_CS,LOW);
  47.   shiftOut(_DIN, _CLK, LSBFIRST, cmd);
  48.   digitalWrite(_CS,HIGH);  
  49. }

  50. void PT6961::sendDigit(char digit, char val)
  51. {
  52.   digitalWrite(_CS,LOW);
  53.   shiftOut(_DIN, _CLK, LSBFIRST, digit);
  54.   shiftOut(_DIN, _CLK, LSBFIRST, val);
  55.   digitalWrite(_CS,HIGH);   
  56. }

  57. void PT6961::sendNum(int num, char colon)
  58. {
  59.   int digit1 = num / 1000;
  60.   int digit2 = (num % 1000) / 100;
  61.   int digit3 = (num % 100) / 10;
  62.   int digit4 = (num % 10);
  63.   
  64.   sendDigits(digit1,digit2,digit3,digit4,colon);
  65. }

  66. void PT6961::sendDigits(char digit1, char digit2, char digit3, char digit4, char colon)
  67. {

  68.   const char DISP[17] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x58, 0x5e, 0x79, 0x71, 0x61};
  69.   
  70.   digitalWrite(_CS,LOW);
  71.   shiftOut(_DIN, _CLK, LSBFIRST, 0xC0);
  72.   
  73.   if(colon == 1)
  74.   {
  75.     shiftOut(_DIN, _CLK, LSBFIRST, DISP[digit1] | 0x80);
  76.   }
  77.   else
  78.   {
  79.     shiftOut(_DIN, _CLK, LSBFIRST, DISP[digit1]);
  80.   }

  81.   shiftOut(_DIN, _CLK, LSBFIRST, 0xC2);

  82.   if(colon == 1)  
  83.   {
  84.     shiftOut(_DIN, _CLK, LSBFIRST, DISP[digit2] | 0x80);
  85.   }
  86.   else
  87.   {
  88.     shiftOut(_DIN, _CLK, LSBFIRST, DISP[digit2]);
  89.   }
  90.   
  91.   shiftOut(_DIN, _CLK, LSBFIRST, 0xC4);
  92.   shiftOut(_DIN, _CLK, LSBFIRST, DISP[digit3]);
  93.   shiftOut(_DIN, _CLK, LSBFIRST, 0xC6);
  94.   shiftOut(_DIN, _CLK, LSBFIRST, DISP[digit4]);
  95.   digitalWrite(_CS,HIGH);   
  96. }
複製代碼





PT6961.h
  1. /*
  2.   PT6961.h - Library for communicating with PT6961 LED driver.
  3.   Created by Garrett Blanton January, 16, 2013.
  4.   Released into the public domain.
  5. */

  6. #ifndef PT6961_h
  7. #define PT6961_h

  8. #include "Arduino.h"

  9. class PT6961
  10. {
  11.   public:
  12.   
  13.     PT6961(int DIN, int CLK, int CS);
  14.     void initDisplay();
  15.     void initRAM();
  16.     void sendCmd(char cmd);
  17.     void sendDigit(char digit, char val);
  18.     void sendNum(int num, char colon);
  19.     void sendDigits(char digit1, char digit2, char digit3, char digit4, char colon);
  20.        
  21.     const static char _DISPLAY_6X12 = 0x02;
  22.     const static char _DISPLAY_7X11 = 0x03;
  23.     const static char _AUTO_INCREMENT = 0x40;
  24.     const static char _FIXED_ADDRESS = 0x44;
  25.     const static char _DISPLAY_OFF = 0x80;
  26.     const static char _DISPLAY_1_16 = 0x88;
  27.     const static char _DISPLAY_2_16 = 0x89;
  28.     const static char _DISPLAY_4_16 = 0x8A;
  29.     const static char _DISPLAY_10_16 = 0x8B;
  30.     const static char _DISPLAY_11_16 = 0x8C;
  31.     const static char _DISPLAY_12_16 = 0x8D;
  32.     const static char _DISPLAY_13_16 = 0x8E;
  33.     const static char _DISPLAY_14_16 = 0x8F;
  34.        
  35.   private:
  36.   
  37.         int _DIN;
  38.     int _CLK;
  39.     int _CS;
  40.        
  41. };

  42. #endif
複製代碼



您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

關閉

站長小叮嚀上一條 /1 下一條

禁閉室|手機版|連繫我們|痞酷網電子技術論壇

GMT+8, 2024-11-5 02:47 PM , Processed in 0.477464 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.