;********************************************************************* ; * ; Tutorial 16 One Shot Timer * ; * ;********************************************************************* ;* TARGET PIC16F877 ;********************************************************************* ; Uses the two compare modules to create one shot timers. ; ;********************************************************************* ;* ;* @version 0.1, 24 September 2001 ;* @author James Caska ;********************************************************************* list p=16F877 #include FLAGS EQU .32 TOGGLE EQU .0 ORG .0 GOTO INIT ;********************************************************************** ;* InterruptVector ;********************************************************************** ORG .4 InterruptVector ;========================================== ;Autogenerated configuration code PIC16F877 ;Config Wiz V0.1, www.virtualbreadboard.com ;========================================== ;======Turn off Timer1 BCF T1CON, TMR1ON ;TMR1ON 0 = Stops Timer1 ;======Nothing else to do.. the Timer is disabled CLRF TMR1L CLRF TMR1H BTFSS INTCON,INTF GOTO Oneshot.end Oneshot.start MOVF PORTB,W MOVWF CCPR1L MOVWF CCPR2L MOVF PORTD,W MOVWF CCPR1H MOVWF CCPR2H BSF PORTC,0 BCF INTCON,INTE ;Disable the INTB0 BSF INTCON, PEIE ;Enabled Peripheral Interrupts GOTO Toggle.CCP1Function Oneshot.end BSF INTCON,INTE ;Enable the INTB0 BCF PORTC,0 BCF INTCON, PEIE ;Disable Peripheral Interrupts Toggle.CCP1Function MOVLW .1 XORWF FLAGS,F BSF CCP1CON,0 ;1001 Compare mode, clear output on match (CCPxIF bit is set) BTFSS FLAGS,TOGGLE BCF CCP1CON,0 ;1000 Compare mode, set output on match (CCPxIF bit is set) BCF INTCON,INTF ;Clear the INTCON Interrupt flag BCF PIR2,CCP2IF ;Ensure CCP1IF InterruptFlag Clear BSF T1CON, TMR1ON ;TMR1ON 1 = Starts the Timer1 RETFIE INIT ;========================================== ;Autogenerated configuration code PIC16F877 ;Config Wiz V0.1, www.virtualbreadboard.com ;========================================== ;======Begin PORT Configuration BSF STATUS, RP0 ;PORT TRIS Registers are on page 1 ;======PORT B MOVLW .255 ;PORTB Configuration Bits MOVWF TRISB ;======PORT C MOVLW .0 ;PORTC Configuration Bits MOVWF TRISC ;======PORT D MOVLW .255 ;PORTd Configuration Bits MOVWF TRISD BCF STATUS, RP0 ;Restore Page0 ;========================================== ;Autogenerated configuration code PIC16F877 ;Config Wiz V0.1, www.virtualbreadboard.com ;========================================== ;======Begin INTBO Configuration BCF INTCON, INTF ;Clear Interrupt flag BSF STATUS,RP0 ;Access bank 1 BSF OPTION_REG,INTEDG ;Rising Edge Detect BCF STATUS,RP0 ;Restore bank 0 BSF INTCON,INTE ;Enable the INB0 Interrupt ;========================================== ;Autogenerated configuration code PIC16F877 ;Config Wiz V0.1, www.virtualbreadboard.com ;========================================== ;====== CONFIGURE CCP1 CLRF CCP1CON ;Turn CCP module off MOVLW B'00001000' ;1000 Compare mode, set output on match (CCPxIF bit is set) MOVWF CCP1CON ;====== CONFIGURE CCP2 CLRF CCP2CON ;Turn CCP module off MOVLW B'00001010' ;1010 Compare mode, generate software interrupt on match (CCPxIF bit is set, CCPx pin is unaffected) MOVWF CCP2CON ;======CCP2 Interrupt BCF PIR2,CCP2IF ;Ensure CCP1IF InterruptFlag Clear BSF STATUS,RP0 ;Access Bank1 BSF PIE2,CCP2IE ;Enable CCP2 Interrupts on Page1 BCF STATUS,RP0 ;Restore Bank0 ;========================================== ;Autogenerated configuration code PIC16F877 ;Config Wiz V0.1, www.virtualbreadboard.com ;========================================== ;======Timer1 Timer Mode, uses Internal clock BCF T1CON, TMR1CS ;TMR1CS 0 = Internal clock (FOSC/4) ;======Prescalor Configuration BCF T1CON, T1CKPS0 ;1:1 BCF T1CON, T1CKPS1 CLRF TMR1L CLRF TMR1H BSF INTCON,GIE ;Turn on Global Interrupt MAIN GOTO MAIN END