PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jun 02, 2011 2:35 pm |
|
|
I modified his code a little bit and it works better now. Here is the revised program:
Code: |
#include <18F4520.h>
#fuses HS,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=20M)
#define PRELOAD (65536 - 180)
#define RED PIN_D0
#define GREEN PIN_D1
#define BLUE PIN_D2
int red_duty;
int green_duty;
int blue_duty;
int Intcount;
#int_timer1
void timer1_isr()
{
set_timer1(PRELOAD + get_timer1());
// Interrupt marker for viewing on oscilloscope.
//output_high(PIN_D7);
//delay_us(1);
//output_low(PIN_D7);
if(Intcount == 255)
{
Intcount = 0;
if(red_duty) output_high(RED);
if(green_duty) output_high(GREEN);
if(blue_duty) output_high(BLUE);
}
if(Intcount == red_duty)
{
output_low(RED);
}
if(Intcount == green_duty)
{
output_low(GREEN);
}
if(Intcount == blue_duty)
{
output_low(BLUE);
}
Intcount++;
}
//=========================================
void main()
{
// Initialize interrupt counter and output pins.
Intcount = 0;
output_low(RED);
output_low(GREEN);
output_low(BLUE);
red_duty = 0;
green_duty = 1;
blue_duty = 2;
//red_duty = 253;
//green_duty = 254;
//blue_duty = 255;
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
while(1);
}
|
|
|