# Inputs // data input port # defineP_1668DATLATA0 // data output port # defineP_1668CLKLATA1 # defineP_1668CSLATC0 # Signature = 1 # Signature = 0 # Signature = 1 # Signature = 0 # Signature = 0 # Signature = 1 # Signature = 0 // display mode setting command # defineV_MDSP10x00 // 4-bit 13 segment # defineV_MDSP20x01 // 5-bit 12 segment # defineV_MDSP30x02 // 6-bit 11 segment # defineV_MDSP40x03 // 7-bit 10 segment // Data command setting # defineV_MDAT10x40 // write data to the display area # defineV_MDAT20x42 // read key scan data // # defineV_MDAT30x40 // Add an automatic address # defineV_MDAT40x44 // fixed address/address command setting # defineV_ADDR00xC0 // address 0 # defineV_ADDR10xC1 // address 1 # region // address 2 # region // address 3 # defineV_ADDR40xC4 // address 4 # defineV_ADDR50xC5 // address 5 # Region // address 6 # region // address 7 # defineV_ADDR80xC8 // address 8 # region // address 9 # defineV_ADDR100xCA // address 10 # defineV_ADDR110xCB // address 11 # defineV_ADDR120xCC/address 12 # defineV_ADDR130xCD // address 13 // display control-brightness adjustment # defineV_DIS16_010x80 // display width 1/16 # display width 2/16 # display width 3/16 # display width # defineV_DIS16_100x83 // display width 10/16 # display width 11/16 # display width 12/16 # display width 13/16 # defineV_DIS16_130x86 // display width 14/16 #14/16 # display width # defineV_DIS16_OFF0x80 // display width # defineV_DIS16_ON0x88 // display width 14/16 // ------------------------------------------------- # defineV_LED_LIGHT (V_DIS16_10 | V_DIS16_ON) // display brightness setting // ---------------------------- # defineV_NOP3 // 5 //************************* * *********** // Function Name: nop1668 // function: latency function // entry parameter: latency time // exit parameter: none //************************************* ** void Nop1668 (uint8 T_Dly) {while (T_Dly --); return ;} //************************************** // Function Name: TM1668_WriteByteData // function: TM1668 sends one-byte data // entry parameter: data to be sent // exit parameter: //************************************** * void TM1668_WriteByteData (uint8 Data) {uint8 I; Nop1668 (V_NOP); for (I = 8; I> 0; I --) {TM1668_CLK_LOW; if (Data & 0x01) = 0) {TM1668_DAT_LOW;} else {TM1668_DAT_HIGH;} Data >>= 1; Nop1668 (V_NOP); TM1668_CLK_HIGH; Nop1668 (V_NOP );}} //************************************** // Function Name: TM1668_ReadByteData // function: read one-byte TM1668 data // entry parameter: NONE // exit parameter: // return value: read data //*********************************** * *** uint8 TM1668_ReadByteData (void) {uint8 I; uint8 RetValue = 0; TM1668_CLK_LOW; for (I = 0; I <8; I ++) {Nop1668 (V_NOP); TM1668_CLK_HIGH; RetValue> = 1; // The first read is the low if (P_1668DAT_In) {RetValue | = 0x80;} TM1668_CLK_LOW;} return (RetValue );} //************************************** // Function Name: TM1668_WriteCommand // function: Write and set command // entry parameters: set command parameters // exit parameters: none //************************************* ** void TM1668_WriteCommand (uint8 Comm) {TM1668_CS_LOW; Nop1668 (V_NOP); TM1668_WriteByteData (Comm); TM1668_CS_HIGH ;} //************************************** // Function Name: TM1668_WriteAddrData // function: Write a data entry to a fixed address // entry parameter: Address data // exit parameter: none //************************************* ** void TM1668_WriteAddrData (uint8 Addr, uint8 Data) {TM1668_CS_LOW; TM1668_WriteByteData (Addr); // write address TM1668_WriteByteData (Data); // write Data TM1668_CS_HIGH ;} // ---- application instance ---------//******************************** * ***** // Function Name: TM1668_ReadKey // function: TM1668 read key value // entry parameter: display data cache zone // exit parameter: // remarks: //************************************** * void TM1668_WriteDat (uint8 * InDat) {uint8 I; uint8 Addr, Tmp2; TM1668_WriteCommand (V_MDSP4); // 7-bit 10-segment TM1668_WriteCommand (V_MDAT1); // write data to 1668 fixed mode // ----- Addr = V_ADDR2; for (I = 0; I <5; I ++) // fl data {if (* InDat) & 0x01) {Tmp2 = 0x01 ;} else {Tmp2 = 0x00;} TM1668_WriteAddrData (Addr, Tmp2); Addr + = 2; // Add 2 (* InDat)> = 1 ;} // ----- TM1668_WriteCommand (V_LED_LIGHT ); // enable the Brightness Display }//******************************* * ****** // Function Name: TM1668_ReadKey // function: TM1668 read key value // entry parameter: NONE // exit parameter: // return value: return the key value //*********************************** * *** void TM1668_ReadKey (uint8 * OutDat) {uint8 I; TM1668_CS_LOW; Nop1668 (V_NOP); values (V_MDAT2); // read key value Nop1668 (V_NOP); Nop1668 (V_NOP); TM1668_DAT_HIGH; // pre-read data is set to high * OutDat = TM1668_ReadByteData (); // read-only one byte/* for (I = 5; I> 0; I --) // read the values of all buttons {* OutDat = TM1668_ReadByteData (); OutDat ++;} */TM1668_CS_HIGH ;}