STC單片機(jī)學(xué)習(xí)型遙控器程序
MOV ISP_DATA,GESHU ;將個(gè)數(shù)輸入到ISP_EEPROM的第一位
MOV ISP_ADDRH,ADDRH
MOV ISP_ADDRL,ADDRL
CLR EA
MOV ISP_CONTR,#WAIT_TIME
ORL ISP_CONTR,#10000000B
MOV ISP_CMD,#ISP_CMD_PROGRAM
MOV ISP_TRIG,#46H
MOV ISP_TRIG,#0B9H
NOP
MOV R1,GESHU
MOV R0,#00H
LOOP_WRITE: LCALL BYTE_WRITE ;將擴(kuò)展寄存器中的計(jì)時(shí)值依次放入ISP_EEPROM第二位開(kāi)始的存儲(chǔ)器中
INC R0
LCALL BYTE_WRITE
INC R0
DJNZ R1,LOOP_WRITE
MOV ISP_CMD,#00H ;ISP指令清零,防止誤觸發(fā)
MOV ISP_TRIG,#00H
MOV ISP_ADDRH,#00H
MOV ISP_ADDRL,#00H
mov p1,geshu
LJMP KEY_MAIN
BYTE_WRITE: MOVX A,@R0
MOV ISP_DATA,A
MOV ISP_ADDRH,ADDRH
INC R0
MOV ISP_ADDRL,R0
DEC R0
CLR EA
MOV ISP_CONTR,#WAIT_TIME
ORL ISP_CONTR,#10000000B
MOV ISP_CMD,#ISP_CMD_PROGRAM
MOV ISP_TRIG,#46H
MOV ISP_TRIG,#0B9H
NOP
RET
ISP_ERASE: MOV ISP_ADDRH,ADDRH
MOV ISP_ADDRL,ADDRL
CLR EA
MOV ISP_CONTR,#WAIT_TIME
ORL ISP_CONTR,#10000000B
MOV ISP_CMD,#ISP_CMD_ERASE
MOV ISP_TRIG,#46H
MOV ISP_TRIG,#0B9H
NOP
RET
TX_START: MOV ISP_ADDRH,ADDRH ;取出第一位的個(gè)數(shù)
MOV ISP_ADDRL,ADDRL
CLR EA
MOV ISP_CONTR,#WAIT_TIME
ORL ISP_CONTR,#10000000B
MOV ISP_CMD,#ISP_CMD_READ
MOV ISP_TRIG,#46H
MOV ISP_TRIG,#0B9H
NOP
MOV ISP_CMD,#00H ;ISP指令清零,防止誤觸發(fā)
MOV ISP_TRIG,#00H
MOV ISP_ADDRH,#00H
MOV ISP_ADDRL,#00H
MOV A,ISP_DATA ;為0FF則是錯(cuò)誤的,回去,不為0FF則繼續(xù)
CJNE A,#0FFH,ISP_READ
LJMP KEY_MAIN
ISP_READ: MOV GESHU,ISP_DATA
MOV R1,GESHU
MOV R0,#00H
LOOP_READ: LCALL BYTE_READ
INC R0
LCALL BYTE_READ
INC R0
DJNZ R1,LOOP_READ
LJMP TX_EXROM
BYTE_READ: INC R0
MOV ISP_ADDRH,ADDRH
MOV ISP_ADDRL,R0
DEC R0
CLR EA
MOV ISP_CONTR,#WAIT_TIME
ORL ISP_CONTR,#10000000B
MOV ISP_CMD,#ISP_CMD_READ
MOV ISP_TRIG,#46H
MOV ISP_TRIG,#0B9H
NOP
MOV A,ISP_DATA
MOVX @R0,A
RET
TX_EXROM: MOV TMOD,#00010010B
MOV TH0,#0F4H
MOV TL0,#0F4H
MOV R1,GESHU
MOV R0,#00H
MOVX A,@R0
MOV TL1,A
INC R0
MOVX A,@R0
MOV TH1,A
INC R0
DEC R1
MOVX A,@R0
MOV ZHIL,A
INC R0
MOVX A,@R0
MOV ZHIH,A
INC R0
DEC R1
SETB ET1
SETB ET0
SETB EA
SETB TR1
SETB TR0
CLR TXOUT
MAIN2:CJNE R1,#00H,MAIN2
CLR TXOUT
mov p1,#55h
LJMP KEY_MAIN
T0IN:CPL TXZAI
RETI
T1IN: MOV TL1,ZHIL
MOV TH1,ZHIH
JB TR0,NEXTT1
SETB TR0
LJMP NEXTT
NEXTT1:CLR TR0
CLR TXZAI
NEXTT:CPL TXOUT
MOVX A,@R0
MOV ZHIL,A
INC R0
MOVX A,@R0
MOV ZHIH,A
INC R0
DJNZ R1,OUTTI
CLR TR1
CLR TR0
CLR TXZAI
CLR TXOUT
OUTTI:RETI
DELAYXMS:MOV R7,#255
DEL1:MOV R6,#4
DEL2:MOV R5,#5
DJNZ R5,$
DJNZ R6,DEL2
DJNZ R7,DEL1
RET
DELAYX2MS:MOV R7,#255
DEL12:MOV R6,#50
DEL22:MOV R5,#50
DJNZ R5,$
DJNZ R6,DEL22
DJNZ R7,DEL12
RET
END
萬(wàn)能遙控器相關(guān)文章:萬(wàn)能遙控器代碼
評(píng)論