;********************************************************************* ; * ; Tutorial 4 Timer 0 External Counter with variable Prescalor * ; * ;********************************************************************* ;* TARGET PIC16F877 ;********************************************************************* ; An external clock pulse increments Timer0 in counter mode. T ; The current Timer0 prescalor is shown on PortB and the current ; Timer value is displayed on PORTC. ;********************************************************************* ;* @version 0.1, 27 September 2001 ;* @author James Caska ;********************************************************************* list p=16F877 #include ORG .0 GOTO INIT ORG .4 INTERRUPTHANDLER BSF STATUS,RP0 BCF OPTION_REG,PSA INCF OPTION_REG,F BCF OPTION_REG,PSA ;Increment the Prescalor MOVF OPTION_REG,W BCF STATUS,RP0 CALL LOOKUPSCALOR MOVWF PORTC BCF INTCON,T0IF RETFIE LOOKUPSCALOR ANDLW .7 ADDWF PCL,F RETLW .2 RETLW .4 RETLW .8 RETLW .16 RETLW .32 RETLW .64 RETLW .128 RETLW .255 ;* Is really 256 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 A MOVLW .63 ;PORTA Configuration Bits MOVWF TRISA ;======PORT B MOVLW .0 ;PORTB Configuration Bits MOVWF TRISB ;======PORT C MOVLW .0 ;PORTC Configuration Bits MOVWF TRISC 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 BSF OPTION_REG,PS0 ;Create so when we INC the first time in the interrupt goes to zero BSF OPTION_REG,PS1 BSF OPTION_REG,PS2 BCF OPTION_REG,T0CS ;T0CS: TMR0 Clock Source Select bit: 0 = Internal instruction cycle clock (CLKOUT) BSF OPTION_REG,PSA ;PSA: Prescaler Assignment bit:1 = Prescaler is assigned to the WDT 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 BSF INTCON, GIE ;Enable Interrupts MOVLW .1 ;Note initially there is no prescalor 1:1 MOVWF PORTC MAIN MOVF TMR0,W MOVWF PORTB GOTO MAIN END