 |
 |
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
|
Posted: Mon Apr 23, 2007 3:53 am |
|
|
You are running into the Warning 216 problem, please run the following demo program. both main() and isr used the same delay_us(), then, the compiler will disable ISR before the delay_us() in main(). i.e. whenever the main() level and ISR using any identical function, this will happen, and you are asking for truoble !
| Code: |
#include <18F452>
#define CLOCK_PERIOD 4 // in unit of 100 usec
#use delay(clock= 40000000)
#use rs232(baud = 115200, xmit=PIN_C6, rcv=PIN_C7)
#use fast_io(B)
int16 ccp1_compare_period, i, k;
void my_delay_us ( int16 n ) // delay n+2 usec
{
while(n--);
}
#INT_CCP1
void rt_daq_ctrl()
{
CCP_1 += ccp1_compare_period; k++;
output_high( PIN_B7 ); // take a scope and watch it carefully
delay_us ( 300 ); // this will cause big trouble
// my_delay_us ( 300 ); // this is the safe solution
output_low ( PIN_B7 );
}
void main()
{
set_tris_B ( 0b00000000 );
setup_ccp1 ( CCP_COMPARE_INT );
setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_8 );
ccp1_compare_period = CLOCK_PERIOD * 125;
enable_interrupts ( INT_CCP1 );
enable_interrupts ( GLOBAL );
while(1)
{
for (i=0; i<500; i++)
{
output_high( PIN_B0 ); // look at scope
delay_us ( 800 );
output_low ( PIN_B0 );
}
printf( "\r\n k= %lu", k ); k= 0;
}
}
|
Have fun !
Best wishes
C-H Wu |
|
 |
|
|
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
|