DanielPHuber 16 Posted June 9, 2015 Share Posted June 9, 2015 A display is a nice thing to have in many projects. A very cheap solution for only 2$ to 4$ is a 4 digit display from Qifei that can be found e.g. at www.Aliexpress.com. Of course, for this price you do not get a user manual! But what beats me is that I could not find a usable description on the internet. Therefore I had to rely on trial and error. Here is what I learned. The device has 2 cascaded 74HC595 shift registers, one for the digit select, the other for segements select. By this the deviceu can only display one digit at a time. Therefore, you must time multiplex the for digits fast enough that there is no flickering visible. Communication is serial, either by Bit banging or you may comfortably use the bult in SPI with the MSP430G2553 CPU. Energia is a very valuable tool for jobs like this. SPI will shift the data into the shift registers, but to output the data you have to shake (rising edge) the RCLK line, this will latch the output lines. Unfortunately this is not implemented in the Energia library for MSP430 (although the manual claims it) and you have to do it "by hand". Negative logic is used to display a digit. That is, a 1 bit switches the corresponding segment off. The segments of a single digit are numbered like: 0 5 1 6 4 2 3 7 where 7 is the decimal point. E.g. to display a 0 with a decimal point you would send: B01000000 The device has 5 input pins: Vcc: 3-5V Gnd DIO: the data signal SCLK: the clock signal, data will be read on the rising edge RCLK: on the rising edge of this signal the data and address will be latched to the output lines of the shift register Details of the interface can be seen in the following example program. It is a counter that counts 1/10 seconds. The interface is in the subroutine "set": // example for interfacing the 4 digit display from Qifei // 1/10 sec counter // The display can only show one single digit at a time. We // therefore need to time multiplex the display fast enough. #include <SPI.h> #define RCLK P2_0 // latch #define SCLK P1_5 // clock #define MOSI P1_7 // data to display //#define MISO P1_6 // data from peripherie, not used here const byte digit[] = //seven segment (+ 1 decimal point) bits { B11000000, //0 B11111001, //1 B10100100, //2 B10110000, //3 B10011001, //4 B10010010, //5 B10000010, //6 B11111000, //7 B10000000, //8 B10010000, //9 B10001000, //A B10000011, //b B11000110, //C B10100001, //d B10000110, //E B10001110 //F }; byte colDig[4] = // digits { B00000001, // digit 1 B00000010, // digit 2 B00000100, // digit 3 B00001000, // digit 4 }; byte dp= B01111111; //Decimal point. AND (&) with data byte empty= B11111111; // clear void setup() { pinMode (RCLK, OUTPUT); digitalWrite(RCLK,LOW); SPI.begin(); // SPI.setDataMode(SPI_MODE0); //default // SPI.setBitOrder(MSBFIRST); //default } void loop() { int del=1; long val=millis(); //decimal while(val>=1000000L) val-= 1000000L; int t1= val/100000L; val-= t1*100000L; int t2= val/10000L; val-= t2*10000L; int t3= val/1000L; val-= t3*1000L; int t4= val/100L; val-= t4*100L; // hexadecimal /* val/=100; int t1= val/4096L; val-= t1*4096L; int t2= val/256L; val-= t2*256L; int t3= val/16L; val-= t3*16L; int t4= val; */ for(int i1=0;i1<4;i1++){ set(digit[t1],colDig[3]);delay(del); set(digit[t2],colDig[2]);delay(del); set(digit[t3] & dp,colDig[1]);delay(del); set(digit[t4],colDig[0]);delay(del); set(empty,colDig[0]); } } // set one digit void set(byte val, byte dig){ digitalWrite(RCLK,LOW); SPI.transfer(val); // value SPI.transfer(dig); // which digit digitalWrite(RCLK,HIGH); } Note that there is a similar device with the TM1637 chip that is different from what I described here. bluehash 1 Quote Link to post Share on other sites
bluehash 1,581 Posted June 9, 2015 Share Posted June 9, 2015 Thanks! pictures? Quote Link to post Share on other sites
Barcooler 0 Posted May 2, 2017 Share Posted May 2, 2017 Hello. Tell me please, how can I use this library? Where can I get the header file SPI.h? In what environment was the program developed? Thank you. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.