//CS,SK,DI,DO,ROW,COL,D_R,R_W
ROW EQU P0
COL EQU P3
ORG 0000H
AJMP MAIN
//键盘处理总函数
MAIN:
zongjianpanchuli:
MOV R6,#04H
KEY:
MOV P1,#0F0H
T2:
MOV A,P1
CJNE A,#0F0H,XU9
AJMP T2
XU9:
LCALL DELAY
MOV R0,#04H
MOV A,#0FEH
MOV R1,A
XIAO1:
MOV P1,R1
MOV A,P1
ANL A,#0F0H
CJNE A,#0F0H,tt5
MOV A,R1
RL A
DJNZ R0,XIAO1
AJMP zongjianpanchuli
tt5:
LCALL DELAY
MOV A,P1
CJNE A,#0EEH,ER2 ; 1
MOV R7, #TAB1
LCALL DIANZHEN
MOV R3,#0EEH
LCALL WEISHU
LCALL SHUXIAN
LCALL CUNCHU
ER2:
MOV A,P1
CJNE A,#0DEH,SAN2 ; 2
MOV R7,#TAB2
LCALL DIANZHEN
MOV R3,#0DEH
LCALL WEISHU
LCALL SHUXIAN
LCALL CUNCHU
SAN2:
MOV A,P1
CJNE A,#0BEH,SI2 ; 3
MOV R7,#TAB3
LCALL DIANZHEN
MOV R3,#0BEH
LCALL WEISHU
LCALL SHUXIAN
LCALL CUNCHU
SI2:
MOV A,P1
CJNE A,#07EH,WU2 ; 4
MOV R7,#TAB4
LCALL DIANZHEN
MOV R3,#07EH
LCALL WEISHU
LCALL SHUXIAN
LCALL CUNCHU
WU2:
MOV A,P1
CJNE A,#0EDH,LIU2 ; 5
MOV R7,#TAB5
LCALL DIANZHEN
MOV R3,#0EDH
LCALL WEISHU
LCALL SHUXIAN
LCALL CUNCHU
LIU2:
MOV A,P1
CJNE A,#0DDH,QI2 ; 6
MOV R7,#TAB6
LCALL DIANZHEN
MOV R3,#0DDH
LCALL WEISHU
LCALL SHUXIAN
LCALL CUNCHU
QI2:
MOV A,P1
CJNE A,#0BDH,BA2 ; 7
MOV R7,#TAB7
LCALL DIANZHEN
MOV R3,#0BDH
LCALL WEISHU
LCALL SHUXIAN
LCALL CUNCHU
BA2:
MOV A,P1
CJNE A,#7DH,JIU2 ; 8
MOV R7,#TAB8
LCALL DIANZHEN
MOV R3,#7DH
LCALL WEISHU
LCALL SHUXIAN
LCALL CUNCHU
JIU2:
MOV A,P1
CJNE A,#0EBH,SHI2 ; 9
MOV R7,#TAB9
LCALL DIANZHEN
MOV R3,#0EBH
LCALL WEISHU
LCALL SHUXIAN
LCALL CUNCHU
SHI2:
MOV A,P1
CJNE A,#0DBH,SHIYI2 ; 0
MOV R7,#TAB0
LCALL DIANZHEN
MOV R3,#0DBH
LCALL WEISHU
LCALL SHUXIAN
LCALL CUNCHU
SHIYI2:
MOV A,P1
CJNE A,#0BBH,SHIER2 ; A10
MOV R7,#TAB10
LCALL DIANZHEN
SHIER2:
MOV A,P1
CJNE A,#7BH,SHISAN2 ; B11
MOV R7,#TAB11
LCALL DIANZHEN
SHISAN2:
MOV A,P1
CJNE A,#0E7H,SHISI2 ; C12
MOV R7,#TAB12
LCALL DIANZHEN
LCALL CUNCHU
MOV R3,60H
MOV R4,80H
LCALL READDATE
MOV 80H,R4
CJNE R3,80H,YEJINGERROR
LCALL CUNCHU
MOV R3,61H
MOV R4,81H
LCALL READDATE
MOV 81H,R4
CJNE R3,81H,YEJINGERROR
LCALL CUNCHU
MOV R3,62H
MOV R4,82H
LCALL READDATE
MOV 82H,R4
CJNE R3,82H,YEJINGERROR
LCALL CUNCHU
MOV R3,63H
MOV R4,83H
LCALL READDATE
MOV 83H,R4
CJNE R3,83H,YEJINGERROR
LCALL CHUSHIHUA
LCALL CLEAR
LCALL WRITEHANZI2
MOV R7,#TAB16
LCALL DIANZHEN;显示笑脸
SHISI2:
MOV R1,P1
CJNE R1,#0D7H,SHIWU2 ; D13
MOV R7,#TAB13
LCALL DIANZHEN
SHIWU2:
MOV R1,P1
CJNE R1,#0B7H,SHILIU2 ; E14
MOV R7,#TAB14
LCALL DIANZHEN
SHILIU2:
MOV R1,P1
CJNE R1,#77H,SHIQI2 ; F15
MOV R7,#TAB15
LCALL DIANZHEN
SHIQI2:
MOV R1,P1
CJNE R1,#03BH,SHIBA2 ; A+B
MOV R7,#TAB17
LCALL DIANZHEN
LCALL CUNCHU
MOV R5,#80H
LCALL READDATE
MOV R1,60H
CJNE R1,A,YEJINGERROR
MOV R5,#81H
CJNE 61H,A,YEJINGERROR
MOV R5,#82H
CJNE 62H,A,YEJINGERROR
MOV R5,#83H
CJNE 63H,A,YEJINGERROR
LCALL WRITEHANZI2
MOV R7,#TAB16
LCALL DIANZHEN;显示笑脸
LCALL SHUMAGUANCLEAR
MOV R4,#80H
LCALL CACHU
MOV R4,#81H
LCALL CACHU
MOV R4,#82H
LCALL CACHU
MOV R4,#83H
LCALL CACHU
LCALL XIECHULI
CJNE P1,#0E7H,TTTT
LCALL WRITEHANZI3
MOV R7,#TAB16
LCALL DIANZHEN;修改成功
TTTT:
AJMP $
SHIBA2:
MOV R1,P1
CJNE R1,#033H,SHIJIU2 ; A+F
MOV R7,#TAB17
LCALL DIANZHEN
SHIJIU2:
AJMP KEY
YEJINGERROR:
LCALL CHUSHIHUA
LCALL CLEAR
LCALL WERITEHANZI1
MOV R7,#TAB17
LCALL DIANZHEN;闪亮的,警告
NOP
NOP
MOV R7,#TAB18
LCALL DIANZHEN
NOP
NOP
MOV R7,#TAB17
LCALL DIANZHEN
NOP
NOP
MOV R7,#TAB18
LCALL DIANZHEN
NOP
NOP
MOV R7,#TAB17
LCALL DIANZHEN
//IIC--EEPROM字节接收函数
REVEICEBYTE:
MOV R0,#08H
RLP:
SETB P2.1
SETB P2.0
MOV A,P2
JNB ACC.1,D0
AJMP D1
RLP1:
DJNZ R0,RLP
RET
D0:
CLR C
MOV A,R2
RLC A
MOV R2,A
CLR P2.1
AJMP RLP1
D1:
SETB C
MOV A,R2
RLC A
MOV R2,A
CLR P2.0
AJMP RLP1
//IIC--EEPROM字节输出函数
INPUTBYTE:
MOV R0,#08H
ZZL:
RLC A
JC W1
AJMP W0
ZZL1:
DJNZ R0,ZLL
NOP
RET
W1:
SETB P2.1
SETB P2.0
NOP
NOP
CLR P2.0
CLR P2.1
AJMP ZLL1
W0:
CLR P2.1
SETB P2.0
NOP
NOP
CLR P2.0
AJMP ZLL1
//IIC--EEPROM读数据函数
READDATE:
PUSH PSW
MOV PSW,#18H
LCALL START
MOV A,R4;指令功能
LCALL INPUTBYTE
LCALL CACK
JB F0,READDATE
MOV A,R4;期间内资地址
LCALL INPUTBYTE
LCALL CACK
JB F0,READDATE
LCALL START
MOV A,#A0H
LCALL INPUTBYTE
LCALL CACK
JB F0,READDATE
MOV R1,R4;接收缓冲区首地址
READ1:
LCALL REVEICEBYTE
MOV R1,A
DJNZ #04H,MORE;四个字节是否读完
LCALL NACK
LCALL STOP
POP PSW
RET
MORE:
LCALL ACK
INC R1
SJMP READ1
//IIC--EEPROM终止信号
STOP:
CLR P2.1
SETB P2.0
NOP
NOP
SETB P2.1
NOP
NOP
CLR P2.0
RET
//IIC--EEPROM 起始信号
START:
SETB P2.1 ;SDA
SETB P2.0 ;SCL
NOP
NOP
CLR P2.1
NOP
NOP
CLR P2.0
RET
//IIC--EEPROM写数据函数
WRITEDATE:
PUSH PSW
RLP:
MOV PSW,#18H
LCALL START
MOV A,R4 ;寻址地址
LCALL INPUTBYTE
LCALL CACK
JB F0,WRITEDATE
MOV R1,R3 ;数据地址
WR:
MOV A,@R1
LCALL INPUTBYTE
LCALL CACK
JB F0,WRITEDATE
INC R1
DJNZ #04H,WR ;#04H发送数据个数
LCALL STOP
POP PSW
RET
//iic--EEPROM应答信号
ACK:
CLR P2.1
SETB P2.0
NOP
NOP
CLR P2.0
NOP
NOP
SETB P2.1
RET
//IIC--EEPROM非应答信号
NACK:
SETB P2.1
SETB P2.0
NOP
NOP
CLR P2.0
NOP
NOP
CLR P2.1
RET
//IIC--EEPROM应答检测
CACK:
SETB P2.1
NOP
SETB P2.0
NOP
CLR F0;表示正常应答位F0=0
MOV A,P2
JNB ACC.1,CND
SETB F0
CND:
CLR P2.0
NOP
RET
//EEPROM保存数据到EEPROM确保数据只保存四位
BAOCUN:
CJNE R6,#03H,YI
MOV R4,#80H
LCALL WRITEDATE
YI:
CJNE R6,#02H,ER
MOV R4,#81H
LCALL WRITEDATE
ER:
CJNE R6,#01H,SAN
MOV R4,#82H
LCALL WRITEDATE
SAN:
CJNE R6,#00H,SI
MOV R4,#83H
LCALL WRITEDATE
SI:
RET
//键盘处理EEPROM写处理函数
XIECHULI:
MOV R6,#04H
MOV P1,#0F0H
T1:
CJNE P1,#0F0H,XU8
AJMP T1
XU8:
LCALL DELAY
MOV R0,#04H
MOV A,#0FEH
XIAO:
MOV P1,A
MOV R1,P1
ANL R1,#0F0H
CJNE R1,#0F0H,tt4
RL A
DJNZ R0,XIAO
RET
tt4:
LCALL DELAY
CJNE P1,#0EEH,ER1
MOV R7,#TAB1
LCALL DIANZEHN
MOV R3,#0EEH
LCALL WEISHU
LCALL SHUXIAN
LCALL BAOCUN
ER1:
CJNE P1,#0DEH,SAN1
MOV R7,#TAB2
LCALL DIANZHEN
MOV R3,#0DEH
LCALL WEISHU
LCALL SHUXIAN
LCALL BAOCUN
SAN1:
CJNE P1,#0BEH,SI1
MOV R7,#TAB3
LCALL DIANZHEN
MOV R3,#0BEH
LCALL WEISHU
LCALL SHUXIAN
LCALL BAOCUN
SI1:
CJNE P1,#7E,WU1
MOV R7,#TAB4
LCALL DIANZHEN
MOV R3,#7EH
LCALL WEISHU
LCALL SHUXIAN
LCALL BAOCUN
WU1:
CJNE P1,#0EDH,LIU1
MOV R7,#TAB5
LCALL DIANZEHN
MOV R3,#0EDH
LCALL WEISHU
LCALL SHUXIAN
LCALL BAOCUN
LIU1:
CJNE P1,#0DDH,QI1
MOV R7,#TAB6
LCALL DIANZHEN
MOV R3,#0DDH
LCALL WEISHU
LCALL SHUXIAN
LCALL BAOCUN
QI1:
CJNE P1,#0BDH,BA1
MOV R7,#TAB7
LCALL DIANZHEN
MOV R3,#0BDH
LCALL WEISHU
LCALL SHUXIAN
LCALL BAOCUN
BA1:
CJNE P1,#7D,JIU1
MOV R7,#TAB8
LCALL DIANZHEN
MOV R3,#7DH
LCALL WEISHU
LCALL SHUXIAN
LCALL BAOCUN
JIU1:
CJNE P1,#0EBH,SHI1
MOV R7,#TAB9
LCALL DIANZEHN
MOV R3,#0EBH
LCALL WEISHU
LCALL SHUXIAN
LCALL BAOCUN
SHI1:
CJNE P1,#0DBH,SHIYI1
MOV R7,#TAB0
LCALL DIANZHEN
MOV R3,#0DBH
LCALL WEISHU
LCALL SHUXIAN
LCALL BAOCUN
SHIYI:
//四位数据存储和EEPROM中的数据比较
CUNCHU:
CJNE R6,#03H,THREE1
MOV 60H,R3
RET
THREE1:
CJNE R6,#02H,TWO1
MOV 61H,R3
RET
TWO1:
CJNE R6,#01H,ONE1
MOV 62H,R3
RET
ONE1:
CJNE R6,#00H,ZERO
MOV 63H,R3
RET
ZERO: RET
// 数码管清零函数
SHUMAGUANCLEAR:
CLR P1.0
CLR P1.1
CLR P1.2
CLR P1.3
NOP
NOP
NOP
SETB P1.0
SETB P1.1
SETB P1.2
SETB P1.3
RET
//数码管显示位置函数
WEISHU:
CJNE R6,#04H,THREE
B bit P1.0
DEC R6
THREE:
CJNE R6,#03H,TWO
B bit P1.1
DEC R6
TWO:
CJNE R6,#02H,ONE
B bit P1.2
DEC R6
ONE:
CJNE R6,#01H,ZERO
B bit P1.3
DEC R6
ZERO:
//数码管显示字符函数
SHUXIAN:
MOV SCON,#00H;采用38译码器了,故需和外部通信
CLR ES
MOV A,R3;R3输入键值
MOV SBUF,A
JNB TI,$
SETB B;B为P1端口某位,一是能数码管
CLR TI
CLR B
RET
// 液晶程序清平函数
CLEAR:
CLR D_I
CLR R_W
MOV P1,#01H;清屏幕指令地址
MOV R0,#01H
LCALL WRITECODE
RET
//液晶程序写汉字函数 1
WRITEHANZI1:
MOV R0,#08H
MOV A,#00H
MOV DPTR,#TAB01
XU1:
MOVC A,@A+DPTR
MOV R1,A
LCALL WEITRDATEYE
MOV A,R1
INC A
DJNZ R0,XU1
RET
// 液晶程序写汉字函数2
WRITEHANZI2:
MOV R0,#08H
MOV A,#00H
MOV DPTR,#TAB02
XU2:
MOVC A,@A+DPTR
MOV R1,A
LCALL WEITRDATEYE
MOV A,R1
INC A
DJNZ R0,XU2
RET
//液晶程序写汉字函数3
WRITEHANZI3:
MOV R0,#08H
MOV A,#00H
MOV DPTR,#TAB03
XU3:
MOVC A,@A+DPTR
MOV R1,A
LCALL WEITRDATEYE
MOV A,R1
INC A
DJNZ R0,XU3
RET
//液晶程序写数据子函数
WRITEDATEYE:
SETB R_W
CLR D_I
LOOP:
MOV P1,#0FFH;令屏幕是忙的状态
SETB E
MOV A,P1
ANL A,#80H
JB ACC.7,LOOP
SETB D_I
CLR R_W
MOV P1,R1;据地址
SETB E
NOP
NOP
CLR E
// 液晶程序写指令子函数
WRITECODE:
setb R_W ;读
sEtb D_I ;0为读或写状态,1为操作数据状态
LOOP:
mov P1,#0ffh
setb E ;e为使能位
mov A,P1
CLR E
ANL A,#80H;判断屏幕是否忙,最高位AF决定
JB ACC.7,LOOP
SETB R_W
CLR D_I;对数据进行操作
MOV P1,R0;d为写入指令的地址
SETB E
NOP
NOP
CLR E
RET
//液晶显示初始化子程序
CHUSHIHUA:
CLR E
MOV R0,#38H
LCALL WRITECODE;地址设定然后调用写指令子函数
LCALL DELAY
MOV R0,#08H;关屏幕指令地址
LCALL WRITECODE
MOV R0,#06H
LCALL WRITECODE
LCALL DELAY
LCALL CLEAR;清屏幕
MOV R0,#0CH;开屏幕指令地址
LCALL WRITECODE
LCALL DELAY
RET
// 点阵显示函数
DIANZHEN:
MOV R0,#08H
MOV A,#00H
MOV ROW,#0FFH
MOV DPTR,R7;0~F以及笑脸的显示
XU:
MOV A,@A+DPTR
MOV COL,A
INC A
DJNZ R0,XU4
RET
//液晶程序显示字符集
ORG 90H
TAB01:
DB C3, DC;密
C2 ,EB;码
B4, ED;错
CE ,F3;误
ORG 100H
TAB02:
DB C3 ,DC;密
C2 ,EB;码
D5 ,FD;正
C8 ,B7;确
ORG 110H
TAB03:
DB D0 ,DE;修
B8 ,C3;改
B3 ,C9;成
B9 ,A6;功
// 点阵字符集
ORG 120H
TAB0:
DB 00H,00H,3EH,41H,41H,41H,3EH,00H//0
ORG 130H
TAB1:
DB 00H,00H,00H,00H,21H,7FH,01H,00H//1
ORG 140H
TAB2:
DB 00H,00H,27H,45H,45H,45H,39H,00H//2
ORG 150H
TAB3:
DB 00H,00H,22H,49H,49H,49H,36H,00H//3
ORG 160H
TAB4:
DB 00H,00H,0CH,14H,24H,7FH,04H,00H//4
ORG 170H
TAB5:
DB 00H,00H,72H,51H,51H,51H,4EH,00H//5
ORG 180H
TAB6:
DB 00H,00H,3EH,49H,49H,49H,26H,00H//6
ORG 190H
TAB7:
DB 00H,00H,40H,40H,40H,4FH,70H,00H//7
ORG 200H
TAB8:
DB 00H,00H,36H,49H,49H,49H,36H,00H//8
ORG 210H
TAB9:
DB 00H,00H,32H,49H,49H,49H,3EH,00H //9
ORG 220H
TAB10:
DB 00H,00H,7EH,90H,90H,7EH,00H,00H //A
ORG 230H
TAB11:
DB 00H,00H,0FEH,92H,92H,7EH,00H,00H //B
ORG 240H
TAB12:
DB 00H,00H,7CH,82H,82H,82H,00H,00H //C
ORG 250H
TAB13:
DB 00H,00H,0FCH,84H,84H,78H,00H,00H//D
ORG 260H
TAB14:
DB 00H,00H,7FH,49H,49H,49H,00H,00H //E
ORG 270H
TAB15:
DB 00H,00H,0FFH,90H,90H,90H,00H,00H//F
ORG 280H
TAB16:
DB 20H,40h,24H,02H,02H,24H,40H,20H//Ц
ORG 290H
TAB17:
DB 0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH
ORG 300H
TAB18:
DB 00H,00H,00H,00H,00H,00H,00H,00H
ORG 310H
DELAY:
MOV R7,#10H
DS1:
MOV R6,#0FFH
DS2:
DJNZ R6,DS2
DJNZ R7,DS1
RET
[/code]