Need help with Interrupts !!!

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need help with Interrupts !!!

909 Views
oldspice12
Contributor I
Hi everyone I am using the the Dragon 12 Plus and the GNU compiler. I am having a major problem using interrupts to completing my project. For my project I am using a sensor to measure a distance and when the distance is under 30 ins it should activate a timer that would count to 10 (displayed on the seven segment) and stop but if the sensor measures under 30 ins again it should restart the counter and count to ten again even if the counter is already counting. The problem that I am having is that every time it measures under 30 ins the counter doesn't want to restart. I have posted the code in question. Any help would be greatly appreciated. Thank You
#include <hcs12.h>
#include <delay.c>
#include <stdio.c>
#include <lcdUtilDragon12.c>
#include <convert.c>
#include <vectors12.h>
//#include <SetClK.c>
#define  INTERRUPT __attribute__((interrupt))
void     INTERRUPT rtiISR(void);
void waitfor20us(void);
void openAD0(void);
char buf[8];
char *msg1 = "Distance = ";
char *blanks = "                ";
char segPat[13] = {0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x67,0x3F,
                   0x06,0x5B,0x4F};
char digit[4]={0xFE,0xFD,0xFB,0xF7};
 char digits[9]=  {0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};
 int temp1,temp2,count1,count2,time,seq,ix,count ;
     char sign,fdigit,frem;
     char *ptr;
    char i,p;
int main()
{
    DDRB=   0xFF;    // configure Port B for output
    DDRP=   0x0F;
     delayby100ms(2);
     openLCD();
     openAD0();
     cmd2LCD(0x80);
     putsLCD(msg1);
    seq     = 0;
    ix      = 0;
    count   = 400;
    asm("ldd #rtiISR");
    asm("pshd");
    asm("ldd #56");
    asm("ldx 0xEEA4");
    asm("jsr 0,x");
    RTICTL  = 0x40; //RTI interrupt interval set to 2**10 OSCCLK cycles
    DDRB    = 0xFF; //configure Port B for output
    DDRP    = 0xFF; //configure Port P for output
  //  CRGINT  |= RTIE;//enable RTI interrupt
   // asm("CLI");     //enable interrupt globally
    //while(1);
     while(1) {
        sign = 0;
        ATD0CTL5 = 0x86;
        while(!(ATD0STAT0 & SCF));
        temp1 = (ATD0DR0 * 10) / 50;
        if (temp1 < 30) {
            CRGINT |= RTIE;
          //  asm("CLI");
        //PTJ=0xfd; PTB=0xff;
      // delayby100ms(2);
        //PTJ=0x00; PTB=0x00;
        //delayby100ms(5);
           // count1 ++;
          // delayby100ms(5);
          }
        if (sign) {
           ptr = &buf[1];
           buf[0] = 0x2D;
        }
        else
           ptr = &buf[0];
        int2alpha(temp1,ptr);
        ptr = &buf[0];
        while(*ptr)
           ptr++;
        *ptr++ = '.';
        *ptr++ = fdigit + 0x30;
        //*ptr++ = 223;
        *ptr++ = 'i';
        *ptr++ = 'n';
        *ptr = 0;
        cmd2LCD(0xC0);
        putsLCD(blanks);
        cmd2LCD(0xC5);
        putsLCD(&buf[0]);
        delayby100ms(2);
     }
}
void openAD0(void)
{
     ATD0CTL2 = 0xE0;
     ATD0CTL3 = 0x0A;
     ATD0CTL4 = 0x25;
     delayby10us(2);
}
void waitfor20us(void)
{
     TSCR1 = 0x90;
    TSCR2 = 0;
     TIOS  |= OC0;
     TC0   = TCNT + 480;
     while(!(TFLG1 & C0F));
}
void INTERRUPT rtiISR(void) {
    CRGFLG = 0x80;   // clear RTIF bit
    PTB = segPat[seq+ix];
    PTP = digit[ix];
    ix++;
    if (ix == 4)
        ix = 0;
    count--;
    if(count == 0){
        seq++;
        count = 400;
    }
    if(seq == 10)
        seq = 0;
}
Labels (1)
0 Kudos
4 Replies

554 Views
AirDragon
Contributor III

What does this part of the code supposed to do?

