Code:
#include <system.h>
#pragma DATA _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _MCLRE_ON
#pragma DATA _CONFIG2, _LVP_OFF & _PLLEN_OFF
#pragma CLOCK_FREQ 8000000 // 8-MHz INTOSC
#define r08 const rom unsigned char
r08 gamma[] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 4,
4, 5, 5, 6, 6, 7, 8, 8, 9, 10,
11, 12, 13, 14, 15, 17, 18, 20, 21, 23,
25, 27, 29, 31, 34, 36, 39, 42, 45, 49,
53, 57, 61, 65, 70, 75, 81, 87, 93,100,
107,114,123,131,140,150,161,172,183,196,
209,224,239,255 };
void main()
{ ansela = 0; // make pins digital
trisa = 0b00000000; // porta all outputs
porta = 0; // all output latches low
osccon = 0b01110010; // initialize 8-MHz INTOSC
while(!oscstat.HFIOFS); // wait until OSC stable
ccp1con = 0b00001100; // pwm mode, p1a active hi
ccpr1l = 0; // 0% duty cycle initially
pr2 = 255; //
t2con = 1<<TMR2ON; // pre 1, post 1, 7812.5 Hz
while(1) //
{ static char duty = 32; // start at ~50% brightness
while(duty < 63) // fade up to 100%
{ ccpr1l = gamma[duty++];
delay_ms(30); // over period of ~1 sec
} //
while(duty > 32) // fade down to ~50%
{ ccpr1l = gamma[duty--];
delay_ms(30); // over period of ~1 sec
} //
delay_ms(100); // pause at 50% brightness
} //
}
Bookmarks