dsPIC Microcontroller PDF
dsPIC Microcontroller PDF
dsPIC
Microcontroller
pg. 1
Programming with dsPIC Microcontroller
INTRODUCTION
EMBEDDED SYSTEMS
dsPIC30F4011
The dsPIC 30F4011 PIC microcontroller is one of the most popular general purpose
microcontrollers. It is of 16-bit which means the most available operations are limited to 16-
bits.
Ports:
There are 5 ports. Port B, Port C, Port D, Port E, Port F.
pg. 2
Programming with dsPIC Microcontroller
pg. 3
Programming with dsPIC Microcontroller
microC Pro for dsPic Microcontroller IDE is a integrated toolset for the development of
embedded application on microchip IC and dsPIC microcontroller.
Install microC Pro For dsPIC Microcontroller IDE by following the instructions sets provided
in your software.
Lab.1 - LED Blinking Using dsPIC 30f4011 Microcontroller using microC pro for
dsPIC Microcontroller.
Open the micro C Pro for dsPIC Microcontroller and you will find a window opened as
shown in the above image.
pg. 4
Programming with dsPIC Microcontroller
Once you navigate Project > New Project, you will find a New Project Wizard opened
like as shown in the above image.
Just click Next as shown in the above image.
Once you click Next, you will find a new screen opened as shown in the above image. You
need to follow some steps as shown in the image above.
pg. 5
Programming with dsPIC Microcontroller
Once you click Next, another window will be opened which will allow you to Select the files
you want to add to project.
Here, without making any changes, just click Next as shown in the above image.
Once you click Next, another window will be opened which will allow you to Select initial
state for library manager.
Here, without making any changes, just click Next as shown in the above image.
pg. 6
Programming with dsPIC Microcontroller
Once you click Next, you will find a window stating You have successfully created a new
project. Click “Finish” to close a wizard.
Just click on Finish without making any changes.
Once you click on Finish, you will find an editor opened as shown in the above image.
Once you find the editor, just paste the code of LED Blinking as given below and then save
and Build it by clicking on Build icon as shown in the image below.
pg. 7
Programming with dsPIC Microcontroller
Once you build the code, you will find “Building Finished Successfully” in the console as
shown in the image above. If you have some errors in your code, then your building will be
unsuccessful and it will show you errors in red fonts inside the console and you need to check
what is the error in your code.
These steps will be followed for each new project which you need to create.
Code :
void main() {
pg. 8
Programming with dsPIC Microcontroller
while(1) {
LATB = ~LATB; // Invert PORTB value
LATC = ~LATC; // Invert PORTC value
LATD = ~LATD; // Invert PORTD value
LATF = ~LATF; // Invert PORTF value
Delay_ms(1000);
}
}
pg. 9
Programming with dsPIC Microcontroller
CODE:
unsigned int oldstate;
void main() {
ADPCFG = 0xFFFF; // initialize AN pins as digital
TRISD = 0xFFFF; // initialize portd as input
TRISB = 0x0000; // initialize portb as output
do {
if (Button(&PORTD, 0, 1, 1)) // detect logical one state
oldstate = 1;
if (oldstate && Button(&PORTD, 0, 1, 0)) { // detect logical one to logical zero transition
LATB = ~LATB; // toggle portb
oldstate = 0;
}
} while(1);
}
pg. 10
Programming with dsPIC Microcontroller
Code:
// LCD module connections
sbit LCD_RS at LATD0_bit;
sbit LCD_EN at LATD1_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;
pg. 11
Programming with dsPIC Microcontroller
unsigned adcRes;
char txt[6];
void main() {
pg. 12
Programming with dsPIC Microcontroller
Code:
char uart_rd;
void main() {
UART1_Write_Text("Start");
UART1_Write(10);
UART1_Write(13);
pg. 13
Programming with dsPIC Microcontroller
Code:
void main() {
ADPCFG = 0xFFFF;
UART1_Init(9600);
Delay_ms(100);
Keypad_Init(); // Initialize Keypad
do {
kp = 0; // Reset key code variable
pg. 14
Programming with dsPIC Microcontroller
}
UART1_Write(kp); // Send value of pressed button to UART
} while (1);
}
pg. 15
Programming with dsPIC Microcontroller
Code:
void main() {
UART1_Write_Text("AT");
UART1_Write(10);
UART1_Write(13);
Delay_ms(1000);
UART1_Write_Text("AT+IPR=9600;");
UART1_Write(10);
UART1_Write(13);
Delay_ms(5000);
UART1_Write_Text("AT");
UART1_Write(10);
UART1_Write(13);
Delay_ms(1000);
UART1_Write_Text("AT+CMGF=1");
UART1_Write(10);
UART1_Write(13);
Delay_ms(1000);
UART1_Write_Text("AT+CMGS=\"9902337012\"");
UART1_Write(10);
UART1_Write(13);
Delay_ms(1000);
UART1_Write_Text("Hi");
UART1_Write(0x1A);
UART1_Write(10);
UART1_Write(13);
Delay_ms(2000);
pg. 16
Programming with dsPIC Microcontroller
pg. 17
Programming with dsPIC Microcontroller
LATB = 0;
TRISB = 0; // Configure PORTB as output
Delay_ms(100);
pg. 18
Programming with dsPIC Microcontroller
pg. 19