CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

help with UART interrupt to restart program sequence

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
xyzsor



Joined: 19 Dec 2010
Posts: 12

View user's profile Send private message Visit poster's website

help with UART interrupt to restart program sequence
PostPosted: Thu Mar 31, 2011 6:26 am     Reply with quote

Hi. Here's a short summary of my program.
Code:

#int_rda
void rda_isr(void)
{
     goto start;    // this part doesn't really work
}

void main()

start:
     data = getc()

    if (data == 0x01)
        pattern1();
    if (data == 0x02)
        pattern2();
    if (data == 0x03)
        pattern3();
}

pattern1() pattern2() and pattern3() are function which does an LED pattern sequence at portb. I just didn't include them as they are quite long, but they are working properly.

I got the interrupt to work. However my problem is in the GOTO START part. I know that code really doesn't work but my question is what can I do at the interrupt part that will make my program restart the entire void main section? Because I want the user to be able to choose a certain sequence at anytime even when it is currently playing a sequence. Thanks for anyone who can help.
Ttelmah



Joined: 11 Mar 2010
Posts: 19540

View user's profile Send private message

PostPosted: Thu Mar 31, 2011 9:46 am     Reply with quote

You need to read the character in the interrupt. The interrupt remains active, _till_ the character is read.
Using the goto in the interrupt, _will_ result in a stack overflow, and major problems.
You need to start thinking differently, and have something like:
Code:

int1 new_data=FALSE;
#int_rda
void rda_isr(void) {
     data=getc()t;   
     new_data=TRUE;
}

void main(void) {
    do {
        if (new_data) {
            new_data=FALSE;
            if (data == 0x01)
               pattern1();
            if (data == 0x02)
               pattern2();
            if (data == 0x03)
               pattern3();
     } while (TRUE);
}


Your 'pattern' routines should also test for 'new_data' going true, and return if it does.

Best Wishes
xyzsor



Joined: 19 Dec 2010
Posts: 12

View user's profile Send private message Visit poster's website

Solved thru reset
PostPosted: Thu Mar 31, 2011 11:28 am     Reply with quote

Ttelmah wrote:
You need to read the character in the interrupt. The interrupt remains active, _till_ the character is read.
Using the goto in the interrupt, _will_ result in a stack overflow, and major problems.
You need to start thinking differently, and have something like:
Code:

int1 new_data=FALSE;
#int_rda
void rda_isr(void) {
     data=getc()t;   
     new_data=TRUE;
}

void main(void) {
    do {
        if (new_data) {
            new_data=FALSE;
            if (data == 0x01)
               pattern1();
            if (data == 0x02)
               pattern2();
            if (data == 0x03)
               pattern3();
     } while (TRUE);
}


Your 'pattern' routines should also test for 'new_data' going true, and return if it does.

Best Wishes


I thought of this process too, however, it wouldnt fit to what i needed since the patterns are very long, and if i have an interrupt, it would take in the characters but still play back the sequence until the entire sequence is complete then proceed to the next.. however i did find this command handy

reset_cpu()

what it does is reset the PIC to go back to the first line, the good part is that is seems to hold in data stored in the RAM of the pic.. I just included the reset_cpu() command on my interrupt..

Thanks for your reply anyway. It may help others on this forum.. again.. Thanks..
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group