Jump to content

shluzzzoid

Members
  • Content Count

    19
  • Joined

  • Last visited

  • Days Won

    1

Reputation Activity

  1. Like
    shluzzzoid got a reaction from larryfraz in ds1394 RTC + led driver tm1638   
    Hello!
     
    This is my project Real Time Clock. The project used RTC module ds1394, temperature sensor ds18b20 and driver 7-segment display tm1638. msp430g2553 MCU integrates devices with two hardware ports SPI (USART1, USART2).
    Clock Functions:- Showing the time, date, day of the week;
    - Set the alarm;
    - Shows the temperature of the sensor ds18b20;
    - Control the brightness of the indicator.
     
    Video:

     
    Russian description
    Source code

     
    Video:


     
    My project site
     
    Project includes:
    - DS1394 msp430 launchpad interface
    - ds18b20 maxim + msp430 launchpad
    - Library for TM1638 to MSP430
     
     
    PS: my son was born! Now I do not know whether the time to continue the projects. I hope that I can find the time to do a good description of the projects.
     
    PPS: Sorry for my english...
  2. Like
    shluzzzoid reacted to t0mpr1c3 in [ ENDED ] Nov 2013 - Jan 2014 - 43oh Project of the Month Contest   
    The background to this project is that when we moved into our house 18 months ago the heat wouldn't turn on. It turned out that the wires connecting the thermostat in the 2nd floor hallway to the furnace in the basement were broken. I moved the thermostat into the basement and ever since we have been trying to guess the settings that will keep the rest of the house a stable and comfortable temperature.
     
    Those days are on the way out. In place of the old thermostat is a wireless thermometer based on my own "Magic Mote" MSP430G2553 sensor node with NRF24L01+ module. I am using aDHT22/AM2303 digital temperature and humidity sensor.
     

     
    Controlling the furnace is a 2-coil latching relay on a very ugly perfboard circuit powered by the doorbell transformer in the basement and governed by a second Magic Mote receiving the 2.4 GHz signals from the temperature sensor.
     

     
    I am satisfied with the hardware design. The only blemish I have  identified is that the TXD and RXD pin labels are reversed.
     

     
    Github repo: https://github.com/t0mpr1c3/magicmote
     
    This picture shows a populated board on a 2xAA battery pack with DS18B20 thermometer.
     

     
    The documentation of the firmware is a work in progress. Wireless communication uses
    the msprf24 library by Spirillis. The DHT22 is read using an interrupt driven routine by TheDZhon ported to C.
     
    Github repository: https://github.com/t...rnace-relay.git
     
    Blog post: http://smokedproject...d-wireless.html
  3. Like
    shluzzzoid reacted to JWoodrell in [ ENDED ] Nov 2013 - Jan 2014 - 43oh Project of the Month Contest   
    I'm going to throw my project on here.
     
    It is a SD card based audible alarm player. *now with sound quality*
     
    the user provides a 24v signal on one of two input wires, and the unit takes that 24v power and uses it to power up the MSP430 and amplifier.  It reads the file linked to that input signal and plays it out the speaker.  I did a couple of tricks to improve sound quality.  right now it is working best with 8kHz 8 bit wav files, but it adapts to other sample rates on the fly.  right now it doesn't understand how to read 16 bit files, but this is just the first draft, and that is in the planning.
     
    http://www.youtube.com/watch?v=wJ-gWZK3wAQ
  4. Like
    shluzzzoid got a reaction from bluehash in ds1394 RTC + led driver tm1638   
    Device:


  5. Like
    shluzzzoid reacted to t0mpr1c3 in [ ENDED ] Nov 2013 - Jan 2014 - 43oh Project of the Month Contest   
    This sounds like a good excuse to get my wireless thermostat project off the ground using those NFR24L01+ backpacks! It's been months since I got them, but now I actually need the heating on.
  6. Like
    shluzzzoid got a reaction from simpleavr in [ ENDED ] Nov 2013 - Jan 2014 - 43oh Project of the Month Contest   
    Hello everyone!
    This is my project a watch with function control RGB-LED tape for the bedroom.
      Video:


     
    Project:
    http://forum.43oh.com/topic/3727-ds1394-rtc-led-driver-tm1638/
     
    Code:
    http://sourceforge.net/projects/msp430clock/
  7. Like
    shluzzzoid got a reaction from bluehash in [ ENDED ] Nov 2013 - Jan 2014 - 43oh Project of the Month Contest   
    Hello everyone!
    This is my project a watch with function control RGB-LED tape for the bedroom.
      Video:


     
    Project:
    http://forum.43oh.com/topic/3727-ds1394-rtc-led-driver-tm1638/
     
    Code:
    http://sourceforge.net/projects/msp430clock/
  8. Like
    shluzzzoid got a reaction from abecedarian in [ ENDED ] Nov 2013 - Jan 2014 - 43oh Project of the Month Contest   
    Hello everyone!
    This is my project a watch with function control RGB-LED tape for the bedroom.
      Video:


     
    Project:
    http://forum.43oh.com/topic/3727-ds1394-rtc-led-driver-tm1638/
     
    Code:
    http://sourceforge.net/projects/msp430clock/
  9. Like
    shluzzzoid got a reaction from gmtii in ds1394 RTC + led driver tm1638   
    Hello!
     
    This is my project Real Time Clock. The project used RTC module ds1394, temperature sensor ds18b20 and driver 7-segment display tm1638. msp430g2553 MCU integrates devices with two hardware ports SPI (USART1, USART2).
    Clock Functions:- Showing the time, date, day of the week;
    - Set the alarm;
    - Shows the temperature of the sensor ds18b20;
    - Control the brightness of the indicator.
     
    Video:

     
    Russian description
    Source code

     
    Video:


     
    My project site
     
    Project includes:
    - DS1394 msp430 launchpad interface
    - ds18b20 maxim + msp430 launchpad
    - Library for TM1638 to MSP430
     
     
    PS: my son was born! Now I do not know whether the time to continue the projects. I hope that I can find the time to do a good description of the projects.
     
    PPS: Sorry for my english...
  10. Like
    shluzzzoid reacted to davebranton in Wireless dual temperature monitor with battery voltage and LCD display   
    I've built a wireless temperature monitor with the following features:
     
    Very low-power (7uA) sleep mode Dual 1-wire dallas temperature sensor inputs, to measure two temperature sensors at the same time. A 2-line LCD display that displays the current measurement for 15 seconds when a button is pushed. 2xAA battery supply, with charge pump to power the LCD, temperature sensors and 433Mhz wireless module. Uses VirtualWire to transmit the data to an MSP430-powered receiver module. This is all currently sitting outside, and the indoor rx unit is uploading the measured temperatures as well as the battery voltage to Cosm.
     
    https://cosm.com/feeds/100842
     
    I've attached to this post the eagle files for the outdoor unit, and the veroboard layout for the same. I'll upload some photos also, and details of the indoor unit and the python script that uploads the data to cosm. The indoor unit is currently sitting on a breadboard, not in a nice project box, but its time will come
     
    TempSensor.zip
     
    I've hacked the VirtualWire library to bits, leaving only the transmitting portion of the code. This was so that I could understand it, and so that I could have it running at a lower timer speed for (very slightly) lower power.
     
    There's a few things in the schematic that might not really be necessary. I've used two fets to switch off the radio and the lcd/sensor separately, because I was under the impression that the radio transmitted the whole time while powered on. I now realise that it only transmits when the data pin is high, so I could have saved myself a component there. Also I'm using a whole hex level shifter IC just for the one input into the radio, because the other shifter's lines are all used up by the LCD. This also isn't necessary, since a singe fet would have done the job if I'd inverted the output of VirtualWire in software.
     
    But in any case, it all works, and seems (so far) fairly reliable. There are some spurious readings that I accidentally uploaded to cosm while working on the receiver end, but other than that I'm pretty happy. What I'm really quite interested in is how the battery voltage is going to change over the coming few years.
     
    Please feel free to use any of the code that I've uploaded, but be aware that in the words of some other forum poster somewhere, it's not supposed to be pretty - it's just supposed to work!
     
    -dave
  11. Like
    shluzzzoid reacted to xmob in Camera Intervalometer With LCD   
    This is the updated version of my camera intervalometer posted here.
     
    The first version was a proof of concept. This is a more feature rich version.
     

     
    What is a camera intervalometer? It's a device that makes your camera take a photo at set intervals. These photos can then be stitched together into a movie. This is often referred to as time lapse photography. A sample video created using this intervalometer is this:


     
    The hardware is what I would consider feature complete for this revision. The software is paused for now. It is functional, but there are several features/improvements that I will be adding in the future.
     
    Compatible cameras
    Currently, the intervalomter works with any Nikon camera that uses the Nikon ML-L3 remote. Support for Canon, Sony and Pentax cameras should be possible. However, I cannot test these so have not spent time on them. Shout up if you have one of the other makes of camera and can test for me!
     
    Operation
    The intervalometer has three buttons: "Menu", "Down" and "Up/Shoot"
     
    On start up the intervalometer is ready to shart shooting at a default interval of 60s. Pressing the "Up/Shoot" button will trigger the camera shutter then start the countdown to the next frame.
     
    At any time the "Menu" button can be pressed to cycle through the various menu options. There are only 2 at the moment; Interval count and interval period.
     
    Interval count is the number of seconds or minutes between frames. Use the "Down" and "Up/Shoot" button to adjust. The interval count can be set to any integer value between 1 and 99. The interval period can be configured to be either seconds or minutes.
     
    Entering the menu will cause any shooting to pause and will wait for you to restart it.
     
    During operation the LCD will display the current interval setting along with how long to go before the next shutter release. It also displays the total number of frames shot during the current session. An on board LED will flash every second to indicate that the intervalometer is currently operating.
     
    Hardware
    The hardware is built around the MSG430G2231. This particular device was chosen simply because it is supplied with the launchpad. Later versions may use a different device with more code space. The 2231 is configured to use the internal DCO clocked in such a way that we are able to get SMCLK to ~38KHz. This frequency is required for the carrier of the IR. SMCLK is connected to P1.4, which drives the IR LED via a 2N2222 transistor.
     
    To save on IO space, the LCD is driven in 4-bit mode via a 74HC595 shift register. This uses only 3 IO instead of 7 (or even 11!).
     
    The input buttons are configured to interrupt on edge changes. A really crafty debounce is possible by adding a delay after entering the interrupt then reading the input level. It's dirty, but it works in this application.
     
    To do
    The hardware supports external triggering (motion sensor, lightning sensor etc) but the software doesn't.
    The hardware supports controlling the LCD backlight but the software doesn't.
    Other camera support.
     
    Resources
    I'll add all the resources here as I've prepared them.
     
    Schematic

     
    Code

    #include "msp430g2231.h" #include #define SHUTTERBUTTON BIT5 #define DOWNBUTTON BIT3 #define MENUBUTTON BIT0 #define IROUT BIT4 #define STATUS BIT6 #define SCLOCK BIT6 #define SDATA BIT7 #define SLATCH BIT7 #define LCDRS 0x02 #define LCDRW 0x04 #define LCDE 0x08 #define SHUTTER nikonShutter() //#define SHUTTER canonShutter() //#define SHUTTER pentaxShutter() //#define SHUTTER sonyShutter() volatile int i; volatile unsigned int shutterInterval = 60; volatile unsigned int intervalCounter; volatile unsigned int delayAcc = 0; volatile unsigned int minAcc = 0; volatile char clockRunning = 0; volatile char period = 's'; volatile unsigned int shutterCount = 0; volatile unsigned int menu = 0; char buf[9] = {0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; void nikonShutter(); void shiftOut(char w, char latch); void LCDdelay(); void resetLCD(); void LCDOut (char b, char d); void LCDString (); void itoa (unsigned int val, char *str); void showMenu(); void main(void) { intervalCounter = shutterInterval; WDTCTL = WDTPW + WDTHOLD; // stop WDT DCOCTL |= DCO0 + DCO1; // DCO = ~300kHz BCSCTL1 |= RSEL0 + RSEL1; BCSCTL1 &= ~(RSEL2 + RSEL3); BCSCTL2 |= DIVS0 + DIVS1; // SMCLK / 8 is ~38kHz P1DIR |= IROUT; // Connect 1.4 to SMCLK which give us our carrier P1OUT &= ~IROUT; P1SEL &= ~IROUT; P1DIR |= STATUS; P1OUT &= ~STATUS; P1REN |= SHUTTERBUTTON + MENUBUTTON + DOWNBUTTON; // pull-up P1OUT |= SHUTTERBUTTON + MENUBUTTON + DOWNBUTTON; // pull-up P1IE |= SHUTTERBUTTON + MENUBUTTON + DOWNBUTTON; // interrupt enabled P1IES |= SHUTTERBUTTON + MENUBUTTON + DOWNBUTTON; // hi/lo edge P1IFG &= ~SHUTTERBUTTON + MENUBUTTON + DOWNBUTTON; P2SEL = 0x00; // User XIN/XOUT as output (P2.6, P2.7) P2DIR |= SCLOCK + SDATA; P1DIR |= SLATCH; // Define timer interrupt TACCR0 = 46; TACTL = TASSEL_2 + MC_1 + ID_0; TACCTL0 = CCIE; __delay_cycles(5000); resetLCD(); showMenu(); _EINT(); } void nikonShutter() { // 628, 8798, 119, 496, 125, 1128, 122, 19973 for (i = 0; i < 2; i++) { P1SEL |= IROUT; __delay_cycles(628); P1SEL &= ~IROUT; __delay_cycles(8798); P1SEL |= IROUT; __delay_cycles(119); P1SEL &= ~IROUT; __delay_cycles(496); P1SEL |= IROUT; __delay_cycles(125); P1SEL &= ~IROUT; __delay_cycles(1128); P1SEL |= IROUT; __delay_cycles(122); P1SEL &= ~IROUT; __delay_cycles(19973); } shutterCount++; clockRunning = 1; } void shiftOut(char w, char latch) { P1OUT &= ~SLATCH; for (i = 0; i < 8; i++) { if ((w & 0x80) == 0x80) { P2OUT |= SDATA; } else { P2OUT &= ~SDATA; } P2OUT |= SCLOCK; w <<= 1; P2OUT &= ~SCLOCK; } if (latch) { P1OUT |= SLATCH; P1OUT &= ~SLATCH; } } // This should be enough for most LCDs. Technically, there should be // at least three different delays but we're trying to save code space. void LCDdelay() { __delay_cycles(150); } void resetLCD() { shiftOut(0x20, 1); // Not in 4 bit mode yet so we have to do it by shifting LCDdelay(); shiftOut(0x20 + LCDE, 1); LCDdelay(); shiftOut(0x20, 1); LCDdelay(); LCDOut(0x28, 0); // 4 bit, 2 lines, 5x7 font LCDOut(0x08, 0); // Enable display, cursor off LCDOut(0x01, 0); // Clear display, move cursor home LCDOut(0x06, 0); // Move cursor LCDOut(0x0c, 0); // Display on } void LCDOut(char b, char d) { char btosend = 0; btosend = (b & 0xf0); // High nibble if (d) { btosend += LCDRS; } shiftOut(btosend, 1); LCDdelay(); shiftOut(btosend + LCDE, 1); LCDdelay(); shiftOut(btosend, 1); LCDdelay(); btosend = (b & 0x0f); // Low nibble btosend <<= 4; // Move it to the high nibble if (d) { btosend += LCDRS; } shiftOut(btosend, 1); LCDdelay(); shiftOut(btosend + LCDE, 1); LCDdelay(); shiftOut(btosend, 1); LCDdelay(); } // Takes whatever is in buf[] and sends it to the LCD void LCDString() { int dp = 0; while (buf[dp] != 0) { LCDOut(buf[dp], 1); dp++; } } void itoa(unsigned int val, char *str) { int temploc = 0; int digit = 0; int strloc = 0; char tempstr[5]; do { digit = val % 10; tempstr[temploc++] = digit + '0'; val /= 10; } while (val > 0); // The digits are now reversed. Let's fix that. while(temploc>0) str[strloc++] = tempstr[--temploc]; str[strloc]=0; } void showMenu() { LCDOut(0x02, 0); if (menu == 0) { strcpy(buf, "Shoot to\0"); LCDString(); LCDOut(0xc0, 0); // Line 2 strcpy(buf, "start. \0"); LCDString(); } if (menu == 1) { strcpy(buf, "Interval\0"); LCDString(); LCDOut(0xc0, 0); // Line 2 itoa(shutterInterval, buf); LCDString(); strcpy(buf, " \n"); LCDString(); } if (menu == 2) { strcpy(buf, "Period \0"); LCDString(); LCDOut(0xc0, 0); // Line 2 if (period == 's') { strcpy(buf, "Seconds \0"); } else { strcpy(buf, "Minutes \0"); } LCDString(); } } #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { // REALLY cheap debounce. // We can get away with this because we're edge triggering but reading the level. __delay_cycles(10000); if ((~P1IN & SHUTTERBUTTON) == SHUTTERBUTTON) { if (menu == 0) { SHUTTER; intervalCounter = shutterInterval; delayAcc = 0; minAcc = 0; } if (menu == 1) { shutterInterval++; if (shutterInterval == 100) { shutterInterval = 99; } } if (menu == 2) { if (period == 's') { period = 'm'; } else { period = 's'; } } } if ((~P1IN & MENUBUTTON) == MENUBUTTON) { clockRunning = 0; shutterCount = 0; menu++; if (menu == 3) { menu = 0; } } if ((~P1IN & DOWNBUTTON) == DOWNBUTTON) { if (menu == 1) { if (shutterInterval != 1) { shutterInterval--; } } if (menu == 2) { if (period == 's') { period = 'm'; } else { period = 's'; } } } if (!clockRunning) { showMenu(); } P1IFG &= ~(SHUTTERBUTTON + MENUBUTTON + DOWNBUTTON); } #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A (void) { if (clockRunning) { delayAcc++; if (delayAcc == 836) { // Near as damn it 1Hz P1OUT ^= STATUS; LCDOut(0x02, 0); itoa(intervalCounter, buf); LCDString(); LCDOut(0x2f, 1); itoa(shutterInterval, buf); LCDString(); LCDOut(period, 1); strcpy(buf, " \0"); LCDString(); if (period == 's') { intervalCounter--; } else { // Not seconds so must be minutes minAcc++; if (minAcc == 60) { intervalCounter--; minAcc = 0; } } if (intervalCounter == 0) { intervalCounter = shutterInterval; SHUTTER; } itoa(shutterCount, buf); LCDOut(0xc0, 0); // Line 2 LCDString(); strcpy(buf, " \0"); LCDString(); delayAcc = 0; } } }
     
    Board layout

    If there's enough interest, I'll be getting several boards made up for sale. Possibly even a kit of parts.
     
    Archive of all files
    Gerber are included in this file.
    LCDIntervalometer.zip
  12. Like
    shluzzzoid got a reaction from bluehash in ds1394 RTC + led driver tm1638   
    Project is updated!
  13. Like
    shluzzzoid got a reaction from PentiumPC in ds1394 RTC + led driver tm1638   
    Hello!
     
    This is my project Real Time Clock. The project used RTC module ds1394, temperature sensor ds18b20 and driver 7-segment display tm1638. msp430g2553 MCU integrates devices with two hardware ports SPI (USART1, USART2).
    Clock Functions:- Showing the time, date, day of the week;
    - Set the alarm;
    - Shows the temperature of the sensor ds18b20;
    - Control the brightness of the indicator.
     
    Video:

     
    Russian description
    Source code

     
    Video:


     
    My project site
     
    Project includes:
    - DS1394 msp430 launchpad interface
    - ds18b20 maxim + msp430 launchpad
    - Library for TM1638 to MSP430
     
     
    PS: my son was born! Now I do not know whether the time to continue the projects. I hope that I can find the time to do a good description of the projects.
     
    PPS: Sorry for my english...
  14. Like
    shluzzzoid got a reaction from roadrunner84 in ds1394 RTC + led driver tm1638   
    Hello!
     
    This is my project Real Time Clock. The project used RTC module ds1394, temperature sensor ds18b20 and driver 7-segment display tm1638. msp430g2553 MCU integrates devices with two hardware ports SPI (USART1, USART2).
    Clock Functions:- Showing the time, date, day of the week;
    - Set the alarm;
    - Shows the temperature of the sensor ds18b20;
    - Control the brightness of the indicator.
     
    Video:

     
    Russian description
    Source code

     
    Video:


     
    My project site
     
    Project includes:
    - DS1394 msp430 launchpad interface
    - ds18b20 maxim + msp430 launchpad
    - Library for TM1638 to MSP430
     
     
    PS: my son was born! Now I do not know whether the time to continue the projects. I hope that I can find the time to do a good description of the projects.
     
    PPS: Sorry for my english...
  15. Like
    shluzzzoid got a reaction from xpg in ds1394 RTC + led driver tm1638   
    Hello!
     
    This is my project Real Time Clock. The project used RTC module ds1394, temperature sensor ds18b20 and driver 7-segment display tm1638. msp430g2553 MCU integrates devices with two hardware ports SPI (USART1, USART2).
    Clock Functions:- Showing the time, date, day of the week;
    - Set the alarm;
    - Shows the temperature of the sensor ds18b20;
    - Control the brightness of the indicator.
     
    Video:

     
    Russian description
    Source code

     
    Video:


     
    My project site
     
    Project includes:
    - DS1394 msp430 launchpad interface
    - ds18b20 maxim + msp430 launchpad
    - Library for TM1638 to MSP430
     
     
    PS: my son was born! Now I do not know whether the time to continue the projects. I hope that I can find the time to do a good description of the projects.
     
    PPS: Sorry for my english...
  16. Like
    shluzzzoid got a reaction from bluehash in ds1394 RTC + led driver tm1638   
    Hello!
     
    This is my project Real Time Clock. The project used RTC module ds1394, temperature sensor ds18b20 and driver 7-segment display tm1638. msp430g2553 MCU integrates devices with two hardware ports SPI (USART1, USART2).
    Clock Functions:- Showing the time, date, day of the week;
    - Set the alarm;
    - Shows the temperature of the sensor ds18b20;
    - Control the brightness of the indicator.
     
    Video:

     
    Russian description
    Source code

     
    Video:


     
    My project site
     
    Project includes:
    - DS1394 msp430 launchpad interface
    - ds18b20 maxim + msp430 launchpad
    - Library for TM1638 to MSP430
     
     
    PS: my son was born! Now I do not know whether the time to continue the projects. I hope that I can find the time to do a good description of the projects.
     
    PPS: Sorry for my english...
  17. Like
    shluzzzoid got a reaction from cubeberg in ds1394 RTC + led driver tm1638   
    Hello!
     
    This is my project Real Time Clock. The project used RTC module ds1394, temperature sensor ds18b20 and driver 7-segment display tm1638. msp430g2553 MCU integrates devices with two hardware ports SPI (USART1, USART2).
    Clock Functions:- Showing the time, date, day of the week;
    - Set the alarm;
    - Shows the temperature of the sensor ds18b20;
    - Control the brightness of the indicator.
     
    Video:

     
    Russian description
    Source code

     
    Video:


     
    My project site
     
    Project includes:
    - DS1394 msp430 launchpad interface
    - ds18b20 maxim + msp430 launchpad
    - Library for TM1638 to MSP430
     
     
    PS: my son was born! Now I do not know whether the time to continue the projects. I hope that I can find the time to do a good description of the projects.
     
    PPS: Sorry for my english...
  18. Like
    shluzzzoid reacted to roadrunner84 in TM1638 LEDs interface _version 1.7.0 available!   
    Why don't you add hexadecimal entries to your character table?
    const unsigned int Num[]= //Code table of symbols { 0x3F, //0 0x06, //1 0x5B, //2 0x4F, //3 0x66, //4 0x6D, //5 0x7D, //6 0x07, //7 0x7F, //8 0x6F, //9 0x77, //A 0x7C, //b 0x39, //C 0x5E, //d 0x79, //E 0x71, //F 0x40, //Minus 0x63, //Degree 0x00, //Blank 0x3E //"U"
  19. Like
    shluzzzoid got a reaction from dubnet in TM1638 LEDs interface _version 1.7.0 available!   
    Hello!

    My library for interacting an MSP430g2553 with a TM1638 (SPI 3-wire mode)



    Description

    MSP430G2xx3 - USCI_A0 SPI Master Interface to TM1638, Read/Write command, key scanning, show digit and switch LEDs on board.
    TM1638 - Driver for Led's indicator, 10 segment output lines, 8 grid output lines, 8 segment/key - 3 lines scanning.

    Features
    Support for the TM1638;
    Support for dimming the display and LEDs;
    Reading simultaneous button presses
    Connection diagramm:


    Code:

    #include "msp430g2553.h" // MSP430 Ports Define #define LED_RED BIT0 //RED Led #define LED_GRE BIT6 //Green Led #define STROBE_TM1638 BIT5 #define DIO BIT2 #define CLK BIT4 // TM1638 Commands Define #define RED_TM1638 0x01 //RED Led #define GRE_TM1638 0x02 //Green Led #define DATA_WRITE_INCR_ADDR 0x40 //Command to switch TM1638 for automatic increment address mode #define DATA_WRITE_FIX_ADDR 0x44 //Command to switch TM1638 for fix address mode #define DATA_READ_KEY_SCAN_MODE 0x42 //Command for read key code from TM1638 #define ADDRSET 0xC0 //Command to set address 0x00 #define DISP_ON 0x8F //Command to Display ON and set (max) brightness #define DISP_OFF 0x80 //Command to Display OFF //#define MIN_VOLT 2700 //Critycal voltage of power OFF const unsigned int Num[]= //Code table of symbols { 0x3F, //0 0x06, //1 0x5B, //2 0x4F, //3 0x66, //4 0x6D, //5 0x7D, //6 0x07, //7 0x7F, //8 0x6F, //9 0x40, //Minus 0x63, //Degree 0x39, //"C" 0x00, //Blank 0x3E //"U" }; const unsigned int ERROR_DATA[] = { 0x79, // E 0x50, // r 0x50, // r 0x5C, // o 0x50, // r 0, 0, 0 }; //Function definitions void init_Ports() { P1OUT = 0x00; // P1 setup for LED & STROBE output P2OUT = 0x00; // P2 setup for output P1DIR = LED_RED + LED_GRE + STROBE_TM1638; P1SEL = BIT1 + BIT2 + BIT4; // Set secondary functions for PORT1 P1SEL2 = BIT1 + BIT2 + BIT4; // P1.1 - TXD, P1.2 - RXD P1OUT |= STROBE_TM1638; // Chip Select, Set STROBE = "1" } void init_WDT() { WDTCTL = WDTPW + WDTHOLD; //Stop watchdog } void init_SPI() { UCA0CTL0 |= UCCKPL + UCMST + UCSYNC; // 3-pin, 8-bit SPI master UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 |= 0x02; // /2 UCA0BR1 = 0; // UCA0MCTL = 0; // No modulation UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** } void SendCommand(unsigned char Command) { //Transmit Command P1OUT &= ~STROBE_TM1638; //Set STROBE = "0" _NOP(); _NOP(); P1OUT |= STROBE_TM1638; //Set STROBE = "1" _NOP(); _NOP(); P1OUT &= ~STROBE_TM1638; //Set STROBE = "0" _NOP(); UCA0TXBUF = Command; while (!(IFG2 & UCA0TXIFG)); P1OUT |= STROBE_TM1638; //Set STROBE = "1" } void SendData(unsigned int address, unsigned int data) { //Transmit Data SendCommand(DATA_WRITE_FIX_ADDR); P1OUT &= ~STROBE_TM1638; //Set STROBE = "0" UCA0TXBUF = (0xC0 | address); while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF = data; while (!(IFG2 & UCA0TXIFG)); P1OUT |= STROBE_TM1638; //Set STROBE = "1" } void ShowDig(int position, int Data, int Dot) //show single digit { SendData(position << 1, Data | (Dot ? 0x80 : 0) ); } void ClearDig(unsigned int pos, unsigned int dot) { ShowDig(pos, 0x00, dot); } void ShowLed(int Number, int Color) { SendData((Number << 1)-1, Color); } void ShowLeds(int color) { unsigned int i; for (i=1; i<9; i++) { ShowLed (i, color); } } void DisplayClean() { //Clean RAM of TM1638 int i; for (i=0; i<17; i++) { SendData(i, 0x00); } } void SetupDisplay(char active, char intensity) { SendCommand (0x80 | (active ? 8 : 0) | intensity); P1OUT |= STROBE_TM1638; // Set STROBE = "1" } void init_Display() { __delay_cycles(100000); //Time to initial TM1638 DisplayClean(); //Clean display SendCommand(DISP_OFF); //Display off SendCommand(DATA_WRITE_FIX_ADDR); //Set address mode SendCommand(ADDRSET); //Set first adress } void ShowError() { unsigned int j; for (j=0; j<8; j++) { ShowDig(j, ERROR_DATA[j], 0); } } int GetKey() { unsigned int KeyData = 0; unsigned int i; P1OUT &= ~STROBE_TM1638; // Set STROBE = "0" UCA0TXBUF = DATA_READ_KEY_SCAN_MODE; while (!(IFG2 & UCA0TXIFG)); __delay_cycles(20); //wait to ready (see datasheet) UCA0TXBUF = 0xff; //Send dummy byte while (!(IFG2 & UCA0TXIFG)); //wait for buffer ready // 1'st reseiving byte = bad for (i=0; i<4; i++) { UCA0TXBUF = 0xff; while (!(IFG2 & UCA0RXIFG)); KeyData |= UCA0RXBUF << i; } P1OUT |= STROBE_TM1638; //Set STROBE = "1" return KeyData; } void main() { unsigned int j; unsigned int Keys = 0; init_WDT(); init_Ports(); init_SPI(); init_Display(); // Example program: for (j=0; j<8; j++) { //example set "01234567" on display ShowDig(j, Num[j], 0); } SetupDisplay(1, 7); // Display ON, max brightness while(1) { ShowLeds(0); //switch all LEDs off switch(GetKey()) { case 1: Keys = 1; break; case 2: Keys = 2; break; case 4: Keys = 3; break; case 8: Keys = 4; break; case 16: Keys = 5; break; case 32: Keys = 6; break; case 64: Keys = 7; break; case 128: Keys = 8; break; default: Keys = 0; break; } if (Keys) { ShowLed(Keys, GRE_TM1638);} ShowDig(7, Num[Keys], 1); } //end of example program } tm1638.rar
  20. Like
    shluzzzoid reacted to bluehash in Hi from Eugene! (Russia, Omsk)   
    You guys should group up and make us nexie tube projects
  21. Like
    shluzzzoid reacted to VeroLom in Hi from Eugene! (Russia, Omsk)   
    Hi from St.Petersburg!
  22. Like
    shluzzzoid reacted to alsenin in Hi from Eugene! (Russia, Omsk)   
    Hi Eugene!
     
    I lived in Omsk! Nice to see Siberian guys here!
  23. Like
    shluzzzoid got a reaction from oPossum in TM1638 LEDs interface _version 1.7.0 available!   
    Hello!

    My library for interacting an MSP430g2553 with a TM1638 (SPI 3-wire mode)



    Description

    MSP430G2xx3 - USCI_A0 SPI Master Interface to TM1638, Read/Write command, key scanning, show digit and switch LEDs on board.
    TM1638 - Driver for Led's indicator, 10 segment output lines, 8 grid output lines, 8 segment/key - 3 lines scanning.

    Features
    Support for the TM1638;
    Support for dimming the display and LEDs;
    Reading simultaneous button presses
    Connection diagramm:


    Code:

    #include "msp430g2553.h" // MSP430 Ports Define #define LED_RED BIT0 //RED Led #define LED_GRE BIT6 //Green Led #define STROBE_TM1638 BIT5 #define DIO BIT2 #define CLK BIT4 // TM1638 Commands Define #define RED_TM1638 0x01 //RED Led #define GRE_TM1638 0x02 //Green Led #define DATA_WRITE_INCR_ADDR 0x40 //Command to switch TM1638 for automatic increment address mode #define DATA_WRITE_FIX_ADDR 0x44 //Command to switch TM1638 for fix address mode #define DATA_READ_KEY_SCAN_MODE 0x42 //Command for read key code from TM1638 #define ADDRSET 0xC0 //Command to set address 0x00 #define DISP_ON 0x8F //Command to Display ON and set (max) brightness #define DISP_OFF 0x80 //Command to Display OFF //#define MIN_VOLT 2700 //Critycal voltage of power OFF const unsigned int Num[]= //Code table of symbols { 0x3F, //0 0x06, //1 0x5B, //2 0x4F, //3 0x66, //4 0x6D, //5 0x7D, //6 0x07, //7 0x7F, //8 0x6F, //9 0x40, //Minus 0x63, //Degree 0x39, //"C" 0x00, //Blank 0x3E //"U" }; const unsigned int ERROR_DATA[] = { 0x79, // E 0x50, // r 0x50, // r 0x5C, // o 0x50, // r 0, 0, 0 }; //Function definitions void init_Ports() { P1OUT = 0x00; // P1 setup for LED & STROBE output P2OUT = 0x00; // P2 setup for output P1DIR = LED_RED + LED_GRE + STROBE_TM1638; P1SEL = BIT1 + BIT2 + BIT4; // Set secondary functions for PORT1 P1SEL2 = BIT1 + BIT2 + BIT4; // P1.1 - TXD, P1.2 - RXD P1OUT |= STROBE_TM1638; // Chip Select, Set STROBE = "1" } void init_WDT() { WDTCTL = WDTPW + WDTHOLD; //Stop watchdog } void init_SPI() { UCA0CTL0 |= UCCKPL + UCMST + UCSYNC; // 3-pin, 8-bit SPI master UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 |= 0x02; // /2 UCA0BR1 = 0; // UCA0MCTL = 0; // No modulation UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** } void SendCommand(unsigned char Command) { //Transmit Command P1OUT &= ~STROBE_TM1638; //Set STROBE = "0" _NOP(); _NOP(); P1OUT |= STROBE_TM1638; //Set STROBE = "1" _NOP(); _NOP(); P1OUT &= ~STROBE_TM1638; //Set STROBE = "0" _NOP(); UCA0TXBUF = Command; while (!(IFG2 & UCA0TXIFG)); P1OUT |= STROBE_TM1638; //Set STROBE = "1" } void SendData(unsigned int address, unsigned int data) { //Transmit Data SendCommand(DATA_WRITE_FIX_ADDR); P1OUT &= ~STROBE_TM1638; //Set STROBE = "0" UCA0TXBUF = (0xC0 | address); while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF = data; while (!(IFG2 & UCA0TXIFG)); P1OUT |= STROBE_TM1638; //Set STROBE = "1" } void ShowDig(int position, int Data, int Dot) //show single digit { SendData(position << 1, Data | (Dot ? 0x80 : 0) ); } void ClearDig(unsigned int pos, unsigned int dot) { ShowDig(pos, 0x00, dot); } void ShowLed(int Number, int Color) { SendData((Number << 1)-1, Color); } void ShowLeds(int color) { unsigned int i; for (i=1; i<9; i++) { ShowLed (i, color); } } void DisplayClean() { //Clean RAM of TM1638 int i; for (i=0; i<17; i++) { SendData(i, 0x00); } } void SetupDisplay(char active, char intensity) { SendCommand (0x80 | (active ? 8 : 0) | intensity); P1OUT |= STROBE_TM1638; // Set STROBE = "1" } void init_Display() { __delay_cycles(100000); //Time to initial TM1638 DisplayClean(); //Clean display SendCommand(DISP_OFF); //Display off SendCommand(DATA_WRITE_FIX_ADDR); //Set address mode SendCommand(ADDRSET); //Set first adress } void ShowError() { unsigned int j; for (j=0; j<8; j++) { ShowDig(j, ERROR_DATA[j], 0); } } int GetKey() { unsigned int KeyData = 0; unsigned int i; P1OUT &= ~STROBE_TM1638; // Set STROBE = "0" UCA0TXBUF = DATA_READ_KEY_SCAN_MODE; while (!(IFG2 & UCA0TXIFG)); __delay_cycles(20); //wait to ready (see datasheet) UCA0TXBUF = 0xff; //Send dummy byte while (!(IFG2 & UCA0TXIFG)); //wait for buffer ready // 1'st reseiving byte = bad for (i=0; i<4; i++) { UCA0TXBUF = 0xff; while (!(IFG2 & UCA0RXIFG)); KeyData |= UCA0RXBUF << i; } P1OUT |= STROBE_TM1638; //Set STROBE = "1" return KeyData; } void main() { unsigned int j; unsigned int Keys = 0; init_WDT(); init_Ports(); init_SPI(); init_Display(); // Example program: for (j=0; j<8; j++) { //example set "01234567" on display ShowDig(j, Num[j], 0); } SetupDisplay(1, 7); // Display ON, max brightness while(1) { ShowLeds(0); //switch all LEDs off switch(GetKey()) { case 1: Keys = 1; break; case 2: Keys = 2; break; case 4: Keys = 3; break; case 8: Keys = 4; break; case 16: Keys = 5; break; case 32: Keys = 6; break; case 64: Keys = 7; break; case 128: Keys = 8; break; default: Keys = 0; break; } if (Keys) { ShowLed(Keys, GRE_TM1638);} ShowDig(7, Num[Keys], 1); } //end of example program } tm1638.rar
  24. Like
    shluzzzoid got a reaction from Rickta59 in TM1638 LEDs interface _version 1.7.0 available!   
    Hello!

    My library for interacting an MSP430g2553 with a TM1638 (SPI 3-wire mode)



    Description

    MSP430G2xx3 - USCI_A0 SPI Master Interface to TM1638, Read/Write command, key scanning, show digit and switch LEDs on board.
    TM1638 - Driver for Led's indicator, 10 segment output lines, 8 grid output lines, 8 segment/key - 3 lines scanning.

    Features
    Support for the TM1638;
    Support for dimming the display and LEDs;
    Reading simultaneous button presses
    Connection diagramm:


    Code:

    #include "msp430g2553.h" // MSP430 Ports Define #define LED_RED BIT0 //RED Led #define LED_GRE BIT6 //Green Led #define STROBE_TM1638 BIT5 #define DIO BIT2 #define CLK BIT4 // TM1638 Commands Define #define RED_TM1638 0x01 //RED Led #define GRE_TM1638 0x02 //Green Led #define DATA_WRITE_INCR_ADDR 0x40 //Command to switch TM1638 for automatic increment address mode #define DATA_WRITE_FIX_ADDR 0x44 //Command to switch TM1638 for fix address mode #define DATA_READ_KEY_SCAN_MODE 0x42 //Command for read key code from TM1638 #define ADDRSET 0xC0 //Command to set address 0x00 #define DISP_ON 0x8F //Command to Display ON and set (max) brightness #define DISP_OFF 0x80 //Command to Display OFF //#define MIN_VOLT 2700 //Critycal voltage of power OFF const unsigned int Num[]= //Code table of symbols { 0x3F, //0 0x06, //1 0x5B, //2 0x4F, //3 0x66, //4 0x6D, //5 0x7D, //6 0x07, //7 0x7F, //8 0x6F, //9 0x40, //Minus 0x63, //Degree 0x39, //"C" 0x00, //Blank 0x3E //"U" }; const unsigned int ERROR_DATA[] = { 0x79, // E 0x50, // r 0x50, // r 0x5C, // o 0x50, // r 0, 0, 0 }; //Function definitions void init_Ports() { P1OUT = 0x00; // P1 setup for LED & STROBE output P2OUT = 0x00; // P2 setup for output P1DIR = LED_RED + LED_GRE + STROBE_TM1638; P1SEL = BIT1 + BIT2 + BIT4; // Set secondary functions for PORT1 P1SEL2 = BIT1 + BIT2 + BIT4; // P1.1 - TXD, P1.2 - RXD P1OUT |= STROBE_TM1638; // Chip Select, Set STROBE = "1" } void init_WDT() { WDTCTL = WDTPW + WDTHOLD; //Stop watchdog } void init_SPI() { UCA0CTL0 |= UCCKPL + UCMST + UCSYNC; // 3-pin, 8-bit SPI master UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 |= 0x02; // /2 UCA0BR1 = 0; // UCA0MCTL = 0; // No modulation UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** } void SendCommand(unsigned char Command) { //Transmit Command P1OUT &= ~STROBE_TM1638; //Set STROBE = "0" _NOP(); _NOP(); P1OUT |= STROBE_TM1638; //Set STROBE = "1" _NOP(); _NOP(); P1OUT &= ~STROBE_TM1638; //Set STROBE = "0" _NOP(); UCA0TXBUF = Command; while (!(IFG2 & UCA0TXIFG)); P1OUT |= STROBE_TM1638; //Set STROBE = "1" } void SendData(unsigned int address, unsigned int data) { //Transmit Data SendCommand(DATA_WRITE_FIX_ADDR); P1OUT &= ~STROBE_TM1638; //Set STROBE = "0" UCA0TXBUF = (0xC0 | address); while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF = data; while (!(IFG2 & UCA0TXIFG)); P1OUT |= STROBE_TM1638; //Set STROBE = "1" } void ShowDig(int position, int Data, int Dot) //show single digit { SendData(position << 1, Data | (Dot ? 0x80 : 0) ); } void ClearDig(unsigned int pos, unsigned int dot) { ShowDig(pos, 0x00, dot); } void ShowLed(int Number, int Color) { SendData((Number << 1)-1, Color); } void ShowLeds(int color) { unsigned int i; for (i=1; i<9; i++) { ShowLed (i, color); } } void DisplayClean() { //Clean RAM of TM1638 int i; for (i=0; i<17; i++) { SendData(i, 0x00); } } void SetupDisplay(char active, char intensity) { SendCommand (0x80 | (active ? 8 : 0) | intensity); P1OUT |= STROBE_TM1638; // Set STROBE = "1" } void init_Display() { __delay_cycles(100000); //Time to initial TM1638 DisplayClean(); //Clean display SendCommand(DISP_OFF); //Display off SendCommand(DATA_WRITE_FIX_ADDR); //Set address mode SendCommand(ADDRSET); //Set first adress } void ShowError() { unsigned int j; for (j=0; j<8; j++) { ShowDig(j, ERROR_DATA[j], 0); } } int GetKey() { unsigned int KeyData = 0; unsigned int i; P1OUT &= ~STROBE_TM1638; // Set STROBE = "0" UCA0TXBUF = DATA_READ_KEY_SCAN_MODE; while (!(IFG2 & UCA0TXIFG)); __delay_cycles(20); //wait to ready (see datasheet) UCA0TXBUF = 0xff; //Send dummy byte while (!(IFG2 & UCA0TXIFG)); //wait for buffer ready // 1'st reseiving byte = bad for (i=0; i<4; i++) { UCA0TXBUF = 0xff; while (!(IFG2 & UCA0RXIFG)); KeyData |= UCA0RXBUF << i; } P1OUT |= STROBE_TM1638; //Set STROBE = "1" return KeyData; } void main() { unsigned int j; unsigned int Keys = 0; init_WDT(); init_Ports(); init_SPI(); init_Display(); // Example program: for (j=0; j<8; j++) { //example set "01234567" on display ShowDig(j, Num[j], 0); } SetupDisplay(1, 7); // Display ON, max brightness while(1) { ShowLeds(0); //switch all LEDs off switch(GetKey()) { case 1: Keys = 1; break; case 2: Keys = 2; break; case 4: Keys = 3; break; case 8: Keys = 4; break; case 16: Keys = 5; break; case 32: Keys = 6; break; case 64: Keys = 7; break; case 128: Keys = 8; break; default: Keys = 0; break; } if (Keys) { ShowLed(Keys, GRE_TM1638);} ShowDig(7, Num[Keys], 1); } //end of example program } tm1638.rar
  25. Like
    shluzzzoid got a reaction from bluehash in TM1638 LEDs interface _version 1.7.0 available!   
    Hello!

    My library for interacting an MSP430g2553 with a TM1638 (SPI 3-wire mode)



    Description

    MSP430G2xx3 - USCI_A0 SPI Master Interface to TM1638, Read/Write command, key scanning, show digit and switch LEDs on board.
    TM1638 - Driver for Led's indicator, 10 segment output lines, 8 grid output lines, 8 segment/key - 3 lines scanning.

    Features
    Support for the TM1638;
    Support for dimming the display and LEDs;
    Reading simultaneous button presses
    Connection diagramm:


    Code:

    #include "msp430g2553.h" // MSP430 Ports Define #define LED_RED BIT0 //RED Led #define LED_GRE BIT6 //Green Led #define STROBE_TM1638 BIT5 #define DIO BIT2 #define CLK BIT4 // TM1638 Commands Define #define RED_TM1638 0x01 //RED Led #define GRE_TM1638 0x02 //Green Led #define DATA_WRITE_INCR_ADDR 0x40 //Command to switch TM1638 for automatic increment address mode #define DATA_WRITE_FIX_ADDR 0x44 //Command to switch TM1638 for fix address mode #define DATA_READ_KEY_SCAN_MODE 0x42 //Command for read key code from TM1638 #define ADDRSET 0xC0 //Command to set address 0x00 #define DISP_ON 0x8F //Command to Display ON and set (max) brightness #define DISP_OFF 0x80 //Command to Display OFF //#define MIN_VOLT 2700 //Critycal voltage of power OFF const unsigned int Num[]= //Code table of symbols { 0x3F, //0 0x06, //1 0x5B, //2 0x4F, //3 0x66, //4 0x6D, //5 0x7D, //6 0x07, //7 0x7F, //8 0x6F, //9 0x40, //Minus 0x63, //Degree 0x39, //"C" 0x00, //Blank 0x3E //"U" }; const unsigned int ERROR_DATA[] = { 0x79, // E 0x50, // r 0x50, // r 0x5C, // o 0x50, // r 0, 0, 0 }; //Function definitions void init_Ports() { P1OUT = 0x00; // P1 setup for LED & STROBE output P2OUT = 0x00; // P2 setup for output P1DIR = LED_RED + LED_GRE + STROBE_TM1638; P1SEL = BIT1 + BIT2 + BIT4; // Set secondary functions for PORT1 P1SEL2 = BIT1 + BIT2 + BIT4; // P1.1 - TXD, P1.2 - RXD P1OUT |= STROBE_TM1638; // Chip Select, Set STROBE = "1" } void init_WDT() { WDTCTL = WDTPW + WDTHOLD; //Stop watchdog } void init_SPI() { UCA0CTL0 |= UCCKPL + UCMST + UCSYNC; // 3-pin, 8-bit SPI master UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 |= 0x02; // /2 UCA0BR1 = 0; // UCA0MCTL = 0; // No modulation UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** } void SendCommand(unsigned char Command) { //Transmit Command P1OUT &= ~STROBE_TM1638; //Set STROBE = "0" _NOP(); _NOP(); P1OUT |= STROBE_TM1638; //Set STROBE = "1" _NOP(); _NOP(); P1OUT &= ~STROBE_TM1638; //Set STROBE = "0" _NOP(); UCA0TXBUF = Command; while (!(IFG2 & UCA0TXIFG)); P1OUT |= STROBE_TM1638; //Set STROBE = "1" } void SendData(unsigned int address, unsigned int data) { //Transmit Data SendCommand(DATA_WRITE_FIX_ADDR); P1OUT &= ~STROBE_TM1638; //Set STROBE = "0" UCA0TXBUF = (0xC0 | address); while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF = data; while (!(IFG2 & UCA0TXIFG)); P1OUT |= STROBE_TM1638; //Set STROBE = "1" } void ShowDig(int position, int Data, int Dot) //show single digit { SendData(position << 1, Data | (Dot ? 0x80 : 0) ); } void ClearDig(unsigned int pos, unsigned int dot) { ShowDig(pos, 0x00, dot); } void ShowLed(int Number, int Color) { SendData((Number << 1)-1, Color); } void ShowLeds(int color) { unsigned int i; for (i=1; i<9; i++) { ShowLed (i, color); } } void DisplayClean() { //Clean RAM of TM1638 int i; for (i=0; i<17; i++) { SendData(i, 0x00); } } void SetupDisplay(char active, char intensity) { SendCommand (0x80 | (active ? 8 : 0) | intensity); P1OUT |= STROBE_TM1638; // Set STROBE = "1" } void init_Display() { __delay_cycles(100000); //Time to initial TM1638 DisplayClean(); //Clean display SendCommand(DISP_OFF); //Display off SendCommand(DATA_WRITE_FIX_ADDR); //Set address mode SendCommand(ADDRSET); //Set first adress } void ShowError() { unsigned int j; for (j=0; j<8; j++) { ShowDig(j, ERROR_DATA[j], 0); } } int GetKey() { unsigned int KeyData = 0; unsigned int i; P1OUT &= ~STROBE_TM1638; // Set STROBE = "0" UCA0TXBUF = DATA_READ_KEY_SCAN_MODE; while (!(IFG2 & UCA0TXIFG)); __delay_cycles(20); //wait to ready (see datasheet) UCA0TXBUF = 0xff; //Send dummy byte while (!(IFG2 & UCA0TXIFG)); //wait for buffer ready // 1'st reseiving byte = bad for (i=0; i<4; i++) { UCA0TXBUF = 0xff; while (!(IFG2 & UCA0RXIFG)); KeyData |= UCA0RXBUF << i; } P1OUT |= STROBE_TM1638; //Set STROBE = "1" return KeyData; } void main() { unsigned int j; unsigned int Keys = 0; init_WDT(); init_Ports(); init_SPI(); init_Display(); // Example program: for (j=0; j<8; j++) { //example set "01234567" on display ShowDig(j, Num[j], 0); } SetupDisplay(1, 7); // Display ON, max brightness while(1) { ShowLeds(0); //switch all LEDs off switch(GetKey()) { case 1: Keys = 1; break; case 2: Keys = 2; break; case 4: Keys = 3; break; case 8: Keys = 4; break; case 16: Keys = 5; break; case 32: Keys = 6; break; case 64: Keys = 7; break; case 128: Keys = 8; break; default: Keys = 0; break; } if (Keys) { ShowLed(Keys, GRE_TM1638);} ShowDig(7, Num[Keys], 1); } //end of example program } tm1638.rar
×
×
  • Create New...