;********************************************************************* ; * ; Tutorial 11 TMR0 write causes 2 cycle inhit, prescalar clears* ; * ;********************************************************************* ;* TARGET PIC16F877 ;********************************************************************* ; Any instruction that write to the TMR0 register inhibits the ; increment for 2 clock cycles and clears the prescalor. ; ; This can result in unexpected results if not taking into ; consideration ; ; ;********************************************************************* ;* ;* @version 0.1, 20 September 2001 ;* @author James Caska ;********************************************************************* list p=16F877 #include COUNTER EQU .32 TEMP EQU .33 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 TIMERloop MOVLW .0 ADDWF TMR0 NOP ADDWF TMR0 NOP NOP ADDWF TMR0 NOP NOP NOP NOP ADDWF TMR0 NOP NOP NOP NOP NOP NOP NOP NOP ADDWF TMR0 RETURN 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, T0IE ;Timer 0 InterruptEnableOff ;======End Timer0 Configuration MAIN CLRF TMR0 CALL TIMERloop MOVF TMR0,W MOVWF PORTB GOTO MAIN END