;************************************************************** ; REMOCL04.ASM 16 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 VOLDN EQU 0xe7 ; Was:77 CMDVOLDN EQU 0xc0 VOLUP EQU 0xdf ; Was:7a CMDVOLUP EQU 0xa0 PREV EQU 0xef CMDPREV EQU 0x88 NEXT EQU 0xdb ; Was:cf CMDNEXT EQU 0x90 STOP EQU 0x7f CMDSTOP EQU 0x84 PLAY EQU 0xbf ; Was:af CMDPLAY EQU 0x82 ; 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 BSF INTCON,GIE ; Enable Global INT, needed for wake on PORTB BSF INTCON,RBIE ; Enable interrupt on RB port change 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 SLEEP ; Go to sleep ;************************************************************** ; Wake from Keypress ;************************************************************** WAKE MOVF PORTB,0 ; Read PortB MOVWF KEYPAD ; Store keypad value MOVLW VOLDN XORWF KEYPAD,0 BTFSC STATUS,Z ; Test if zero GOTO OUTVOLDN MOVLW VOLUP XORWF KEYPAD,0 BTFSC STATUS,Z ; Test if zero GOTO OUTVOLUP MOVLW PREV XORWF KEYPAD,0 BTFSC STATUS,Z ; Test if zero GOTO OUTPREV MOVLW NEXT XORWF KEYPAD,0 BTFSC STATUS,Z ; Test if zero GOTO OUTNEXT MOVLW PLAY XORWF KEYPAD,0 BTFSC STATUS,Z ; Test if zero GOTO OUTPLAY MOVLW STOP XORWF KEYPAD,0 BTFSC STATUS,Z ; Test if zero GOTO OUTSTOP DEBOUNCE CALL WAIT10MS ; Debounce CALL WAIT10MS CALL WAIT10MS CALL WAIT10MS CALL WAIT10MS CALL WAIT10MS CALL WAIT10MS CALL WAIT10MS CALL WAIT10MS CALL WAIT10MS SLEEP ; There was no match ;************************************************************** ; Surely there must be a more intelligent way to solve this... ;************************************************************** OUTVOLDN MOVLW CMDVOLDN CALL PUTCHAR GOTO DEBOUNCE OUTVOLUP MOVLW CMDVOLUP CALL PUTCHAR GOTO DEBOUNCE OUTPREV MOVLW CMDPREV CALL PUTCHAR GOTO DEBOUNCE OUTNEXT MOVLW CMDNEXT CALL PUTCHAR GOTO DEBOUNCE OUTSTOP MOVLW CMDSTOP CALL PUTCHAR GOTO DEBOUNCE OUTPLAY MOVLW CMDPLAY CALL PUTCHAR GOTO DEBOUNCE ;************************************************************** ; Subroutine PUTCHAR ; Output the RS232 Character ;************************************************************** PUTCHAR MOVWF DATABYTE MOVLW 0x07 MOVWF BITCOUNT MORE RRF DATABYTE,1 ; Rotate DATABYTE through Carry BTFSS STATUS,C ; Test Carry GOTO ZERO BSF PORTA,4 ; Send a one GOTO NEXTBIT ZERO BCF PORTA,4 ; Send a zero NEXTBIT NOP NOP NOP NOP NOP DECFSZ BITCOUNT,1 GOTO MORE ; CHECK CORRECT DELAY!!! Need 11 cycles total per bit for 9600 baud (approx...) BSF PORTA,4 ; Send a one (just to be sure...) 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