📄 prog47a.asm
字号:
; PROG47 - Working through the Electronic Breakout Box
;
; Simple Test of the LCD.
;
; This Application waits for 30 msecs and then puts "Hello" onto the LCD's
; Screen.
;
; Myke Predko
; 98.06.17
;
; Hardware Notes:
; DS87C520 is used as the Microcontroller
; - Oscillator Speed is 11.052 MHz
; P2.4-7 are the LCD Data Bits (NOTE: Bits Are Reversed)
; P0.3 is Pulled up with a 4.7L K resistor and used for the LCD "RS" Bit
; P0.4 is Pulled up with a 4.7K Resistor and used for the LCD "E" Bit
; Constant Declarations
define RS=P0.3 ; Define the LCD "RS" Bit
define EStrobe=P0.4 ; Define the LCD "E" Bit
; Variable Declarations
; Macros
; Mainline
org 0 ; Execution Starts Here
MainLine: ; Mainline of the Program
clr EStrobe ; Make Sure the "E" Line is Low
acall Dlay5 ; Wait 30 msecs for the LCD to Power Up
acall Dlay5
acall Dlay5
acall Dlay5
acall Dlay5
acall Dlay5
clr RS ; Sending Instructions
mov P2,#0C0h ; Output the Reset Command
setb EStrobe ; Try this instead of "E"?
clr EStrobe
acall Dlay5
setb EStrobe ; Send the Reset Again
clr EStrobe
acall Dlay200 ; Wait 200 msecs
setb EStrobe ; Send Reset for the Last Time
clr EStrobe
acall Dlay200
mov P2,#040h ; Now, Put the LCD in 4 Bit Mode
setb EStrobe
clr EStrobe
acall Dlay200
mov A,#028h ; Set the Number of Display Lines to 2
acall CharSend ; and a 5x7 Font
mov A,#008h ; Turn the Display Off
acall CharSend
mov A,#001h ; Clear the Display RAM
acall CharSend
mov A,#006h ; Enable Cursor Increment
acall CharSend
mov A,#00Eh ; Turn on the Display
acall CharSend
mov A,#'A' ; Put an "A" on the LCD
setb RS
acall CharSend
Loop: ; Loop Here forever
ajmp Loop
; Subroutines
CharSend: ; Send the Character in the Accumulator
mov R7,#8 ; Have to Reverse the Bits
CSLoop: ; Loop Here Until R6 Has the Value
rrc a ; Shift the LSB into the Carry Flag
xch A,R6
rlc a ; Shift in the New MSB
xch A,R6
djnz R7,CSLoop ; Loop Around
xch A,R6 ; Save R6 for Tests
swap a ; Make Low Byte high Byte...
mov P2,A ; Output the High Nybble First
setb EStrobe
clr EStrobe
swap A ; Now, Output the Low Nybble
mov P2,A
setb EStrobe
clr EStrobe
acall Dlay200
jb RS,CharSendEnd ; If Outputting a Character, Not a Long Instruction
anl A,#03Fh ; Are we Executing a Long Instruction?
jnz CharSendEnd
acall Dlay5 ; Yes, Delay 5 msec
CharSendEnd:
ret
Dlay200: ; Use R7 to Delay 200 usecs
mov R7,#192
Dlay200Loop:
djnz R7,Dlay200Loop ; 3 Cycles
ret
Dlay5: ; Use R6 and R7 to Delay 5 msecs
mov R6,#0
mov R7,#19
Dlay5Loop:
djnz R6,Dlay5Loop ; 3 Cycles
djnz R7,Dlay5Loop ; 3x256 + 3 = 771 Cycles
ret
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -