VIVA PIC16 - PWM Hello World Led Example

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

C: \ Mi cr ocont r ol l er s\ VI VA PI C16 Exampl es\ 03 Hel l o Wor l d PWM ( C) \ mai n.

c
1 #i ncl ude <ht c. h>
2
3 void i ni t _vi va_pwm( void)
4 {
5 / / See page 91 i n PI C16F1829 dat asheet
6 / / Di sabl e TMR2' s i nt er r upt
7 PI E1, TMR2I E = 0;
8 / / See pages 219 and 125
9 / / Di sabl e RA5 ( CCP2) as out put
10 TRI SA5 = 1;
11 / / See page 122
12 / / Sel ect RA5 f or CCP2, al t er nat i vel y, RC3
13 APFCON1, CCP2SEL = 1;
14 / / See page 202
15 / / PWM per i od
16 PR2 = 0x80;
17 / / See page 236
18 CCP2CON = 0b00001111;
19 / / See page 36, not wel l document ed
20 / / Dut y Cycl e Low, smal l er - > br i ght er
21 CCPR2L = 0x22;
22 / / See page 237
23 / / Sel ect TMR2
24 CCPTMRS = 0x00;
25 / / See page 201
26 / / Conf i gur e and st ar t TMR2
27 T2CON = 0b00000101;
28 / / See page 219
29 / / Enabl e RA5 ( CCP2) as out put
30 TRI SA5 = 0;
31 }
32
33 void mai n( void)
34 {
35 i ni t _vi va_pwm( ) ;
36 while ( 1) {
37 CCPR2L = 0x00;
38 _del ay( 100000) ;
39 CCPR2L = 0xFF;
40 _del ay( 100000) ;
41 }
42 }
1

You might also like