if (sign){  ptr = &buf[1];  buf[0] = 0x2D;}else{  ptr = &buf[0];}int2alpha(temp1,ptr);ptr = &buf[0];while(*ptr){  ptr++;}*ptr++ = '.';*ptr++ = fdigit + 0x30;//*ptr++ = 223;*ptr++ = 'i';*ptr++ = 'n';*ptr = 0;cmd2LCD(0xC0);putsLCD(blanks);cmd2LCD(0xC5);putsLCD(&buf[0]);delayby100ms(2);}

 Also, could you please use the "Insert code" button( just to the right of the smiley with a hand over its eyes)? It should help preserve your formatting.

 

0 Kudos

554 Views
oldspice12
Contributor I
#include <hcs12.h>#include <delay.c>#include <stdio.c>#include <lcdUtilDragon12.c>#include <convert.c>#include <vectors12.h>//#include <SetClK.c>#define  INTERRUPT __attribute__((interrupt))void     INTERRUPT rtiISR(void);void waitfor20us(void);void openAD0(void);char buf[8];char *msg1 = "Distance = ";char *blanks = "                ";char segPat[13] = {0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x67,0x3F,                   0x06,0x5B,0x4F};char digit[4]={0xFE,0xFD,0xFB,0xF7}; char digits[9]=  {0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67}; int temp1,temp2,count1,count2,time,seq,ix,count ;     char sign,fdigit,frem;     char *ptr;    char i,p;int main(){    DDRB=   0xFF;    // configure Port B for output    DDRP=   0x0F;     delayby100ms(2);     openLCD();     openAD0();     cmd2LCD(0x80);     putsLCD(msg1);    seq     = 0;    ix      = 0;    count   = 400;    asm("ldd #rtiISR");    asm("pshd");    asm("ldd #56");    asm("ldx 0xEEA4");    asm("jsr 0,x");    RTICTL  = 0x40; //RTI interrupt interval set to 2**10 OSCCLK cycles    DDRB    = 0xFF; //configure Port B for output    DDRP    = 0xFF; //configure Port P for output  //  CRGINT  |= RTIE;//enable RTI interrupt    asm("CLI");     //enable interrupt globally    //while(1);     while(1) {        sign = 0;        ATD0CTL5 = 0x86;        while(!(ATD0STAT0 & SCF));        temp1 = (ATD0DR0 * 10) / 50;        if (temp1 < 30) {            CRGINT |= RTIE;          //  asm("CLI");        //PTJ=0xfd; PTB=0xff;      // delayby100ms(2);        //PTJ=0x00; PTB=0x00;        //delayby100ms(5);           // count1 ++;          // delayby100ms(5);          }        if (sign) {           ptr = &buf[1];           buf[0] = 0x2D;        }        else           ptr = &buf[0];        int2alpha(temp1,ptr);        ptr = &buf[0];        while(*ptr)           ptr++;        *ptr++ = '.';        *ptr++ = fdigit + 0x30;        //*ptr++ = 223;        *ptr++ = 'i';        *ptr++ = 'n';        *ptr = 0;        cmd2LCD(0xC0);        putsLCD(blanks);        cmd2LCD(0xC5);        putsLCD(&buf[0]);        delayby100ms(2);     }}void openAD0(void){     ATD0CTL2 = 0xE0;     ATD0CTL3 = 0x0A;     ATD0CTL4 = 0x25;     delayby10us(2);}void waitfor20us(void){     TSCR1 = 0x90;    TSCR2 = 0;     TIOS  |= OC0;     TC0   = TCNT + 480;     while(!(TFLG1 & C0F));}void INTERRUPT rtiISR(void) {    CRGFLG = 0x80;   // clear RTIF bit    PTB = segPat[seq+ix];    PTP = digit[ix];    ix++;    if (ix == 4)        ix = 0;    count--;    if(count == 0){        seq++;        count = 400;    }    if(seq == 10)        seq = 0;}

 

0 Kudos

554 Views
bigmac
Specialist III

Hello,

 

  1. Is your ISR code located in non-banked flash?
  2. Is your ISR function address incorporated within the vector table code?

It is unorthodox to #include any code generating .c files.  Normally, only the required header .h files would be included.  A header file should not generate any code.

 

Regards,

Mac

 

0 Kudos

554 Views
oldspice12
Contributor I

That part of the code is configuring the LCD screen so that I can display the distance.

0 Kudos