mikroC

mikroC - C Compiler for Microchip PIC microcontrollers

making it simple...

Library Example

/*The example changes PWM duty ratio on pin RC2 continually. If LED is connected to RC2, you can observe the gradual change of emitted light. */

char i = 0, j = 0;

void main() { PORTC = 0xFF; Pwm_Init(5000); Pwm_Start();

//PORTC is output

//Initialize PWM module at 5KHz

//Start PWM

while (1) {

//Slow down, allow us to see the change on LED: for (i = 0; i < 20; i++) Delay_us(500);

j++;

Pwm_Change_Duty(j);

// Change duty ratio

}

}

Hardware Connection

+5V

10K

Reset

+5V

 

4MHz

PIC16F877A

MCLR/Vpp/THV RB7/PGD

RA0/AN0

RB6/PGC

RA1/AN1

RB5

RA2/AN2/Vref-

RB4

RA3/AN3/Vref+

RB3/PGM

RA4/TOCKI

RB2

RA5/AN4

RB1

 

 

 

 

 

RE0/RD/AN5

RB0/INT

 

 

 

 

RE1/WR/AN6

Vdd

RE2/CS/AN7

Vss

Vdd

RD7/PSP7

Vss

RD6/PSP6

OSC1

RD5/PSP5

OSC2

RD4/PSP4

RCO/T1OSO

RC7/RX/DT

RC1/T1OSI

RC6/TX/CK

RC2/CCP1

RC5

RC3

RC4

RD0/PSP0

RD3/PSP3

RD1/PSP1

RD2/PSP2

330R

page

 

242

MikroElektronika: Development tools - Books - Compilers