Program M : ;************************************ ; written by : John Morton * ; date : 24/08/97 * ; version : 1.0 * ; file saved as : Quiz * ; for PIC71 * ; clock frequency : 2.47 MHz * ;************************************ ; PROGRAM FUNCTION : To detect which of four push buttons has been pressed first ; and turn on the corresponding LED. A buzzer is also turned on for one second. list P=16C71 include "c:\pic\p16c71.inc" ;============ ; Declarations : porta equ 05 portb equ 06 Ten equ 0C org 0 goto Start ;=========== ; Subroutines : Init clrf porta ; resets input/output ports clrf portb goto InitContinue ; skips address 0004 goto isr ; at address 0004, goes to isr InitContinue bsf STATUS, 5 ; selects bank 1 clrf TRISA ; RA0 : buzzer, RA1 - RA4 : not connected movlw b'11110000' ; RB0 - RB3 : LEDs, RB4 - RB7 : push buttons movwf TRISB ; movlw b'10000111' ; sets up timing register (Port B pull-ups OFF!) movwf OPTION_REG ; bcf STATUS, 5 ; goes back to bank 0 movlw b'10001000' ; enables RBChange, and global interrupts movwf INTCON ; movlw d'10' ; moves the decimal number 10 into the G.P.F. movwf Ten ; called Ten return ; returns from interrupt ;======== isr btfss INTCON, 0 ; tests RBChange flag b Timer ; TMR0 interrupt occured ; RBChange interrupt occured swapf portb, f ; turns appropiate LED on bsf porta, 0 ; turns on buzzer movlw b'00100000' ; enables TMR0 interrupt, disables RBChange movwf INTCON ; retfie ; returns, setting the global interrupt enable Timer bcf INTCON, 2 ; resets TMR0 interrupt flag decfsz Ten, f ; has this happened 10 times? retfie ; no, so returns, enabling the global int. bit bcf porta, 0 ; yes, so turns off buzzer movlw b'10001000' ; global and RBChange enabled movwf INTCON ; sleep ; goes into low power consuming mode return ;============= ; Program Start : Start call Init ; sets everything up Main goto Main ; keeps looping until interrupted END