bayabi
Newbie level 6
Hello there
I have the following code in order to drive my step motor and use some functions I want to implement. However; whenever it is supposed to undergo interrupt part, it does not work and stops right there? I want to use RB0 pin s external interrupt feature. I dont want to use interrupt priority, thus I didnt define interrupt_high_vector nor low_vector:
*Is it because I forgot to include some header files?
*Or I define interrupt incorrectly?
*Or is there another way to use RB0 interrupt that i am missing?
*Or do i have to define interrupt_high and interrupt_low even if i dont use priority?
#include <p18cxxx.h>
#include <delays.h>
#include "..\usb\typedefs.h"
//-----------------------------
#pragma config CPUDIV = OSC1_PLL2,PLLDIV = 5,USBDIV = 2
#pragma config FOSC = HSPLL_HS,IESO = OFF
#pragma config PWRT = OFF,BOR = OFF,VREGEN = ON
#pragma config WDT = OFF,MCLRE = OFF,LPT1OSC = OFF
#pragma config PBADEN = OFF,LVP = OFF
static BOOL optCnt = TRUE;
//byte const step[4] = {0xAA,0x99,0x55,0x66}; //sag=1, sol=0
byte const step[4] = {0x33,0xAA,0xCC,0x55};
void inter(void);
void MotorSur(int Adim,int Yon);
void SetOutput(byte output);
void hassas_ayar();
#pragma interrupt inter
void inter(void)
{
INTCONbits.INT0IF = 0;
INTCONbits.GIE = 0;
hassas_ayar();
//hassas_ayar();
}
void hassas_ayar()
{
while (PORTBbits.RB0 == 0 && optCnt )
{
MotorSur(8,1); //sağa 5 adım
}
while (PORTBbits.RB0 == 1 && optCnt )
{
MotorSur(5,0); //sola 1 adım
}
optCnt =FALSE;
}
void send_to_left()
{
MotorSur(50,0); //sola 50 adım
}
void main (void)
{
TRISB = 0x01;
ADCON1 = 0xFF;
TRISA = 0x00;
if (PORTBbits.RB0 == 1)
{
INTCONbits.GIE = 1;
INTCONbits.INT0IE = 1;
INTCONbits.INT0IF = 0;
INTCON2bits.INTEDG0 = 0;
while(optCnt)
{
send_to_left();
}
}
else if(PORTBbits.RB0 == 0)
{
hassas_ayar();
}
}
void MotorSur (int Adim,int Yon)
{
int i;
if (Yon == 1)
{
for(i = Adim; i>0; i--)
{
byte output = step[i%4];
SetOutput(output);
Delay10KTCYx(2);
SetOutput(0x00);
Delay10KTCYx(2);
}
}
else if (Yon == 0)
{
for(i = 0; i<Adim; i++)
{
byte output = step[i%4];
SetOutput(output);
Delay10KTCYx(2);
SetOutput(0x00);
Delay10KTCYx(2);
}
}
}
The code continues but important part for me is the interrupt part
Thanks for your attention
I have the following code in order to drive my step motor and use some functions I want to implement. However; whenever it is supposed to undergo interrupt part, it does not work and stops right there? I want to use RB0 pin s external interrupt feature. I dont want to use interrupt priority, thus I didnt define interrupt_high_vector nor low_vector:
*Is it because I forgot to include some header files?
*Or I define interrupt incorrectly?
*Or is there another way to use RB0 interrupt that i am missing?
*Or do i have to define interrupt_high and interrupt_low even if i dont use priority?
#include <p18cxxx.h>
#include <delays.h>
#include "..\usb\typedefs.h"
//-----------------------------
#pragma config CPUDIV = OSC1_PLL2,PLLDIV = 5,USBDIV = 2
#pragma config FOSC = HSPLL_HS,IESO = OFF
#pragma config PWRT = OFF,BOR = OFF,VREGEN = ON
#pragma config WDT = OFF,MCLRE = OFF,LPT1OSC = OFF
#pragma config PBADEN = OFF,LVP = OFF
static BOOL optCnt = TRUE;
//byte const step[4] = {0xAA,0x99,0x55,0x66}; //sag=1, sol=0
byte const step[4] = {0x33,0xAA,0xCC,0x55};
void inter(void);
void MotorSur(int Adim,int Yon);
void SetOutput(byte output);
void hassas_ayar();
#pragma interrupt inter
void inter(void)
{
INTCONbits.INT0IF = 0;
INTCONbits.GIE = 0;
hassas_ayar();
//hassas_ayar();
}
void hassas_ayar()
{
while (PORTBbits.RB0 == 0 && optCnt )
{
MotorSur(8,1); //sağa 5 adım
}
while (PORTBbits.RB0 == 1 && optCnt )
{
MotorSur(5,0); //sola 1 adım
}
optCnt =FALSE;
}
void send_to_left()
{
MotorSur(50,0); //sola 50 adım
}
void main (void)
{
TRISB = 0x01;
ADCON1 = 0xFF;
TRISA = 0x00;
if (PORTBbits.RB0 == 1)
{
INTCONbits.GIE = 1;
INTCONbits.INT0IE = 1;
INTCONbits.INT0IF = 0;
INTCON2bits.INTEDG0 = 0;
while(optCnt)
{
send_to_left();
}
}
else if(PORTBbits.RB0 == 0)
{
hassas_ayar();
}
}
void MotorSur (int Adim,int Yon)
{
int i;
if (Yon == 1)
{
for(i = Adim; i>0; i--)
{
byte output = step[i%4];
SetOutput(output);
Delay10KTCYx(2);
SetOutput(0x00);
Delay10KTCYx(2);
}
}
else if (Yon == 0)
{
for(i = 0; i<Adim; i++)
{
byte output = step[i%4];
SetOutput(output);
Delay10KTCYx(2);
SetOutput(0x00);
Delay10KTCYx(2);
}
}
}
The code continues but important part for me is the interrupt part
Thanks for your attention