;********************************************************************* ; * ; Tutorial 9 1ms Duty, 500Hz Signal using Timer0 * ; * ;********************************************************************* ;* TARGET PIC16F877 ;********************************************************************* ; Tests the Timer0 in Timer mode, with preload and prescalor, ; ; Expected Result. ; ; PortB<0> to toggle high/low every 1ms, creating a 500Hz signal ;********************************************************************* ;* ;* @version 0.1, 20 September 2001 ;* @author James Caska ;********************************************************************* list p=16F877 #include ORG .0 GOTO INIT ;********************************************************************** ;* InterruptVector ;********************************************************************** ;* The Interrupt is called on Timer0 overflow ;********************************************************************** ORG .4 InterruptVector MOVLW .1 XORWF PORTB,F MOVLW .6 ;Preload (add) TMR0 ADDWF TMR0,F BCF INTCON,T0IF ;Clear Timer0 Interrupt 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 .0 ;PORTB Configuration Bits MOVWF TRISB BCF STATUS, RP0 ;Restore Page0 ;========================================== ;Autogenerated configuration code PIC16F877 ;Config Wiz V0.1, www.virtualbreadboard.com ;========================================== ;======Begin Timer0 Configuration BSF STATUS, RP0 ;Timer 0 config register on page 1 ;======Timer0 Timer Mode, uses Internal clock BCF OPTION_REG,T0CS ;T0CS: TMR0 Clock Source Select bit: 0 = Internal instruction cycle clock (CLKOUT) ;======Timer0 Prescalor Configuration BCF OPTION_REG,PSA ;PSA: Prescaler Assignment bit:0 = Prescaler is assigned to the Timer0 module BSF OPTION_REG, PS0 ;1:4 BCF OPTION_REG, PS1 BCF OPTION_REG, PS2 BCF STATUS, RP0 ;Restore page 1 ;======Timer0 Interrupt Configuration BCF INTCON, T0IF ;Timer 0 Clear Timer0 Interrupt flag BSF INTCON, T0IE ;Enabled Timer 0 Interrupt Mask ;======End Timer0 Configuration CLRF TMR0 ;First shot not pre-loaded BSF INTCON,GIE ;Turn on the global interrupt MAIN GOTO MAIN END