📄 13组源程序.txt
字号:
;********************************************************************** *
; Filename:38.asm *
; Date:2006.9.18 *
; Author: *
;**********************************************************************
;**********************************************************************
; 单片机控制三八译码器
; 源程序代码
;**************************************************************************
status equ 3h ;定义状态寄存器地址
rp0 equ 5h ;定义体0
rp1 equ 6h ;定义体1
portb equ 6h ;定义端口B的数据寄存器地址
trisb equ 86h ;定义端口B的方向控制寄存器地址
portd equ 8h ;定义端口D的数据寄存器地址
trisd equ 88h ;定义端口D的方向控制寄存器地址
m equ 25h ;定义一个延时变量寄存器
n equ 26h ;定义另一个延时变量寄存器
;*******************************************************************************
org 0000h ;定义程序存放区域的起始地址
nop ;放置一条lcd必须的空操作指令
bcf status,rp1 ;选择体1
bsf status,rp0
movlw 00h
movwf trisb ;RB全部设为输出
movwf trisd ;RD全部设为输出
bcf status,rp0
goto display1
;*******************************************************************************
display1 ;第二个数码管发光程序
call display2 ;调用第一个数码管循环发光程序
movlw b'10000000'
movwf portd ;第二个数码管第一段不发光
call delay ;调用延时子程序
call delay
call delay
call display2
movlw b'10000001' ;第二个数码管第二段不发光
movwf portd
call delay
call delay
call delay
call display2
movlw b'10000010' ;第二个数码管第三段不发光
movwf portd
call delay
call delay
call delay
call display2
movlw b'10000011' ;第二个数码管第四段不发光
movwf portd
call delay
call delay
call delay
call display2
movlw b'10000100' ;第二个数码管第五段不发光
movwf portd
call delay
call delay
call delay
call display2
movlw b'10000101' ;第二个数码管第六段不发光
movwf portd
call delay
call delay
call delay
call display2
movlw b'10000110' ;第二个数码管第七段不发光
movwf portd
call delay
call delay
call delay
call display2
movlw b'00000000' ;两个数码管全亮作为间隔
movwf portb
movwf portd
call delay
call delay
goto display1
;****************************************************************
display2
movlw b'10000000' ;第一个数码管第一段不发光
movwf portb
call delay
call delay
call delay
call delay
movlw b'10000001' ;第一个数码管第二段不发光
movwf portb
call delay
call delay
call delay
call delay
movlw b'10000010' ;第一个数码管第三段不发光
movwf portb
call delay
call delay
call delay
call delay
movlw b'10000011' ;第一个数码管第四段不发光
movwf portb
call delay
call delay
call delay
call delay
movlw b'10000100' ;第一个数码管第五段不发光
movwf portb
call delay
call delay
call delay
call delay
movlw b'10000101' ;第一个数码管第六段不发光
movwf portb
call delay
call delay
call delay
call delay
movlw b'10000110' ;第一个数码管第七段不发光
movwf portb
call delay
call delay
call delay
call delay
return
;*********************************************************************
delay ;延时子程序
movlw d'225'
movwf m
lpp1
movlw d'180'
movwf n
lpp2
decfsz n,1
goto lpp2
decfsz m,1
goto lpp1
return
;***************************程序结束****************************
end
;********************************************************************** *
; Filename:mms.asm *
; Date:2006.9.18 *
; Author:张易 *
;**********************************************************************
;***************************************************************
; 利用单片机实现的密码锁
; 源程序代码
;***************************************************************
tmr0 equ 1h ;定义定时器/计数器0寄存器地址
pcl equ 2h ;指令计数器相关寄存器
status equ 3h ;定义状态寄存器地址
rp0 equ 5h ;定义状态寄存器中的页选位RP0
rp1 equ 6h ;定义状态寄存器中的页选位RP1
z equ 2h ;定义0标志位地址
porta equ 05h ;A端口定义(数据寄存器地址)
trisa equ 85h ;(方向控制寄存器地址)
portb equ 06h ;B端口定义
trisb equ 86h
portc equ 07h ;C端口定义
trisc equ 87h
portd equ 08h ;D端口定义
trisd equ 88h
porte equ 09h ;E端口定义
trise equ 89h
data1 equ 21h ;延时变量寄存器定义
value equ 22h ;暂存按键列码和位置码
mm6 equ 23h ;判别密码正确累加寄存器
data2 equ 24h ;延时变量寄存器定义
gengkz equ 28h ;是否更改密码控制变量寄存器
m1 equ 29h ;6位输入密码地址
m2 equ 2ah
m3 equ 2bh
m4 equ 2ch
m5 equ 2dh
m6 equ 2eh
mi equ 2fh ;密码控制变量
ym1 equ 30h ;读取6位旧密码寄存器
ym2 equ 31h
ym3 equ 32h
ym4 equ 33h
ym5 equ 34h
ym6 equ 35h
count3 equ 38h ;三次输入密码错误判定寄存器
count4 equ 39h
intcon equ 0bh ;中断控制寄存器
fsr equ 04h ;间接寻址寄存器
option_reg equ 81h ;选项寄存器地址定义
rbup equ 07h ;上拉电阻使能位位地址定义
table equ 40h ;按键表头地址
n2 equ 0ffh ;内层循环延时常数
mvalue equ 71h ;写密码暂用寄存器
tmr0b equ 0fch ;定义TMR0寄存器初始值1,用于喇叭发声延时1ms
tmr0c equ 9ch ;定义TMR0寄存器初始值2,用于喇叭发声延时250ms
temp_reg equ 25h ;控制输送数据寄存器
temp_char equ 26h ;输送数据存放寄存器
init_reg equ 27h ;液晶初始化常量定义
eecon1 equ 18ch ;定义烧写控制寄存器1的地址
eecon2 equ 18dh ;定义烧写控制寄存器2的地址
eedata equ 10ch ;定义读/写数据寄存器地址
eeadr equ 10dh ;定义读/写地址寄存器地址
rd equ 0 ;定义读出启动控制位位址
wr equ 1 ;定义烧写启动控制位位址
wren equ 2 ;定义烧写使能控制位位址
eepgd equ 7 ;定义访问目标选择控制位位址
f equ 1 ;定义目标寄存器为RAM的指示符
w equ 0 ;定义目标寄存器为W的指示符
addr equ 70h ;定义地址变量
mvalue equ 71h ;定义数据变量
;**************************************
setcommand Macro ;屏幕设置宏定义
movlw 0x02
movwf porte
ENDM
clearcommand Macro ;清屏设置宏定义
movlw 0x00
movwf porte
ENDM
;******************************************************
;*****************初始化及显示程序*********************
org 0000h ;程序起始地址
nop
goto mainline
stringtable ;显示"welcome use"
movf temp_reg,w
addwf pcl,1
retlw 'w' ;77h
retlw 'e' ;65h
retlw 'l' ;69h
retlw 'c' ;63h
retlw 'o' ;6fh
retlw 'm' ;6dh
retlw 'e' ;65h
retlw ' ' ;20h
retlw 'u' ;75h
retlw 's' ;73h
retlw 'e' ;65h
stringtable1 ;显示"enter the code"
movf temp_reg,w
addwf pcl,1
retlw 'e' ;65h
retlw 'n' ;6eh
retlw 't' ;74h
retlw 'e' ;65h
retlw 'r' ;72h
retlw ' ' ;20h
retlw 't' ;74h
retlw 'h' ;68h
retlw 'e' ;65h
retlw ' ' ;20h
retlw 'c' ;63h
retlw 'o' ;6fh
retlw 'd' ;64h
retlw 'e' ;65h
stringtable2 ;显示"code is right"
movf temp_reg,w
addwf pcl,1
retlw 'c' ;63h
retlw 'o' ;6fh
retlw 'd' ;64h
retlw 'e' ;65h
retlw ' ' ;20h
retlw 'i' ;69h
retlw 's' ;73h
retlw ' ' ;20h
retlw 'r' ;72h
retlw 'i' ;69h
retlw 'g' ;67h
retlw 'h' ;68h
retlw 't' ;74h
stringtable3 ;显示"code is wrong"
movf temp_reg,w
addwf pcl,1
retlw 'c' ;63h
retlw 'o' ;6fh
retlw 'd' ;64h
retlw 'e' ;65h
retlw ' ' ;20h
retlw 'i' ;69h
retlw 's' ;73h
retlw ' ' ;20h
retlw 'w' ;77h
retlw 'r' ;72h
retlw 'o' ;6fh
retlw 'n' ;6eh
retlw 'g' ;67h
stringtable4 ;显示"rewrite code"
movf temp_reg,w
addwf pcl,1
retlw 'r' ;72h
retlw 'e' ;65h
retlw 'w' ;77h
retlw 'r' ;72h
retlw 'i' ;69h
retlw 't' ;74h
retlw 'e' ;65h
retlw ' ' ;20h
retlw 'c' ;63h
retlw 'o' ;6fh
retlw 'd' ;64h
retlw 'e' ;65h
stringtable5 ;显示"rewrite success"
movf temp_reg,w
addwf pcl,1
retlw 'r' ;72h
retlw 'e' ;65h
retlw 'w' ;77h
retlw 'r' ;72h
retlw 'i' ;69h
retlw 't' ;74h
retlw 'e' ;65h
retlw ' ' ;20h
retlw 's' ;73h
retlw 'u' ;75h
retlw 'c' ;63h
retlw 'c' ;63h
retlw 'e' ;65h
retlw 's' ;73h
retlw 's' ;73h
stringtable6 ;显示"rewrite failed"
movf temp_reg,w
addwf pcl,1
retlw 'r' ;72h
retlw 'e' ;65h
retlw 'w' ;77h
retlw 'r' ;72h
retlw 'i' ;69h
retlw 't' ;74h
retlw 'e' ;65h
retlw ' ' ;20h
retlw 'f' ;66h
retlw 'a' ;61h
retlw 'i' ;69h
retlw 'l' ;6ch
retlw 'e' ;65h
retlw 'd' ;64h
stringtable7 ;显示"exit"
movf temp_reg,w
addwf pcl,1
retlw 'e' ;65h
retlw 'x' ;78h
retlw 'i' ;69h
retlw 't' ;74h
;*****************************************************
;*******************液晶初始化************************
mainline
bsf status,rp0 ;设置文件寄存器的体1
bcf status,rp1
clrf trisc ;端口c设置
bcf status,rp0
movlw 092h ;上锁状态显黄灯
movwf portc
call initial ;液晶初始化
call showstring ;输出"WELCOME USE"
goto line1 ;矩阵键盘扫描与按键识别
initial ;液晶初始化开始
bsf status,rp0 ;体1
bcf status,rp1
clrf trise ;端口设置
clrf trisd
bcf status,rp0 ;体0
movlw 0x03 ;输送三次
movwf init_reg
;******************************
init_loop
movlw 0x01
movwf porte
movlw 0x30
movwf portd
movlw 0x00
movwf porte
call delay4ms
decfsz init_reg,1
goto init_loop
setcommand ;液晶功能设置 接口数据位数8位 2行 5*7点阵
movlw 0x38
movwf portd
clearcommand
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -