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.

Could someone please help!!!

Status
Not open for further replies.

aidantmurphy

New Member
The following is my code for creating interrupts. My problem is that the delay is 20ms, i want the user to be able to change the delay as they wish. Does anyone know how to do this? Have been looking at it how a couple of days now and im basically confusing myself.

#include <io16f877.h>


#pragma vector = 0x1
__interrupt void externISR()
{
if(INTF) //loop controllling software design of interrupts on PIC
{
RA0 = 0; // ensuring RA0 set low
// TMR1H and TMR1L = TMR1
TMR1H = 0xF6; // Pre - load timer with this value = 63035
TMR1L = 0x3B; // We want an overflow after 2500 ticks (interval of 20ms)
// As (2^16 -1)-2500 = 63035
TMR1IF = 0; // no interrupt flag
while(!TMR1IF); // interrupt flag ocuuring

RA0 = 1; // RA0 set high when interrupt occurs

INTF = 0; //related with INTCON register in void main, set to 0 here to clear interrupt.
}
}

void main()
{
TRISA = 0x0; //Set as an output on PortA
TRISB = 0x1; //Set as an input on PortB
RA0 = 0; // RA0 always set low

INTEDG = 0x1; // Set to trigger off the rising clock edge.
INTCON = 0x90; //this is our control and status of our interrupts.
T1CON = 0x3d; // sets the prescaler value of clock 1:8, oscillator enabled,internal clock selected
TMR1IE = 1;
TMR1IF = 0; // set at zero, flags are seen when = 1

while(1);
}
 
Here is a modified way of manipulating the TRM1 High and Low, that I picked up from https://www.microchipc.com (I've used this with Hi-Tech C picclite compiler on 16f877).

Code:
static int TICK_PERIOD;

#define TMR1_RESET (0xFFFF - TICK_PERIOD)
#define TMR1_RESET_HIGH TMR1_RESET >> 8
#define TMR1_RESET_LOW TMR1_RESET & 0xFF

TMR1H = TMR1_RESET_HIGH;
TMR1L = TMR1_RESET_LOW;

TICK_PERIOD can be then manipulated by the user (serial, buttons etc ...).

Hope this helps
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top