PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Dec 01, 2010 1:04 pm |
|
|
I stripped your program down to the minimum necessary code to show
the problem. There is a problem with the setup_timer_2() function in
vs. 4.114 for the 18F45K22. It writes to incorrect registers. This can
be fixed with the work-around macro shown below. The compiler will
substitute the macro code for it's own built-in function. Then it works.
This bug should be emailed to CCS support. Do you want to do it, or
do you want me to do it ?
Code: |
#include <18F45K22.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#byte T2CON = 0xFBA
#byte PR2 = 0xFBB
#define setup_timer_2(prescaler, PR2val, postscaler) \
if(prescaler) \
{ \
PR2 = PR2val; \
T2CON = prescaler | ((postscaler -1) << 3); \
} \
else \
T2CON = 0;
//======================================
void main(void)
{
setup_timer_2(T2_DIV_BY_1, 255, 1);
setup_ccp1(CCP_PWM);
set_pwm1_duty(120);
while(1);
} |
|
|