I don't think I have a clear understanding of what you are doing, but let me see if this is close. It sounds like you need an interrupt service routine that hits every 10 milliseconds, that does PORTB=PAT[i]; meanwhile, it also needs to increment i on every interrupt, and test whether I is > 240, in which case it will do something else (what I am not sure). Setting up the timer will depend on your system, I'll leave that up to you. You'll have to enable the interrupts for that timer, and figure out how to get it to interrupt every 10 ms. You will probably have to stuff a number into the timer counter register at the end of every interrupt service routine to get this to work. Considering there may be some overhead due to the C compiler's context saving routine, I would simulate this to make sure that you have the "magic numbers" correct. I haven't ever been able to calculate these to an accuracy that satisfied me. I am assuming you are using Hitech C? So your interrupt routine might look like this: void interrupt int_handler(void){ if (TMR1IF){ // Test if it was a timer1 interrupt (assuming you use timer1) TMR1IF = 0; if(i++ > 240){ i = 0; } PORTB=PAT[i]; if(PORTB==0x55){ .. whatever needs to be done here- I don't quite understand it. } TIMER1H = MAGIC_NUMBER_#1 // calculate these and then simulate them to see if you have them right. TIMER1L = MAGIC_NUMBER_#2 } Meanwhile your main program can be very trivial. If you have nothing else to do then it could even be: main{ ... Setup and initialization code do{ }while(1); } -- Lawrence Lile Andre Abelian Sent by: pic microcontroller discussion list 03/04/2003 06:54 PM Please respond to pic microcontroller discussion list To: PICLIST@MITVMA.MIT.EDU cc: Subject: [PIC]: Generating 5 pulses at the same time Hi to all, Apologies if the tag isn't right for c code: In this code I used 240 byte of data to be cycled I need to make Rb1 high 8 time but duty cycle to be 3 times Smaller then other pulses. Only RB1 needs to be like that My question is how do I do that without interrupting main Array my guess is I have to use interrupt in background I think it called (ring loop)or some thing any help Will appreciate. Andre /*################################################## # pic18f452: # Hardware info: # portb,0= will gen 16x8=128 pulses per rev # portb,1= will gen 8 pulses per rev # portb,2= will gen 4 pulses per rev # portb,3= will gen 4 pulses per rev # portb,4= will gen 4 pulses per rev # cyl_1=0B00000001 # cyl_2=0B00000101 # cyl_3=0B00001001 # cyl_4=0B00001101 # cyl_5=0B00010001 # cyl_6=0B00010101 # cyl_7=0B00011001 # cyl_8=0B00011101 #################################################### */ #include #include "delay.c" #define PORTBIT(adr, bit) ((unsigned)(&adr)*8+(bit)) #define XTAL_FREQ 4MHZ static bit led @ PORTBIT(PORTB, 7); // function decaration void port_init(void); void run(); // main program void main(void) { port_init(); // setup port run(); } // main program void run(){ unsigned char c; unsigned char i=0; unsigned char const PAT[]={0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00, 0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00, 0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00, 0B00000101, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00, 0B00001001, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00, 0B00001101, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00, 0B00010001, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00, 0B00010101, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00, 0B00011001, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00, 0B00011101, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x55}; for(c=0;c<240;c++){ // setup count 128 PORTB=PAT[i]; // read the table and display it DelayBigMs(10); if(PORTB==0x55){ break;} // see if it passed over 0x55 last array (not used) i++; } } // Port Init void port_init(void){ TRISB=0; // set portb output TRISA=0xFF; // set porta all input PORTB=0; // make sure all leds off } -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.