Code for PIC
Just a few examples of code for MikroC (www.mikroelektronika.co.yu). #1 - Led PWM Much inspired by the tmr0 example, this code regulates a led connected to a 12F675: /*Led PWM PHermansson 2006 For mikroC compiler for PIC, www.mikroelektronika.co.yu */ char counter; void interrupt(){ counter ++; // increment counter TMR0 = 200; INTCON = 0x20; // set T0IE, clear T0IF } void main() { OPTION_REG = 0x80; // TMR0 prescaler TRISIO = 0; // gpio = output GPIO = 0xFF; // initialize gpio counter = 0; // set counter TMR0 = 200; // set timer0 INTCON = 0xA0; // TMRO interrupt enabled do{ // Loop if (counter > 250) // Counts from 0 to 255 and then flips to 0 GPIO = 0; // Counter > x sets pwm period, lower value = brighter led. else GPIO = 255; } while(1); }