Display effect: full screen display 0---9: the program test passed

Publisher:数字梦想Latest update time:2011-02-27 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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

Reference address:Display effect: full screen display 0---9: the program test passed

Previous article:Super twisted nematic display
Next article:How do you get the code in the data table?

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号