(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++;
}
}
*************************************************************************************************
Previous article:128*64 LCD display function realization
Next article:12864_8 line library program
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- ADS1220 driver compilation error
- [Evaluation of EC-01F-Kit, the NB-IoT development board of Anxinke] + Simple networking test
- W806 uses OLED display
- Evaluation Weekly Report 20220314: Domestic FPGA Anlu is here, while Tuya, Arteli, and Qinhengjia products are still in the application process
- A brief introduction to commonly used wireless technologies
- Which time parameter is related to the maximum transmission speed that MOS can achieve?
- Build common logic gate circuits using transistors
- How to learn Python for beginners
- Disassembly of the SPX01W power bank that supports wireless charging
- (1) Unboxing experience based on the STM32L4R9 MEMS sensor board (IKS01A3)