LCD display-tm1640 chip driver

Source: Internet
Author: User

Tm1640 chip driver


Din: serial data input. The input data changes at the low level of sclk and is transmitted at the high level of sclk.

Sclk: input data on the rising edge.

/* Includes ------------------------------------------------------------------ */# include "stm8s. H "# include" Global. H "# include" string. H "/* Private typedef restart * // * Private define restart */# define data_commend 0x40 // Data Control Command 0100 0000 automatic address 0100 fixed address # define disp_close 0x80 // display off/* Private macro Optional * // * private variables variable */uint8_t displaybuff [14]; // uint8_t displaybufffinal [14]; uint8_t dispopenvalue = 0x8f; // display the opening 1000 1011 pulse width as 10/16 const uint8_t mmap_tab [] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};/* Private function prototypes --------------------------------------- -------- * // * Private functions --------------------------------------------------------- */static void dispdata_mmap (); // void dispdata_trans (); // void dispdata_bittrans (); // bitwise address translation/* Public Functions ----------------------------------------------------------*//*************************** **************************************** * *********** function: initialize port parameters: return value: no *************************************** ******* * ********************************/Void tm1640_port_init (void) {gpio_init (tm1640_clk_gpio_port, tm1640_clk_gpio_pin, gpio_mode_out_pp_high_slow); tm1640_din_out_mode ;} /*************************************** **************************************** function: delay function MS Ms parameter: return value: no *************************************** **************************************** /void tm1640_delayms (uint8_t MS) {unsigned short JJ; For (JJ = 1; JJ <= MS; JJ ++) {Nop ();}} /*************************************** **************************************** function: command Transmission start flag parameter: return value: no *************************************** **************************************** /void tm1640_start () {latency; tm1640_delayms (5); tm1640_din_high; tm1640_delayms (5); tm1640_clk_high; tm1640_delayms (10); tm1640_din_low; latency (5 );} /************** **************************************** * ************************ Function: command Transmission end parameter: return value: no *************************************** **************************************** /void tm1640_end () {latency; tm1640_delayms (5); tm1640_din_low; tm1640_delayms (5); tm1640_clk_high; tm1640_delayms (10); tm1640_din_high; latency (5 );} /*************************************** *********************************** * *** Function: Write a byte function parameter: DAT --- return value of one byte of data written: no *************************************** **************************************** /void tm1640_write_byte (unsigned char dat) {uint8_t I; // start the first byte of valid Dio input as the instruction // valid chip selection signal for (I = 0; I <8; I ++) {tm1640_clk_low; if (DAT & 0x01) {tm1640_din_high;} else {tm1640_din_low; // write low position first} tm1640_delayms (10); tm1640_clk_high; // The rising edge of the clock, send a data tm1640_delayms (10); dat >>= 1;} Tm1640_clk_low; tm1640_delayms (5 );} /*************************************** **************************************** function: fixed address 1: display function parameters: * dat --- display data array pointer return value: no *************************************** **************************************** /void tm1640_write_string () {uint8_t I; dispdata_mmap (); // dispdata_trans (); // dispdata_bittrans (); tm1640_start (); Round (data_commend); tm1640_end (); TM1 640_delayms (5); tm1640_start (); tm1640_write_byte (0xc0); for (I = 0; I <14; I ++) {tm1640_write_byte (displaybuff [I]); // terminate (g_systemdisplaydata.buffer [I]);} tm1640_end (); tm1640_delayms (5); tm1640_start (); terminate (dispopenvalue); // enable tm1640_end ();} /*************************************** **************************************** function: parameter of the initialization function of tm1640: no return value: No ************************ **************************************** * **************/Void tm1640_init (void) {tm1640_port_init (); tm1640_start (); tm1640_write_byte (dispopenvalue); // display OFF 1000 0000 tm1640_end (); tm1640_delayms (5 );} /*************************************** **************************************** function: display ing function (due to unreasonable hardware design, the corresponding conversion is required) return value: no *************************************** **************************************** /STAT IC void dispdata_mmap () {uint8_t I, j; for (I = 0; I <= 13; I ++) {if (I <= 7) // convert the first 8 bytes along the diagonal line {for (j = 0; j <= 7; j ++) {If (g_systemdisplaydata.buffer [J] & mmap_tab [I]) {displaybuff [I] | = mmap_tab [J];} else {displaybuff [I] & = ~ Mmap_tab [J] ;}} else {displaybuff [I] = g_systemdisplaydata.buffer [I] ;}}// void dispdata_trans () // segment address translation // {// displaybufffinal [0] = displaybuff [3]; // displaybufffinal [1] = displaybuff [4]; // displaybufffinal [2] = displaybuff [12]; // displaybufffinal [3] = displaybuff [10]; // displaybufffinal [4] = displaybuff [1]; // displaybufffinal [5] = displaybuff [2]; // displaybufffinal [6] = displaybuff [9]; // displaybufffinal [7] = displaybuff [13]; // displaybufffinal [8] = displaybuff [0]; // displaybufffinal [9] = displaybuff [11]; // displaybufffinal [10] = displaybuff [8]; // displaybufffinal [11] = displaybuff [7]; // displaybufffinal [12] = displaybuff [5]; // displaybufffinal [13] = displaybuff [6]; ///} // void dispdata_bittrans () // bit address conversion // {// uint8_t I; // memset (displaybuff, 0, sizeof (displaybuff); // for (I = 0; I <14; I ++) // {// displaybuff [I] | = (displaybufffinal [I] & mmap_tab [1])> 1 ); // bit 0 // displaybuff [I] | = (displaybufffinal [I] & mmap_tab [0]) <1 ); // bit 1 // displaybuff [I] | = (displaybufffinal [I] & mmap_tab [2]); // bit 2 // displaybuff [I] | = (displaybufffinal [I] & mmap_tab [3]); // bit 3 // displaybuff [I] | = (displaybufffinal [I] & mmap_tab [6])> 2 ); // bit 4 // displaybuff [I] | = (displaybufffinal [I] & mmap_tab [7])> 2 ); // bit 5 // displaybuff [I] | = (displaybufffinal [I] & mmap_tab [5]) <1 ); // bit 6 // displaybuff [I] | = (displaybufffinal [I] & mmap_tab [4]) <3); // bit 7 //}//}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.