1. 求用51单片机控制的简单密码锁原理
还是原来学汇编的时候的程序了
今天整理看到了
送给有用的人
code_seg segment code
data_seg segment data
stack_seg segment idata
spk bit p1.3
rseg data_seg
frq:ds 1
tmp:ds 1
rseg stack_seg
stack:ds 20
cseg at 00000h
ljmp main
cseg at 0003h
ljmp zd
rseg code_seg
jmp main
PORTA EQU 8FFFH ;8255A口地址
PORTB EQU 9FFFH ;8255B口地址
PORTC EQU 0AFFFH ;8255C口地址
CADDR EQU 0BFFFH ;8255控制字地址
main: MOV A,#88H ;方式0
MOV DPTR,#CADDR
MOVX @DPTR,A
CLR P1.2
mov r0,#50h ;初始密码首地址
mov r1,#08h
szmm: mov @r0,#00h ;设置密码
inc r0
djnz r1,szmm
mov r2,#03h ;设置输入密码的次数
K:mov ie,#81h ;中断方式设置
mov tcon,#01h
k1:mov a,p1
clr p1.2 ;判断开关位置
mov r1,a
anl a,#03h
jz dmm
dec a
jz xianshi
dec a
jz xianshi
dec a
jz dmm
dmm: mov r3,#08h ;读密码 八位
mov r6,#80h ;闪动位控制
mov r0,#60h ;读入值的首地址
ll:acall display
acall KSI
jz ll
ACALL DISPLAY
acall KEYI
mov @r0,30h
inc r0
mov a,r6
rr a
mov r6,a
djnz r3,ll
pdmm:mov r1,#50h ;判断密码
mov r0,#60h
mov r3,#08h
cxpd:mov a,@r0
mov r4,a
mov a,@r1
subb a,r4
jnz baojin
inc r0
inc r1
djnz r3,cxpd
mov r0,#0ffh
god: mov r1,#0fh ;密码正确显示good
good: acall display1
djnz r1,good
djnz r0,god
mov a,p1
clr p1.2 ;判断是否改密码
anl a,#03h
jz gmm
dec a
jz xianshi
dec a
jz xianshi
dec a
jz dmm
jmp k1
baojin: mov ie,#00h ;报警
djnz r2,k3
mov r7,#0ffh
acall sg
jmp k
k3:mov r7,#0fh
acall sg
mov r5,#03h
jmp k
xianshi:mov r0,#0fh ;待机显示
as: mov r6,#00h
acall display
djnz r0, as
jmp k1
gmm:mov r3,#08h ;改密码
mov r6,#80h
mov r0,#50h
lty: acall display
acall KSI
jz lty
acall KEYI
MOV @R0,30H
inc r0
mov a,r6
rr a
mov r6,a
djnz r3,lty
jmp k1
sg:nop ;bao警子程序
ls:mov r6,#0ffh
lm: mov r5,#0ffh
djnz r5,$
cpl p1.3
djnz r6,lm
djnz r7,ls
mov p1,#0ffh
ret
zd: mov 30h,a ;复位程序
mov a,r6
rl a
mov r6,a
mov a,30h
inc r3
acall d1ms
acall d1ms
acall d1ms
acall d1ms
acall d1ms
acall d1ms
mov tcon,#01h
reti
KEYI: MOV 30h,#00H
MOV R4,#00H
ACALL DISPLAY
ACALL KSI
JNZ LK2
AJMP KEYI
LK2: MOV R1,#04H
MOV R2,#0FEH
MOV R4,#00H
LK4:MOV DPTR,#PORTC
MOV A,R2
MOVX @DPTR,A
NOP
NOP
MOVX A,@DPTR
JB ACC.4,LONE
MOV A,#00H
AJMP LKP
LONE:JB ACC.5,LTWO
MOV A,#04H
AJMP LKP
LTWO:JB ACC.6,LTHR
MOV A,#08H
AJMP LKP
LTHR:JB ACC.7,NEXT
MOV A,#0CH
LKP:
ADD A,R4
PUSH ACC
LK3:ACALL DISPLAY
ACALL KSI
JNZ LK3
POP ACC
MOV 30H,A
ret
NEXT:INC R4
MOV A,R2
JNB ACC.3,KND
RL A
MOV R2,A
DJNZ R1,LK4
KND:ret
KSI:MOV DPTR,#PORTC
MOV A,#00H
MOVX @DPTR,A
NOP
NOP
MOVX A,@DPTR
CPL A
ANL A,#0F0H
RET
display:mov r5,#02h ;显示
lool:mov r4,#0FFh
dplop: mov a,#0ffh ;取个位数
MOV A,#7fh;查个位数的7段代
MOV DPTR,#PORTA
MOVX @DPTR,A ;送出个位的7段代码
MOV DPTR,#PORTB
MOV A,r6
MOVX @DPTR ,A;开个位显示
acall d1ms ;显示162微秒
djnz r4,dplop ;循环执行250次
djnz r5,lool
mov r5,#02h
poop:mov r4,#0FFh
ppdd: mov a,#07fh ;取个位数
;查个位数的7段代
MOV DPTR,#PORTA
MOVX @DPTR,A ;送出个位的7段代码
MOV DPTR,#PORTB
MOV A,#00h
MOVX @DPTR ,A;开个位显示
acall d1ms ;显示162微秒
MOV DPTR,#PORTB
MOV A,#0FFH
MOVX @DPTR ,A;关闭个位显示,防止鬼影
djnz r4,ppdd ;循环执行250次
djnz r5,poop
ret
display1: mov r5,#08h
mov r4,#7fh
ww:mov a,r5
dec a
mov dptr,#sttab
MOVC A,@A+DPTR ;查个位数的7段代
MOV DPTR,#PORTA
MOVX @DPTR,A ;取个位数
;查个位数的7段代
MOV DPTR,#PORTB
MOV A,r4
MOVX @DPTR ,A;开个位显示
acall d1ms ;显示162微秒
MOV DPTR,#PORTB
MOV A,#0ffH
MOVX @DPTR ,A;关闭个位显示,防止鬼影
mov a,r4
rr a
mov r4,a
djnz r5,ww
ret
;2+2X80=162微秒,延时按12MHZ计算
D1MS: MOV R7,#150
DJNZ R7,$
ret
sttab: db 3dh,5ch,5ch,3fh,40h,40h,40h,40h
end
2. 51单片机密码锁的原理是什么
简单密码锁,扫描按键,获得6位或8位数字,与事先设定好的密码比较,相同则开锁,不同则返回或报警。简单的程序密码可以直接写进程序中。
3. 51单片机能DIY哪些小东西
51单片机能DIY:
1.
多功能时钟,秒表,报警器,计数器,红外门禁检测,密码门;
2.
计算器,能想到的东西都可以啊,还有温湿度等付感器相关的;
3.
或者电压表,电流表,测电阻的,测电容电感的,无线通信类的东西,或者电源逆变之类的;
4.
还有机械控制电机之类的。
4. 51单片机独立按键控制门禁密码
#include "reg51.h"
#include "display_7seg_4.h"
sbit KEY1 = P1^0;
sbit KEY2 = P1^1;
sbit KEY3 = P1^2;
sbit KEY4 = P1^3;
sbit KEY5 = P3^0;
sbit KEY6 = P3^1;
sbit KEY7 = P3^2;
sbit KEY8 = P3^3;
sbit KEY9 = P3^4;
sbit KEY0 = P3^5;
sbit KEYE = P3^6;
sbit LED = P1^5;
unsigned int count=0;
void main(void)
{
unsigned char keyvalue;
unsigned char i=0;
unsigned char dis[4]={10,10,10,10};
unsigned int password;
LED = 0;
while(1)
{
keyvalue = 20;
if(KEY1 == 0)
{
while(!KEY1);
keyvalue = 1;
}
if(KEY2 == 0)
{
while(!KEY2);
keyvalue = 2;
}
if(KEY3 == 0)
{
while(!KEY3);
keyvalue = 3;
}
if(KEY4 == 0)
{
while(!KEY4);
keyvalue = 4;
}
if(KEY5 == 0)
{
while(!KEY5);
keyvalue = 5;
}
if(KEY6 == 0)
{
while(!KEY6);
keyvalue = 6;
}
if(KEY7 == 0)
{
while(!KEY7);
keyvalue = 7;
}
if(KEY8 == 0)
{
while(!KEY8);
keyvalue = 8;
}
if(KEY9 == 0)
{
while(!KEY9);
keyvalue = 9;
}
if(KEY0 == 0)
{
while(!KEY0);
keyvalue = 0;
}
if(KEYE == 0)
{
while(!KEYE);
keyvalue = 10;
}
if(keyvalue != 20)
{
if(keyvalue == 10)
{
i=0;
password = dis[0]*1000+dis[1]*100+dis[2]*10+dis[3];
if(password == 1234)
{
LED = 1;
}
else
{
LED = 0;
}
dis[0] = 10;
dis[1] = 10;
dis[2] = 10;
dis[3] = 10;
}
else
{
dis[i] = keyvalue;
i++;
}
}
display_seg(dis);
}
}