HT48R50A的 AT24C02 IIC 示例程序
扫描二维码
随时随地手机看文章
;*************************************************
;Function:基于HT48R50A的AT24C02IIC示例程序*
;MicroProcessor:HT48R50A-1/28SKDIP-A*
;Author:www.picavr.com*
;Crystal:4MHz*
;*************************************************
#INCLUDEHT48R50A-1.INC
OKEQU0CCH
ERROREQU0DDH
;--------------------------------------------------------------------
PUBLICHT_DEVICE_ADD
PUBLICHT_DATA
PUBLICHT_DATA_ADD
;--------------------------------------------------------------------
EXTERNLCD_RESET:NEAR
EXTERNLCD_CURSOR:NEAR
EXTERNLCD_PUT_A_CHAR:NEAR
EXTERNDELAY_LONG:NEAR
EXTERNKEY_GET:NEAR
EXTERNKEY_IN_ADDRESS:NEAR
EXTERNKEY_IN_DATA:NEAR
EXTERNBYTE_WRITE:NEAR
EXTERNPAGE_WRITE:NEAR
EXTERNCURRENT_READ:NEAR
EXTERNRANDOM_READ:NEAR
EXTERNSEQUENTIAL_READ:NEAR
EXTERNMESSAGE_01:NEAR
EXTERNMESSAGE_02:NEAR
EXTERNMESSAGE_03:NEAR
EXTERNMESSAGE_04:NEAR
EXTERNMESSAGE_05:NEAR
EXTERNMESSAGE_06:NEAR
EXTERNMESSAGE_07:NEAR
EXTERNMESSAGE_08:NEAR
EXTERNMESSAGE_09:NEAR
EXTERNMESSAGE_10:NEAR
EXTERNMESSAGE_11:NEAR
EXTERNMESSAGE_12:NEAR
EXTERNMESSAGE_13:NEAR
EXTERNMESSAGE_14:NEAR
EXTERNMESSAGE_15:NEAR
EXTERNMESSAGE_16:NEAR
EXTERNMESSAGE_17:NEAR
EXTERNBIN_TO_HEX_TABLE:NEAR
EXTERNDEC_TO_HEX_TABLE:NEAR
EXTERNHEX_TO_TEXT_TABLE:NEAR
;--------------------------------------------------------------------
EXTERNKEY_DATA:BYTE
EXTERNKEY_IN_ADD_BUFFER:BYTE
EXTERNKEY_IN_DATA_BUFFER:BYTE
EXTERNSEQUENTIAL_READ_BUFFER:BYTE
;--------------------------------------------------------------------
DATA_9724.SECTIONAT60H’DATA’
HT_DEVICE_ADDDB?
HT_DATADB?
HT_DATA_ADDDB?
COUNTERDB?
DATA_REGISTERDB?
ADDRESS_REGISTERDB?
SEQ_COUNTERDB?
;--------------------------------------------------------------------
CODE.SECTIONAT00H’CODE’
ORG00H
JMPSTART
START:
SETPBC
SETPB
CALLLCD_RESET
CALLMESSAGE_01
CALLKEY_GET
;--------------------------------------------------------------------
SELECT_12:
CALLMESSAGE_02
MOV A,4FH
CALLLCD_CURSOR
AGAIN_12:
CALLKEY_GET
MOV A,KEY_DATA
SUBA,0DH
SZACC
JMPCOMPARE_12_1
JMPSELECT_34
COMPARE_12_1:
MOV A,KEY_DATA
SUBA,01H
SZACC
JMPCOMPARE_12_2
JMPFUNCTION_1
COMPARE_12_2:
MOV A,KEY_DATA
SUBA,02H
SZACC
JMPAGAIN_12
JMPFUNCTION_2
RET
;--------------------------------------------------------------------
SELECT_34:
CALLMESSAGE_03
MOV A,4FH
CALLLCD_CURSOR
AGAIN_34:
CALLKEY_GET
MOV A,KEY_DATA
SUBA,0CH
SZACC
JMPCOMPARE_34_D
JMPSELECT_12
COMPARE_34_D:
MOV A,KEY_DATA
SUBA,0DH
SZACC
JMPCOMPARE_34_3
JMPSELECT_56
COMPARE_34_3:
MOV A,KEY_DATA
SUBA,03H
SZACC
JMPCOMPARE_34_4
JMPFUNCTION_3
COMPARE_34_4:
MOV A,KEY_DATA
SUBA,04H
SZACC
JMPAGAIN_34
JMPFUNCTION_4
RET
;--------------------------------------------------------------------
SELECT_56:
CALLMESSAGE_04
MOV A,4FH
CALLLCD_CURSOR
AGAIN_56:
CALLKEY_GET
MOV A,KEY_DATA
SUBA,0CH
SZACC
JMPCOMPARE_56_D
JMPSELECT_34
COMPARE_56_D:
MOV A,KEY_DATA
SUBA,0DH
SZACC
JMPCOMPARE_56_5
JMPSELECT_7
COMPARE_56_5:
MOV A,KEY_DATA
SUBA,05H
SZACC
JMPCOMPARE_56_6
JMPFUNCTION_5
COMPARE_56_6:
MOV A,KEY_DATA
SUBA,06H
SZACC
JMPAGAIN_56
JMPFUNCTION_6
RET
;--------------------------------------------------------------------
SELECT_7:
CALLMESSAGE_05
MOV A,4FH
CALLLCD_CURSOR
AGAIN_7:
CALLKEY_GET
MOV A,KEY_DATA
SUBA,0CH
SZACC
JMPCOMPARE_7_7
JMPSELECT_56
COMPARE_7_7:
MOV A,KEY_DATA
SUBA,07H
SZACC
JMPAGAIN_7
JMPFUNCTION_7
RET
;--------------------------------------------------------------------
FUNCTION_1:
CALLMESSAGE_08
MOV A,4FH
CALLLCD_CURSOR
F_1_AGAIN:
CALLKEY_GET
MOV A,KEY_DATA
SUBA,01H
SZACC
JMPF_1_COMPARE_2
CALLMESSAGE_09
SETPC.4;WRITEPROTECT
CALLKEY_GET;ENABLE
JMPF_1_END
F_1_COMPARE_2:
MOV A,KEY_DATA
SUBA,02H
SZACC
JMPF_1_AGAIN
CALLMESSAGE_10
CLRPC.4;WRITEPROTECT
CALLKEY_GET;DISABLE
F_1_END:
JMPSELECT_12
RET
;--------------------------------------------------------------------
FUNCTION_2:
CALLMESSAGE_06
MOV A,41H
CALLLCD_CURSOR
CALLKEY_IN_ADDRESS
CALLBIN_TO_HEX
SUBA,OK
SZACC
JMPF_2_ERROR
CALLMESSAGE_07
CALLKEY_GET
JMPF_2_END
F_2_ERROR:
CALLMESSAGE_15
CALLKEY_GET
F_2_END:
JMPSELECT_12
RET
;--------------------------------------------------------------------
FUNCTION_3:
CALLMESSAGE_11
MOV A,41H
CALLLCD_CURSOR
CALLKEY_IN_ADDRESS
CALLDEC_TO_HEX
SUBA,OK
SZACC
JMPF_3_ERROR
CALLMESSAGE_12
MOV A,42H
CALLLCD_CURSOR
CALLKEY_IN_DATA
CALLHEX_TO_HEX
CALLBYTE_WRITE
CALLMESSAGE_16
CALLKEY_GET
JMPF_3_END
F_3_ERROR:
CALLMESSAGE_15
CALLKEY_GET
F_3_END:
JMPSELECT_34
RET
;--------------------------------------------------------------------
FUNCTION_4:
CALLMESSAGE_11
MOV A,41H
CALLLCD_CURSOR
CALLKEY_IN_ADDRESS
CALLDEC_TO_HEX
SUBA,OK
SZACC
JMPF_4_ERROR
CALLMESSAGE_12
MOV A,42H
CALLLCD_CURSOR
CALLKEY_IN_DATA
CALLHEX_TO_HEX
CALLPAGE_WRITE
CALLMESSAGE_17
CALLKEY_GET
JMPF_4_END
F_4_ERROR:
CALLMESSAGE_15
CALLKEY_GET
F_4_END:
JMPSELECT_34
RET
;--------------------------------------------------------------------
FUNCTION_5:
CALLCURRENT_READ
CALLMESSAGE_13
CALLADDRESS_DATA_DISPLAY
CALLKEY_GET
JMPSELECT_56
RET
;--------------------------------------------------------------------
FUNCTION_6:
CALLMESSAGE_11
MOV A,41H
CALLLCD_CURSOR
CALLKEY_IN_ADDRESS
CALLDEC_TO_HEX
SUBA,OK
SZACC
JMPF_6_ERROR
CALLRANDOM_READ
CALLMESSAGE_13
CALLADDRESS_DATA_DISPLAY
CALLKEY_GET
JMPF_6_END
F_6_ERROR:
CALLMESSAGE_15
CALLKEY_GET
F_6_END:
JMPSELECT_56
RET
;--------------------------------------------------------------------
FUNCTION_7:
CALLMESSAGE_11
MOV A,41H
CALLLCD_CURSOR
CALLKEY_IN_ADDRESS
CALLDEC_TO_HEX
SUBA,OK
SZACC
JMPF_7_ERROR
CALLSEQUENTIAL_READ
CALLMESSAGE_13
CALLSEQ_READ_BUFFER_DISPLAY
JMPF_7_END
F_7_ERROR:
CALLMESSAGE_15
CALLKEY_GET
F_7_END:
JMPSELECT_7
RET
;--------------------------------------------------------------------
BIN_TO_HEXPROC
CLRHT_DEVICE_ADD
MOV A,OFFSETBIN_TO_HEX_TABLE+2
MOV TBLP,A
MOV A,OFFSETKEY_IN_ADD_BUFFER+2
MOV MP0,A
MOV A,03H
MOV COUNTER,A
BIN_LOOP:
MOV A,R0
SUBA,01
SZACC
JMPBIN_BIT_X_0
TABRDLACC
ADDMA,HT_DEVICE_ADD
JMPBIN_NEXT
BIN_BIT_X_0:
MOV A,R0
SZACC
JMPBIN_ERROR
BIN_NEXT:
DECTBLP
DECMP0
SDZCOUNTER
JMPBIN_LOOP
MOV A,OK
JMPBIN_END
BIN_ERROR:
MOV A,ERROR
BIN_END:
RET
BIN_TO_HEXENDP
;--------------------------------------------------------------------
DEC_TO_HEXPROC
MOV A,HT_DATA_ADD
MOV ADDRESS_REGISTER,A
CLRHT_DATA_ADD
MOV A,OFFSETDEC_TO_HEX_TABLE
MOV TBLP,A
MOV A,OFFSETKEY_IN_ADD_BUFFER+2
MOV MP0,A
MOV A,R0
ADDMA,HT_DATA_ADD
DECMP0
MOV A,R0
ADDMA,TBLP
TABRDLACC
ADDMA,HT_DATA_ADD
DECMP0
MOV A,R0
SNZACC.0
JMPCHECK_ZERO
MOV A,64H
ADDMA,HT_DATA_ADD
JMPCHECK_ERROR
CHECK_ZERO:
MOV A,R0
SZACC
JMPDEC_TO_HEX_ERROR
JMPDEC_TO_HEX_OK
CHECK_ERROR:
MOV A,7FH
SUBA,HT_DATA_ADD
SNZACC.7
JMPDEC_TO_HEX_OK
DEC_TO_HEX_ERROR:
MOV A,ADDRESS_REGISTER
MOV HT_DATA_ADD,A
MOV A,ERROR
JMPDEC_TO_HEX_END
DEC_TO_HEX_OK:
MOV A,OK
DEC_TO_HEX_END:
RET
DEC_TO_HEXENDP
;--------------------------------------------------------------------
HEX_TO_HEXPROC
CLRHT_DATA
MOV A,OFFSETKEY_IN_DATA_BUFFER+1
MOV MP0,A
MOV A,R0
ADDMA,HT_DATA
DECMP0
MOV A,R0
SWAPACC
ADDMA,HT_DATA
RET
HEX_TO_HEXENDP
;--------------------------------------------------------------------
ADDRESS_DATA_DISPLAYPROC
MOV A,OFFSETKEY_IN_ADD_BUFFER+2
MOV MP0,A
CLRR0
DECMP0
CLRR0
DECMP0
CLRR0
MOV A,HT_DATA_ADD
SZACC
JMPTRANSFER_BEGIN
JMPADDRESS_DISPLAY_BEGIN
TRANSFER_BEGIN:
MOV A,HT_DATA_ADD
MOV COUNTER,A
TRANSFER:
MOV A,OFFSETKEY_IN_ADD_BUFFER+2
MOV MP0,A
MOV A,R0
SUBA,09H
SNZACC.7
JMPBYTE_1
INCR0
JMPTRANSFER_END
BYTE_1:
CLRR0
DECMP0
MOV A,R0
SUBA,09H
SNZACC.7
JMPBYTE_2
INCR0
JMPTRANSFER_END
BYTE_2:
CLRR0
DECMP0
INCR0
TRANSFER_END:
SDZCOUNTER
JMPTRANSFER
ADDRESS_DISPLAY_BEGIN:
MOV A,OFFSETKEY_IN_ADD_BUFFER
MOV MP0,A
MOV A,08H
CALLLCD_CURSOR
MOV A,7FH
DAAACC
MOV A,03H
MOV COUNTER,A
ADDRESS_DISPLAY:
MOV A,OFFSETHEX_TO_TEXT_TABLE
MOV TBLP,A
MOV A,R0
ADDMA,TBLP
TABRDLACC
CALLLCD_PUT_A_CHAR
INCMP0
SDZCOUNTER
JMPADDRESS_DISPLAY
MOV A,OFFSETKEY_IN_DATA_BUFFER+1
MOV MP0,A
MOV A,HT_DATA
ANDA,0FH
MOV R0,A
DECMP0
MOV A,HT_DATA
SWAPACC
ANDA,0FH
MOV R0,A
MOV A,48H
CALLLCD_CURSOR
MOV A,02H
MOV COUNTER,A
DATA_DISPLAY:
MOV A,OFFSETHEX_TO_TEXT_TABLE
MOV TBLP,A
MOV A,R0
ADDMA,TBLP
TABRDLACC
CALLLCD_PUT_A_CHAR
INCMP0
SDZCOUNTER
JMPDATA_DISPLAY
MOV A,50H
CALLLCD_CURSOR
RET
ADDRESS_DATA_DISPLAYENDP
;--------------------------------------------------------------------
SEQ_READ_BUFFER_DISPLAYPROC
MOV A,HT_DATA
MOV DATA_REGISTER,A
MOV A,HT_DATA_ADD
MOV ADDRESS_REGISTER,A
MOV A,HT_DATA_ADD
SUBA,07H
SNZACC.7
JMPSEQ_DATA_ADD_CHANGE
MOV A,HT_DATA_ADD
ADDA,80H
SUBA,07H
MOV HT_DATA_ADD,A
JMPSEQ_DISPLAY_BEGIN
SEQ_DATA_ADD_CHANGE:
MOV A,HT_DATA_ADD
SUBA,07H
MOV HT_DATA_ADD,A
SEQ_DISPLAY_BEGIN:
MOV A,OFFSETSEQUENTIAL_READ_BUFFER
MOV MP1,A
MOV A,08H
MOV SEQ_COUNTER,A
SEQ_LOOP:
MOV A,40H
CALLLCD_CURSOR
MOV A,SEQ_COUNTER
ADDA,30H
CALLLCD_PUT_A_CHAR
MOV A,R1
MOV HT_DATA,A
CALLADDRESS_DATA_DISPLAY
INCMP1
MOV A,HT_DATA_ADD
SUBA,7FH
SZACC
JMPSEQ_NOT_ZERO
CLRHT_DATA_ADD
JMPSEQ_END
SEQ_NOT_ZERO:
INCHT_DATA_ADD
SEQ_END:
MOV A,40H
CALLLCD_CURSOR
CALLKEY_GET
CALLDELAY_LONG
SDZSEQ_COUNTER
JMPSEQ_LOOP
MOV A,DATA_REGISTER
MOV HT_DATA,A
MOV A,ADDRESS_REGISTER
MOV HT_DATA_ADD,A
RET
SEQ_READ_BUFFER_DISPLAYENDP
;--------------------------------------------------------------------
END