Skip to content

Commit 5cc336f

Browse files
committed
added PWM Code
1 parent fd40435 commit 5cc336f

26 files changed

+8363
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# .gitignore file
2+
3+
# MPLAB X IDE (Netbeans) specific
4+
**/*.X/~*.*
5+
**/*.X/build/
6+
**/*.X/debug/
7+
**/*.X/dist/
8+
**/*.X/disassembly/
9+
**/*.X/.generated_files/
10+
**/*.X/nbproject/private/
11+
**/*.X/nbproject/*.mk
12+
**/*.X/nbproject/*.bash
13+
**/*.X/nbproject/Makefile-genesis.properties
14+
15+
# Object files
16+
*.o
17+
*.ko
18+
*.obj
19+
*.elf
20+
21+
# Executables
22+
*.exe
23+
24+
25+
# KDE specific
26+
.directory
27+
28+
# Misc
29+
.svn
30+
*.bak

PIC_Microcontroller/PWM.X/Makefile

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#
2+
# There exist several targets which are by default empty and which can be
3+
# used for execution of your targets. These targets are usually executed
4+
# before and after some main targets. They are:
5+
#
6+
# .build-pre: called before 'build' target
7+
# .build-post: called after 'build' target
8+
# .clean-pre: called before 'clean' target
9+
# .clean-post: called after 'clean' target
10+
# .clobber-pre: called before 'clobber' target
11+
# .clobber-post: called after 'clobber' target
12+
# .all-pre: called before 'all' target
13+
# .all-post: called after 'all' target
14+
# .help-pre: called before 'help' target
15+
# .help-post: called after 'help' target
16+
#
17+
# Targets beginning with '.' are not intended to be called on their own.
18+
#
19+
# Main targets can be executed directly, and they are:
20+
#
21+
# build build a specific configuration
22+
# clean remove built files from a configuration
23+
# clobber remove all built files
24+
# all build all configurations
25+
# help print help mesage
26+
#
27+
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
28+
# .help-impl are implemented in nbproject/makefile-impl.mk.
29+
#
30+
# Available make variables:
31+
#
32+
# CND_BASEDIR base directory for relative paths
33+
# CND_DISTDIR default top distribution directory (build artifacts)
34+
# CND_BUILDDIR default top build directory (object files, ...)
35+
# CONF name of current configuration
36+
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
37+
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
38+
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
39+
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
40+
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
41+
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
42+
#
43+
# NOCDDL
44+
45+
46+
# Environment
47+
MKDIR=mkdir
48+
CP=cp
49+
CCADMIN=CCadmin
50+
RANLIB=ranlib
51+
52+
53+
# build
54+
build: .build-post
55+
56+
.build-pre:
57+
# Add your pre 'build' code here...
58+
59+
.build-post: .build-impl
60+
# Add your post 'build' code here...
61+
62+
63+
# clean
64+
clean: .clean-post
65+
66+
.clean-pre:
67+
# Add your pre 'clean' code here...
68+
# WARNING: the IDE does not call this target since it takes a long time to
69+
# simply run make. Instead, the IDE removes the configuration directories
70+
# under build and dist directly without calling make.
71+
# This target is left here so people can do a clean when running a clean
72+
# outside the IDE.
73+
74+
.clean-post: .clean-impl
75+
# Add your post 'clean' code here...
76+
77+
78+
# clobber
79+
clobber: .clobber-post
80+
81+
.clobber-pre:
82+
# Add your pre 'clobber' code here...
83+
84+
.clobber-post: .clobber-impl
85+
# Add your post 'clobber' code here...
86+
87+
88+
# all
89+
all: .all-post
90+
91+
.all-pre:
92+
# Add your pre 'all' code here...
93+
94+
.all-post: .all-impl
95+
# Add your post 'all' code here...
96+
97+
98+
# help
99+
help: .help-post
100+
101+
.help-pre:
102+
# Add your pre 'help' code here...
103+
104+
.help-post: .help-impl
105+
# Add your post 'help' code here...
106+
107+
108+
109+
# include project implementation makefile
110+
include nbproject/Makefile-impl.mk
111+
112+
# include project make variables
113+
include nbproject/Makefile-variables.mk
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <xc.h>
2+
//Configuration bits setting/
3+
#pragma config OSC = HS //Oscillator Selection
4+
#pragma config WDT = OFF //Disable Watchdog timer
5+
#pragma config LVP = OFF //Disable Low Voltage Programming
6+
#pragma config PBADEN = OFF //Disable PORTB Analog inputs
7+
#pragma config CCP2MX = PORTBE // CCP2 MUX bit (CCP2 input/output is multiplexed with RB3)
8+
9+
#define _XTAL_FREQ 20000000
10+
11+
void main(void)
12+
{
13+
TRISBbits.RB3 = 0;
14+
PR2 = 249; //PWM Frequency 5KHz
15+
CCP2CONbits.CCP2M = 0b1111; // PWM Mode
16+
T2CONbits.T2CKPS = 0b01; // Prescaler divide by 4
17+
T2CONbits.TMR2ON = 1;
18+
CCPR2L = 1;
19+
CCP2CONbits.DC2B = 0b00;
20+
while(1)
21+
{
22+
for (unsigned char i= 0; i < 250; i += 10)
23+
{
24+
CCPR2L = i;
25+
26+
__delay_ms(50);
27+
}
28+
29+
30+
31+
}
32+
33+
34+
35+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <xc.h>
2+
//Configuration bits setting/
3+
#pragma config OSC = HS //Oscillator Selection
4+
#pragma config WDT = OFF //Disable Watchdog timer
5+
#pragma config LVP = OFF //Disable Low Voltage Programming
6+
#pragma config PBADEN = OFF //Disable PORTB Analog inputs
7+
#pragma config CCP2MX = PORTBE // CCP2 MUX bit (CCP2 input/output is multiplexed with RB3)
8+
9+
#define _XTAL_FREQ 20000000
10+
11+
void main(void)
12+
{
13+
TRISBbits.RB3 = 0;
14+
PR2 = 249; //PWM Frequency 5KHz
15+
CCP2CONbits.CCP2M = 0b1111; // PWM Mode
16+
T2CONbits.T2CKPS = 0b01; // Prescaler divide by 4
17+
T2CONbits.TMR2ON = 1;
18+
CCPR2L = 1;
19+
CCP2CONbits.DC2B = 0b00;
20+
while(1)
21+
{
22+
for (unsigned char i= 0; i < 250; i += 10)
23+
{
24+
CCPR2L = i;
25+
26+
__delay_ms(50);
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)