msp430g2553: dual line 12864 library program

Publisher:tyloo820Latest update time:2016-12-13 Source: eefocusKeywords:msp430g2553 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

(Display) msp430g2553: dual-line 12864 library program

 

**************************************************************************************************

LCD12864.H

 

****************************************************************
LCD12864 2-wire program
   rs (CS) has been externally connected to a high level
   rw (SID) P2.0
   en (SCLK) P2.1
   PSB has been externally connected to a low level
   RST has been externally connected to a high level
  hardware circuit, the resistance between the 10K resistor connected to pin 3 and the ground is generally 8.8k-9.5k
(one power supply +, two common ground wires)  
*****************************************************************

 

#ifndef __LCD12864_H__
#define __LCD12864_H__

 

#include"msp430g2553.h"

 

********************************
       Pin Definition
********************************
#define SID_0 P2OUT &= ~BIT0
#define SID_1 P2OUT |= BIT0
#define SCLK_0 P2OUT &= ~BIT1
#define SCLK_1 P2OUT |= BIT1

 

******************************
        Command character definition
******************************
#define First_Line 0x80
#define Second_Line 0x90
#define Third_Line 0x88
#define Fourth_Line 0x98

 

************************************************************
                       函数定义
************************************************************
extern void LCD12864_Port_Init(void);
extern void LCD12864_write_one_byte(unsigned int byte);
extern void LCD12864_write_command(unsigned int com);
extern void LCD12864_write_data(unsigned int dat);
extern void LCD12864_Init(void);

 

extern void LCD12864_write_string(char adress,char *str);


#endif

**************************************************************************************************

 

 

**************************************************************************************************

LCD12864.C

 

#include"LCD12864.H"

 

****************************
       Port initialization
****************************
void LCD12864_Port_Init(void)
{
 P2DIR=BIT0+BIT1;
}

 

****************************************
 Transfer byte function:
     byte type data, 1: SID transmits a high level
                 0: SID transmits a low level
******************************************
void LCD12864_write_one_byte(unsigned int byte)
{
 unsigned int i;
 for(i=0;i<8;i++)
 {
   if( byte & 0x80 )
     SID_1;
   else
     SID_0;
   SCLK_1;
   __delay_cycles(10);
   SCLK_0;
   byte<<=1;
   __delay_cycles(10);
 }
}

 

 

************************************************************************************
2-wire 128*64 data transmission:
 first determine whether to transmit commands or data
   1. The first byte: the first five must be high level, and the 12864 is initialized for two-wire transmission.
                 The sixth level is RW, the seventh is RS, and the eighth must be low level 0.
                 (1 1 1 1 1 RW RS 0)
                 (This is to correspond to the 8-wire command. Data is transmitted through the SID data line, and
                     CS is always high).               
                          RW RS byte
            write command: 0 0 0xf8
            write data: 0 1 0xfa 
            read busy: 1 0 0xfc
            read data: 1 1 0xfe          
 then start to transmit data
   2. The second byte: the upper four bits are the upper four bits of the data to be transmitted, and the lower four bits are all 0. (D7 D6 D5 D4 0 0 0 0)
   3. The third byte: the upper four bits are the lower four bits of the data to be transmitted, and the lower four bits are all 0. (D3 D2 D1 D0 0 0 0 0)
Data* command transmission completed
******************************************************************************

 

******************************
       写命令函数
******************************
void LCD12864_write_command(unsigned int com)
{
 unsigned int com_init=0xf8;
 unsigned int com_h,com_l;
 com_h = com & 0xf0;
 com_l = (com<<4) & 0xf0;
 
 LCD12864_write_one_byte(com_init);
 LCD12864_write_one_byte(com_h);
 LCD12864_write_one_byte(com_l);
}

 

*****************************
       写数据函数
*****************************
void LCD12864_write_data(unsigned int dat)
{
 unsigned int dat_init=0xfa;
 unsigned int dat_h,dat_l;
 dat_h = dat & 0xf0;
 dat_l = (dat<<4) & 0xf0;
 
 LCD12864_write_one_byte(dat_init);
 LCD12864_write_one_byte(dat_h);
 LCD12864_write_one_byte(dat_l);
}


************************************************************************************
     Init function (some places that must be set)
   command function                 
    0x30 Basic instruction set                
    0x01 Clear screen                     
    0x06 Transmit a character, cursor right, AC+1, display does not move          
    0x0c Display on
    0x0f Display on, cursor on, cursor flashing
**********************************************************************************
void LCD12864_Init(void)
{
 LCD12864_write_command(0x30);
 LCD12864_write_command(0x01);
 LCD12864_write_command(0x06);
 LCD12864_write_command(0x0f);
}

 

**************************************************
       The string transfer function
   sets the first position of the string, and then displays the written string
************************************************
void LCD12864_write_string(char adress,char *str)
{
 __delay_cycles(1000);
 LCD12864_write_command(adress);
 while(*str!='\0')
 {
   LCD12864_write_data(*str);
   str++;
 }
}
*************************************************************************************************


Keywords:msp430g2553 Reference address:msp430g2553: dual line 12864 library program

Previous article:128*64 LCD display function realization
Next article:12864_8 line library program

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号