MSP430 library 12864 LCD Library

Source: Internet
Author: User

LCD is one of the most commonly used display devices in single chip microcomputer systems.ProgramThe database is tested on the msp430f169 and msp1430f149 single-chip microcomputer and can be used with confidence. LCD uses the 12864 liquid crystal of the ocmj4x8c model and the control liquid crystal uses the parallel method, the three control ports are p3.0, p3.1, and p3.2, and the data uses the P5 data IO port.

  1. Hardware introduction:

    430 digital IO port:

    Msp430f149, msp430f169 has a total of 48 I/O Ports for each 8-bit P1-P6; a large number of I/O ports are available for use, so the 8-bit parallel data mode can be used for LCD control; each IO port of 430 is a two-way IO port, and its data transmission direction is controlled through registers, which is convenient and practical; for information about the I/O port of the MSP430 microcontroller, refer to the user guide and data manual provided by Texas Instruments.

    Liquid Crystal ocmj4x8c:

    This module displays letters, numbers, Chinese fonts, and graphics, and displays both the drawing and text. Three Control interfaces are provided: Eight-bit microprocessor interfaces, four-bit microprocessor interfaces, and serial interfaces (ocmj4x16a/B without serial interfaces ). All functions, including Ram and font generators, are included in a single chip. As long as there is a minimum microprocessing system, the module can be conveniently operated.

    The built-in 2 m-bit Chinese font Rom (cgrom) provides a total of 8192 Chinese fonts (16x16 lattice) and 16 k half width font Rom (hcgrom) A total of 126 symbolic fonts (16x8 lattice) are provided, 64x16 fonts generate RAM (cgram), and the drawing display screen provides a drawing area (gdram) with 64 X points ), it can be mixed with text images.

    Ocmj4x8c pin description:

    Pin

    Name

    Direction

    Description

    1

    VSS

    -

    Gnd (0 V)

    2

    VDD

    -

    Supply voltage for logic (+ 5 V)

    3

    NC

    -

    Supply voltage for LCD (suspended)

    4

    RS (CS)

    I

    H: Data L: instruction code

    5

    R/W (STD)

    I

    H: Read L: Write

    6

    E (sclk)

    I

    Enable signal, valid at a high level

    7

    Db0

    I/O

    DATA 0

    8

    Db1

    I/O

    Data 1

    9

    DB2

    I/O

    Data 2

    10

    Db3

    I/O

    Data 3

    11

    Db4

    I/O

    Data 4

    12

    DB5

    I/O

    Data 5

    13

    Db6

    I/O

    Data 6

    14

    Db7

    I/O

    Data 7

    15

    PSB

    I

    H: parallel mode l: serial mode

    16

    NC

    -

    Empty foot

    17

    /Rst

    I

    Reset signal, effective at low level

    18

    NC

    -

    Empty foot

    19

    Leda

    -

    Backlight positive pole (+ 5 V)

    20

    Ledk

    -

    Negative backlight (0 V)

    Pin Connection Mode: PSB, RST connected to high level (3.3 V); RS connected to p3.0; R/W connected to p3.1; e connected to p3.2; DB0-DB7 connected to P5 port, power supply connected to 3.3 V (including backlight) Gnd ground (including backlight ).

    Steps for displaying Chinese characters:

    1. Ram (ddram)

    The display data Ram provides 64x2 bytes of space, and can control up to 4 lines of 16 characters (64 words) of the Chinese font display. When you enter the display data Ram, the cgrom, hcgrom, and cgram fonts can be displayed separately. This series of modules can display three types of fonts: half-width hcgrom, cgram, and Chinese cgrom, selected from the encoding written in ddram, in bytes H ~ 0006 H fixed font, H ~ In the 7fh encoding, the semi-encoding will select the cgram self-wide English numeric font, And the encoding above A1 will automatically combine with the next byte, the two bytes are encoded to form a Chinese font.

    Big5 (a140 ~ D75f) GB (a1a0 ~ F7ff), the detailed font encoding is as follows:

    1). Display font half width: Write 8-bit data into ddram, range: 02h ~ 7fh encoding.

    2) display cgram: Write 16-bit data into ddram. There are four types of codes: 0000 h, 0002 H, 0004 H, and 0006 H.

    3). display Chinese characters: Write 16-bit data into ddram, range: a140h ~ D75fh encoding (big5), a1a0h ~ F7ffh encoding (GB ). Write 16-bit data into ddram by writing two bytes of data through a connection. Write the data to the high byte first (d15 ~ D8) then writes low bytes (D7 ~ D0 ).

    2. Drawing RAM (gdram)

    The drawing display Ram provides 64x32 bytes of memory space (the drawing RAM address is set by the Extended Instruction). It can control up to x 64 points of two-dimensional drawing buffer space. When you change the drawing Ram, set the gdram address by the expansion command, set the vertical address, and then set the horizontal address (write two bytes of data to complete the vertical and horizontal coordinate addresses), and then write two 8-bit data to the drawing Ram, the address counter (AC) will automatically add one. The steps for writing to the drawing RAM are as follows:

    1) first write the vertical byte coordinate (y) into the drawing RAM address.

    2). Write the horizontal byte coordinate (x) into the drawing RAM address.

    3). Change D15 ~ D8 is written to Ram (the first bytes is written ).

    4). Convert D7 ~ D0 is written to Ram (the second bytes is written ).

    LCD display address:

    For more information about liquid crystal, see section 12864.

  2. Program Implementation:
    • conclusion: wait until the LCD module is idle.

      LCD module requirements: before receiving the command, the module must first confirm that the module is not busy, that is, when reading the BF mark, BF must be 0, before receiving a new command. If the BF flag is not checked before sending an order, the previous command and the command must be delayed for a long time, that is, wait for the execution of the previous command to complete; here, I choose to wait for the busy sign to end. The program is as follows:

        void  waitforenable () { char  busy; clr_rs; set_rw; data_dir_in;  DO   // busy sentence  {set_en; _ Nop (); busy = data_in; clr_en ;}< span style = "color: Blue"> while  (Busy & 0x80); data_dir_out ;} 

      in this way, each time you write a command or data to an LCD, you only need to call this function first, and the function will be blocked, until the busy sign changes back to 0 (Internal idle, can accept commands ).

    • Write Data: write data to the module Ram.

      Write Data to ddram to display the LCD. Write function:

      VoidLcdwritedata (CharData) {waitforenable (); set_rs; clr_rw; data_out = data;// Write dataSet_en; _ Nop (); clr_en ;}

      Similarly, you can call this function to write data to other Ram instances to complete relevant operations.

    • Write command: write command to module.

      You can use the LCD instruction set to control the functions of the LCD. The procedure is as follows:

      VoidLcdwritecomm (CharCMD) {waitforenable ();// Detect busy signals?Clr_rs; clr_rw; data_out = cmd;// Write commandSet_en; _ Nop (); clr_en ;}

      If CMD is 0x80-0x9f, the address is written to the LCD. For the address table, see the hardware description section above.

    • write string: Write string to display.

      writing a string is to write data multiple times and write the string to the LCD for display. The program is as follows:

        void  lcdwritestring ( char  ADDR,  char  * Str) {lcdwritecomm (ADDR );  while  (* Str! =  '\ 0' ) {lcdwritedata (* Str); STR ++ ;}} 

      This is a string written to an address, and the liquid crystal is displayed to the corresponding position. This function has a requirement that the string is a Chinese string. If not, the English letters of each place must be connected; otherwise, garbled characters are displayed. If there is only one English character, spaces can be added. For example: lcdwritestring (0x90, "1 ABCD hello"); 1 + space + ABCD + only one character in Chinese characters, plus space, AB, CD.

    • LCD initialization: the LCD can be used normally only after initialization.

      Initialization is a series of commands to complete the initial work of the liquid crystal status, so that the liquid crystal can be used normally. The procedure is as follows:

      VoidLcdinit () {ctrl_dir_out; delaynms (500); lcdwritecomm (0x30 );// Basic Instruction SetLcdwritecomm (0x01 );// Clear screen, address 00 hLcdwritecomm (0x06 );// Move the cursorLcdwritecomm (0x0c );// On display, close the cursor}

      After running this function, the LCD can display normally. before calling the function, you must call this function.

    The program implementation will come here first, and you can also add functions such as displaying images; you have to pack up and go back, and other functions are not implemented for the moment, and you will need to add them later.

  3. Example:

    This program is used in the same way as the serial library. Add the c file to the project. Include the H file in the source file of the program to be called.

    VoidMain (Void){// Stop watchdog timer to prevent time out ResetWdtctl = wdtpw + wdthold; clkinit (); lcdinit (); lcdwritestring (0x90,"1. How are you doing with ABCD");}

    After this function is run, the 1 ABCD character string will be displayed in the second line. If the space after 1 is removed, the Chinese part will be garbled. Clkinit (); this function is the same as the one called in the previous one. It sets the master system clock to 8 MHz and the smclk to 1 MHz. For more information, see the library mian. C.

At this point, the LCD driver is basically complete, and other functions are added later.

If there is something wrong or bad, you are welcome to raise it. Thank you.

Appendix: Library

Author:Give me a drink

Source: http://Engin.cnblogs.com/

The copyright of this article is shared by the author and the blog Park. You are welcome to repost it. repost the text and indicate the source. Thank you.

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.