;********************************************************************* ; * ; Tutorial 8 Timer0 Counter Bar-Graph Tacho * ; * ;********************************************************************* ;* TARGET PIC16F877 ;********************************************************************* ; Counts the clocks on A4/TOKI in a accumulation period and shows ; a bar graph value representative of the accumulated count on ; PortB ; ; Expected Result. ; ; Using a Ramping frequency stimulus file, the bargraph is ; expected to start empty and then increment until all elements ; are lit up before reseting to all clear. ;********************************************************************* ;* ;* @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 LOOKUPBARGRAPH MOVWF TEMP ANDLW B'11111000' ;If 8 or greater then return maximum bar graph BTFSS STATUS,Z RETLW B'11111111' MOVF TEMP,W ADDWF PCL,F RETLW B'00000000' RETLW B'00000001' RETLW B'00000011' RETLW B'00000111' RETLW B'00001111' RETLW B'00011111' RETLW B'00111111' RETLW B'01111111' RETLW B'11111111' 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 .16 ;PORTA Configuration Bits MOVWF TRISA ;======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 Counter Mode, uses External clock source BSF OPTION_REG,T0CS ;T0CS: TMR0 Clock Source Select bit: 1 = Transition on T0CKI pin BCF OPTION_REG,T0SE ;T0SE: TMR0 Source Edge Select bit: 0 = Increment on low-to-high transition on T0CKI pin 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, T0IE ;Timer 0 InterruptEnableOff ;======End Timer0 Configuration MAIN CLRF TMR0 MOVLW .255 MOVWF COUNTER ;================================ ; Wait for Measurement period [TimeBase] ;================================ LOOP NOP NOP NOP DECFSZ COUNTER,F GOTO LOOP ;================================ ; Construct the BarGraph [0..10] ;================================ MOVF TMR0,W CALL LOOKUPBARGRAPH MOVWF PORTB GOTO MAIN END