112884 views|1 replies
- Last login
- 2006-11-27
- Online Time
- 0 hours
- Prestige
- 26712 points
- Points
- -87 points
|
;The chip is EM78P153 ;P64, P65 are connected to the crystal oscillator, the oscillation mode is 4MHz crystal oscillator ;Watchdog is off, the instruction cycle is 2 CLOCKs, P63 is the reset pin ;********************IO port definition************************ PORT6 EQU 0X06 IOC60 EQU 0X06 ;***************Special function register definition*************** TCC EQU 0X01 PC EQU 0X02 PSW EQU 0X03 IOCD0 EQU 0X0D IOCE0 EQU 0X0E IOCF0 EQU 0X0F RF EQU 0X0F ;***************User-defined registers******************* COUNTER EQU 0X10 CODE1 EQU 0X11 CODE2 EQU 0X12 CODE3 EQU 0X13 CODE4 EQU 0X14 LP_CNT0 EQU 0X15 LP_CNT1 EQU 0X16 TEMP EQU 0X17 TEMPCODE EQU 0X18 REPEAT_COUNTER EQU 0X19 SEND_DATA EQU 0X1A USER_CODE EQU 0X1B FLAG EQU 0X1C ;*******************FLAG bit definition********************** C EQU 0 Z EQU 2 TCIF EQU 0 LEAD EQU 0 REPEAT EQU 1 INPUT EQU 1 OUTPUT EQU 0 ORG 0X000 NOP NOP NOP NOP JMP 0X50 ;************************Table conversion subroutine program****************** TABLE_CONVER: CLR TEMP TABLE_CONVER_1: MOV A,TEMP CALL TABLE_CONVERSION_IN BC PSW,Z _3 RETL 0X90 ;KEY_4 RETL 0X18 ; KEY_5 RETL 0X98 ; KEY_6 RETL 0XE0 ; KEY_7 RETL 0X68 ;KEY_8 RETL 0XE8 ;KEY_9 RETL 0X28 ;KEY_0 RETL 0X20 ;KEY_3D RETL 0XA0 ; KEY_MUTE RETL 0X40 ;KEY_VOCAL RETL 0XE2 ;KEY_VOL+ RETL 0XA2 ;KEY_VOL- RETL 0X52 ;KEY_TUNE FWD RETL 0X22 ;KEY_TUNE REV RETL 0X12 ;KEY_STOP RETL 0X82 ;KEY_|> RETL 0X02 ;KEY_OK RETL 0XF0 ;KEY_TUNER RETL 0X78 ;KEY_AM/FM RETL 0XF8 ;KEY_SAVE RETL 0X50 ;KEY_AUDIO ;************************Table conversion program OUT************************ TABLE_CONVERSION_OUT: MOV A,TEMP ADD PC,A RETL 0X35 ;KEY_1 RETL 0X2D ;KEY_2 RETL 0X25 ;KEY_3 RETL 0X1D ; KEY_4 RETL 0X34 ;KEY_5 RETL 0X2C ;KEY_6 RETL 0X24 ;KEY_7 RETL 0X1C ;KEY_8 RETL 0X33 ;KEY_9 RETL 0X2B ;KEY_0 RETL 0X10 ;KEY_3D
; KEY_STOP RETL 0X31 ; KEY_<| RETL 0X21 ;KEY_|> RETL 0X29 ;KEY_OK RETL 0X2E ;KEY_TUNER RETL 0X20 ;KEY_AUX-1 RETL 0X23 ;KEY_AUX-2 RETL 0X17 ;KEY_DVD ORG 0X050 MAIN: ;************************Initialize registers********************** MOV A,@0B00000000 IOW IOCE0 MOV A,@0B11111101 IOW IOCD0 MOV A,@0B00000010 IOW IOC60 MOV A,@0B00000001 MOV PORT6,A MOV A,@0B00000001 IOW IOCF0 CLR FLAG CLR TEMPCODE CLR COUNTER CLR CODE1 CLR CODE2 CLR CODE3 CLR CODE4 MOV A,@0B10010000 MOV USER_CODE,A ;************************Scan boot code********************** SCAN_LEAD_CODE: JBC PORT6,INPUT JMP SCAN_LEAD_CODE CLR FLAG CLR REPEAT_COUNTER CLR TEMPCODE CALL JUDGE_START_CODE JBS FLAG,LEAD JMP SCAN_LEAD_CODE ;*********************Receive data*********************** RECEIVE_DATA_PROCEE: CLR TEMPCODE CALL RECEIVE_DATA MOV A,TEMPCODE MOV CODE1,A MOV A,@0 ;Judge whether the user code is 00 BC PSW,Z XOR A,CODE1 JBS PSW,Z JMP SCAN_LEAD_CODE CLR TEMPCODE CALL RECEIVE_DATA MOV A,TEMPCODE MOV CODE2,A MOV A,@0XFF ;Judge whether the user code is FF BC PSW,Z XOR A,CODE2 JBS PSW,Z JMP SCAN_LEAD_CODE CLR TEMPCODE CALL RECEIVE_DATA MOV A,TEMPCODE MOV CODE3,A CLR TEMPCODE CALL RECEIVE_DATA MOV A,TEMPCODE MOV CODE4,A CLR FLAG ;*********************Send data************************** SEND_DATA_PROCEE: JBS USER_CODE,6 ;Invert the second highest bit of ST code JMP COM_1 ;=0 JMP COM_2 ;=1 COM_1: BS USER_CODE,6 JMP VVV COM_2: BC USER_CODE,6 JMP VVV VVV: CALL TABLE_CONVER ;Call code table conversion subroutine MOV CODE3,A REP: CALL TRANSMIT_DATA BS PORT6,OUTPUT CALL JUDGE_REPEAT_CODE ;Is the scan lead code repeated? JBS FLAG,LEAD JMP SCAN_LEAD_CODE JBC FLAG,REPEAT JMP REP ;The lead code is repeated, continue scanning JMP RECEIVE_DATA_PROCEE ; The boot code is not repeated, and new data is received ; ****************** Boot code detection subroutine ******************* JUDGE_START_CODE: CLR COUNTER ; Clear counter JUDGE_START_CODE_0:
JBC PORT6,INPUT JMP NO_HIGH CALL DELAY0.5MS JBC PORT6,INPUT JMP NO_HIGH INC COUNTER JMP JUDGE_START_CODE_0 NO_HIGH: MOV A,COUNTER BC PSW,C SUB A,@20 ;20-A JBS PSW,C JMP EXIT_0 ;C=1, COUNTER>20 MOV A,COUNTER BC PSW,C SUB A,@16 ;16-A JBC PSW,C JMP EXIT_0 ;C=0,COUNTER<16 BS FLAG,LEAD EXIT_0: JBC PORT6,INPUT JMP EXIT_0 INC REPEAT_COUNTER RET ;*********** *****Receive data subroutine********************** RECEIVE_DATA: MOV A,@8 MOV COUNTER,A MOV A,@0B00100000 CONTW ;Stop counting CONTINUE_1: JBS PORT6,INPUT JMP CONTINUE_1 CLR TCC MOV A,@0B00000100 CONTW ;TCC start counting CONTINUE_2: MOV A,TCC MOV TEMP,A BC PSW,C SUB A,@250 JBS PSW,C JMP SCAN_LEAD_CODE ;C=0,TCC>250
JBC PORT6,INPUT JMP CONTINUE_2 MOV A,TCC MOV TEMP,A BC PSW,C SUB A,@60;142 JBC PSW,C JMP X1 ;C=1,TCC<60 JMP X2 ;C=0,TCC>60 X1: BC TEMPCODE,0 JMP EXIT_1 X2: BS TEMPCODE,0 JMP EXIT_1 EXIT_1: DJZ COUNTER JMP HH MOV A,@0B00100000 CONTW ;Stop counting RET HH: BC PSW,C RLC TEMPCODE JMP CONTINUE_1
;********************Send Data subroutine *********************** TRANSMIT_DATA: MOV A,@4 MOV COUNTER,A MOV A,USER_CODE ;@0B10010000 ;Send ST user code MOV SEND_DATA,A CYCLE_1: JBS SEND_DATA,7 JMP SEND_P_0 JMP SEND_P_1 SEND_P_1: CALL SEND_CODE_1 JMP EXIT_3 SEND_P_0: CALL SEND_CODE_0 JMP EXIT_3 EXIT_3: RLC SEND_DATA DJZ COUNTER JMP CYCLE_1
MOV A,@8 MOV COUNTER,A MOV A,CODE3 MOV SEND_DATA,A RLC SEND_DATA CYCLE_2: JBS SEND_DATA,7 JMP SEND_Q_0 JMP SEND_Q_1 SEND_Q_1: CALL SEND_CODE_1 JMP EXIT_4 SEND_Q_0: CALL SEND_CODE_0 JMP EXIT_4 EXIT_4: RLC SEND_DATA DJZ COUNTER JMP CYCLE_2 RET ;***************Send data "1" subroutine******************** SEND_CODE_1: MOV A,@ 0B00100000 CONTW ; stop counting MOV A,@0B00000001 ; enable TCC interrupt IOW IOCF0 MOV A,@35 ; preset value of guide pulse MOV TCC,A MOV A,@0B00000001 ;Select pre-scaling ratio as 1:4 CONTW BC PORT6,OUTPUT WAIT_1: JBS RF,TCIF JMP WAIT_1 MOV A,@0B00100000 CONTW ;Stop counting BC RF,TCIF MOV A,@32 ;Preset value of code "1" MOV TCC,A MOV A,@0B00000101 ;Select pre-scaling ratio as 1:64 CONTW BS PORT6,OUTPUT WAIT_2: JBS RF,TCIF JMP WAIT_2 BC RF,TCIF MOV A,@0B00100000 CONTW ;Stop counting RET ;***************Subroutine for sending data "0"******************** SEND_CODE_0: MOV A,@0B00100000 CONTW ;Stop counting MOV A,@0B00000001 ;Enable TCC interrupt IOW IOCF0 MOV A,@35 ;Preset value of guide pulse MOV TCC,A MOV A,@0B00000001 ;Select prescaler ratio as 1:4 CONTW BC PORT6,OUTPUT WAIT_3: JBS RF,TCIF JMP WAIT_3 MOV A,@0B00100000 CONTW ;Stop counting BC RF,TCIF
MOV A,@114 ;Preset value of code "0" MOV TCC,A MOV A,@0B00000101 ;Select prescaler ratio as 1:64 CONTW BS PORT6,OUTPUT WAIT_4: JBS RF,TCIF JMP WAIT_4 NOP BC RF,TCIF MOV A,@0B00100000 CONTW ; Stop counting RET ;****************Repeat code detection subroutine****************** JUDGE_REPEAT_CODE: CLR COUNTER ; Clear counter CLR FLAG JUDGE_REPEAT_CODE_0: JBC PORT6,INPUT JMP JUDGE_REPEAT_CODE_0 SS: JBC PORT6,INPUT JMP JUDGE_REPEAT_CODE_1 CALL DELAY0.5MS JBC PORT6,INPUT JMP JUDGE_REPEAT_CODE_1 INC COUNTER JMP SS JUDGE_REPEAT_CODE_1: MOV A,COUNTER BC PSW,C SUB A,@20 ;20-A JBS PSW,C JMP EXIT_2 ;C=1,COUNTER>20 MOV A,COUNTER BC PSW,C SUB A,@16;16-A JBC PSW,C JMP EXIT_2;C=0,COUNTER<16 BS FLAG,LEAD JMP JUDGE_REPEAT_CODE_2 EXIT_2: RET JUDGE_REPEAT_CODE_2: CLR COUNTER;Clear counter JUDGE_REPEAT_CODE_3: JBS PORT6,INPUT JMP JUDGE_REPEAT_CODE_4 CALL DELAY0.5MS JBS PORT6,INPUT JMP JUDGE_REPEAT_CODE_4 INC COUNTER JMP JUDGE_REPEAT_CODE_3 JUDGE_REPEAT_CODE_4: MOV A,COUNTER BC PSW,C SUB A,@7 ;7-A JBS PSW,C JMP NO_REPEAT ;C=0,COUNTER>7 JMP YES_REPEAT ;C=1,COUNTER<7 NO_REPEAT: BC FLAG,REPEAT CLR REPEAT_COUNTER RET YES_REPEAT: BS FLAG,REPEAT INC REPEAT_COUNTER RET ;****************Delay 0.5mS subroutine************************ DELAY0.5MS: MOV A,@2 MOV LP_CNT0,A DELAY0.5MS_1: MOV A,@82 MOV LP_CNT1,A DELAY0.5MS_2: NOP NOP NOP DJZ LP_CNT1 JMP DELAY0.5MS_2 DJZ LP_CNT0 JMP DELAY0.5MS_1 RET
|
|