Demo Clock with Nucleo-F303RE and Starter Shield

Dependents:   Nucleo_StarterShileld_Clock mojo main job ... more

Committer:
rogerzuber
Date:
Thu May 18 08:02:54 2017 +0000
Revision:
0:864e710889fa
Child:
1:e4450fb0849a
Demo Clock with Nucleo-F303RE and Starter Shield

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rogerzuber 0:864e710889fa 1 // Author:Frankie.Chu
rogerzuber 0:864e710889fa 2 // Date:9 April,2012
rogerzuber 0:864e710889fa 3 //
rogerzuber 0:864e710889fa 4 // This library is free software; you can redistribute it and/or
rogerzuber 0:864e710889fa 5 // modify it under the terms of the GNU Lesser General Public
rogerzuber 0:864e710889fa 6 // License as published by the Free Software Foundation; either
rogerzuber 0:864e710889fa 7 // version 2.1 of the License, or (at your option) any later version.
rogerzuber 0:864e710889fa 8 //
rogerzuber 0:864e710889fa 9 // This library is distributed in the hope that it will be useful,
rogerzuber 0:864e710889fa 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
rogerzuber 0:864e710889fa 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
rogerzuber 0:864e710889fa 12 // Lesser General Public License for more details.
rogerzuber 0:864e710889fa 13 //
rogerzuber 0:864e710889fa 14 // You should have received a copy of the GNU Lesser General Public
rogerzuber 0:864e710889fa 15 // License along with this library; if not, write to the Free Software
rogerzuber 0:864e710889fa 16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
rogerzuber 0:864e710889fa 17 //
rogerzuber 0:864e710889fa 18 // Modified record:
rogerzuber 0:864e710889fa 19 //
rogerzuber 0:864e710889fa 20 /*******************************************************************************/
rogerzuber 0:864e710889fa 21
rogerzuber 0:864e710889fa 22 #ifndef TM1636_h
rogerzuber 0:864e710889fa 23 #define TM1636_h
rogerzuber 0:864e710889fa 24 #include "mbed.h"
rogerzuber 0:864e710889fa 25 #include <inttypes.h>
rogerzuber 0:864e710889fa 26
rogerzuber 0:864e710889fa 27 //************definitions for TM1636*********************
rogerzuber 0:864e710889fa 28 #define ADDR_AUTO 0x40
rogerzuber 0:864e710889fa 29 #define ADDR_FIXED 0x44
rogerzuber 0:864e710889fa 30
rogerzuber 0:864e710889fa 31 #define STARTADDR 0xc0
rogerzuber 0:864e710889fa 32 /**** definitions for the clock point of the digit tube *******/
rogerzuber 0:864e710889fa 33 #define POINT_ON 1
rogerzuber 0:864e710889fa 34 #define POINT_OFF 0
rogerzuber 0:864e710889fa 35 /**************definitions for brightness***********************/
rogerzuber 0:864e710889fa 36 #define BRIGHT_DARKEST 0
rogerzuber 0:864e710889fa 37 #define BRIGHT_TYPICAL 2
rogerzuber 0:864e710889fa 38 #define BRIGHTEST 7
rogerzuber 0:864e710889fa 39
rogerzuber 0:864e710889fa 40 //--------------------------------------------------------//
rogerzuber 0:864e710889fa 41 //Special characters index of tube table
rogerzuber 0:864e710889fa 42 #define INDEX_NEGATIVE_SIGN 16
rogerzuber 0:864e710889fa 43 #define INDEX_BLANK 17
rogerzuber 0:864e710889fa 44
rogerzuber 0:864e710889fa 45 #define LOW 0
rogerzuber 0:864e710889fa 46 #define HIGH 1
rogerzuber 0:864e710889fa 47
rogerzuber 0:864e710889fa 48 class TM1636
rogerzuber 0:864e710889fa 49 {
rogerzuber 0:864e710889fa 50 public:
rogerzuber 0:864e710889fa 51 uint8_t Cmd_SetData;
rogerzuber 0:864e710889fa 52 uint8_t Cmd_SetAddr;
rogerzuber 0:864e710889fa 53 uint8_t Cmd_DispCtrl;
rogerzuber 0:864e710889fa 54 bool _PointFlag; // _PointFlag=1:the clock point on
rogerzuber 0:864e710889fa 55 uint8_t _brightness;
rogerzuber 0:864e710889fa 56 TM1636(PinName Clk, PinName Data);
rogerzuber 0:864e710889fa 57 void init(void); // To clear the display
rogerzuber 0:864e710889fa 58 void writeByte(int8_t wr_data); // write 8bit data to tm1637
rogerzuber 0:864e710889fa 59 void start(void); // send start bits
rogerzuber 0:864e710889fa 60 void stop(void); // send stop bits
rogerzuber 0:864e710889fa 61 void display(int8_t DispData[]);
rogerzuber 0:864e710889fa 62 void display(uint8_t BitAddr,int8_t DispData);
rogerzuber 0:864e710889fa 63 void clearDisplay(void);
rogerzuber 0:864e710889fa 64 void set(uint8_t = BRIGHT_TYPICAL,uint8_t = 0x40,uint8_t = 0xc0); //To take effect the next time it displays.
rogerzuber 0:864e710889fa 65 void point(bool PointFlag); // whether to light the clock point ":".To take effect the next time it displays.
rogerzuber 0:864e710889fa 66 void coding(int8_t DispData[]);
rogerzuber 0:864e710889fa 67 int8_t coding(int8_t DispData);
rogerzuber 0:864e710889fa 68 inline void setBrightness(uint8_t brightness) {
rogerzuber 0:864e710889fa 69 _brightness = brightness;
rogerzuber 0:864e710889fa 70 }
rogerzuber 0:864e710889fa 71 inline uint8_t getBrightness(){
rogerzuber 0:864e710889fa 72 return _brightness;
rogerzuber 0:864e710889fa 73 }
rogerzuber 0:864e710889fa 74 private:
rogerzuber 0:864e710889fa 75 DigitalInOut Clkpin;
rogerzuber 0:864e710889fa 76 DigitalInOut Datapin;
rogerzuber 0:864e710889fa 77 };
rogerzuber 0:864e710889fa 78 #endif
rogerzuber 0:864e710889fa 79