TITLE "HZSO2R.asm" ;====================================================================================================== ;* HZSO2R ;* SO2R Audio controller ;* Version 1.0 ;* ;* Dr. Pedro E. Colla (LU7HZ) Argentina 2011 ;====================================================================================================== ;* Compiler directives ;====================================================================================================== List P=12F675, R=DEC INCLUDE "p12F675.inc" ;*---> Uncomment when debugging .... ;#DEFINE DEBUG ;====================================================================================================== ;* EQUates ;====================================================================================================== ;*------------------------------------------------------------------------------------------------- ;* General EQUates ;*------------------------------------------------------------------------------------------------- PERIOD EQU 12D ; Final delay is PERIOD*TIMEBASE*1 mSec ;====================================================================================================== ;* MACROS ;====================================================================================================== ;*------------------------------------------------------------------------------------------------- ;* Macro to Read from EEPROM ;* Address to read informed at WData to write assumed to be left at W (pls note his is not a call but inline code). ;* Data recovered returned on W ;*------------------------------------------------------------------------------------------------- READEE MACRO ; Data is at W bsf STATUS,RP0 movwf EEADR bsf EECON1,RD movf EEDATA,W bcf STATUS,RP0 ENDM ; End of macro ;*------------------------------------------------------------------------------------------------- ;* Macro to Write into from EEPROM ;* Data to write assumed to be at W, while address is stored on a memory variable called TEMP ;*------------------------------------------------------------------------------------------------- WRITEE MACRO ; Data in W local wait bsf STATUS,RP0 ; set bank1 wait CLRWDT ; clear watchdog btfsc EECON1,WR ; Verify if there is an on-going write goto wait ; Yes, wait bcf STATUS,RP0 ; Move to Bank1 movwf EEDATA ; Load data into register movf TEMP,W ; Change writing address movwf EEADR ; Load into register bsf STATUS,RP0 ; Swap to Bank1 ;*--- This is black magic as recommended by the 12F675 data sheet bcf EECON1,EEIF ; Raise EoW flag bsf EECON1,WREN ; Allow access to write movlw 0x55 ; Load 0x55 movwf EECON2 ; send command movlw 0xAA ; Load 0xAA movwf EECON2 ; send commaand ;*--- End of black magic bsf EECON1,WR ; complete writing cycle bcf EECON1,WREN ; Continue with next bcf STATUS,RP0 ; return to Bank0 endm ;*------------------------------------------------------------------------------------------------- ;* DATA segment ;*------------------------------------------------------------------------------------------------- CBLOCK 0x20 DEL ; Delay variable TEMP ; Temporary variable for general use GPIOx ; DEBUG DX ; Counter, auxiliar CX ; Counter, auxiliar BX ; Counter, auxiliar ENDC ;*------------------------------------------------------------------------------------------------- ;* CODE segment ;*------------------------------------------------------------------------------------------------- PAGE ifdef DEBUG __CONFIG _BODEN_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT else __CONFIG _BODEN_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT endif ;*------------------------------------------------------------------------------------------------- ;* Interrupt vector table (BOOT origin) ;*------------------------------------------------------------------------------------------------- Org 0x00 ; Start program at the beginning of the CODE area GOTO INIT ORG 0x04 ; Better not enable GIE otherwise, He'll loop! INTVEC GOTO INTVEC ;*------------------------------------------------------------------------------------------------- ;* main performing loop ;*------------------------------------------------------------------------------------------------- main ;*------------------------------------------------------------------------------------------------- ;* Get status from all three inputs ;*------------------------------------------------------------------------------------------------- btfss GPIO,2 goto SetA_B btfss GPIO,5 goto SetA btfss GPIO,4 goto SetB ;*------------------------------------------------------------------------------------------------- ;* Wait till next verify ;*------------------------------------------------------------------------------------------------- call delay100 ; wait 100 mSec goto main ;*------------------------------------------------------------------------------------------------- ;* Debouncer for A+B switch ;*------------------------------------------------------------------------------------------------- SetA_B bcf GPIO,0 bcf GPIO,1 waitA_B btfsc GPIO,2 goto main call delay100 goto waitA_B ;*------------------------------------------------------------------------------------------------- ;* Debouncer for A switch ;*------------------------------------------------------------------------------------------------- SetA bsf GPIO,0 bcf GPIO,1 waitA btfsc GPIO,5 goto main call delay100 goto waitA ;*------------------------------------------------------------------------------------------------- ;* Debouncer for B switch ;*------------------------------------------------------------------------------------------------- SetB bcf GPIO,0 bsf GPIO,1 waitB btfsc GPIO,4 goto main call delay100 goto waitB ;*------------------------------------------------------------------------------------------------- ;* This is the tailored version of the master delay, expected to last 100 mSec ;*------------------------------------------------------------------------------------------------- delay100 movlw 02H movwf BX delay100start movlw 7fH movwf CX decfsz BX,1 goto delay100loop goto delay100end delay100loop call delay decfsz CX,1 goto delay100loop goto delay100start delay100end return ;*------------------------------------------------------------------------------------------------- ;* This is the master delay routine, all delays are built using it ;* delay routine (5 uSecs * 200 = 1 mSec) for PIC12675 @ 4 MHz ;*------------------------------------------------------------------------------------------------- delay ; a delay for del milliseconds movlw 1 ; movwf DEL ; delayloop movlw 200 delay0 sublw 1 ; this loop takes 5us*200 = 1ms sublw 0 btfss STATUS, Z ; goto $-3 ; decfsz DEL,1 ; goto delayloop ; return ; ;*------------------------------------------------------------------------------------------------- ;* Initialization code ;* External inputs has been mapped as ;* bit 0 GP0 (o) Digital (=0 Pulsed,=1 Open) ;* bit 1 GP1 (o) Digital (=0 Rotary,=1 Counter) ;* bit 2 A+B (i) Select A+B ;* bit 3 A (i) Select A ;* bit 4 B (i) Select B ;* bit 5 N/A (o) Not used ;* ;*------------------------------------------------------------------------------------------------- INIT bcf STATUS,RP0 ; select BANK0 clrf GPIO ; clear GPIO clrf INTCON ; clear INTCON (all interrupts disabled) movlw 0x07 ; movwf CMCON ; comparator OFF movlw B'00000000' ; init A/D ensure shift to left thru channel AN1 movwf ADCON0 ; ;*--- BANK1 bsf STATUS,RP0 ; select BANK1 movlw B'00000000' ; No input is analog movwf ANSEL ; clrf PIE1 ; reset peripherical clrf IOC ; clrf WPU ; movlw B'00001111' ; Assign pre-scaler to WDT and 1:128 value (2.18 Sec) movwf OPTION_REG ; movlw B'00111100' ; Assign pins as per the definition of inputs and outputs movwf TRISIO ; ;*--- End of BANK1 bcf STATUS,RP0 ; select BANK0 again clrf GPIO ;*--- Initialization test movlw 3 movwf DX looptest movlw 0ffh movwf GPIO call delay100 movlw 00h movwf GPIO call delay100 decfsz DX goto looptest movlw 00h movwf GPIO goto main ;*---- End of code ;*=================================================================================================== ;* EEPROM ;* Variables to be left at EEPROM memory ;*=================================================================================================== org 0x2100 ; Starting EEPROM Address CTLWS DE 08h end