![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
Hi I am beginner in PIC programming. I need help with Timer1 in PIC 16F877. My code is: list p=16f877a #include <p16f877A.inc> org 000 goto start org 004 nop retfie start bsf STATUS,RP0 bsf PIE1,0 bcf STATUS,RP0 bsf INTCON,7 bsf T1CON,0 man nop nop nop goto man end My problem: I will not receive the interrupt when the Timer1 overflows and I don't know why. The PIR1 <0> bit is correctly set to log1 on overflow. But the interrupt routine don't start. I use the PIC simulator MPLAB IDE 6.6 and MPLAB SIM debugger. | |
| |
| | #2 |
|
I've not bothered looking at the datasheet to test your code, but you're not writing any value to Timer1?.
| |
| |
| | #3 | |
| Quote:
Code: list p=16f877a #include <p16f877A.inc> org 000 goto start org 004 nop ;interrupt routine - doesn't work retfie start bsf STATUS,RP0 bsf PIE1,0 ;allow timer1 interrupt bcf STATUS,RP0 bsf INTCON,7 ;allow global interrupt movlw 000h movwf TMR1L ;set the value movwf TMR1H bsf T1CON,0 ;run timer man nop nop nop goto man end | ||
| |
| | #4 | |
| Quote:
| ||
| |
| | #5 | |
| Quote:
| ||
| |
| | #6 |
|
Two things: 1. You also need to set INTCON,PEIE to enable timer1 interrupts to get through. 2. You have to clear PIR1,TMR1IF in the interrupt service.
__________________ "Having to do with Motion Control" | |
| |
| | #7 | |
| Quote:
PIEI that is it. There is no word in the data sheet. Thank you very much. | ||
| |
|
| Tags |
| pic, timer1 |
| Thread Tools | |
| Display Modes | |
| |