📄 prog47c.asm
字号:
; PROG47c - Working through the Electronic Breakout Box
;
;
; Start Taking User Input.
;
; PROG47C - Output a Table and Save the Blank Positions in R5, R6 and R7
;
; Myke Predko
; 98.06.20
;
; 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
acall LCDInit ; Initialize the LCD
mov A,#3 ; Display The Forth Message
acall MsgSend ; Output the Message
; #### - Put in Function Code Here
Loop: ; Loop Here forever
ajmp Loop
; Subroutines
MsgSend: ; Send the Specified Message to the Display
mov R1,A ; Save the Message Number
mov R0,#0 ; Use R0 as the Offset Counter
MsgSend_Find: ; Look for the Appropriate Message
mov A,R1 ; Are we Now At Zero?
jz MsgSend_Output ; If Count is Zero
mov A,#LOW(MsgSendTable-MsgSendFindGet)
add A,R0 ; Get Current Address
movc A,@A+PC ; Get the Character in the Displays
MsgSendFindGet:
inc R0 ; Point to the Next Character
jnz MsgSend_Find ; If NOT Equal to Zero,
dec R1 ; It is, Decrement the Message Counter
ajmp MsgSend_Find
MsgSend_Output: ; Now, Output the String to '\0'
mov 2,R0 ; Save the Start of the Message
mov R5,#0FFh ; Set the Registers As Invalid
mov R6,#0FFh
mov R7,#0FFh
setb RS ; Make Sure Characters Are going out
MsgSendOutput_Loop: ; Output Each Character in the Table to "\0"
mov A,R0
add A,#LOW(MsgSendTable-MsgSendOutputGet)
movc A,@A+PC ; Read the Table
MsgSendOutputGet:
inc R0 ; Point to the Next Character
jz MsgSendOutput_Check ; If at Zero, Stop the Reading
mov R1,A ; Save the Character
acall CharSend
cjne R1,#' ',MsgSendOutput_Loop
mov 5,R6 ; Save the Blank Position
mov 6,R7
mov A,R0 ; Calculate the Offset
setb C
subb A,R2
mov R7,A
ajmp MsgSendOutput_Loop
MsgSendOutput_Check: ; Now, Shift down the Blanks
mov A,R7 ; Do we Have No Blanks?
xrl A,#0FFh
jz MsgSend_End
MsgSendOutputCheck_Loop: ; May Only Have One Blank
cjne R5,#0FFh,MsgSend_End ; Everything Shifted Down
mov 5,R6 ; Shift the Data Down Until All Blanks Saved
mov 6,R7
mov R7,#0FFh
ajmp MsgSendOutputCheck_Loop
MsgSend_End: ; Message Output and Blanks Setup
ret
MsgSendTable: ; Messages to be Displayed
db 'Left ', 0 ; Message 0
db 'Right ', 0 ; Message 1
db 'BREAKOUT BOX',0 ; Message 2
db ' Run Configure',0 ; Message 3
db 'Speed',0 ; Message 4
db ' 110 300 Cont',0 ; Message 5
db 'Speed -',0 ; Message 6
db ' 1200 2400 Cont', 0 ; Message 7
db 'Speed |',0 ; Message 8
db ' 9600 19200 Cont',0 ; Message 9
db 'Port Type',0 ; Message 10
db ' DCE DTE',0 ; Message 11
db 'Modem Ctrl',0 ; Message 12
db ' Enble Loop None',0 ; Message 13
db 'Display',0 ; Message 14
db ' String Byte/Bit',0 ; Message 15
LCDInit: ; LCD Initialize Blank Offsets
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
ret
CharSend: ; Send the Character in the Accumulator
mov R3,#8 ; Have to Reverse the Bits
CSLoop: ; Loop Here Until R4 Has the Value Reversed
rrc a ; Shift the LSB into the Carry Flag
xch A,R4
rlc a ; Shift in the New MSB
xch A,R4
djnz R3,CSLoop ; Loop Around
xch A,R4 ; Save R4 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 R3,#192
Dlay200Loop:
djnz R3,Dlay200Loop ; 3 Cycles
ret
Dlay5: ; Use R6 and R7 to Delay 5 msecs
mov R3,#0
mov R4,#19
Dlay5Loop:
djnz R3,Dlay5Loop ; 3 Cycles
djnz R4,Dlay5Loop ; 3x256 + 3 = 771 Cycles
ret
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -