mitchf14
- 9th January 2009, 16:13
I'm learning how to use the hardware timers, and it can't seem to get the TMR1 working, i am using a pic16f628 with two 4 mhz crystals 1 on pins ra6,ra7 and they other on pins rb6,rb7 which i don't know for sure if it is necessary or should just use they internal crystal ?
This is the code i have so far
LED VAR PORTB.0
LED1 VAR PORTB.1
ON INTERRUPT GOTO TIMER1INT
LED = 0
LED1 = 0
TRISA = %00000000
TRISB = %00000000
INTCON.7 = 1 ' ENABLE THE GLOBAL INTERRUPT
PIE1.0 = 1 ' ENABLE THEY TMR1 INTERRUPT
T1CON.1 = 1 ' SETS THE MODE TO EXTERNAL CLOCK RB6,RB7
T1CON.2 = 0 ' SYNCORNOSES BOTH CRYSTALS
T1CON.3 = 1 ' ENABLES THEY OSCILATOR RB6,RB7 ON
T1CON.4 = 1 ' SETS THE SECOND BIT OF THE PRESCALER
T1CON.5 = 1 ' SETS THE FIRST BIT OF THE PRESCALER
TMR1L = 220 ' SETS THE LOW BIT PRESCALER
TMR1H = 11 ' SETS THE HIGH BIT PRESCALER
T1CON.0 = 0 ' ACTIVES THE TIMER
Start:
GoTo Start
TIMER1INT:
IF LED = 1 THEN
LED = 0
LED1 = 1
ELSE
LED = 1
LED1 = 0
ENDIF
RETURN
end
Could really use some help thanks.
This is the code i have so far
LED VAR PORTB.0
LED1 VAR PORTB.1
ON INTERRUPT GOTO TIMER1INT
LED = 0
LED1 = 0
TRISA = %00000000
TRISB = %00000000
INTCON.7 = 1 ' ENABLE THE GLOBAL INTERRUPT
PIE1.0 = 1 ' ENABLE THEY TMR1 INTERRUPT
T1CON.1 = 1 ' SETS THE MODE TO EXTERNAL CLOCK RB6,RB7
T1CON.2 = 0 ' SYNCORNOSES BOTH CRYSTALS
T1CON.3 = 1 ' ENABLES THEY OSCILATOR RB6,RB7 ON
T1CON.4 = 1 ' SETS THE SECOND BIT OF THE PRESCALER
T1CON.5 = 1 ' SETS THE FIRST BIT OF THE PRESCALER
TMR1L = 220 ' SETS THE LOW BIT PRESCALER
TMR1H = 11 ' SETS THE HIGH BIT PRESCALER
T1CON.0 = 0 ' ACTIVES THE TIMER
Start:
GoTo Start
TIMER1INT:
IF LED = 1 THEN
LED = 0
LED1 = 1
ELSE
LED = 1
LED1 = 0
ENDIF
RETURN
end
Could really use some help thanks.