Introduction to PIC12C508
Hello everyone! I hope you all will be absolutely fine and having fun. Today, I am going to share my knowledge aboutÂ
Introduction to PIC12C508. PIC 12C-508 belongs to the family of high performance and cost effective micro controllers. It is a fully static eight (8) bit device. PIC 12C 508 micro controller is Complementary Metal Oxide Semiconductor (CMOS) which is based on EEPROM, EPROM and ROM.
PIC 12C-508
Microcontroller has Reduced Instruction Set Computing (RISC) having thirty three (33) instructions based on single words. Except program branches all of the instructions are single cycled i.e. 1 millisecond. Whereas two cycles are taken by the program branches.
 PIC 12C 508 has a lot amazing features e.g. eight (8) bit real time clock, power on reset, wake-up from sleep on pin change, device reset timer, select able oscillator options, power saving sleep mode etc. Its applications may include security systems, small foot print, personal appliances etc. Further detail about PIC 12C-508 will be given later in this tutorial.
Introduction to PIC12C508
PIC 12C508Â is a low cost and high performance
PIC Microcontroller. Its an 8 bit device based on EEPROM and EPROM CMOS as explained above. Its has reduced RISC with all information having 33 single words except program branches. Program branches take two (2) cycles. PIC 12C 508 is shown in the figure below.
1. PIC12C508 Pins
- PIC 12C 508 has eight (8) pins, four (4) on the right side and other four (4) on the left side of the IC.
- Pins are different in different PIC Microcontrollers like PIC16F877a Microcontroller has 40 Pins.
- All of the eight pins are given along with their number, in the table shown below.
2. PIC12C508 Pins Description
- Each pin has different features associated with it.
- The description of each pin is given in the table shown below.
3. PIC12C508 Pinout
- Pinout diagram basically shows the initial necessary information about any device e.g. pins information.
- PIC 12C508 pinout diagram along with animation and symbolic representation is shown in the figure below.
4. PIC 12C508 Block Diagram
- The block diagram of an equipment shows its proper step by step working, that how the device works sequentially.
- PIC 12C508 block diagram is shown in the figure below.
5. PIC 12C508 Characteristics
- Characteristics may include operating speed, EPROM program, RAM data, ROM data etc.
- PIC 12C 508 characteristics are given in the table shown below.
6. PIC 12C508 Stack and Program Memory
- Program memory and stack presents the flow of programming.
- PIC 12C 508 is shown in the figure below.
7. PIC 12C508 Clock Cycle
- Clock input is divided into four parts internally in order to generate four non overlapping clocks named as sQ2, Q3 and Q4.
- All of these clocks are shown in the figure given below.
8. PIC 12C508 Features
PIC-12C508 has a lot of features, a few of which are given below.
- Power on reset.
- Device reset timer.
- More than 40 years of EEPROM data retention.
- Wake-up on sleep while changing the pin.
- Internal weak pull-ups on input/output puns.
- Programmable protection of code.
- Select able oscillator options.
9. PIC 12C508 Applications
PIC 12C508 has several different real life applications e.g.
- Security systems.
- Personal care appliances.
- Low power remote transmitters.
- Low power remote receivers.
- .Small foot print packages.
That was the detailed discussion aboutÂ
Introduction to PIC 12C508. I tried to cover all the important details about PIC 12C508. Let me know if have missed any point. If you have any problems you can freely ask me in comments anytime. Me and my team is 24/7 available here to entertain you. Further IC's will be explained in the upcoming tutorials. Till then, take care :)
Introduction to PIC18F4550
Hello friends I hope you all are doing great. Today, I am going to give you a detailed
Introduction to PIC18F4550. Its one of the most renowned PIC Microcontroller and is used in almost every field. You should also have a look at my previous tutorial
Introduction to PIC16F877a, as it will also be helpful. PIC18F4550 also has 40 Pins and is quite similar to PIC16F877a with some additional features.
In today's post we will get the general overview of this microcontroller, which is very essential if you wanna start working on it. If you have any problem in any part of it then ask your questions in comments and I will try my best to resolve them out. So, now let's get started with Introduction to PIC18F4550:
Introduction to PIC18F4550
PIC18F4550 is a
8-bit and
40-Pin PIC Microcontroller which belongs to PIC18 Family and has a
Program Memory of 32KB,
RAM of 2048Bytes,
EEPROM Memory of 256Bytes and
CPU Speed of 12MIPS. It is mostly used in embedded projects and is quite used in Engineering Projects. Few of its main features are:
- It has five Ports on it starting from Port A to Port E.
- It has below mentioned Ports for Data Communication.
- USB Port
- Serial Port
- I2C Port
- It also has interrupt functionality in it and we can place any kind of interrupt in it.
- Here's the Pin Diagram of PIC18F4550:
- Each Pin of PIC18F4550 can perform more than one task, as you can see in above figure that Pins are having more than one label.
- So, now again we have to design its Basic Circuit as we did for PIC16F877a.
1. PIC18F4550 Basic Circuit
- As I have mentioned in my previous tutorial on PIC16F877a that each PIC Microcontroller needs a Basic circuit, this basic circuit is like a a power supply to PIC Microcontroller.
- You must be wondering why am I forcing again and again to read previous tutorial on PIC16F877a, its because I have discuss that tutorial quite in detail and no matter what PIC Microcontrolelr you are using that basic information will remain the same. So again must read that tutorial. :)
- Anyways here's the PIC18F4550 Basic Circuit:
- If you remember than its exactly the same as for PIC16F877a, so I am not gonna explain it much.
- All the Grounded lines are shown in black color and Power Lines with +5V are shown with Red Lines.
- We also have Crystal Oscillator for frequency here connected to Pin # 12 & Pin # 13.
- Now, let's have a look at PIC18F4550 Ports:
2. PIC18F4550 Ports
- Again it has same Ports as of our Previous Microcontroller starting from Port A to Port E.
- PIC16F877a has 5 Ports in total which are:
- Port A: It has 6 Pins in total starting from Pin # 2 to Pin # 7.
- Port B: It has 8 Pins in total starting from Pin # 33 to Pin # 40.
- Port C: It has 8 Pins in total. It’s pins are not aligned together. First four Pins of Port C are located at Pin # 15 – Pin # 18, while the last four are located at Pin # 23 – Pin # 26.
- Port D: It has 8 Pins in total. It’s pins are also not aligned together. First four Pins of Port D are located at Pin # 19 – Pin # 22, while the last four are located at Pin # 27 – Pin # 30.
- Port E: It has 3 Pins in total starting from Pin # 8 to Pin # 10.
3. PIC18F4550 Compiler
- Their official Compiler is available online at Microchip website and can be used free of cost.
- I use MikroC Pro for PIC Compiler which you can download from their official site and it has a demo version but you have to buy the full version.
- You should also read this list of Top 3 PIC C Compiler.
4. PIC18F4550 USB Communication
- Here's the main reason of PIC18F4550's popularity, it supports USB Communication.
- Here's the simplest circuit diagram for PIC18F4550 USB Communication, I will post tutorial on it soon.
- So, we can do the PIC18F4550 USB Communication by using below two Pins:
- Pin # 23: (D-)
- Pin # 24: (D+)
5. PIC18F4550 Serial Communication
- We can also do the PIC18F4550 Serial Communication.
- PIC18F4550 Serial Communication Pins are shown in below figure:
- You can see in above figure that below two pins are used for PIC18F4550 Serial Communication:
- Pin # 25 (TX).
- Pin # 26 (RX).
Moreover, it also supports I2C communication and it also has interrupts in it. So, that's all for today. I hope you got something out of it. :) Will meet you guys in next tutorial till then take care and have fun !!! :)
Introduction to PIC16F877a
Hello friends, I hope you all are doing great and having fun with your lives. Today, I am going to give you guys a detailed Introduction to PIC16F877a. It's the most commonly used PIC Microcontroller because of its operational flexibility, availability and low cost. You can buy this PIC Microcontroller from almost every online electronic shop for just $2 - $3.
If you are new to PIC Microcontroller then read this complete post carefully and ask your queries in the comments. You should also have a look at this video in which I have given an Introduction to PIC16F877a:
Note:
- You can download PIC16F877a Datasheet by Clicking below button:
Download PIC16F877a Datasheet
Introduction to PIC16F877a
- PIC16F877a is a 40-pin PIC Microcontroller, designed using RISC architecture, manufactured by Microchip and is used in Embedded Projects.
- It has five Ports on it, starting from Port A to Port E.
- It has three Timers in it, two of which are 8-bit Timers while 1 is of 16 Bit.
- It supports many communication protocols like:
- Serial Protocol.
- Parallel Protocol.
- I2C Protocol.
- It supports both hardware pin interrupts and timer interrupts.
- Here's the PIC16F877a Pin Diagram, I have mentioned the names of all the Pins and have also given different colors to different Ports.
- The above image gives you the overall idea of PIC16F877a Pins and Ports.
- You should also have a look at Introduction to Atmega328, it's another microcontroller, you should compare them.
Important Note:
- You can see in the above image that pins of PIC Microcontroller have more than one name, its because each pin of PIC can perform multiple tasks.
- For example, check Pin # 25, it can be used as a digital Port C Pin # 6 (RC6) and can also be used as a Transmitter (TX) for serial communication.
- So, you have to specify in the programming, how you want to use these pins.
- In the next section, I am going to explain all of these Pin features one by one.
- So, first of all, we are going to have a look at the Basic circuit of PIC16F877a:
PIC16F877a Basic Circuit
- Each Microcontroller has a basic circuit and if you won't design the basic circuit, it won't work.
- It's just like providing power to your PIC Microcontroller and it works on +5V level.
- If you want to turn ON the fan then what will you do? You will simply provide it power and that's what we are going to do with a PIC.
- But in this case, along with power, we also need to provide the frequency at which it will operate.
- So, now we know that we need to design the basic circuit and this basic circuit contains power as well as the frequency at which it will operate.
- In order to provide frequency to PIC Microcontroller, we use a crystal oscillator and for PIC16F877a, you can use a crystal oscillator of frequency range from 4MHz to 40MHz.
- So, here's the PIC16F877a Basic Circuit which you need to design:
- I have tried my best to make this PIC16F877a basic circuit as simple as possible.
- The above circuit may seem a bit complex but it is really not, let me explain it pin by pin:
- Pin # 1: This Pin is called MCLR (Master Clear) and we need to provide 5V to this pin through a 10k-ohm resistance.
- Pin # 11 & Pin # 32: These Pins are labeled as Vdd so we also need to provide it +5V and you can see these lines are in red color in above figure.
- Pin # 12 & Pin # 31: These Pins are Vss, so we have provided GND (Ground) at this pin and its lines are in black color.
- Pin # 13 & 14: These Pins are named OSC1 (Oscillator 1) and OSC2 (Oscillator 2), now we have to attach our Crystal Oscillator (16MHz) at these pins which I have lined in Orange color. After the Crystal Oscillator, we have 33pF capacitors and then they are grounded.
- We have designed our basic circuit and now our PIC Microcontroller is ready to work but you can also see an LED attached at Pin # 21 and that's because we also need to check whether it's running or not so we can turn this LED ON or OFF.
- You should have a look at LED Blinking Project on PIC Microcontroller, in which I have blinked the LED using PIC Microcontroller.
- Here's the video in which I have designed this PIC16F877a basic circuit:
PIC16F877a Pinout
- So, now I hope that you got the complete understanding of PIC16F877a Basic Circuit, so now if you have noticed that in the basic circuit, we have used all the power pins of PIC Microcontroller, while all the Ports Pins were free.
- So, now as we have powered up our PIC Microcontroller, the next thing we need to do is to design some code and use the PIC Microcontroller Ports. First, let's have a look at these PIC16F877a Ports.
- PIC16F877a has 5 Ports in total which are:
- Port A: It has 6 Pins in total starting from Pin # 2 to Pin # 7. Port A Pins are labeled from RA0 to RA5 where RA0 is the label of the first Pin of Port A.
- Port B: It has 8 Pins in total starting from Pin # 33 to Pin # 40. Port B Pins are labeled from RB0 to RB7 where RB0 is the label of the first Pin of Port B.
- Port C: It has 8 Pins in total. Its pins are not aligned together. The first four Pins of Port C are located at Pin # 15 - Pin # 18, while the last four are located at Pin # 23 - Pin # 26.
- Port D: It has 8 Pins in total. Its pins are also not aligned together. The first four Pins of Port D are located at Pin # 19 - Pin # 22, while the last four are located at Pin # 27 - Pin # 30.
- Port E: It has 3 Pins in total starting from Pin # 8 to Pin # 10. Port E Pins are labeled from RE0 to RE2 where RE0 is the label of the first Pin of Port E.
- All these Ports are labeled in the below figure:
- You can see all these PIC16F877a Ports in the above figure, now let's have a look at how to use them.
- First of all, what you need to decide is whether you want your Port Pins to be Input or Output.
- Confused? :P Let's suppose you have some sensor and you want to get its value, then you have to connect this sensor with PIC Microcontroller, now in this case your PIC Pin will be acting as Input Pin because it will be inputting value from the sensor. The sensor is sending the value and PIC is receiving it.
- But in the case of a DC Motor Control with PIC, you have to send commands from PIC Microcontroller to DC Motor, so your PIC Pin is acting as Output Pin.
Important Note:
- Each Port of PIC Microcontroller is associated with two registers, for examples Port D registers are:
- Both of these registers are of 8 bit because Port D contains 8 Pins.
- TRISD decides whether the Port is output or input and we can also assign values to each pin separately. If we have assigned 0 then it will be OUTPUT and if we have provided 1 then it will be INPUT.
- For example, if I have assigned TRISD = 0x01, then the first 7 pins of Port D will be Output but the last pin will be input because 0x01 is actually 00000001 in binary.
- PortD register contains the actual value and this value is actually the combination of all 8 pins.
PIC16F877a Compiler
- The official Compiler of the PIC Microcontroller is MPLAB C18 Compiler, which is available online from Microchip Official Site.
- There are also other compilers available and the one I normally use is MikroC Pro For PIC.
- You should have a look at this list of Top 3 PIC C Compilers.
- We write code in PIC Compilers and then compile it. After compilation, a hex file is generated which we upload in PIC Microcontroller using a programmer/burner.
PIC16F877a Serial Port
- PIC16F877a has one serial port in it which is used for data communication.
- In the below figure, I have mentioned the Serial Pins of PIC16F877a.
- AS you can see in the above figure that:
- Pin # 25 is acting as TX as well so if you want to do Serial Communication then it will be used for sending the serial data.
- Pin # 26 is acting as RX as well so if you want to do Serial Communication then it will be used for receiving the serial data.
- You should also have a look at What is Serial Port if you don't know much about Serial Port.
PIC16F877a I2C Communication
- PIC16F877a also has one I2C Port using which we can easily do the I2C Communication.
- These PIC16F877a I2C Communication Pins are shown in the below figure:
- As you can see in the above figure, PIC16F877a I2C Communication Pins are:
- Pin # 18: It is acting as SCL which is an abbreviation of Serial Clock Line.
- Pin # 23: It is acting as SDA which is an abbreviation of Serial Data Line.
- Now you can see we have Serial Port and I2C Port in Port C, so we can use Port C as a simple Port but can also do these two communications with its pins, so its totally on the programmer.
PIC16F877a Interrupts
- I hope you all know about interrupts, if not then you should have a look at Interrupts in PIC Microcontroller.
- PIC16F877a has 8 interrupt sources in it. An interrupt source is some event that generates interrupt, this source could be a timer like interrupts are generated after every 1 sec, or it could also be pin state change event, like if pin state is changed then interrupt will be generated.
- So, PIC16F877a Interrupts can be generated by following 8 ways:
- External Interrupts.
- Timer Interrupts ( Timer0 / Timer1).
- Port B State Change.
- Parallel Slave Port Read/Write.
- A/D Converter.
- Serial Receive / Transmit.
- PWM (CCP1 / CCP2).
- EEPROM Write Operation.
- PIC16F877a Interrupts are associated with below 5 registers:
- INTCON
- PIE1
- PIR1
- PIE2
- PIR2
So, that was all about
PIC16F877a, I hope you have enjoyed today's tutorial. I have tried my best to cover all aspects of this PIC Microcontroller and I would suggest you to read the links which I have provided in each section. These links will also help you more because they are focusing on that particular topic. If you have any problem with this Introduction to PIC16F877a, then you can ask in the comments below. Thanks for reading. Take care and have fun !!! :)
Interfacing of Keypad with PIC Microcontroller
Hello everyone, I hope you all are doing great. Today, I am going to share a very basic tutorial on PIC Microcontroller, which is Interfacing of Keypad with PIC Microcontroller. I have designed this simulation of Keypad with PIC Microcontroller in Proteus ISIS and the simulation along with code is given below for download. But I would suggest you to read it first and then design it on your own so that you learn most out of it.
In today's tutorial, I am not gonna discuss the details of How keypad works because I have discussed it in detail in my old tutorial
Interfacing of Keypad with Arduino so if you don't have much idea about working of keypad then I would recommend you to read that tutorial first, before proceeding with today's tutorial. I have also interface this Keypad with 8051 Microcontroller, so today we are gonna interface this keypad with PIC Microcontroller. I have written programming code for this project in MikroC Pro For PIC. So, let's get started with Interfacing of Keypad with PIC Microcontroller:
Interfacing of Keypad with PIC Microcontroller
- First of all, you can download the Simulation for this project along with programming code by clicking the below button:
Download Code & Simulation
- Now, let's design it step by step.
- I have used LCD Library for Proteus so download it first and then run this simulation.
- First of all, design a simple simulation in Proteus software as shown in below figure:
- Now paste the below programming code in MikroC Pro For PIC.
- In this Programming code, the key pressed on keypad will be displayed on the LCD.
- So, when you press any button on the keypad, it will appear on the LCD.
- Here's the code which you need to use in MikroC Pro For PIC:
unsigned short kp, cnt, oldstate = 0;
char txt[6];
char keypadPort at PORTD;
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
void main() {
cnt = 0;
Keypad_Init();
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(3, 2, "The Engineering");
Lcd_Out(4, 5, "Projects");
Lcd_Out(1, 1, "Key Pressed:");
do {
kp = 0;
do
kp = Keypad_Key_Click();
while (!kp);
switch (kp) {
case 10: kp = 42; break; // '*'
case 11: kp = 48; break; // '0'
case 12: kp = 35; break; // '#'
case 1: kp = 49; break; // 1
case 2: kp = 50; break; // 2
case 3: kp = 51; break; // 3
case 4: kp = 65; break; // A
case 5: kp = 52; break; // 4
case 6: kp = 53; break; // 5
case 7: kp = 54; break; // 6
case 8: kp = 66; break; // B
case 9: kp = 55; break; // 7
case 10: kp = 56; break; // 8
case 11: kp = 57; break; // 9
case 12: kp = 67; break; // C
case 13: kp = 42; break; // *
case 14: kp = 48; break; // 0
case 15: kp = 35; break; // #
case 16: kp = 68; break; // D
}
Lcd_Chr(1, 14, kp);
} while (1);
}
- Now get your hex file and upload it in your Proteus Simulation.
- Run your simulation and if everything goes fine then you will get results as shown in below figure:
- So, in the above figure, I have pressed button 5 on the keypad and it is shown on the LCD.
- Here's the video demonstration which will help you better in understanding this project:
So, that's how we can interface our Keypad with PIC Microcontroller. If you got into any trouble following this tutorial then ask your problems in the comments and I will help you out. That's all for today, I hope you guys can now interface keypad with PIC Microcontroller easily. :)
Receive SMS with Sim900 & PIC
Hello friends, I hope you all are fine and having fun with your lives. Today, I am going to share a new project which is Receive SMS with Sim900 & PIC Microcontroller using AT Commands. I have already posted this same project on Arduino named as Receive SMS with AT Commands using Sim900 & Arduino. In that project, I have interfaced SIM900 module with Arduino but today I am gonna interface it with PIC Microcontroller.
I have also designed a GSM Library for Proteus using which you can easily now simulate your SIM900D module in Proteus. Sim900 Module is used to send and receive SMS and it is widely used in automation and security projects. I have also posted another Project in which I have designed the Proteus simulation of GSM based Home Security System. I have already posted the Send SMS with PIC Microcontroller & SIM900 project in which we have seen How to send SMS from your GSM module to your mobile phone but today we will send SMS from our mobile phone and then will receive this SMS on the SIM900 module and will perform certain action. Forexample you want to turn your Light ON using GSM then what you need to do is to send SMS from your mobile to SIM900 module and when it receives the message, it will do the required task. Moreover if you are working on Sending SMS instead of receiving then you should have a look at How to Send SMS with PIC Microcontroller & SIM900d and if this sending is via Arduino board then there's How to Send SMS with Arduino and Sim900.
I have used PIC18F452 for this project but you can use this code for any PIC Microcontroller but it has to support the serial port. Moreover, I have used MikroC Pro for PIC Compiler to design code for receive SMS with AT commands using SIM900 & PIC Microcontroller. So, let's have a look at How to Receive SMS with Sim900 & PIC Microcontroller using AT command.
Receive SMS with Sim900 & PIC Microcontroller
- SIM900 module works on Serial Protocol. If you don't know much about Serial Port then you should read What is Serial Port?
- In serial Port we have two pins for communication, one is named as TX (transmitting) and other as RX (receiving).
- In order to Receive SMS with Sim900 & PIC Microcontroller using AT command, connections are exactly the same as we did in Send SMS with PIC Microcontroller & SIM900.
- The SIM900 module I have used for receiving SMS is shown in the below figure:
- If you have a different GSM module then there's no need to get panicked because most of the GSM modules work on Serial protocol so what you need to do is to simply find the TX and RX pins of your SIM900 module.
- As you can see inthe above SIM900 image that it has TX and RX Pins so you all need to find these pins on your SIM900 module and then connect them with RX and TX pin of your PIC Microcontroller.
- RX pin of Sim900 into Pin # 25 (TX) of PIC Microcontroller.
- TX pin of Sim900 into Pin # 26 (RX) of PIC Microcontroller.
- Moreover, you will also need to common the GND of SIM900 and PIC Microcontroller, if you are using separate power supplies for PIC Microcontroller and SIM900.
- One more thing you will also need the basic circuit of PIC Microcontroller, which is as follows:
- Here's my design for How to Receive SMS with Sim900 & PIC Microcontroller using AT command on Vero Board:
- The above hardware design on Vero Board is exactly the same and I have done the connections of my SIM900 module with PIC Microcontrolelr on the back side.
Note:
- The TX Pin of PIC Microcontroller will be connected with RX Pin of GSM Module.
- The RX Pin of PIC Microcontroller will be connected with TX Pin of GSM Module.
- GND of both GSM and PIC Microcontroller must be common.
- Now upload the hex file of the below code in your PIC Microcontroller so that we can Receive SMS with Sim900 & PIC Microcontroller using AT command.
char IncData;
int x = 0;
char RcvdMsg[60] = "";
int RcvdCheck = 0;
int RcvdConf = 0;
int index = 0;
int RcvdEnd = 0;
char MsgMob[15];
char MsgTxt[10];
int MsgLength = 0;
void RecSMS();
void ClearBuffers();
void Config();
void main() {
TRISC.F7 = 1;
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
Config();
while(1)
{
RecSMS();
}
}
void RecSMS() // Receiving the SMS and extracting the Sender Mobile number & Message Text
{
if (UART1_Data_Ready())
{
IncData = UART1_Read();
//UART1_Write_Text(IncData);
if(IncData == '+'){RcvdCheck = 1;}
if((IncData == 'C') && (RcvdCheck == 1)){RcvdCheck = 2;}
if((IncData == 'M') && (RcvdCheck == 2)){RcvdCheck = 3;}
if((IncData == 'T') && (RcvdCheck == 3)){RcvdCheck = 4;}
if(RcvdCheck == 4){index = 0;RcvdConf = 1; RcvdCheck = 0;}
if(RcvdConf == 1)
{
if(IncData == 'n'){RcvdEnd++;}
if(RcvdEnd == 3){RcvdEnd = 0;}
RcvdMsg[index] = IncData;
index++;
if(RcvdEnd == 2){RcvdConf = 0;MsgLength = index-2;index = 0;}
if(RcvdConf == 0)
{
//PortD.F3 = 1;
//UART1_Write_Text("Mobile Number is: ");
for(x = 4;x < 17;x++)
{
MsgMob[x-4] = RcvdMsg[x];
//UART1_Write(MsgMob[x-4]);
}
// UART1_Write_Text("Message Text: ");
for(x = 46;x < MsgLength;x++)
{
MsgTxt[x-46] = RcvdMsg[x];
//UART1_Write(MsgTxt[x-46]);
}
if(MsgTxt[0] == 'A'){ PortD.F0 = 1;}//L1ON();}
if(MsgTxt[0] == 'B'){ PortD.F0 = 0;}//L1OF();}
if(MsgTxt[0] == 'C'){ PortD.F1 = 1;}//L2ON();}
if(MsgTxt[0] == 'D'){ PortD.F1 = 0;}//L2OF();}
if(MsgTxt[0] == 'E'){ PortD.F2 = 1;}//L3ON();}
if(MsgTxt[0] == 'F'){ PortD.F2 = 0;}//L3OF();}
if(MsgTxt[0] == 'G'){ PortD.F3 = 1;}//L4ON();}
if(MsgTxt[0] == 'H'){ PortD.F3 = 0;}//L4OF();}
ClearBuffers();
}
}
}
}
void ClearBuffers()
{
strcpy(RcvdMsg,"");
RcvdCheck = 0;
RcvdConf = 0;
index = 0;
RcvdEnd = 0;
strcpy(MsgMob,"");
strcpy(MsgTxt,"");
MsgLength = 0;
}
void Config()
{
   Delay_ms(2000);
   UART1_Write_Text("ATE0rn");
   Delay_ms(1000);
   UART1_Write_Text("ATrn");
   Delay_ms(1000);
   UART1_Write_Text("AT+CMGF=1rn");
   Delay_ms(1000);
   UART1_Write_Text("AT+CNMI=1,2,0,0,0rn");
   Delay_ms(1000);
}
- The above code is quite self explanatory but let's have a quick explanation of this code for How to Receive SMS with Sim900 & PIC Microcontroller using AT command.
Code Explanation
- This code is designed in MikroC Pro For PIC Compiler and its written for PIC18F4520 but you can use it with any PIC Microcontroller which supports Serial Port.
- I have shown the working of the code in a block diagram in below figure:
- In this code I am using three functions other than the main function, named as:
- Config();
- RecSMS();
- ClearBuffers();
- First of all, I have used the Config() function, which is doing the Configuration settings of our GSM Module.
- In these configurations, I am making the Echo OFF and also converting my GSM modem to text messages.
- In the RecSMS() function, I am checking for +CMT, once its received then I have extracted the SMS body and the mobile number from it.
- In the ClearBuffers() function, I am clearing all the variables so that we can receive the next SMS.
So, that's all for today. I hope you guys are gonna enjoy this project How to Receive SMS with Sim900 & PIC Microcontroller using AT command. So, will meet you guys in the next tutorial. Till then take care and have fun !!! :)
Speed Control of DC Motor using PIC Microcontroller
Hello friends, hope you all are fine and having fun with your lives. Today's tutorial is about speed control of DC Motor using PIC Microcontroller. I haven't written this tutorial by myself. Instead this tutorial is written by one of my very good friend Salah Dahouathi. We had an interaction through his awesome Facebook group Let's Think Binary and I would suggest you guys to join it as well, because he posted many projects in his group. So, after having a look at his work, I asked him to write for our blog which he gladly accepted and here's his first post. :) I hope you guys are gonna enjoy this one and will get knowledge out of it. So let's get started with this speed control of DC Motor using PIC Microcontroller tutorial.
Many applications in industry such us robotics controls, swing machines, electronic bikes, winding machines, Spinning and Weaving machines and many others applications need a variable speed of DC motor. The best method for speed control of DC motor is the use of Pulse Width Modulation technique. This is a method to control the output voltage with the of constant frequency switching and by adjusting on duration of switching and in other words by changing duty cycle of switching.
Speed Control of DC Motor using PIC Microcontroller
- You can download the complete Proteus Simulation along with the Programming Code in MikroC Pro for PIC Compiler for Speed Control of DC Motor by clicking the below button:
Download Proteus Simulation
- The scheme of the project is given in the circuit below :
- Where :
- CONTROL STAGEÂ : The microcontroller is PIC16F877A
- POWER STAGE : BUCK structure : L, C, D, MOSFET
- INTERFACE STAGEÂ : IR2110
- Now in the above project, I have used IR2110 using which I have controlled the speed of DC Motor.
- You can see the PWM pin of PIC Microcontroller is coming to IR2110.
- Mr. Salah has designed the code in MikroC Pro for PIC compiler and the code is given below:
unsigned short current_duty1, current_duty2,dt;
void main()
{
ADCON1 |= 6; // all ports as digital
CMCON |= 7; // comparators off
TRISD = 0X03;
PORTD=0;
PWM1_Init(5000); // Initialize PWM module at 5KHz
PWM1_Start(); // start PWM1
while (1) { // endless loop
if (RD0_bit==1 && RD1_bit == 0) // button on RD0 pressed
{
Delay_ms(40);
//current_duty1=127; // Set duty ratio to 50%
current_duty1=64; // Set duty ratio to 25%
// duty ratio can be calculated as (Percent*255)/100
PWM1_Set_Duty(current_duty1);
}
else if (RD1_bit==1 && RD0_bit == 0 ) // button on RD1 pressed
{
Delay_ms(40);
//current_duty1=192; // Set duty ratio to 75%
current_duty2=216; // Set duty ratio to 85%
// duty ratio can be calculated as (Percent*255)/100
PWM1_Set_Duty(current_duty2);
}
else
{
Delay_ms(40);
dt=0;
PWM1_Set_Duty(dt);
}
Delay_ms(10); // slow down change pace a little
}
}
- In the above code, you can see he has used the PWM to do the speed control the DC Motor.
- Few of important commands used in above code are given below:
-
- PWM1_Init(constant long frequency) : This function initializes the PWM module with duty ratio 0. Frequency parameter is the desired frequency in Hz. It should be a numeric constant, should not be a variable.
- PWM1_Set_Duty(unsigned short duty_ratio) :Â This function is used to set the duty cycle of the PWM. The parameter duty_ratio takes values from 0 to 255, ie 0 means 0% , 127 means 50% and 255 means 100% duty cycle. The PWM1_Init() routine must be called before using this.
- PWM1_Start() :Â This function starts the PWM output. PWM1_Init() must be called before calling this routine,
- PWM1_Stop() :Â This function stops the PWM output. PWM1_Init() must be called before calling this routine. PWM1_Start() should be called before calling this function otherwise calling this function will not have any effect as PWM module is not running.
- When you run your simulation then in High speed it will look something as shown in below figure:
- As you can see in the above figure that the voltage across DC Motor is around 18V and if you are running the simulation then you will see the motor will be moving quite fast.
- Now let's move our motor in slow speed, in order to do that you have to turn ON Low speed switch as shown in below figure:
- Now if you check the voltage across DC Motor then you can see its 6V and the Dc Motor will now move at slow speed.
- Here's the video for the above project which will give you better idea of How it works:
That's all for today, thanks for reading Speed Control of DC Motor using PIC Microcontroller. I hope you have enjoyed this tutorial. In the end, I again wanna thanks to my dear friend Salah Dahouathi who has spend time in designing this great simulation, programming code and tutorial. You should also like his Facebook Group where he keeps on posting such Arduino related projects, name of his Facebook group is Let's Think Binary. So, will see you guys in next tutorial, till then take care and have fun !!! :)
Password Protection using PIC Microcontroller
Hello friends, hope you all are fine and having fun with your lives. Today, I am going to share a new project which is Password Protection using PIC Microcontroller. In this project I am going to use keypad and LCD and will be designing a system in which I am gonna drive a motor if the correct password is supplied. If you entered the wrong password then the motor will not move and you will get another chance to enter the correct password. I hope you guys are gonna enjoy this one.
I have used Keypad, LCD and PIC Microcontroller in order to design the simulation in Proteus ISIS software. You should also have a look at Electronic Door Lock using PIC Microcontroller, which is quite similar with the only difference of keypad. In that previous project, I have used serial monitor for taking inputs but in today's tutorial, I have used Keypad for taking inputs. I hope you are gonna enjoy this one.
I have used Proteus software for designing the simulation and I have used MikroC Pro for PIC compiler for designing the programming code for PIC Microcontroller and I have used PIC16F877 Microcontroller for designing this project. The code and simulation is given below for download. If you have any problem then ask in comments and I will try my best to resolve them. So, let's get started with Password Protection using PIC Microcontroller.
Password Protection using PIC Microcontroller
- You can download the complete simulation along with the code by clicking the below button but as I always suggests that you should design it on your own so that you get most out of it:
Download Project Files
- So, now let's design this Password Protection using PIC Microcontroller project, so design a circuit as shown in below figure:
- You can see in the above figure that I have used LCD 20x4 along with Keypad, motor and PIC Microcontroller.
- I have also used a transistor which is kind of a driver for DC Motor, because DC motor is operated at 12V while PIC Microcontroller signal is of 5V so we need this transistor in order to drive our motor.
Note:
- If you want to use this new stylish LCD in your Proteus simulation then you need to download and install this New LCD Library for Proteus. All instructions are given in this link for using this LCD.
- Next thing we need to do is to design a programming code for this project.
- I have designed the code in MikroC Pro for PIC compiler so copy the below code and paste it in your project of MikroC Pro for PIC and compile to get the hex file:
unsigned short kp;
char actual_password[] = "123123";
char given_password[] = "000000";
int count;
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
// Keypad module connections
char keypadPort at PORTD;
// End Keypad module connections
void Password_prompt(){
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1, 1, "Motor is Off");
Lcd_Out(2,1,"and Locked");
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1, 1, "Enter 6 digit no:");
Lcd_Cmd(_LCD_BLINK_CURSOR_ON); // Cursor off
Lcd_Cmd(_LCD_SECOND_ROW);
}
//Initialization starts here-------------------------------
void Init(){
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1, 1, "Welcome to");
Lcd_Out(2, 1, "Password Lock");
Lcd_Out(3, 2, "www.TheEngineering");
Lcd_Out(4, 5,"Projects.com");
Delay_ms(5000);
Password_prompt();
TRISB=0;
count=0;
Keypad_Init(); // Initialize Keypad
}
//Initilization ends here----------------------------------------
//Password check routine starts here-----------------------------
int Check_password(){
Lcd_Cmd(_LCD_CLEAR);
if(!memcmp(actual_password, given_password, 6)){
Lcd_Out(1, 1, "Password Matched");
Lcd_Out(2,1,"Motor is on");
return 1;
}
else{
Lcd_Out(1, 1, "Incorrect Password");
Lcd_Out(2, 1, "Try Again!");
Delay_ms(2000);
Password_prompt();
return 0;
//Enter_password();
}
count=0;
}
//Password check routine ends here-----------------------------
void main() {
Init();
do {
kp = 0; // Reset key code variable
if(count==6)
{
PORTB.B7=Check_password(); //0/1 according to password check and drives the motor
count=0;
if(PORTB.B7==1){
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
//Lcd_Cmd(_LCD_FIRST_ROW);*/
Lcd_Out(1,1,"Press * to Off");
Lcd_Out(2,1,"and Lock again");
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
do
// kp = Keypad_Key_Press(); // Store key code in kp variable
kp = Keypad_Key_Click(); // Store key code in kp variable
while (kp!=13);
if(kp==13){
PORTB.B7=0;
Password_prompt();
}
}
}
// Wait for key to be pressed and released
do
// kp = Keypad_Key_Press(); // Store key code in kp variable
kp = Keypad_Key_Click(); // Store key code in kp variable
while (!kp);
switch (kp) {
case 1: kp = 49;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 1 // Uncomment this block for keypad4x4
case 2: kp = 50;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 2
case 3: kp = 51;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 3
case 4: kp = 65;Lcd_Chr_Cp(kp); break; // A
case 5: kp = 52;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 4
case 6: kp = 53;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 5
case 7: kp = 54;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 6
case 8: kp = 66;Lcd_Chr_Cp(kp); break; // B
case 9: kp = 55;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 7
case 10: kp = 56;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 8
case 11: kp = 57;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 9
case 12: kp = 67;Lcd_Chr_Cp(kp); break; // C
case 13: kp = 42;Lcd_Cmd(_LCD_MOVE_CURSOR_LEFT);count--; break; // *
case 14: kp = 48;Lcd_Chr_Cp(kp);given_password[count]=kp;count++; break; // 0
case 15: kp = 35;Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);count++; break; // #
case 16: kp = 68;Lcd_Chr_Cp(kp); break; // D
}
} while (1);
}
- This code is used for design the code for this Password Protection using PIC Microcontroller project.
- Now after getting the hex file from this code, upload it in your simulation and if everything goes fine then you will get results as shown in below figure.
- The first screen will be look like something as shown below:
- So, its saying Welcome to Password Lock and the the link of our blog.
- After that it will ask for 6 digit password, as shown in below figure:
- Now the default password for this project is 123123, so if you have given the correct password then the motor will start moving but if you given the wrong password then it wont move and will ask for password again.
- So, let's give it a wrong password at first:
- Now you can see in the above figure that when I have given the wrong password then it says Incorrect Password and Try again.
- The motor will also remain stationary.
- Now I am gonna give it a correct password and we will see the motor will start moving as shown in below figure:
- Now when I have given the correct password, the motor started moving and the LCD says, press * to OFF and Lock again.
- So, now when you press * then the motor will stop and it will again ask you to enter 6 digit password.
- I have design this below video which will give you a better idea of working of this project:
So, that's all for today, I hope you have understood all about Password Protection using PIC Microcontroller. Will meet you guys in the next tutorial, till then take care and have fun !!! :)
Stepper Motor Control using PIC Microcontroller
Hello everyone, today I am going to share Stepper Motor Control using PIC Microcontroller. We are all quite well aware of stepper motor but if you don't have much of the idea about this motor then you should give it a google search. :P Stepper motor is used in such projects where precise movement is required. Projects where we need to move the object at some particular angle. Stepper Motor works on electromagnetic phenomena. Electromagnets are present in the stepper motor and when we supply voltage across them, these electromagnets got polarized and produce a magnetic field and in order to depolarize them, what we need to do is simply depolarize these electromagnets. We all know that in motors, we have rotor and stater so in stepper motor these electromagnets act as a stater and we need to polarize them one by one. When we polarize the first electromagnet then it attracts the stater towards it and then we depolarize this first electromagnet and polarize the second electromagnet. And the rotor attracts towards the second electromagnet. In this way, we can move our stepper motor from first to the last electromagnet and then start the process again.
So, that was a brief introduction about Stepper Motor and if you wanna read in detail about it then you should read the Wiki Page of Stepper Motor because they have explained each and everything about stepper motor in detail. I would also recommend you to read Stepper Motor Drive Circuit in Proteus ISIS because in this post I have given the basic movement of the stepper motor in detail. Our today's task is stepper motor control using PIC Microcontroller. I have used PIC16F877A for stepper motor control and I have designed the simulation for stepper motor control in Proteus ISIS software. Code written for PIC Microcontroller is designed in MikroC Pro for PIC Compiler. Simulation and Programming code is given below for download but I would recommend you to design it on your own so that you learn most of it. Anyways, let's get started with Stepper Motor Control using PIC Microcontroller.
Stepper Motor Control using PIC Microcontroller
- In this project, I am gonna control the speed angle and direction of the stepper motor using a PIC Microcontroller.
- I will send commands via Serial Terminal and on the basis of these commands, our stepper motor will change its step size as well as direction.
- You can download the stepper motor control simulation and code by clicking the below button:
Download Simulation and Code
- Now let's design it in Proteus, first of all, design a circuit as shown in the below figure:
- Now you can see in the above figure that I have used L297 and L298 as stepper motor drivers.
- You can do stepper motor control without these drivers in Proteus software but when you design it in real hardware then these drivers will be required.
- Moreover, I have used the COMPIM which is used for serial control. We will send commands via serial port and the motor will follow the instructions.
- So, now upload the below code in your PIC compiler and get your hex file.
char uart_rd;
void main()
{
TRISB = 0;
PORTB = 0;
UART1_Init(9600);
Delay_ms(100);
while(1)
{
PORTB.F0 = 1;
Delay_ms(250);
PORTB.F0 = 0;
Delay_ms(250);
if (UART1_Read() == ('e') ) {
PORTB.F2 = 0;
}
else {
PORTB.F2 = 1; }
if (UART1_Read() == ('a') ) {
PORTB.F3 = 1;
}
else {
}
if (UART1_Read() == ('b') ) {
PPORTB.F3 = 0;
}
else {
}
if (UART1_Read() == ('c') ) {
PPORTB.F4 = 0;
}
else {
}
if (UART1_Read() == ('d') ) {
PPORTB.F4 = 1;
}
else {
}
}}
- Now upload the hex file in your PIC Microcontroller and run your simulation, if everything goes fine then you will get results as shown in the below figure:
- Obviously, you can't see the motor running in the above picture but you can see it has moved to some angle.
- In actuality, it will start moving continuously and will stop when you send a command on the Serial terminal.
- The below video will explain the whole project in detail:
So, that's all about stepper motor control. I hope you have liked it and it will help you in some way. In the coming post, I will share the stepper motor control with the Arduino board. So stay tuned and have fun!!! :)
Electronic Door Locks using PIC Microcontroller
Hello friends, hope you are having fun. Today, I am going to share two types of Electronic Door Locks design using PIC Microcontroller and simulated in Proteus ISIS software. We all know about Electronic Door Locks as we have seen them in many homes. In electronic door locks, there's some password that is only known to some persons. Now if you enter the wrong password then the door won't open up and will ask for the password again. And if you keep on trying the wrong password then it will start the buzzer or can alert the concerned person via SMS etc. So, such electronic door locks are quite common in our society and are considered among the best electronic door locks.
Today, I am going to share a similar project in which I have simulated an Electronic Door lock using PIC Microcontroller. I have used PIC18F452 Microcontroller and the compiler I have used for designing the code in MikroC Pro For PIC and the simulation is designed in Proteus ISIS. The code and the Proteus simulation are given for download below. You can also design this project using Arduino or any other microcontroller like 8051 Microcontroller. Let's start with this project.
Note:
Electronic Door Locks using PIC Microcontroller
I have divided this Electronic Door Locks Project into few parts, and I have explained them separately. You can download the complete project along with the Proteus simulation by clicking the below button. But as I always suggest don't just download it, also design it on your own so that you learn more from it:
Electronic Door Locks using PIC Microcontroller
Project Overview of Smart Door Lock
- In this smart door lock project, I have used a solenoid along with a relay.
- We all know that in order to lock a door we have to use either a DC Motor or some solenoid, which should be connected with the manual lock of the door.
- Now, all we need to do is to move that motor according to our needs automatically. Like if I move the motor in one direction, the door goes locked and if I move it in opposite direction then it got unlocked.
- So, in my simulation, I have used a solenoid valve for locking purposes and I have represented it using Inductors in my simulation.
- Moreover, I have used Serial Terminal as a communication medium, means we are gonna input for password etc in the serial monitor.
- I have also used EEPROM in this project to save the current password.
- There's an option in this project to change the password, so if the user changed the current password then the new password will be saved in EEPROM.
- So, even if the device restarts, the newly changed password will remain active as it's saved in EEPROM.
- If the user entered the wrong password then the system will for the password again.
- But if the user entered the wrong password three consecutive times, the system will shut down and will start blinking the RGD lights, which I have used as an indication.
Schematics Diagram of Smart Door Lock
- Let's first design the schematics diagram of the Electronic Smart Door Lock using a PIC Microcontroller.
- I have designed the schematic in Proteus ISIS software as it's the best simulating software.
- The schematic diagram is shown in the below figure:
- It's quite clear from the above figure that I have used a PIC Microcontroller as the brain of the system.
- I have a serial terminal, which is used to take inputs from the users.
- I have used two relays and in order to drive those relays, I have used transistors.
- Transistors are converting 5V coming from Microcontroller into 12V which are driving relays.
- Moreover, I have also used optocouplers, which are just used for protection.
- Finally, I have used three LEDs that are acting as RGB and will just indicate the wrong password.
- These two relays are actually actuating the solenoid which will lock or unlock the door.
- There's no active solenoid component available in Proteus that's why I have used a simple inductor.
- Now, let's have a look at the programming code for this project.
Programming Code of Electronic Door Lock
- I have designed the programming code for PIC Microcontroller in MkiroC Pro for PIC compiler.
- You should have a look at these Top 3 PIC C Compilers and can select the one you like.
- The PIC Microcontroller used in this Electronic door locks project is PIC18F4520. You can also use other PIC Microcontrollers like PIC16F877a etc.
- You can use any other PIC Microcontroller if you want. You just need to change it in simulation and in code settings.
- Now here's the complete programming code for Electronic Door Locks using PIC Microcontroller:
char Indata;
char P1 = '1';
char P2 = '2';
char P3 = '3';
int PassCheck = 0;
int WrongCheck = 0;
int CPassCheck = 0;
void Initialization()
{
UART1_Init(9600);
TRISD = 0;
PortD = 0;
P1 = EEPROM_Read(0x01);
P2 = EEPROM_Read(0x02);
P3 = EEPROM_Read(0x03);
}
void PassChange()
{
while(1)
{
if (UART1_Data_Ready())
{
Indata = UART1_Read();
if(CPassCheck == 2){
CPassCheck = 3;
EEPROM_Write(0x03, Indata);
P3 = EEPROM_Read(0x03);}
if(CPassCheck == 1){
CPassCheck = 2;
EEPROM_Write(0x02, Indata);
P2 = EEPROM_Read(0x02);}
if(CPassCheck == 0){
CPassCheck = 1;
EEPROM_Write(0x01, Indata);
P1 = EEPROM_Read(0x01);}
UART1_Write_Text("*");
if(CPassCheck == 3){break;}
}
}
UART1_Write(10);
UART1_Write(13);
UART1_Write(10);
UART1_Write(13);
}
void CorrectPass()
{
UART1_Write(10);
UART1_Write(13);
UART1_Write(10);
UART1_Write(13);
UART1_Write_Text("Select one of the below Options: ");
UART1_Write(10);
UART1_Write(13);
UART1_Write(10);
UART1_Write(13);
UART1_Write_Text("1) Press Y to Lock.");
UART1_Write(10);
UART1_Write(13);
UART1_Write_Text("2) Press N to Unlock.");
UART1_Write(10);
UART1_Write(13);
UART1_Write_Text("3) Press C to Change Password.");
UART1_Write(10);
UART1_Write(13);
UART1_Write(10);
UART1_Write(13);
UART1_Write_Text("Waiting for Response: ");
while(1)
{
if (UART1_Data_Ready())
{
Indata = UART1_Read();
if((Indata == 'Y') || (Indata == 'y')){
UART1_Write_Text("Y");
PortD.F0 = 1;
PortD.F1 = 0;
UART1_Write(10);
UART1_Write(13);
UART1_Write(10);
UART1_Write(13); break;}
if((Indata == 'N') || (Indata == 'n')){
UART1_Write_Text("N");
PortD.F0 = 0;
PortD.F1 = 1;
UART1_Write(10);
UART1_Write(13);
UART1_Write(10);
UART1_Write(13); break;}
if((Indata == 'C') || (Indata == 'c')){
UART1_Write_Text("C");
UART1_Write(10);
UART1_Write(13);
UART1_Write(10);
UART1_Write(13);
UART1_Write_Text("Enter New Password: ");
PassChange();break;}
}
}
}
void WrongPass()
{
int x = 0;
PortD.F5 = 1;
while(1)
{
PortD.F2 = 1;
Delay_ms(100);
PortD.F2 = 0;
PortD.F3 = 1;
Delay_ms(100);
PortD.F3 = 0;
PortD.F4 = 1;
Delay_ms(100);
PortD.F4 = 0;
x = x + 1;
if(x > 30){break;}
}
PortD.F5 = 0;
}
void main() {
Initialization();
do
{
UART1_Write_Text("Enter Password: ");
while(1)
{
if (UART1_Data_Ready())
{
Indata = UART1_Read();
if((Indata == P1) && (PassCheck == 0)){PassCheck = 1;}
if((Indata == P2) && (PassCheck == 1)){PassCheck = 2;}
if((Indata == P3) && (PassCheck == 2)){PassCheck = 3;}
if((Indata == 13) && (PassCheck == 3)){
PassCheck = 0;
WrongCheck = 0;
UART1_Write(10);
UART1_Write(13);
UART1_Write_Text("Correct Password.");
CorrectPass();break;}
if((Indata == 13) && (PassCheck != 3)){
PassCheck = 0;
UART1_Write(10);
UART1_Write(13);
UART1_Write_Text("Wrong Password.");
WrongCheck = WrongCheck + 1;
if(WrongCheck == 3){WrongPass();}
UART1_Write(10); UART1_Write(13);
UART1_Write(10); UART1_Write(13);break;}
UART1_Write_Text("*");
}
}
} while(1);
}
- I have placed checks on the Enter button like when the user presses Enter button then it will check either password is correct or wrong and then will decide and on or off the respective relays.
- Moreover, the third option is to change the password and you can see right after the change password, I have used EEPROM commands to save the password for later use.
- Let's now start the simulation and test our project.
Note: If you are not much familiar with relays, then you should read these tutorials on relays:
Electronic Door Lock Simulation Result
- We have seen all the details about the project and I am quite confident that now you can quite easily design this project on your own.
- So, now let's start the simulation and have a look at the results.
- When you start your simulation then you will have such a screen:
- Now you can see, it's asking for a password in the Virtual Terminal.
- The default password set is "123". So, I am gonna give it 123.
- Now, when I gave it the correct password, it asked for the correct option.
- I have added a total of 3 options to it, which are shown in the above figure.
- So, if the user presses Y then it will lock the door and if he presses N then it will unlock the door and last option is to change the password which is set for C.
- So, that's how this project is working.
- Similarly, if I gave it the wrong password the nit will ask for try again for 3 times and then will set off the RGB lights to warn.
- Complete demonstration and working of this project is given in the below video:
That's all for the electronic smart door lock project using PIC Microcontroller. I hope you have enjoyed it. Will meet you guys in the next tutorial soon. Till then take care and have fun. :)
Top 3 PIC C Compiler
Hello friends, hope you all are fine and having fun in your lives. Today, I am going to share Top 3 PIC C Compiler. We all know about PIC Microcontrollers because of which now we can quite easily add complex automation in our projects. So, today, I am going to share C compilers for PIC Microcontrollers. When an engineer starts working on some engineering project then he must have to choose a microcontroller. PIC is most commonly used Microcontroller in engineering projects. So, now when you have selected that you are gonna use PIC Microcontroller in your project then there comes a need which compiler to use for designing programming code for PIC Microcontroller.
It's quite a difficult as well as important decision because I have seen that once you started working on some compiler then its quite difficult to switch from that compiler to any other compiler. The reason is, you have to first learn that compiler and then you start designing your codes on it and after learning one compiler you don't want to learn any other compiler. So, today I am going to share a List of PIC C compiler which are quite useful and I consider them the best compilers for PIC Microcontroller. Before going into details, lets first have a look at what is compiler.
What is Compiler ???
- In the start when microcontrollers were newly introduced, they were programmed in Machine language which is in the form of 0 and 1. We can also call it binary language. So, programming a microcontroller in machine language was quite difficult so designers did some research and they cme up with the idea of assembler.
- In assembler we write programming codes for Microcontrollers in assembly language then function of assembler is to convert that assembly language code into machine language and create the hex file and then we upload that hex file in our Microcontroller. But, if you have worked on assembly language then you must have the idea that assembly language is also not much easy and you have to write a lot of code just to perform a simple task and then researchers did some more work and finally they invented compilers. (Thanks a lot to them :D )
- Now in those compilers, we write our code in C Language and then these compilers convert those C Language codes into machine language and we get our hex file which is then uploaded in any microcontroller like PIC, Atmel, 8051 Microcontroller etc.
- Using compilers, the programming has become quite easy, we have ready to use libraries in these compilers using which we can do complex to complex tasks in just 2 to 3 lines.
- Now in different compilers the back end generated machine code is almost same but the front end C coding syntax is quite different. For example if you are working on LCD then it has different commands for printing in different compilers. So, that's why I mentioned earlier that if you are working in one compiler then switching to another compiler is quite difficult as in that case you first have to learn the syntax of that second compiler.
- There are lots of C Compilers available in market using which we can quite easily write our programming code. For different microcontrollers there are different compilers and today, I am going to share compilers for PIC Microcontroller. So let's get started with it.
Here's the list of
PIC C Compiler,which we are gonna discuss in detail below:
- MPLAB C18 Compiler
- MikroC Pro for PIC
- CCS Compiler
Top 3 PIC C Compiler
As the topic indicates, today I am going to share top 3 PIC C Compiler. These compilers are best compilers for PIC Microcontroller. I have worked on all 3 of them and that's why I have quite an idea that all of them are best compilers. They have their pros and cons but still you can work on any of them. You can say this list is a result of my 5 years hard work. :) So, let's get started with them:
1) MPLAB C18 Compiler
- MPLAB C18 compiler comes at top in the list of top 3 PIC C Compiler as its the best one in the series. MPLAB is an official software developed by Microchip for PIC Microcontroller.
- It is free to use and you can download it from official site of Microchip.
- First of all, you need to install the MPLAB software so you should read How to install MPLAB software in Windows.
- Once you installed the MPLAB software, then you should install the MPLAB C18 Compiler so you should read How to Install MPLAB C18 Compiler in Windows.
- In MPLAB you can work on assembly language as well but using the C18 compiler you can write your code in C Language.
- MPLAB is the most flexible compiler for PIC Microcontroller as you can do anything in it with you PIC Microcontroller. But its a bit difficult to learn and program as in MPLAB you have to set every bit on your own.
- When I started my programming career, then I first started working on this compiler as I like it the most.
- So, if you want complete grip on your project then this is the compiler for you.
- If you are interested in working on this compiler then you should also read Getting started with MPLAB software.
2) MikroC Pro for PIC
- MikroC Pro for PIC comes at second place in my list of top 3 PIC C Compiler.
- Its not free but has a student version using which you can compile your up to some limit. If the size of you code exceeds that limit then you can't compile your code using it.
- Its also one of my favorite compiler because of its easiness and user friendly environment.
- MikroC has a long list of built in libraries using which you can quite easily perform your tasks.
- Its not much flexible but is very user friendly, it gives you all the setting in hand and you can set them just by clicking some combo boxes.
- These days, I am working on this compiler because its easy to use and you have a great team at its back which gives you great support. So, if you ask me then I will recommend this PIC C Compiler.
Note:
Here are few projects designed in MikroC Pro for PIC Compiler:
3) CCS Compiler
- CCS Compiler comes at third place in PIC C Compiler list.
- I have used it in some projects where there was a restriction to use this compiler.
- Its a bit difficult to learn and program because of its pure C style syntax but also has a great list of libraries with it.
- If you have already worked on C Compiler for windows then I think this one is best for you as the syntax is almost similar and you can learn it easily.
That's all for top 3 PIC C Compiler. I hope you have learn something out of it. Let me know if you have any comments and I will reply you.