this application demo PWM for animation dimmer on screen 7segments
common cathode
//////////////////////////////////////////////////////////////////////////
/* MCU : 16f877A USED ROM 154 / USED RAM 30 */
/* CLOCK : 12mhz */
/* compiler : mikroc 6.2.1 its the best */
/* dev : oshonsoft test bourd http://www.oshonsoft.com/ */
/* notes : i have made the same test_bourd its good
its very cheap
you can do its one hand made
i also test it on boot mode */
// variables //
unsigned short duty=0;
unsigned char dcurr=0;
unsigned char dimm = 0;
unsigned char digit = 0x10;
unsigned char data[4]={0};
unsigned int range =0;
unsigned char set_step = 0x01;
// interrupt prototype //
void interrupt()
{
portb = 0;
portb = data[dcurr];
portd = digit ;
digit<<=1;
dcurr++;
if(dcurr == 4){
dcurr =0;
digit= 0x10;
}
// PWM sofware reclage
if(duty<=dimm) // 1 to 63 dimmer range
trisb = 0x00;
else trisb = 0xff;
duty++;
duty &= 0b00111111;
range++;
if(range>12)
{
set_step++;
}
if(set_step==0x3f)set_step=0x01;
set_step&=0b00111111 ;
INTCON.T0IF = 0; // clr flag TMR0IF
}
// MAIN HERE //
void main()
{
portb=0; // output portd leds anode
trisb = 0;
//==========
portd = 0x10; //portd hi nibble scann common cathode
trisd = 0;
//=============
option_reg = 0x80; // internal clock TMR0 over flow
INTCON = (1<<GIE) | (1<<T0IE); // enable interrupt TMR0IE GIE
//===========================
// print "boot" on 7_segments 1x4 //
data[0] = 0x7C;
data[1] = 0x5C;
data[2] = 0x5C;
data[3] = 0x70;
while(1){
// to do add your codes here
dimm = set_step;
delay_ms(100);
}
}
// END HERE //
//////////////////////////////////////////////////////////////////