root/RF_BT_Tail/mcc_generated_files/pwm1.c

Revision 244, 4.5 kB (checked in by phil, 4 years ago)

added initial Tail Source Package

Line 
1 /**
2   PWM1 Generated Driver File
3
4   @Company
5     Microchip Technology Inc.
6
7   @File Name
8     pwm1.c
9
10   @Summary
11     This is the generated driver implementation file for the PWM1 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
12
13   @Description
14     This header file provides implementations for driver APIs for PWM1.
15     Generation Information :
16         Product Revision  :  PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.65.2
17         Device            :  PIC16F1579
18         Driver Version    :  2.01
19     The generated drivers are tested against the following:
20         Compiler          :  XC8 1.45 or later
21         MPLAB             :  MPLAB X 4.15
22 */
23
24 /*
25     (c) 2018 Microchip Technology Inc. and its subsidiaries.
26    
27     Subject to your compliance with these terms, you may use Microchip software and any
28     derivatives exclusively with Microchip products. It is your responsibility to comply with third party
29     license terms applicable to your use of third party software (including open source software) that
30     may accompany Microchip software.
31    
32     THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
33     EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
34     IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
35     FOR A PARTICULAR PURPOSE.
36    
37     IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
38     INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
39     WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
40     HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
41     THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
42     CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
43     OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
44     SOFTWARE.
45 */
46
47 /**
48   Section: Included Files
49 */
50
51 #include <xc.h>
52 #include "pwm1.h"
53
54 /**
55   Section: PWM1 APIs
56 */
57
58 void PWM1_Initialize(void)
59 {
60     // set the PWM1 to the options selected in the User Interface
61
62      //PHIE disabled; DCIE disabled; OFIE disabled; PRIE disabled;
63     PWM1INTE = 0x00;
64
65      //PHIF cleared; OFIF cleared; DCIF cleared; PRIF cleared;
66     PWM1INTF = 0x00;
67
68      //PS Divide_clock_src_by_4; CS FOSC;
69     PWM1CLKCON = 0x20;
70
71      //LDS LD1_trigger; LDT disabled; LDA do_not_load;
72     PWM1LDCON = 0x00;
73
74      //OFM independent_run; OFS OF1_match; OFO match_incrementing;
75     PWM1OFCON = 0x00;
76
77      //PWM1PHH 0;
78     PWM1PHH = 0x00;
79
80      //PWM1PHL 0;
81     PWM1PHL = 0x00;
82
83      //PWM1DCH 10;
84     PWM1DCH = 0x0A;
85
86      //PWM1DCL 240;
87     PWM1DCL = 0xF0;
88
89      //PWM1PRH 156;
90     PWM1PRH = 0x9C;
91
92      //PWM1PRL 63;
93     PWM1PRL = 0x3F;
94
95      //PWM1OFH 0;
96     PWM1OFH = 0x00;
97
98      //PWM1OFL 1;
99     PWM1OFL = 0x01;
100
101      //PWM1TMRH 0;
102     PWM1TMRH = 0x00;
103
104      //PWM1TMRL 0;
105     PWM1TMRL = 0x00;
106
107      //MODE standard_PWM; POL active_hi; EN enabled;
108     PWM1CON = 0x80;
109
110 }   
111
112
113 void PWM1_Start(void)
114 {
115     PWM1CONbits.EN = 1;         
116 }
117
118 void PWM1_Stop(void)
119 {
120     PWM1CONbits.EN = 0;         
121 }
122
123 bool PWM1_CheckOutputStatus(void)
124 {
125     return (PWM1CONbits.OUT);           
126 }
127
128 void PWM1_LoadBufferSet(void)
129 {
130     PWM1LDCONbits.LDA = 1;             
131 }
132
133 void PWM1_PhaseSet(uint16_t phaseCount)
134 {
135     PWM1PHH = (phaseCount>>8);        //writing 8 MSBs to PWMPHH register
136     PWM1PHL = (phaseCount);           //writing 8 LSBs to PWMPHL register
137 }
138
139 void PWM1_DutyCycleSet(uint16_t dutyCycleCount)
140 {
141     PWM1DCH = (dutyCycleCount>>8);      //writing 8 MSBs to PWMDCH register
142     PWM1DCL = (dutyCycleCount); //writing 8 LSBs to PWMDCL register             
143 }
144
145 void PWM1_PeriodSet(uint16_t periodCount)
146 {
147     PWM1PRH = (periodCount>>8); //writing 8 MSBs to PWMPRH register
148     PWM1PRL = (periodCount);    //writing 8 LSBs to PWMPRL register             
149 }
150
151 void PWM1_OffsetSet(uint16_t offsetCount)
152 {
153     PWM1OFH = (offsetCount>>8); //writing 8 MSBs to PWMOFH register
154     PWM1OFL = (offsetCount);    //writing 8 LSBs to PWMOFL register             
155 }
156
157 uint16_t PWM1_TimerCountGet(void)
158 {
159     return ((uint16_t)((PWM1TMRH<<8) | PWM1TMRL));                     
160 }
161
162 bool PWM1_IsOffsetMatchOccured(void)
163 {
164     return (PWM1INTFbits.OFIF);         
165 }
166
167 bool PWM1_IsPhaseMatchOccured(void)
168 {
169     return (PWM1INTFbits.PHIF);
170 }
171
172 bool PWM1_IsDutyCycleMatchOccured(void)
173 {
174     return (PWM1INTFbits.DCIF);         
175 }
176
177 bool PWM1_IsPeriodMatchOccured(void)
178 {
179     return (PWM1INTFbits.PRIF);         
180 }
181
182 /**
183  End of File
184 */
185
186
Note: See TracBrowser for help on using the browser.