📄 mbg1.asm
字号:
;file : mgb1.asm
;date : 8aug2002
;for lcd module "rcl display etd ,Mbg06406b series"
;
user: equ 0000h
pdata: reg p1
rs: reg p3.2
la0: reg p3.2
e: reg p3.3
cs1: reg p3.4
lcde0: reg p3.4
cs2: reg p3.5
lcde1: reg p3.5
cr: equ 0dh
lf: equ 0ah
spp: equ 50h
org user
jmp init
org user+3h
jmp ext_int0
org user+bh ;timer 0
jmp ctc0_int_serv
org user+13h ;low battery
jmp ext_int1
org user+1bh
jmp ctc0_int_serv
org user+23h
jmp sio_int
org user+100h
jmp init
init:
; initialize ctc 0 for time clock use 11.0592 mhz crystal
; 11.0592 mhz / 12 / 256 / 180 / = 20 hz
; crystal cyc tl0 th0 = interrupt rate
orl tmod,#00000001b ; set ctc 0 mode 1
mov tl0,#256-256 ; set low byte divide 256
mov th0,#256-180 ; set high byte divide 180
setb tr0 ; start ctc 0
; initialize ctc 1 for sio baud rate use 11.0592 mhz crystal
; 11.0592 mhz / 12 / 2 / 3 / 16 = 9600
; crystal cyc smod ctc 1 sio = baud rate
orl tmod,#00100000b ; set ctc mode 2 auto reload
; internal clock source
mov th1,#256-3 ; 3=9600 6=4800
mov tl1,#256-3 ; 12=2400 24=1200
setb tr1 ; start ctc 1
orl scon,#01010000b ; set sio mode 1, enable receive
;mov a,pcon
;orl a,#80h
;mov pcon,a
mov sp,#spp
mov dptr,#prompt_start
call send_text
start: setb rs
setb e
setb lcde0
setb lcde1
call line
jmp fullon
inkey: call receiv
mov r1,a
xrl a,#'o' ;full on
jz fullon
mov a,r1
xrl a,#'f' ;full off
jz fulloff
mov a,r1 ;out data
xrl a,#'l'
jz line1
jmp inkey
fullon: mov a,#'o'
call send_data
clr la0 ;command
mov r3,#3fh ;display on
acall pw2
jmp inkey
fulloff: mov a,#'f'
call send_data
clr la0 ;command
mov r3,#3fh ;display off
acall pw2
jmp inkey
line1: call line
jmp inkey
;*************************************
;* *
;* ctc 0 interrupt service routine *
;* *
;*************************************
ctc0_int_serv: push psw ; save program status word
push a ; save accumulator
push dph
push dpl
mov th0,#256-180 ; reload high byte of ctc 0
ctc0_ret: pop dpl
pop dph
pop a ; reload accumulator
pop psw ; reload program status word
reti
sio_int: reti
ext_int0: reti
ext_int1: reti
;************************************************************************
;* *
;* subroutine : init lcd *
;* *
;************************************************************************
inilcd: mov r3,#38h
call initlcd1
mov r3,#38h
call initlcd1
mov r3,#38h
call initlcd1
mov r3,#38h
call initlcd1
mov r3,#01h
call initlcd1
mov r3,#02h
call initlcd1
mov r3,#06h
call initlcd1
mov r3,#0ch
call initlcd1
mov r3,#01h
call initlcd1
mov r3,#06h
initlcd1: call lcd_ctrl
ljmp ldelay
ldelay: push r7
mov r7,#4h
dlp1: mov r6,#8h
dlp2: djnz r6,dlp2
djnz r7,dlp1
pop r7
ret
;--------------------------------------------------------
;
lcd_ctrl: clr la0
jmp display
lcd_data: setb la0
pw2:
display: setb e
mov a,r3
mov p1,a
clr e
call ldelay
clr lcde0
setb e
call ldelay
clr e
;clr lcde1
call ldelay
clr e
setb lcde0
;setb lcde1
call ldelay
setb e
ret
receiv: jnb ri,receiv
clr ri
rec_ok: mov a,sbuf
ret
new_line: push a
mov a,#lf
call send_data
mov a,#cr
call send_data
pop a
ret
;*************************
;* *
;* text message tables *
;* *
;*************************
send_text: push a
push r7
mov r7,#00h
send_text1: mov a,r7
movc a,@a+dptr
jz send_text_ret ; end of text table
call send_data
inc r7
cjne r7,#00h,send_text1
inc dph
jmp send_text1
send_text_ret pop r7
pop a
ret
;**********************************************************
;* *
;* subroutine : convert hex number to ascii characters. *
;* *
;* input : a = hex number in low nibble. *
;* *
;* output : a = corresponding ascii character. *
;* *
;**********************************************************
hex_asc: anl a,#00001111b
inc a
movc a,@a+pc
ret
db '0123456789ABCDEF0'
;************************************************************************
;* *
;* subroutine : convert a hex number to corresponding ascii character *
;* and send it out. *
;* *
;************************************************************************
send_hex_asc: push a
swap a
call hex_asc
call send_data
pop a
push a
call hex_asc
call send_data
pop a
ret
send_data: mov sbuf,a
jnb ti,$
clr ti
ret
line: mov a,#'a'
call send_data
clr la0 ;command
mov r3,#3eh ;display on
acall pw2
mov r3,#40h ;set address
acall pw2
mov r3,#b8h ;set page (x address)
acall pw2
mov r3,#c8h ;display start line (z address)
acall pw2
setb la0 ;data
mov r3,#0aah
call pw2
mov r2,#10
loop0: mov r3,#aah
acall pw2
mov r3,#55h
acall pw2
djnz r2,loop0
clr la0
mov a,#'b'
call send_data
ret
graphic_1: db 0ffh,00h,00h,00h,08h
db 0f8h,0f8h,88h,88h,0f8h,70h,00h,0f8h,0f8h,80h,80h,80h,0f8h
db 0f8h,00h,00h,08h,0f8h,0f8h,08h,00h,00h,00h,08h,0f8h,0f8h
db 08h,00h,00h,00h,00h,00h,08h,0f8h,0f8h,08h,00h,00h,00h
db 08h,0f8h,0f8h,88h,88h,0f8h,70h,00h,30h,78h,0c8h,88h,88h
db 38h,30h,00h,00h,00h,00h,00h,00h,00h,00h,00h,08h,0f8h
db 0f8h,08h,00h,00h,00h,00h,0e0h,0f0h,18h,08h,08h,18h,30h
db 00h,08h,0f8h,0f8h,08h,18h,0f0h,0e0h,00h,00h,00h,00h,0ffh
prompt_start: db "start",lf,cr,0
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -