PDA

View Full Version : Timers and Interrupts



senior project1
- 25th November 2008, 06:10
Hi
I have a code that should write on Port B on the P18F452. It should write on the first timer's interrupt four states on Port B and then wait for the next interrupt. What happens is that it doesn't write the right sequence, can any one figure out why?

My code:
-----------------------------

#include <p18f452.h>
#include <timers.h>
#include <delays.h>

/* Set configuration bits
* - set RC oscillator
* - disable watchdog timer
* - disable low voltage programming
* - disable brownout reset
* - enable master clear
*/

#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config BOR = OFF
//#pragma config MCLRE = ON

unsigned int count=0;

void MyHighInt(void); // prototypes for the interrupt
#pragma interrupt MyHighInt // MyHighInt is an interrupt
#pragma code high_vector=0x08 // high_vector is at 0x0008

void high_vector(void) // the high prioity vector
{
_asm GOTO MyHighInt _endasm // goto high software
}
#pragma code // start code here
void MyHighInt(void)
{
char myarry[16]={0x60,0x65,0x66,0x6B,0x60,0x64,0x66,0x6A,0x62,0x6 3,0x68,0x69,0x61,0x67,0x68,0x69};
char arry[16]={0x20,0x25,0x26,0x2B,0x20,0x24,0x26,0x2A,0x22,0x2 3,0x28,0x29,0x21,0x27,0x28,0x29};
int j,i;
TRISB=0x00;
INTCONbits.TMR0IF=0;
for(i=0;i<16;i++)
{
PORTB=arry[i];
}

for(j=count;j<count+4;j++)
{
PORTB=myarry[j];
if(j==15)
count=0;
}

count=count+4;
}

// main program
void main (void)
{

INTCON2bits.TMR0IP=1;
INTCONbits.TMR0IF=0;
INTCONbits.TMR0IE=1;
T0CONbits.TMR0ON=1;

OpenTimer0 (TIMER_INT_ON & T0_8BIT & T0_SOURCE_INT & T0_PS_1_8);
RCONbits.IPEN = 1; // IPEN = 1 to enable priority interrupts
INTCONbits.PEIE=1;
INTCONbits.GIEH = 1; // enable high priority interrupt

while(1);
}

HenrikOlsson
- 25th November 2008, 08:02
Hi,
I'm sure someone will be able to figure it out but the chance of getting hold of that someone is much bigger if you post the question on the forum for your particular compiler. This forum is targeting PicBASIC and PicBASICPRO from MicroEngineeringLabs and you are obviously using some flavour of C.

Good luck!
/Henrik.

Bruce
- 25th November 2008, 14:17
You want the Microchip C18 compiler forum here: http://forum.microchip.com/