Now: I will lead you to start with the character type 1602 LCD and master the LCD programming step by step.
SMC1602 interface program (MCS51 analog port line mode)
The above are photos of the operation, which is actually dynamic, from 0--9
;********************************************************************************
;1602 LCD full screen displays 0-9 *
;********************************************************************************
;* Date: 2007-3-25 *
;* Version: 3.0 *
;* Author: Shenzhen Xuelin Electronics Co., Ltd. Professional 8051 Microcontroller Tutorial Station*
;* Email: sxj1974@163.com *
;* Website: http://www.51c51.com http://www.8951.com For more routines, please visit the website*
;********************************************************************************
;* Hardware: This program is run on our company's xlisp series microcontroller experiment instrument*
;********************************************************************************
;* 【Copyright】 Copyright(C) Shenzhen Xuelin Electronics Co., Ltd. www.51c51.com All Rights Reserved *
;* 【Statement】 This program is for learning and reference only. Please indicate the copyright and author information when quoting! *
;********************************************************************************
RSPIN EQU P2.0
RWPIN EQU P2.1
EPIN EQU P2.2
XPOS EQU 20H ; Column direction address pointer (for LCDPOS subroutine)
YPOS EQU 21H ; Row direction address pointer (for LCDPOS subroutine)
ORG 0000H
JMP START
START: MOV SP,#60H
CLR EPIN
MAIN:
MOV R7,#'0' ; Test main program
MN_PA: ; The whole screen displays "0" to "9" and spaces in a cycle
CALL LCDRESET
MOV A,R7
CALL LCDFILL
CALL DELAY400MS
INC R7
MOV A,R7
CJNE A,#'9'+1,MN_PA
MOV A,#' '
CALL LCDFILL
CALL DELAY400MS
JMP MAIN
LCDFILL:
MOV B,A
MOV YPOS,#0
LFL_PB: MOV XPOS,#0 ;Display the character represented by A on the entire screen
LFL_PA: MOV A,B
CALL LCDWRITE
INC XPOS
MOV A,XPOS
CJNE A,#20,LFL_PA
INC YPOS
MOV A,YPOS
CJNE A,#4,LFL_PB
RET
LCDPOS: ;Set the DDRAM address of the (XPOS,YPOS)th character
PUSH ACC
CLR C ;X position range (0 to 19)
MOV A,XPOS
SUBB A,#20
JC LPS_LBX
MOV XPOS,#0
LPS_LBX:ANL YPOS,#03H ;Y position range (0 to 3)
MOV A,YPOS ;(XPOS,YPOS) corresponds to DDRAM address
CJNE A,#00,LPS_LA1
MOV A,XPOS ;(first line)X: 0----19th character
JMP LPS_LAX ; DDRAM: 0----13H
LPS_LA1:CJNE A,#01,LPS_LA2
MOV A,XPOS; (second line)X: 0----19th character
ADD A,#40H; DDRAM: 40----53H
JMP LPS_LAX;
LPS_LA2:CJNE A,#02,LPS_LAY
MOV A,XPOS ;(the third line)X: 0th----19th character
ADD A,#14H ; DDRAM: 14----27H
JMP LPS_LAX
LPS_LAY:MOV A,XPOS ;(the fourth line)X: 0th----19th character
ADD A,#54H ; DDRAM: 54----67H
LPS_LAX:ORL A,#80H ;Set DDRAM address
CALL LCDWC
POP ACC
RET
LCDWRITE: ;Position write character subroutine
CALL LCDPOS ;Position display address
CALL LCDWD ;Write character
RET
LCDRESET: ;Initialization program
CALL DELAY5MS ;Delay 15MS
CALL DELAY5MS
CALL DELAY5MS
MOV A,#38H ;Display mode setting (do not detect busy signal)
CALL LCDWCN ;Three times in total
CALL DELAY5MS
MOV A,#38H
CALL LCDWCN
CALL DELAY5MS
MOV A,#38H
CALL LCDWCN
MOV A,#38H ;Display mode setting (busy signal will be detected in the future)
CALL LCDWC
MOV A,#08H ;Display offCALL
LCDWC
MOV A,#01H ;Display clearCALL
LCDWC
MOV A,#06H ;Display cursor movement settingCALL
LCDWC
MOV A,#0CH ;Display on and cursor settingCALL
LCDWC
RET
LCDWC: ;Send control word subroutine (busy signal detection)
CALL WAITIDLE
LCDWCN: ;Send control word subroutine (no busy signal detection)
CLR RSPIN ;RS=0 RW=0 E=high pulseCLR
RWPIN
MOV P0,A
SETB EPIN
NOP
CLR EPIN
RET
LCDWD: ;Write character subroutineCALL
WAITIDLE
SETB RSPIN ;RS=1 RW=0 E=high pulse
CLR RWPIN
MOV P0,A
SETB EPIN
NOP
CLR EPIN
RET
WAITIDLE:
PUSH ACC ; LCD controller status must be detected before normal read and write operations
MOV P0,#0FFH
CLR RSPIN ; RS=0 RW=1 E=high level
SETB RWPIN
SETB EPIN
WTD_PA: NOP ; DB7: 0 LCD controller idle
JB P0.7,WTD_PA ; 1 LCD controller busy
CLR EPIN
POP ACC
RET
DELAY5MS:
MOV R1,#25 ; Delay subroutine (5MS)
DL5_PA: MOV R2,#100
DJNZ R2,$
DJNZ R1,DL5_PA
RET
DELAY400MS:
MOV R0,#20 ; Delay subroutine (400MS)
DL4_PA: MOV R1,#100
DL4_PB: MOV R2,#100
DJNZ R2,$
DJNZ R1,DL4_PB
DJNZ R0,DL4_PA
RET
END
Previous article:Super twisted nematic display
Next article:How do you get the code in the data table?
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Recruitment position: MCU engineer (urgent) 1 person
- STM32 virtual serial port (USB driver)
- New Tang 8051 (1T) Quickly build the entry keil environment
- A python comic
- A display solution for APF system information——Based on Topmicro intelligent display module
- Is there any way in KEIL4 to find out whether == in IF() is written as =?
- [Analog Electronics Course Selection Test] + Strongly targeted functions
- Why does CCS need to install a driver?
- The age of gadgets freeing your hands
- How does BLUE NRG1 achieve one-to-many communication?