;********************************************************************** ;* convert 10 key input to 4 bit binary ;********************************************************************** list P=PIC16F88 #include __CONFIG _CONFIG1, _INTRC_IO &_CP_OFF & _WDT_OFF & _PWRTE_ON &_LVP_OFF & _MCLR_OFF & _CCP1_RB3 __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF ;***** VARIABLE DEFINITIONS w_temp EQU 0x0C ; variable used for context saving status_temp EQU 0x0D ; variable used for context saving tmp EQU 0x0F CNT0 EQU 0x20 CNT1 EQU 0x21 CNT2 EQU 0x22 CNT3 EQU 0x23 CNT4 EQU 0x24 w_temp0 EQU 0x25 w_temp1 EQU 0x26 w_temp2 EQU 0x27 w_temp3 EQU 0x28 w_temp4 EQU 0x29 daddr EQU 0x2a ;***** EEPROM Setting org 0x2100 DE 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xb, 0xf, 0xf, 0xf, 0x9, 0xf, 0x6, 0x3, 0xf DE 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0x0, 0xf, 0xf, 0xf, 0x8, 0xf, 0x5, 0x2, 0xf DE 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xa, 0xf, 0xf, 0xf, 0x7, 0xf, 0x4, 0x1, 0xf ;********************************************************************** ;RESET_VECTOR CODE 0x000 ; processor reset vector org 0x000 goto Init ; go to beginning of program org 0x008 ;ISR CODE 0x004 ; interrupt vector location ; goto Interrupt ; go to the interrupt location ;MAIN_PROGRAM CODE ;Interrupt: ; movwf w_temp ; save off current W register contents ; movf STATUS,w ; move status register into W register ; movwf status_temp ; save off contents of STATUS register ; movf status_temp,w ; retrieve copy of STATUS register ; movwf STATUS ; restore pre-isr STATUS register contents ; swapf w_temp,f ; swapf w_temp,w ; restore pre-isr W register contents ; retfie ; return from interrupt Init: ;***** PORT mode set ***** ;RA0:3 binary out ;RB0:2 out(key pad 1-3 pin) ;RB3 out(Buzzer) ;RB4:7 in(key pad 4-7 pin) ;AN0:4 disable ;CCP1 disable BCF INTCON,GIE ;Interrupt Disable BSF INTCON,RBIE ;PortB Interrupt Enable BSF STATUS,RP0 ;Set page 1 CLRF TRISA MOVLW 0xf0 MOVWF TRISB CLRF ANSEL ; Analog input disable MOVLW 0x70 ; set INTOSC to 8Mhz MOVWF OSCCON BCF STATUS,RP0 ;Set page 0 ; CLRF CCP1CON ; CCP1 disable MOVLW 0xff MOVWF PORTA ;**** CALL Buzzer CALL Sleep100ms CALL Buzzer Main: MOVLW 0xff MOVWF PORTB Row1: CLRF daddr ; set 0 to high addr BCF PORTB,0 ; xxxx1110 SWAPF PORTB,W ; read port B and swap high and low BSF PORTB,0 ; xxxx1111 ANDLW 0x0f ; get low addr ADDWF daddr,F ; set low to ROM addr XORLW 0x0f ; if low addr == 1111(not push row1 key) BTFSS STATUS,Z GOTO Output_Data Row2: MOVLW 0x10 MOVWF daddr ; set 1 to high addr BCF PORTB,1 ; xxxx1101 SWAPF PORTB,W ; read port B and swap high and low BSF PORTB,1 ; xxxx1111 ANDLW 0x0f ; get low addr ADDWF daddr,F ; set low to ROM addr XORLW 0x0f ; if low addr == 1111(not push row2 key) BTFSS STATUS,Z GOTO Output_Data Row3: MOVLW 0x20 MOVWF daddr BCF PORTB,2 ; xxxx1011 SWAPF PORTB,W ; read port B and swap high and low BSF PORTB,2 ; xxxx1111 ANDLW 0x0f ; get low addr ADDWF daddr,F ; set low to ROM addr XORLW 0x0f ; if low addr == 1111(not push row3 key) BTFSs STATUS,Z GOTO Output_Data No_Input: ; no keys pushed CALL Sleep100ms MOVLW 0xff MOVWF PORTA MOVLW 0x08 MOVWF PORTB BCF INTCON,RBIF SLEEP CALL Buzzer GOTO Main Output_Data: MOVF daddr,W BANKSEL EEADR MOVWF EEADR ; set ROM address BANKSEL EECON1 BCF EECON1,EEPGD BSF EECON1,RD ; RD bit set BANKSEL EEDATA MOVF EEDATA,W ; read ROM data BANKSEL PORTA ; set page0 MOVWF PORTA ; write ROM data to port A GOTO Main ;***** Buzzer routines ***** ; Buzzer connected to PortB:3 ; 1kHz, 20 msec Buzzer: MOVWF w_temp4 MOVLW D'20' MOVWF CNT4 RB3_Hi: BCF PORTB,3 CALL Sleep500us BSF PORTB,3 CALL Sleep500us DECFSZ CNT4, F GOTO RB3_Hi MOVF w_temp4, W RETURN ;***** sleep routines ***** Sleep1s: MOVWF w_temp0 MOVLW D'10' MOVWF CNT0 Loop0: CALL Sleep100ms DECFSZ CNT0, F GOTO Loop0 MOVF w_temp0, W RETURN Sleep100ms: MOVWF w_temp1 MOVLW D'199' MOVWF CNT1 Loop1: CALL Sleep500us DECFSZ CNT1, F GOTO Loop1 MOVF w_temp1,W RETURN Sleep500us: MOVWF w_temp2 MOVLW D'199' MOVWF CNT2 Loop2: NOP NOP DECFSZ CNT2, F GOTO Loop2 MOVF w_temp2,W RETURN END ; directive 'end of program'