这个程序是51单片机与pt2258的5。1音响遥控解码程序, 搞定这个程序, 51单片机就算毕业了:
COUNTER EQU 35H;显示计数
REMVOL EQU 36H;音量连续控制
DISPBUFF1 EQU 37H;
DISPBUFF2 EQU 38H;
DISPBUFF3 EQU 39H;
DISPBUFF EQU 3AH;
SDA BIT P3.4
SCL BIT P3.2
MTD EQU 30H;PT2258数据首址
NUMBYT EQU 3BH;PT2258数据位数
CS_X1 EQU 3CH;遥控
CS0_X1 EQU 3DH
U0_X1 EQU 3EH;遥控数据暂存区
NO_M EQU 40H;数据码
FRONT EQU 41H
REAR EQU 42H
CEN EQU 43H
S_UB EQU 44H
RVER EQU 45H
CVER EQU 46H
SVER EQU 47H
FVER EQU 48H
PHONE EQU 49H
NO_N EQU 51H
;-----------------------
ORG 0000H
AJMP START
ORG 000BH
AJMP ITT0
ORG 0013H
AJMP INO1
ORG 001BH
AJMP DISP
;------------------------
START:
MOV SP,#60H
MOV PSW,#00H
MOV IE,#00H
MOV IP,#00H
CLR P3.1;刚开机时待机
CLR EA
CLR P3.5;LED显示
SETB P3.7;数码管不显示
MOV P1,#7FH;电源灯亮
SETB P3.2;
SETB P3.4;让SDA,SLK保持高电平
CLR P3.0;AC-3状态
SETB P3.3
MOV TMOD,#00010001B
MOV TH1,#0f0H
MOV TL1,#60H
MOV TH0,#00H
MOV TL0,#00H
SETB TR0
SETB ET0;开定时器1中断
SETB EA
SETB EX1
SETB IT1
CLR EX0
clr tr1
CLR (29H).0;遥控识别位
mov remvol,#02h
MOV COUNTER,#0H
MOV FRONT,#34H
MOV REAR,#34H
MOV CEN,#34H
MOV S_UB,#34H
MOV RVER,#5H
MOV CVER,#5H
MOV SVER,#5H
MOV FVER,#5H
MOV DISPBUFF,#40H
acall delay;刚开机时不能马上给PT2258送数
NOP
acall delay
nop
acall delay
nop
acall delay
nop
acall delay
nop
MOV 30H,#0C0H
MOV NUMBYT,#01H
ACALL WRNBYT
NOP
NOP
MOV 30H,#0D3H
MOV 31H,#0E4H
MOV NUMBYT,#02H
ACALL WRNBYT
NOP
MOV NO_M,#00H
MOV NO_N,#00H
MOV DISPBUFF3,#0DFH
MAIN:
setb ea
CLR TR1
clr et1
SETB P3.7
MOV P1,#7FH
CLR P3.5
CLR P3.1 ;待机端
SETB P3.2
SETB P3.4
MOV 30H,#0f9H
MOV NUMBYT,#01H
ACALL WRNBYT
NOP
PW_1:
SETB P3.2
SETB P3.4
MOV A,NO_M
JZ PW_1
MOV NO_M,#00H
XRL A,#01H
JNZ PW_1
SETB P3.1
SETB TR1
SETB ET1
CLR (29H).1
acall clmut
NOP
MOV R2,#00H
MOV R3,#0FH
LOOP:
SETB P3.2
SETB P3.4
MOV A,R3
XRL A,#0fh
jnz key
MOV R3,#00h
MOV A,DISPBUFF3
ORL A,#01010110B
MOV DISPBUFF3,A
CLR (29H).2
CLR (29H).3
CLR (29H).4
CLR (29H).5
mov r5,dispbuff
acall disp_vol
NOP
KEY:
MOV A,NO_M
JZ LOOP
MOV NO_M,#00H
RL A
MOV DPTR,#TAB_KEY
NOP
JMP @A+DPTR
TAB_KEY:
AJMP LOOP
AJMP MAIN
AJMP MUTE
AJMP AC_33
AJMP RESET
AJMP STEREO
AJMP FRONT_V
AJMP CEN_V
AJMP REAR_V
AJMP SUB_V
AJMP VOLDN
AJMP VOLUP
AJMP LOOP
AJMP LOOP
RESET:
CLR P3.0;AC-3
MOV FRONT,#34H
MOV REAR,#34H
MOV CEN,#34H
MOV S_UB,#34H
MOV RVER,#5H
MOV CVER,#5H
MOV SVER,#5H
MOV FVER,#5H
MOV DISPBUFF,#40H
MOV DISPBUFF3,#0DFH
MOV 30H,#0D3H
MOV 31H,#0E4H
MOV NUMBYT,#02H
ACALL WRNBYT
NOP
AJMP INPUT_A
AC_33:
mov 30h,#0f9h
mov numbyt,#01h
acall wrnbyt
NOP
acall delay
NOP
MOV DISPBUFF3,#0DFH
CLR P3.0
NOP
AJMP INPUT_A
STERE
mov 30h,#0f9h
mov numbyt,#01h
acall wrnbyt
NOP
acall delay
NOP
MOV DISPBUFF3,#0F7H
SETB P3.0
INPUT_A:
SETB (29H).1
acall delay
NOP
MOV 30H,#0F8H
MOV NUMBYT,#01H
ACALL WRNBYT
NOP
MOV R3,#0FH
mov r2,#00H
NOP
AJMP LOOP
MUTE:
CPL (29H).1
JB (29H).1,MUT_1
MOV 30H,#0F9H
WRN_1:
MOV NUMBYT,#1H
LCALL WRNBYT
NOP
mov r2,#00H
MOV R3,#0FH
NOP
AJMP LOOP
MUT_1:
MOV 30H,#0F8H
MOV A,DISPBUFF3
ORL A,#10000000B
MOV DISPBUFF3,A
NOP
AJMP WRN_1
FRONT_V:
SETB (29H).2
CLR (29H).3
CLR (29H).4
CLR (29H).5
mov r5,fver
MOV A,DISPBUFF3
ANL A,#11101111B
ORL A,#01000110B
NOP
AJMP LOOP_d
REAR_V:
CLR (29H).2
SETB (29H).3
CLR (29H).4
CLR (29H).5
mov r5,rver
MOV A,DISPBUFF3
ANL A,#10111111B
ORL A,#00010110B
NOP
AJMP LOOP_d
CEN_V:
CLR (29H).2
CLR (29H).3
SETB (29H).4
CLR (29H).5
mov r5,cver
MOV A,DISPBUFF3
ANL A,#11111101B
ORL A,#01010100B
NOP
AJMP LOOP_d
SUB_V:
CLR (29H).2
CLR (29H).3
CLR (29H).4
SETB (29H).5
mov r5,sver
MOV A,DISPBUFF3
ANL A,#11111011B
ORL A,#01010010B
loop_d:
MOV DISPBUFF3,A
acall disp_vol
NOP
acall clmut
NOP
MOV R2,#00H
MOV R3,#00H
LOOP_A:
NOP
ajmp loop
CN_VOLUP_1:
NOP
AJMP CN_VOLUP
SB_VOLUP_1:
NOP
AJMP SB_VOLUP
VOLUP:
MOV 30H,#0C0H
MOV NUMBYT,#01H
ACALL WRNBYT
NOP
acall clmut
NOP
MOV R3,#0
JB (29H).2,FR_VOLUP
JB (29H).3,RR_VOLUP
JB (29H).4,CN_VOLUP_1
JB (29H).5,SB_VOLUP_1
MOV A,DISPBUFF
XRL A,#69H
JZ LOOP_A
MOV PHONE,FRONT
ACALL DAA
NOP
MOV FRONT,PHONE
MOV PHONE,REAR
ACALL DAA
NOP
MOV REAR,PHONE
MOV PHONE,CEN
ACALL DAA
NOP
MOV CEN,PHONE
MOV PHONE,S_UB
ACALL DAA
NOP
MOV S_UB,PHONE
MOV PHONE,DISPBUFF
ACALL UAA
NOP
MOV DISPBUFF,PHONE
ACALL FRDATA
NOP
ACALL RRDATA
NOP
ACALL CNDATA
NOP
ACALL SBDATA
NOP
mov r5,dispbuff
NOP
ajmp tt_volup
FR_VOLUP:
MOV A,FVER
XRL A,#10H
JZ LOOP_B
MOV PHONE,FVER
ACALL UAA
NOP
MOV FVER,PHONE
MOV PHONE,FRONT
ACALL DAA
NOP
MOV FRONT,PHONE
ACALL FRDATA
NOP
mov r5,fver
NOP
ajmp tt_volup
LOOP_B:
NOP
AJMP LOOP
RR_VOLUP:
MOV A,RVER
XRL A,#10H
JZ LOOP_B
MOV PHONE,RVER
ACALL UAA
NOP
MOV RVER,PHONE
MOV PHONE,REAR
ACALL DAA
NOP
MOV REAR,PHONE
ACALL RRDATA
NOP
mov r5,rver
NOP
ajmp tt_volup
CN_VOLUP:
MOV A,CVER
XRL A,#10H
JZ LOOP_B
MOV PHONE,CVER
ACALL UAA
NOP
MOV CVER,PHONE
MOV PHONE,CEN
ACALL DAA
NOP
MOV CEN,PHONE
ACALL CNDATA
NOP
mov r5,cver
NOP
ajmp tt_volup
SB_VOLUP:
MOV A,SVER
XRL A,#10H
JZ LOOP_C
MOV PHONE,SVER
ACALL UAA
NOP
MOV SVER,PHONE
MOV PHONE,S_UB
ACALL DAA
NOP
MOV S_UB,PHONE
ACALL SBDATA
NOP
mov r5,sver
tt_volup:
acall disp_vol
NOP
LOOP_C:
NOP
AJMP LOOP
CN_VOLDN_1:
NOP
AJMP CN_VOLDN
SB_VOLDN_1:
NOP
AJMP SB_VOLDN
VOLDN:
acall clmut
NOP
mov r3,#0
JB (29H).2,FR_VOLDN
JB (29H).3,RR_VOLDN
JB (29H).4,CN_VOLDN_1
JB (29H).5,SB_VOLDN_1
MOV A,DISPBUFF
JZ LOOP_C
MOV PHONE,FRONT
ACALL UAA
NOP
MOV FRONT,PHONE
MOV PHONE,REAR
ACALL UAA
NOP
MOV REAR,PHONE
MOV PHONE,CEN
ACALL UAA
NOP
MOV CEN,PHONE
MOV PHONE,S_UB
ACALL UAA
NOP
MOV S_UB,PHONE
MOV PHONE,DISPBUFF
ACALL DAA
NOP
MOV DISPBUFF,PHONE
ACALL FRDATA
NOP
ACALL RRDATA
NOP
ACALL CNDATA
NOP
ACALL SBDATA
NOP
mov r5,dispbuff
NOP
ajmp tt_volup
FR_VOLDN:
MOV A,FVER
JZ LOOP_C
MOV PHONE,FVER
ACALL DAA
NOP
MOV FVER,PHONE
MOV PHONE,FRONT
ACALL UAA
NOP
MOV FRONT,PHONE
ACALL FRDATA
NOP
mov r5,fver
NOP
ajmp tt_volup
RR_VOLDN:
MOV A,RVER
JZ LOOP_E
MOV PHONE,RVER
ACALL DAA
NOP
MOV RVER,PHONE
MOV PHONE,REAR
ACALL UAA
NOP
MOV REAR,PHONE
ACALL RRDATA
NOP
mov r5,rver
NOP
ajmp tt_volup
LOOP_E:
NOP
AJMP LOOP
CN_VOLDN:
MOV A,CVER
JZ LOOP_E
MOV PHONE,CVER
ACALL DAA
NOP
MOV CVER,PHONE
MOV PHONE,CEN
ACALL UAA
NOP
MOV CEN,PHONE
ACALL CNDATA
NOP
mov r5,cver
NOP
ajmp tt_volup
SB_VOLDN:
MOV A,SVER
JZ LOOP_E
MOV PHONE,SVER
ACALL DAA
NOP
MOV SVER,PHONE
MOV PHONE,S_UB
ACALL UAA
NOP
MOV S_UB,PHONE
ACALL SBDATA
NOP
mov r5,sver
NOP
ajmp tt_volup
FRDATA:
MOV A,FRONT
SWAP A
ANL A,#0FH
ADD A,#60H
MOV 30H,A
MOV A,FRONT
ANL A,#0FH
ADD A,#70H
MOV 31H,A
MOV NUMBYT,#02H
CALL WRNBYT
NOP
MOV A,FRONT
SWAP A
ANL A,#0FH
ADD A,#0a0H
MOV 30H,A
MOV A,FRONT
ANL A,#0FH
ADD A,#0b0H
MOV 31H,A
MOV NUMBYT,#02H
LCALL WRNBYT
NOP
RET
RRDATA:
MOV A,REAR
SWAP A
ANL A,#0FH
ADD A,#80H
MOV 30H,A
MOV A,REAR
ANL A,#0FH
ADD A,#90H
MOV 31H,A
MOV NUMBYT,#02H
CALL WRNBYT
NOP
MOV A,REAR
SWAP A
ANL A,#0FH
ADD A,#40H
MOV 30H,A
MOV A,REAR
ANL A,#0FH
ADD A,#50H
MOV 31H,A
MOV NUMBYT,#02H
LCALL WRNBYT
NOP
RET
CNDATA:
MOV A,CEN
SWAP A
ANL A,#0FH
ADD A,#00H
MOV 30H,A
MOV A,CEN
ANL A,#0FH
ADD A,#10H
MOV 31H,A
MOV NUMBYT,#02H
LCALL WRNBYT
NOP
RET
SBDATA:
MOV A,S_UB
SWAP A
ANL A,#0FH
ADD A,#20H
MOV 30H,A
MOV A,S_UB
ANL A,#0FH
ADD A,#30H
MOV 31H,A
MOV NUMBYT,#02H
LCALL WRNBYT
NOP
RET
disp_vol:
MOV a,r5
SWAP A
ANL A,#0FH
MOV DISPBUFF1,A
MOV A,r5
ANL A,#0FH
MOV DISPBUFF2,A
RET
UAA:
MOV A,PHONE
SWAP A
ANL A,#0FH
MOV R5,A
MOV A,PHONE
ANL A,#0FH
NOP
CJNE A,#09H,UAA_1
NOP
MOV R4,#00H
INC R5
AJMP UAA_2
UAA_1:
INC A
MOV R4,A
UAA_2:
MOV A,R5
SWAP A
ADD A,R4
MOV PHONE,A
RET
DAA:
MOV A,PHONE
SWAP A
ANL A,#0FH
MOV R5,A
MOV A,PHONE
ANL A,#0FH
JNZ DAA_1
MOV R4,#09H
DEC R5
NOP
SJMP DAA_2
DAA_1:
DEC A
MOV R4,A
DAA_2:
MOV A,R5
SWAP A
ADD A,R4
MOV PHONE,A
RET
DISP:
PUSH ACC
PUSH PSW
mov psw,#00h
MOV TH1,#0e8H
MOV TL1,#30H
SETB P3.5
SETB P3.7
SETB P1.0
INC NO_N
MOV A,NO_N
XRL A,#9FH
JNZ NONTE
MOV NO_N,#80H
NONTE:
INC R2
MOV A,R2
XRL A,#5AH
JNZ DE
MOV R2,#00H
INC R3
JB (29H).1,LED_1
MOV A,DISPBUFF3
XRL A,#10000000B
MOV DISPBUFF3,A
NOP
AJMP LED_11
LED_1:
MOV A,DISPBUFF3
ORL A,#10000000B
MOV DISPBUFF3,A
LED_11:
JNB (29H).2,LED_2
MOV A,DISPBUFF3
XRL A,#00010000B
MOV DISPBUFF3,A
LED_2:
JNB (29H).3,LED_3
MOV A,DISPBUFF3
XRL A,#01000000B
MOV DISPBUFF3,A
LED_3:
JNB (29H).4,LED_4
MOV A,DISPBUFF3
XRL A,#00000010B
MOV DISPBUFF3,A
LED_4:
JNB (29H).5,DE
MOV A,DISPBUFF3
XRL A,#00000100B
MOV DISPBUFF3,A
DE:
MOV A,COUNTER
JNZ DE_1
MOV A,DISPBUFF2
MOV DPTR,#TAB1
MOVC A,@A+DPTR
MOV P1,A
NOP
AJMP DISPNEXT
DE_1:
XRL A,#01H
JNZ DE_2
MOV A,DISPBUFF1
MOV DPTR,#TAB2
MOVC A,@A+DPTR
MOV P1,A
CLR P3.7
NOP
AJMP DISPNEXT
DE_2:
MOV P1,DISPBUFF3
CLR P3.5
DISPNEXT:
INC COUNTER
MOV A,COUNTER
XRL A,#03H
JNZ DISPEXIT
MOV COUNTER,#00H
DISPEXIT:
POP PSW
POP ACC
RETI
TAB1:DB 10H,7cH,88H,28H,64H
DB 22H,02H,78H,00H,20H
TAB2:DB 11H,7dH,89H,29H,65H
DB 23H,03H,79H,01H,21H
WRNBYT:
PUSH ACC
PUSH PSW
MOV PSW,#18H
WRNBYT1:
NOP
LCALL STA
NOP
MOV A,#88H
NOP
LCALL WRBYT
NOP
LCALL CACK
NOP
JB F0,WRNBYT1
MOV R1,#MTD
WRDA:
MOV A,@R1
NOP
LCALL WRBYT
NOP
LCALL CACK
NOP
JB F0,WRNBYT1
INC R1
DJNZ NUMBYT,WRDA
NOP
LCALL STOP
NOP
POP PSW
POP ACC
RET
STA:
SETB SDA
nop
NOP
SETB SCL
WAITS:JNB SCL,WAITS
NOP
NOP
NOP
nop
CLR SDA
NOP
NOP
NOP
NOP
nop
NOP
CLR SCL
NOP
RET
STOP:
CLR SDA
nop
NOP
SETB SCL
WAITP:
JNB SCL,WAITP
NOP
NOP
nop
NOP
SETB SDA
NOP
NOP
NOP
NOP
nop
NOP
CLR SCL
NOP
RET
CACK:SETB SDA
nop
NOP
SETB SCL
NOP
CLR F0
JNB SDA,CEND
SETB F0
CEND:
nop
CLR SCL
nop
NOP
NOP
NOP
RET
WRBYT:
MOV R0,#07H
RLC A
JC NEXT1
CLR SDA
NOP
NOP
SJMP NEXT0
NEXT1:
SETB SDA
NOP
NOP
NEXT0:
SETB SCL
WAITW:
JNB SCL,WAITW
NOP
NOP
nop
NOP
CLR SCL
nop
NOP
CLR SDA
WLP:
RLC A
JC WR1
NOP
AJMP WR0
WLP1:
DJNZ R0,WLP
RET
WR1:
SETB SDA
nop
NOP
SETB SCL
nop
NOP
NOP
NOP
NOP
NOP
CLR SCL
nop
NOP
CLR SDA
NOP
NOP
AJMP WLP1
WR0:
CLR SDA
nop
NOP
SETB SCL
nop
NOP
NOP
NOP
NOP
NOP
CLR SCL
NOP
NOP
LJMP WLP1
DELAY:
MOV R7,#255
D2:
MOV R6,#200
DJNZ R6,$
DJNZ R7,D2
RET
clmut:
jb (29h).1,clmut_ex
SETB (29H).1
MOV 30H,#0F8H
MOV NUMBYT,#01H
NOP
ACALL WRNBYT
NOP
clmut_ex:
ret
INO1:
PUSH ACC
PUSH PSW
MOV PSW,#10H
CLR TR0
CLR EX1
MOV 27H,TH0
MOV 28H,TL0
MOV TH0,#00H
MOV TL0,#00H
SETB TR0
JNB (29H).0,REST_12
MOV 4AH,27H
MOV 4BH,28H
MOV 4CH,#03H
MOV 4DH,#9DH
NOP
LCALL SUB0
NOP
JC X1_009
MOV 4CH,#05H
MOV 4DH,#2DH
MOV 4AH,27H
MOV 4BH,28H
NOP
LCALL SUB0
NOP
JNC X1_01
CLR C
NOP
LJMP X1_02
X1_009:
NOP
AJMP X1_005
X1_OO1:
NOP
AJMP X1_OUT1
REST_12:
NOP
AJMP REST_1
X1_01:
MOV 4CH,#07H
MOV 4DH,#0D0H
MOV 4AH,27H
MOV 4BH,28H
NOP
LCALL SUB0
NOP
JC X1_009
MOV 4CH,#09H
MOV 4DH,#0C4H
MOV 4AH,27H
MOV 4BH,28H
NOP
LCALL SUB0
NOP
JC X_01T
NOP
AJMP X1_005
X_01T:
NOP
AJMP X_01
REST_1:
MOV 4CH,#2AH
MOV 4DH,#0F8H
MOV 4AH,27H
MOV 4BH,28H
NOP
LCALL SUB0
NOP
JC X1_009
MOV 4CH,#2EH
MOV 4DH,#0E0H
MOV 4AH,27H
MOV 4BH,28H
NOP
LCALL SUB0
NOP
JNC REST_2
MOV 4CH,#03H
MOV 4DH,#08H
MOV 4AH,#03H
MOV 4BH,NO_N
NOP
LCALL SUB0
NOP
JC X1_005
MOV 4CH,#03H
MOV 4DH,#1EH
MOV 4AH,#03H
MOV 4BH,NO_N
NOP
LCALL SUB0
NOP
JNC X1_005
MOV NO_N,#00H
djnz remvol,x1_005
mov remvol,#01h
MOV A,2CH
XRL A,#00H
JNZ REST_3
NOP
AJMP X1_10
REST_3:
MOV A,2CH
XRL A,#01H
JNZ X1_005
NOP
AJMP X1_10
REST_2:
MOV 4CH,#33H
MOV 4DH,#90H
MOV 4AH,27H
MOV 4BH,28H
NOP
LCALL SUB0
NOP
JC X1_005
MOV 4CH,#35H
MOV 4DH,#0E8H
MOV 4AH,27H
MOV 4BH,28H
NOP
LCALL SUB0
NOP
JNC X1_005
SETB (29H).0
MOV CS_X1,#08H
MOV CS0_X1,#04H
MOV R1,#2AH
NOP
AJMP X1_OUT1
X1_005:
NOP
AJMP X1S_06
X_01:
SETB C
X1_02:
MOV A,U0_X1
RRC A
MOV U0_X1,A
DJNZ CS_X1,X1_OUT1
MOV CS_X1,#08H
MOV @R1,U0_X1
INC R1
DJNZ CS0_X1,X1_OUT1
mov remvol,#02h
NOP
LJMP X1_10
X1_OUT1:
SETB EX1
POP PSW
POP ACC
RETI
RETI
X1_10:
MOV A,2AH
XRL A,#00H
JNZ X1S_06
MOV A,2BH
XRL A,#0DFH
JNZ X1S_06
MOV A,2CH
CPL A
XRL A,2DH
JNZ X1S_06
MOV R0,#0BH
MOV DPTR,#TAB_REMOT
LOOKUP_1:
MOV A,R0
MOVC A,@A+DPTR
XRL A,2CH
JZ REM_BAK0
DJNZ R0,LOOKUP_1
REM_BAK0:
MOV NO_M,R0
MOV NO_N,#00H
NOP
SJMP X1S_06
REM_BAK:MOV NO_M,#0
X1S_06:
CLR (29H).0
SETB EX1
POP PSW
POP ACC
RETI
RETI
SUB0:CLR CY
MOV A,4BH
SUBB A,4DH
JNC X1_S1
DEC 4AH
X1_S1:
CLR CY
MOV A,4AH
SUBB A,4CH
RET
RET
ITT0:
MOV TH0,#00h
mov tl0,#00h
RETI
RETI
TAB_REMOT:
DB 00H
;POWER,MUTE,AC-3,RESET,STEREO
DB 16H,14H,0EH,0DH,0CH
;FRONT,CEN,REAR,SUB,VOL-,VOL+
DB 0AH,09H,08H,05H,01H,00H
org 07c7h
nop
nop
mov dptr,#loop
MOV A,#00H
jmp @A+DPTR
END