PROGRAM N ;*************************************** ; written by: John Morton * ; date: 14/03/05 * ; version: 1.0 * ; file saved as: quiz.asm * ; for PIC12F675 * ; clock frequency: Int. 4 MHz * ; *************************************** ; Program Description: Quiz controller for 3 players, including reset button for the ; quiz master list P=12F675 include Òc:\pic\p12f675.incÓ ;============== ; Declarations: temp equ 20h Post16 equ 21h org 0 ; first instruction to be executed goto Start ; org 4 ; interrupt service routine goto isr ; ;=========== ; Subroutines: Init bsf STATUS, RP0 ; goes to Bank 1 call 3FFh ; calls calibration address movwf OSCCAL ; moves w. reg into OSCCAL movlw bÕ011110Õ ; GP5: Buzzer, GP3: Reset button movwf TRISIO ; GP1,2,4: LEDs/Buttons (inputs ; to start with), GP0: LED enable movlw bÕ010110Õ ; GP1,2,4 have weak pull-ups movwf WPU ; enabled movlw bÕ00000111Õ ; pull-ups enabled, TMR0 presc. movwf OPTION_REG ; by maximum amount (256) clrf PIE1 ; turns off peripheral interrupts movlw bÕ010110Õ ; enables GPIO change interrupt movwf IOC ; on GP1, GP2 and GP4 only clrf VRCON ; turns off comparator V. ref. clrf ANSEL ; makes GP0:3 digital I/O pins bcf STATUS, RP0 ; back to Bank 0 clrf GPIO ; resets input/output port movlw bÕ00001000Õ ; enables GPIO change interrupt movwf INTCON ; only movlw bÕ00000111Õ ; turns off comparator movwf CMCON ; clrf T1CON ; turns off TMR1 clrf ADCON0 ; turns off A to D converter movlw dÕ16Õ ; sets up postscaler movwf Post16 ; retfie ; returns, enabling interrupts ;==================== ; Interrupt Service Routine isr btfss INTCON, 0 ; checks GPIO change int. flag goto Timer ; TMR0 interrupt occurredÉ ; GPIO interrupt occurredÉ bcf INTCON, 0 ; resets interrupt flag comf GPIO, w ; stores state of GPIO andlw b'010110' ; masks all except buttons movwf temp ; btfsc STATUS, Z ; are any buttons actually pressed? retfie ; false alarm bsf STATUS, RP0 ; moves to Bank 1 movlw b'001000' ; makes GP1,2,4 outputs movwf TRISIO ; bcf STATUS, RP0 ; moves to Bank 0 movfw temp ; moves temp back into GPIO, addlw bÕ100001Õ ; sets GP5 and GP0 (turns on movwf GPIO ; buzzer and enables LEDs) movlw bÕ00100000Õ ; enables TMR0 interrupt, disables movwf INTCON ; the GPIO change interrupt retfie ; returns, enabling GIE Timer bcf INTCON, 2 ; resets TMR0 interrupt flag decfsz Post16, f ; is this the 16th TMR0 interrupt retfie ; bcf GPIO, 5 ; turn off buzzer clrf INTCON ; turns off all interrupts sleep ; goes into low power mode ;============ ; Program Start Start call Init ; initialisation routine Main goto Main ; keeps looping END