AtomSoft
Well-Known Member
Ok for some reason i keep getting a halt on my second delay
Code:
#pragma config OSC=INTIO2, WDT=OFF, LVP=OFF, DEBUG=ON
#include <p18f1320.h>
// ----------------------------------------------------------
void InterruptHandlerHigh(void);
void InterruptVectorHigh(void);
void MyDelay(int x);
void MyFlash(int qTimes);
// ----------------------------------------------------------
void main(void)
{
int count;
int countA = 0;
ADCON1 = 0; // make RA0 digital
TRISA = 0b10111110;
while(1) // loop forever
{
LATA=0b00000001; // Turn LED on
MyDelay(200);
LATA=0b00000000; // Turn LED off
[b] MyDelay(200); // The program halts here. Any thoughts?[/b]
countA = countA + 1;
if (countA > 3) {
MyFlash(3);
countA = 0;
}
}
}
// ----------------------------------------------------------
void MyDelay(int xD)
{
int countD = 0;
while (countD < xD)
{
countD = countD + 1;
}
}
// ----------------------------------------------------------
void MyFlash (int qTimes)
{
int x = qTimes;
while(x != 0) {
TRISA = 0b10111110;
LATA = 0b00000001;
MyDelay(10);
LATA = 0b01000000;
MyDelay(10);
TRISA = 0b00111111;
LATA = 0b01000000;
MyDelay(10);
LATA = 0b10000000;
MyDelay(10);
TRISA = 0b01111110;
LATA = 0b10000000;
MyDelay(10);
LATA = 0b00000001;
MyDelay(10);
x--;
}
TRISA = 0b10111110;
}
//----------------------------------------------------------------------------
// High priority interrupt vector
#pragma code InterruptVectorHigh = 0x08
void InterruptVectorHigh (void)
{
_asm
goto InterruptHandlerHigh //jump to interrupt routine
_endasm
}
//----------------------------------------------------------------------------
// High priority interrupt routine
#pragma code
#pragma interrupt InterruptHandlerHigh
void InterruptHandlerHigh ()
{
int countF;
if (INTCONbits.RBIF) {
INTCONbits.RBIF = 0; //clear interrupt flag
countF = 15;
INTCON3 = 0;
MyFlash(20);
}
}
}
//----------------------------------------------------------------------------
Last edited: