| 
	
	|  |  |  
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| xyzsor 
 
 
 Joined: 19 Dec 2010
 Posts: 12
 
 
 
			      
 
 | 
			
				| help with UART interrupt to restart program sequence |  
				|  Posted: Thu Mar 31, 2011 6:26 am |   |  
				| 
 |  
				| 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: 19966
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Mar 31, 2011 9:46 am |   |  
				| 
 |  
				| 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
 
 
 
			      
 
 | 
			
				| Solved thru reset |  
				|  Posted: Thu Mar 31, 2011 11:28 am |   |  
				| 
 |  
				|  	  | 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..
 |  |  
		|  |  
		|  |  
  
	| 
 
 | 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
 
 |