2018年4月4日 星期三

TM1638 範例 使用NODEMCU

TM1638 範例

To activate the board and set the display brightness we use the 1000abbb (0x8?) command where the bit marked as a is used to activate/deactivate the board and bits marked as bbb are used to set the brightness of the display. For example to activate the board and set the brightness of the display to the maximum value we need to send 0x8f. This function does not have any arguments.
To write a byte at specific address we send the 010000100 (0x44) command followed by the address in the form of 1100aaaa (aaaa bits denote the location we want to write to) followed by the value. For example to write the value 0x45 at address 0x0a we would have to send the following sequence of bytes: 0x44 0xca 0x45.
If we want to write values at consecutive addresses (very helpful to reset the board) we would send 01000000 (0x40) followed by the starting address (again in the form of 1100aaaa) followed by the values we want to write. For instance if we send 0x40 0xc0 0x00 0x01 0x02 0 would be written at address 0, 1 would be written at address 1 and 2 would be written at address 2. Note that we have 4 bits to select the address which means there are sixteen locations that can be written to. If you continue writing after reaching the address 0x0f it will wrap and you will start again from address 0x00.
To read buttons we send the 010000010 (0x42) command, set the data pin as INPUT and read 4 bytes containing button status.
CommandArgumentsDescription
0x8? (1000abbb)(none)activate board (bit a), set brightness (bits b)
0x44 (01000100)0xc? 0x??write value 0x?? at location 0xc? (single address mode)
0x40 (01000000)0xc? 0x?? 0x?? 0x??write values 0x?? starting from location 0xc? (address auto increment mode)
0x42 (01000010)N/Aread buttons


使用NODEMCU 

const int strobe = 4;   //D2
const int clock = 5;    //D1
const int data = 16;    //D0

int COUNTING_digit=0xc0;
int  digit = 0;

void sendCommand(uint8_t value)
{
  digitalWrite(strobe, LOW);
  shiftOut(data, clock, LSBFIRST, value);
  digitalWrite(strobe, HIGH);
}

void reset()
{
  sendCommand(0x40); // set auto increment mode
  digitalWrite(strobe, LOW);
  shiftOut(data, clock, LSBFIRST, 0xc0);   // set starting address to 0
  for(uint8_t i = 0; i < 16; i++)
  {
    shiftOut(data, clock, LSBFIRST, 0x00);
  }
  digitalWrite(strobe, HIGH);
}

void setup()
{
  pinMode(strobe, OUTPUT);
  pinMode(clock, OUTPUT);
  pinMode(data, OUTPUT);

  sendCommand(0x8f);  // activate
  reset();
}

int number=9500;
void loop()
{
                       /*0*/ /*1*/ /*2*/ /*3*/ /*4*/ /*5*/ /*6*/ /*7*/ /*8*/ /*9*/
  uint8_t digits[] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f ,0x00};

  int number1=number; 
  int n3=number1/1000;
  number1=number1%1000;
  int n2=number1/100;
  number1=number1%100;
  int n1=number1/10;
  int n0=number1%10;

  sendCommand(0x44);  // set single address
  digitalWrite(strobe, LOW);
  shiftOut(data, clock, LSBFIRST, 0xc8); // 4st digit
  shiftOut(data, clock, LSBFIRST, digits[n3]);
  digitalWrite(strobe, HIGH);

  digitalWrite(strobe, LOW);
  shiftOut(data, clock, LSBFIRST, 0xca); // 3st digit
  shiftOut(data, clock, LSBFIRST, digits[n2]);
  digitalWrite(strobe, HIGH);

  digitalWrite(strobe, LOW);
  shiftOut(data, clock, LSBFIRST, 0xcc); // 2st digit
  shiftOut(data, clock, LSBFIRST, digits[n1]);
  digitalWrite(strobe, HIGH);

  digitalWrite(strobe, LOW);
  shiftOut(data, clock, LSBFIRST, 0xce); // 1st digit
  shiftOut(data, clock, LSBFIRST, digits[n0]);
  digitalWrite(strobe, HIGH);


  digitalWrite(strobe, LOW);
  shiftOut(data, clock, LSBFIRST, 0xcf); // 1st LED
  shiftOut(data, clock, LSBFIRST, n0%2);
  digitalWrite(strobe, HIGH);

 //0xc0  第8個 七段   0xc2  第7個 七段   0xc4   第6個 七段   0xc6  第5個 七段  0xc8  第4個 七段
//0xc1   第8個 LED   0xc3  第7個 LED   0xc5   第6個 LED   0xc7   第5個 LED  0xc9   第4個 LED   


  number = number+1;
  if (number>=10000)
      number=0;
  delay(100);
  
}


沒有留言:

張貼留言

113 學年度第 1 學期 RFID應用課程 Arduino程式

113 學年度第 1 學期 RFID應用課程 Arduino程式 https://www.mediafire.com/file/zr0h0p3iosq12jw/MFRC522+(2).7z/file 內含修改過後的 MFRC522 程式庫 (原程式有錯誤) //定義MFRC522...