Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Pic 16f877 - Interrupts?? HELP REQUIRED!

Status
Not open for further replies.

aidantmurphy

New Member
hiya,

Does any one have any "C-code" for creating interrupts on the Pic 16f877?? and how do i view them on a oscillscope? (i am using a PIC PLUS2 demo board.)

The time delay is set at a constant. Im looking for c-code that when the timer reaches this delay, it causes an interrupt and resets back. id be very grateful we have no experience in using the pic before.
thanks
 
Depending on which C compiler you are using code like this in an interrupt handling function would get triggered when the timer reached the threshold.

Code:
        // TMR1 interrupt handler (assuming that you are using TMR1)
        if(TMR1IF) {
                // reset timer1
                TMR1IF=0;
                /*
                    ..... do whatever e.g. pulse a led, motor coil ...
               */
        }

TMR1IF is the flag that indicates that Timer1 generated an interrupt. You would need to enable global interrupts and the Timer1 interrupt.
Code:
//in a config function somewhere
   GIE = 1;   // global interrupts enabled
    PEIE = 1; // peripheral interrupts enabled
   TMR1IE = 1; // timer1 interrupt enabled

Check your compiler for samples. Remember to keep your interrupt routine small (set flags to trigger operations elsewere) so that it can be fast.

Hope this helps
 
USART Problem

Hi,

I am coding in C for PIC16F73 and I also seem to have problems with the interrupts. I am using nearly the same code for the interrupt routine as I am using tmr1 to time for 20ms (to control servos). when 20ms is reached, the interrupt routine outputs the 1.5ms to the servos.

However, this seem to cause problems to the command received via the USART. Bytes like 0b11110000 or 0b10000000can be received reliably but not 0b10101010 or 0b01111110.

(The interrupt routine services the reception as well. eg. when RCIF is set, the interrupt routine retrieves the received byte from RCREG.)

What seems to be the problem? I suppose what I am trying to do has been done by many people before. How is this kind of problems resovled?

Thanks
 
WIthout seeing any code, the problem might not be with the isr but with the way that the serial data is dealt with.

<shot in the dark> :roll:
Interrupt service routine should execute quickly ... i.e. flag is set that indicates that the USART needs to be processed (this is then done outside of the isr). Could variables be getting corrupted?
</shot in the dark>

Check also that your settings for the USART are correct.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top