;************************************************************** ; REMOCL06.ASM 17 December 2001 ;************************************************************** ; ; This PIC16LF84 program emulates the Zilog chip inside the ; remote intended for use with the Archos Jukebox 6000 ; ; Written by Tjerk "T.J." Schuringa, hardware engineer (ouch) ; ; Inputs are according to prototype board ; ;************************************************************** LIST P=16F84, F=INHX8M __CONFIG _CP_OFF & _WDT_OFF & _XT_OSC #include ".\p16f84.inc" ;************************************************************** ; f_osc = 429 kHz yields cycle time of 9.32 µs ;************************************************************** ; Equates RESET_V EQU 0x00 ; Address of RESET Vector OSC_FREQ EQU D'429000' ; Oscillator Frequency is 429 kHz STOP EQU 7 PLAY EQU 6 VOLU EQU 5 PREV EQU 4 VOLD EQU 3 NEXT EQU 2 ; Registers KEYPAD EQU 0x0F DATABYTE EQU 0x10 BITCOUNT EQU 0x11 WAIT EQU 0x12 ;************************************************************** ; Begin Program ;************************************************************** ORG RESET_V ; RESET vector location RESET GOTO START ORG 4 ; INT vector GOTO WAKE ;************************************************************** ; Initialization Routine ;************************************************************** START ; POWER_ON Reset (Beginning of program) CLRF STATUS ; Do initialization, Select bank 0 CLRF INTCON ; Clear int-flags, Disable interrupts CLRF PCLATH ; Keep in lower 2KByte CLRF PORTA ; ALL PORT output should output Low. CLRF PORTB BSF STATUS,RP0 ; Select bank 1 MOVLW 0xff CLRF TRISA ; RA4-0 Outputs MOVWF TRISB ; RB7-0 Inputs BCF OPTION_REG,NOT_RBPU ; Enable PORTB pull-ups BCF STATUS,RP0 ; Select bank 0 BSF PORTA,4 ; Make Ring2 High BSF INTCON,GIE ; Enable global interrupt LOOP BSF INTCON,RBIE ; Enable interrupt on RB port change SLEEP ; Go to sleep GOTO LOOP ;************************************************************** ; Wake from Keypress ;************************************************************** WAKE BCF INTCON,RBIF ; Clear Change on PortB flag MOVLW 0xFE ; databyte[7..0] = {1,1,1,1,1,1,1,0}; MOVWF DATABYTE MOVF PORTB,0 ; keypad[7..0] = PORTB[7..0]; MOVWF KEYPAD BTFSC KEYPAD,VOLD BTFSS KEYPAD,PLAY ; databyte[1] = 1 if key PLAY pressed; BCF DATABYTE,1 BTFSS KEYPAD,STOP ; databyte[2] = 1 if key STOP pressed; BCF DATABYTE,2 BTFSS KEYPAD,VOLD BTFSS KEYPAD,PREV ; databyte[3] = 1 if key PREV pressed; BCF DATABYTE,3 BTFSS KEYPAD,NEXT ; databyte[4] = 1 if key NEXT pressed; BCF DATABYTE,4 BTFSS KEYPAD,NEXT BTFSS KEYPAD,VOLU ; databyte[5] = 1 if key VOL+ pressed; BCF DATABYTE,5 BTFSS KEYPAD,VOLD ; databyte[6] = 1 if key VOL- pressed; BCF DATABYTE,6 CALL PUTCHAR DEBOUNCE CALL WAIT10MS ; Debounce CALL WAIT10MS CALL WAIT10MS CALL WAIT10MS CALL WAIT10MS CALL WAIT10MS CALL WAIT10MS CALL WAIT10MS CALL WAIT10MS CALL WAIT10MS RETFIE ;************************************************************** ; Subroutine PUTCHAR ; Output the RS232 Character ;************************************************************** PUTCHAR ; databyte[7..0] = { 1,VOL-,VOL+,NEXT,PREV,STOP,PLAY,0}; MOVLW 0x08 RLF DATABYTE,1 MOVWF BITCOUNT MORE RRF DATABYTE,1 NOP NOP SWAPF DATABYTE,0 ; W[4] = databyte[0] NOP NOP MOVWF PORTA ; PORTA[4] = W[4] NOP NOP DECFSZ BITCOUNT,1 GOTO MORE ; CHECK CORRECT DELAY!!! Need 11 cycles total per bit for 9600 baud (approx...) RETURN ;************************************************************** ; Subroutine WAIT10MS ; Wait 10 ms ;************************************************************** WAIT10MS ; Do nothing for some time (10 ms) MOVLW 0xD7 MOVWF WAIT LOOP NOP NOP DECFSZ WAIT,1 GOTO LOOP RETURN END