Interfacing of LM35 with PIC Microcontroller
Hello friends, I hope you all are fine and having fun with your lives. In today's post, I am going to share How to interface LM35 with PIC Microcontroller. I have already shared Interfacing of LM35 with Arduino so now we are gonna interface this same temperature sensor with PIC Microcontroller. Interfacing LM35 with PIC isn't much difficult as its a simple sensor which gives us analog output and we just need to read this output and convert it into temperature format. Before going into details, you should first read the Interfacing of LM35 with Arduino as I have given the basic details of this LM35 sensor in that post. You should also have a look at How to use 18B20 in Proteus.
So, today I am not gonna go into the details of this temperature sensor. Instead let's start with Interfacing of LM35 with PIC Microcontroller. I have used Proteus software for simulation purposes but you can also test it on hardware. It will work fine on hardware as I have already tested it. I have used PIC 16F876A Microcontroler for this simulation and the PIC Compiler used for writing the programming code is MikroC Pro for PIC. If you have any problem then as k in comments and I will try to resolve them as soon as possible.
I have already posted the tutorial on Arduino and today we are having a look at interfacing of LM35 with PIC Microcontroller and soon I will also post the tutorial on Interfacing of LM35 with 8051 Microcontroller. ITs a simple sensor which you can interface with any kind of Microcontroller like PIC, Atmel, Arduino or 8051 Microcontroller. Anyways let's get started with interfacing of LM35 with PIC Microcontroller.
Interfacing of LM35 with PIC Microcontroller
- You can download the complete simulation along with programming code by clicking on the below button:
Download LM35 Code and Simulation
- First of all, design a simple circuit as shown in the below figure:
- You should also try our New LCD Library for Proteus, it will give a better look to your project.
- As you can see in the above figure, we have used LM35 sensor in Proteus which is connected with PIC Microcontroller.
- Moreover, we have also connected LCD with PIC Microcontroller.
- PIC Microcontroller we have used is PIC16F876A, but you can use any other PIC Microcontroller here.
- LCD is used to display the Termperature Sensor LM35 value.
- Now copy the below code and place it in your MikroC Pro For PIC Compiler and get the hex file.
// 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
char display[16]="";
void Move_Delay() { // Function used for text moving
Delay_ms(500); // You can change the moving speed here
}
void main() {
unsigned int result;
float volt,temp;
trisb=0;
trisa=0xff;
adcon1=0x80;
lcd_init();
lcd_cmd(_lcd_clear);
lcd_cmd(_LCD_CURSOR_OFF);
lcd_out(3,2,"www.TheEngineering");
lcd_out(4,5,"Projects.com");
while(1)
{
result=adc_read(0);
volt=result*4.88;
temp=volt/10;
lcd_out(1,1,"Temp = ");
floattostr(temp,display);
lcd_out_cp(display);
lcd_chr(1,14,223); //print at pos(row=1,col=13) "°" =223 =0xdf
lcd_out_cp("C"); //celcius
//delay_ms(1000);
//Lcd_Cmd(_LCD_CLEAR);
}
}
- When you get the hex file upload it in your Proteus software and run your Proteus simulation.
- If everything goes fine then you will get something as shown in below figure:
- As you can see in the above figure, LCD is displaying the same temperature values as in LM35 temperature sensor.
- Now you can change this temperature value and the updated value will be displayed in LCD as you can see in below figure:
- Now you can see in above figure that the temperature sensor LM35 value is 100 and same is displayed on LCD.
- You should also have a look at How to use 18B20 in Proteus, which is another temperature sensor.
- You should also try 18B20 with PIC Microcontroller.
That's all for today. That's how you can interface LM35 with PIC Microcontroller and can get the temperature of your room. Will meet you guys in the next tutorial, till then take care and have fun!!! :)
Pure Sine Wave Inverter Simulation in Proteus
Hello friends, hope you all are fine and having fun with your lives. Today, I am going to share Pure Sine Wave Inverter Simulation in Proteus. I have already posted a tutorial on Pure Sine Wave Inverter Design, which got quite popular and I got a lot of requests on posting its simulation in Proteus. So, I worked on it and finally I got it working and here I am sharing it with your guys. As, it got a lot of effort to design it in Proteus that's why its not open source but I have placed a very small amount of $50 on it and you can easily buy it from shop by clicking on the below button. It include the complete code as well as the Proteus Simulation working perfectly.
Let's start with the basics of Pure Sine Wave Inverter Simulation, first of all, I would recommend you to read the Pure Sine Wave Inverter Design as I have shared all the basics in it. AC voltage is actually a fluctuating voltage and is in the form of sine wave. If you got a pure sine wave then it has no losses in it, but if your design has losses then you never got able to get a pure sine wave. Instead you get a modified sine wave. Efficiency of pure sine wave is approximately 100% and you decrease the efficiency your sine wave also start to distract. So, in short pure sine wave contains no losses and is highly desirable. So, let's get started with Pure Sine Wave Inverter Simulation in Proteus ISIS:
Note:
- The buying package contains complete working Proteus Simulation, along with Programming code and hex file for PIC16F877A.
- You can buy it from shop by clicking on below button.
Buy this Simulation
Pure Sine Wave Inverter Simulation - Logical Model
- Now, let's get started with the pure sine wave inverter simulation in Proteus. In this project I have used 12V DC battery and then converted it into 220V AC voltage and the AC we got was pure sine wave.
- In order to do so you have to follow a proper pattern as shown in below figure:
- Its quite obvious in the above figure, you are getting 12V supply from a battery so what you need to do is to pass it through a H-bridge. H bridge converter the 12V DC into 12V AC.
- This is the most important block for pure sine wave as it does the real working. Depending on the switching of H- bridge either you get a pure sine wave or a modified sine wave.
- Switching of H-bridge is done by the Microcontroller, here I have used PIC16F877A, which is normally used.
- Now, after H-bridge you have 12V AC voltage, now there's a need to convert these 12V into 220V so that you could use it and for that I have used Transformer. Its a step up transformer which converts 12V AC into 220V AC.
- Finally I have used a small LC circuit which acts as a filter and removes the ripples or noise if there's any. Noise normally comes from transformer. So, its a good precaution to use a filter rite after Transformer.
Pure Sine Wave Inverter Simulation in Proteus
- Following these steps mentioned above, I have designed the Pure Sine Wave Inverter Simulation in Proteus.
- First of all, I have designed a power supply to convert 12V into 5V so that I could feed it to microcontroller. The circuit is shown below:
- As you can see in the above figure, I have used 12V supply and then converted it into 5V using 7805, which is a voltage regulator. The output of 7805 is then fed to PIC Microcontroller which is 5V.
- Next block shown in below figure is the PIC itself and its basic circuit along with AND gates. AND gates are used to convert the signal into positive and negative because normally microcontrollers contain single CCP pin so that's why I have used one pin here and converted this single signal into positive and negative waveform of sine wave. Figure is shown below:
- So here, we are generating the pure sine wave via PWM, the carrier frequency used in this code is 20kHz. Let's have a look at this scope.
- Next comes is the main part which is the H bridge design, where we are inputting these signals coming from the PIC Microcontroller, to switch them accordingly. and after this H-bridge is the Transformer which is converting the 12V into 220V AC output. The image is shown below:
- Now let's have a look on this second scope where we should get the Pure Sine Wave. I have inputted both the terminals of AC into oscilloscope so you will get sine wave on one end and inverted sine wave on the other end, both will be displayed in the oscilloscope. The image is shown below:
- Here we got the pure sine wave at the output. Now I am not sharing the code here as I mentioned above we have designed it after a lot of efforts so its not free but we have placed a small amount on it of $50 so that you can buy it. You can get it from the shop by clicking on the button above.
- The buying package contains complete working Proteus Simulation along with Programming Code and hex file.
That's all for today. I hope you have enjoyed this
Pure Sine Wave Inverter Simulation in Proteus ISIS. If you have any questions regarding Pure Sine Wave Inverter Simulation, please ask in comments. Will meet in the next post. Till then take care and have fun !!! :)
Send SMS with PIC Microcontroller & SIM900
Hello friends, in today's post I am gonna show how to send SMS with PIC Microcontroller and SIM900. In my previous posts, we have seen how to Send SMS with Arduino and SIM900D and have also seen how to Receive SMS with Arduino and sim900D, both of them were using Arduino board. So, today I thought to post same project using PIC Microcontroller. The logics I am gonna use are exactly the sameas I did for Arduino but the only thing gonna change is the programming syntax. I am using MikroC Pro for PIC compiler for PIC Microcontroller and PIC18F452 is gonna use here. I have also posted on How to Receive SMS with AT Commands using SIM900 & PIC Microcontroller, so check it out as well if you are planning to work on PIC Microcontroller and SIM900.
There are different GSM modules available in the market but they all work on the same principal. They all are operated via Serial port, also known as UART, and are controlled via AT commands. You need to connect the PIC Microcontroller with GSM module via TX / RX pins and you are ready to start working on it. Today, I am gonna share how to send SMS with PIC Microcontroller and SIM900 and in the next post I will share how to receive SMS with SIM900 on PIC Microcontroller. So, lets start with it.
Send SMS With PIC Microcontroller & SIM900
- Sim900 shield I am gonna use is shown below, but if you don't have this one then no need to panic, simply find the TX and RX pins from your Sim900 shield.
- As you can see above I have mentioned the TX and RX pins, so you are gonna just need these two pins and connect them with PIC Microcontroller. The connections will be:
- RX pin of Sim900 into Pin # 25 (TX) of PIC Microcontroller.
- TX pin of Sim900 into Pin # 26 (RX) of PIC Microcontroller.
- One more thing you will also need the basic circuit of PIC Microcontroller, which is as follows:
- Finally, don't forget to make the GND common for PIC Microcontroller and Sim900, as PIC Microcontroller is working on 5V while the GSM module is working on 12V. There are also GSM modules available which work on 5V or 3.3V. So, whatever the case, just make sure their GND is common with GND of PIC Microcontroller.
- So, now I hope you are done with the connections and ready to start with programming, so open your MikroC Pro for PIC compiler and upload the below code into it.
void Initialization()
{
UART1_Init(9600); // Initialize Serial Port at 9600 baud rate
}
void SendSms()
{
Delay_ms(2000);
UART1_Write_Text("ATE0rn"); // AT command for Echo OFF
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);
UART1_Write_Text("AT+CMGS="+923326062060"rn");
delay_ms(500);
UART1_Write_text("www.TheEngineeringProjects.com rn");
UART1_Write(26);
}
void main() {
delay_ms(5000);
delay_ms(5000);
Initialization();
SendSms();
do
{
} while(1);
}
- Its quite a simple code, in which I first initialized the serial port at 9600 bad rate and after that I sent AT commands to our SIM900 module, which will then send the SMS.
- In the above code, change the mobile number which I have highlighted and also change the message body, change it with whatever you wanna send. Right now I am sending www.TheEngineeringProjects.com which is my website. :P
- The AT commands description is as follows:
- ATE0: It is used to turn off the Echo of Sim900 module.
- AT: It is used to test the Sim900 module.
- AT+CMGF = 1: This command is converting our Sim900 module to text mode.
- AT+CNMI=1,2,0,0,0: This command is configuring our Sim900 module. Its not compulsary but is better to use, its actual benefit will be in the next tutorial of receving sms.
- AT+CMGS: This is the actual command to send the SMS. It gets number and SMS body and then send the sms.
Note:
- In all AT commands, we need to press Enter in order to send that command to SIM900, that's why I have used rn after every command.
- But for AT+CMGS command, we have to use Cntrl+Z after sending the command and thaat's why I have used UART1_Write(26); where 26 is the ascii code for Cntrl+Z.
That's all for today, hope it will help you in some way. I have also posted on How to Receive SMS with AT Commands using SIM900 & PIC Microcontroller, so check it out as well if you are planning to work on PIC Microcontroller and SIM900. Till then have fun. :)
PIC Microcontroller Projects
Hello everyone, hope you are fine and having fun with you life.Here I am gonna post all the PIC Microcontroller Projects links, which I have posted on my blog. I am gonna make it as guide, in which I will start from very beginning and slowly will move into the pro projects. First of all, I am gonna post about basics of PIC Microcontroller, how it works? how you can write program in it? What are the software used for PIC Microcontroller Programming? Which compilers are available for PIC Microcontroller Programming? etc. So, if you are new to PIC Microcontroller and you wanna design PIC Microcontroller Projects, then here's the guide for you. Follow all these tutorials from beginning and if you feel any problem then ask in comments and I will try my best to resolve your issues.
One more thing, don't just read the posts here, instead make them practically run on your boards. Its the best way of learning because just reading the posts won't help you in understanding the problems occurred while designing PIC Microcontroller Projects. So, the best way of learning about PIC Microtroller is by reading and then implementing. Another thing electronic projects and particularly PIC Microcontroller Projects never work perfectly in the first run, and it will happen that you will thought you are doing everything perfectly fine but still not getting the required output, which is quite common. So be patient while implementing your PIC Microcontroller Projects and if you are not getting the required output then just test and test again because you must be making some slightest mistake and not realizing it. :)
All the tutorial links below are completely designed by TEP team and thus TEP owns all the rights for these projects. They are for educational purposes and if you wanna share it then do mention us, that will be a great favor. And I am mentioning again that when you got into some trouble then do ask in comments and I will surely help you out.Moreover, you can also share your PIC Microcontroller projects with us and we will post them on our blog for the others to learn. So, now let's started.
Basics of PIC Microcontroller - Must Read
Below tutorials are the basic tutorials for PIC Microcontroller, which are must learn for the engineer who are planning to work on PIC Microcontroller. Just read and understand them as they will go you the basic information about PIC Microcontrollers. If you already know the basics then you can skip this section but still I recommend you to read them once at least.
- Getting Started With Microcontrollers ? In this tutorial, I have given an overview of Microcontrollers. Its a very basic tutorial so if you are already familiar with the concept of microcontrollers then you don't need to read this article but its always good to have a taste of basics. :)
- Getting Started With PIC Microcontrollers ? After covering the basics of Microcontrollers, next thing I have covered is the basics of PIC Microcontroller, because we are dealing with PIC Microcontroller Projects here. So, first we will have the basic intro of PIC Microcontroller and then we will move forward.
- Functions available in PIC 18F452 Microcontroller ? In this tutorial, I have discussed the basic functions available in PIC18F452 Microcontroller. I have used this PIC Microcontroller in most of my tutorials so that's why I have first highlighted its main features.
- Top 3 PIC C Compilers ? Now, we have decided which Microcontroller we are gonna use so now let's discuss the C Compilers for PIC Microcontroller. So, I have discussed top 3 PIC C Compilers in this post and have a given kind of a comparison here. Its a must read post.
Compiler Installation guide for PIC Microcontroller - MPLAB
These tutorials are about compiler installation for PIC Microcontroller, Compilers are used to design the programming code for PIC Microcontroller. There are numerous Compilers available in market. The most commonly used compilers are :
- MPLAB
- MikroC Pro For PIC
- CCS Compiler For PIC
MPLAB is official compiler from Microchip and thus is free to use while the other compilers are paid but they have trial versions for testing. Personally I like MPLAB compiler as it gives the complete control over PIC Microcontrollers. After MPLAB, I work on MikroC Pro For PIC Compiler, as it has many built in functions and libraries which reduces the codes and thus efforts quite a lot.
- How to Install MPLAB Software in Windows ? MPLAB is official compiler of PIC Microcontroller so in this post, I have discussed in detail how to install this MPLAB software in Windows. Using this software you can only design assembly language code for PIC Microcontroller.
- How to Install MPLAB C18 Compiler in Windows ? Now that you have installed the MPLAB software so now its time to install its C18 Compiler so that we can write our codes for PIC Microcontroller Projects in C Language instead of Assembly Language.
- Getting Started With MPLAB ? Now that we are done with the installation of compilers so now its time to get started with MPLAB software so that's why I have given an overview of how to get started with MPLAB compiler.
PIC Microcontroller Projects
Below are different projects designed on PIC Microcontroller, I have posted them in sequence from basics to pro. The list is quite short rite now because I haven't posted much on PIC Microcontroller yet but it will keep on increasing, whenever I am gonna post any new project on PIC Microcontroller, I will add the link below.
Introduction to MPLAB Compiler
Hello friends, I hope you all are doing great. In today's tutorial, I am going to give you a detailed Introduction to MPLAB Compiler. MPLAB is used for PIC programming both in assembly and C languages. In my previous posts, I have completely explain
how to install MPLAB software and also the
C compiler for MPLAB.Today I am going to explain
getting started with MPLAB. This chapter doesn't belong to programming but the initials required for programming. Setting a project in MPLAB is not much difficult but obviously beginners don't know much about it and they think that its a crap and very difficult. Although its not and i think its the best programming compiler for
PIC Microcontroller. Easy and fully controllable. In the coming tutorial we are gonna design a small project in which we will do
LED Blinking using PIC Microcontroller. So let's start it.
Steps To Follow
I believe that you have installed the MPLAB Software which I have emailed to all the subscribed users on our site. If anyone didn't receive it yet then get subscribed on our site and I will email it to you. You should also have a look at these Top 3 PIC C Compilers. Now follow these steps carefully and if you feel any problem let me know in comments.
Step 1
- Open the software by clicking on the icon placed on your desktop or in the start menu. It will open as shown in the figure below:
Step 2
- Now first we need to make a new project to start our programming so click on Project and then New.
Step 3
- By clicking on New, it will open a new dialog box, where you need to put the Project name and the destination of your project and click OK.
- I recommend to choose a separate folder for each of your project so that the files never mixed up.
Step 4
- After clicking OK you will see that nothing changed and you are unable to see your newly created project.
- So to view your project click on the View and then Project as shown in image below:
- Now after clicking on project a small window on the right side will open.
- Its called Tree in programming language and it shows all the files you are using in your project but right now its empty because you didn't add any file in your project, you have just created it.
Step 5
- Lets add files in your project. So for this click on the File and then New and you will see a file will open with the name Untitled. this is the file in which we will add our programming code.
- But first we need to add it in our project otherwise it will remain just a notepad file.
- Sorry, I don't have image for this step actually it got lost, i think its not much difficult :))
Step 6
- So now to add you file in your project, click on the File and the Save as.
- A new dialog box will open, now enter name of your project and add it in the same location where you created your project.(it's not necessary but files of project should remain in the same location) and then click Save.
- Here comes the important part must add .c extension after the name of your file. This .c extension will tell the compiler that its our C programming file.
Step 7
- Now we have created our c file but we didn't add it in our project. ( Saving in same location doesn't mean that you have added it your project)
- So to add the file in your project, right click on the Source File in the left side panel and then click on Add Files as shown in the image below.
- It will open a dialog box now select your recently created file with the extension .c and click save and you will see that it will appear under the Source File folder.
Step 8
- Now we need to add the header, library and linker files in our project.
- So repeat the same process and right click on the Header Files and then Add Files.
- Now the question is where to find the header file.Move to the location where you have installed your C compiler, the default location is C drive and the name is MCC18.
- Open MCC18 Folder and there you will see many folders.
- To add the header file click on the folder with the name "h" (h for header).
- In this folder you will see a lot of files, which file to select depends on the PIC you are using.
- As I am using PIC18F452 so I wrote p18F452 in the File name box and in the suggestions i got my file with the name p18f452.h and i selected it and click save as shown in the image below.
Step 9
- Repeat the same process for linker and library files.
- For linker file open the folder with the name "lkr" in the MCC18 folder and for library file open the folder "lib" and select the file with name of your Microcontroller.
- I have added all my files as shown in the image below and now my project is complete.
- That's all our project structure has completed, now if you want to do coding just add it in your newly created .c file and if you want to save the project then click on File and then Save Workspace and it will save your project.
- In our next class we will add the code in the .c file and execute it on our pic.
I hope you have enjoyed this detailed
Introduction to MPLAB Compiler for PIC Microcontroller. Till next tutorial ALLAH HAFIZ ...... stay blessed ..... and keep remembering me in your prayers .... :))
Installation of MPLAB C Compiler
Hello friends, hope you all are fine and enjoying good health. In today's tutorial we are gonna have a look at Installation of MPLAB C Compiler in Windows. In the previous part of this chapter, I have explained How to install the MPLAB software in Windows, that part was not much tricky and we did very easily and our software was then ready to use, but as we didn't install the C compiler so we can't do C programming for PIC Microcontroller on MPLAB. We can only do assembly programming on it. Now in this post I will teach you how to install MPLAB C18 compiler so that we can do programming of PIC in C. There are many different compilers available in the market, one of them is MikroC and another famous one is CCS but they are paid compilers means you have to buy them, in order to work on them. You should also have a look at Introduction to MPLAB Compiler.
Although they provide some demo version as well which has some limit of hex size. Why MPLAB is better than MikroC or any other compiler is because it is very flexible. You can change any bit of your Microcontroller in MPLAB but this thing isn't possible in other compilers. But on the other side it also more difficult than other compilers. MikroC has builtin libraries using which you can save quite a lot of time. Suppose you wanna run LCD, then in MikroC you just need to write 2 lines but in MPLAB there will be quite a lot code lines need to be written. Here's a comparison of Top 3 PIC C Compilers. So, anyways its just a little comparison, now lets come back to our tutorial and start with Installation of MPLAB C Compiler.
Installation of MPLAB C Compiler
- The software has already been emailed to all the subscribed members. If you are not subscribed yet then get subscribed and it will be emailed to you as well.
- Open the rar file and you will see there are two folders in it, this time open the second folder named MPLAB C18 F and run the exe file in it.
- The next screen appears will be like the below image. On this step click Next.
- Now the below image will appear, click on I Accept and then click Next.
- Browse for the location where you want to install the compiler but i will recommend to install it in the C so don't change the location.
- Now don't change any option and just click Next again as shown in below image:
- Now here comes the real part, check all the boxes as shown in below image, they make the work easier and while making a project you don't need to add them manually.
- Again you will come with four option and do the same thing check all the boxes as shown in the image below.
- Now simply click on Next.
- And finally your software will begin to install.
- When the installation process is completed , uncheck all the options and just click on the finish button and your C compiler is now ready for use.
Advice
- Always install the MPLAB software first and then the C compiler. Actually C compiler links itself with the MPLAB software so it will become very handy for you.
- It seems like a lengthy proces but in actual its not, just a few clicks and you are done.
I hope you have enjoyed today's tutorial and now can easily install MPLAB C Compiler for
PIC Microcontroller. Will meet you guys in next tutorial. Till then take care & have fun !!! :)
Functions Available in PIC18F452 Microcontroller
In the previous tutorial, I explained Getting Started with PIC microcontrollers and the software etc. Today, I am going to explain the hardware of PIC18F452 i.e. the functions available in PIC18F452. In other words, working of pins. We have a total of 40 pins in 18F452 microcontroller. Different PIC microcontrollers have different pins and different functions. Some of the PIC Microcontrollers lack the below functions and some of them have much more functions than these. So, here I am just discussing the PIC Microcontroller 18F452 because it is a moderate one and is mostly used in engineering projects. It's an 8-bit microcontroller. So now we are gonna have a look at the functions available in the PIC18F452 microcontroller. In the next tutorial, I have discussed How to install MPLAB software in Windows and have also discussed How to Install MPLAB C18 Compiler.
Ports
There are a total of five ports in PIC18F452. Each port is 1 byte (8 bits) and so each port has 8 pins of microcontroller except the portE which has 3 pins. These ports are named as:
- PORTA ( Pin # 2 to Pin # 10 )
- PORTB ( Pin # 33 to Pin # 40 )
- PORTC ( Pin # 15 to Pin # 18 & Pin # 23 to Pin # 26 )
- PORTD ( Pin # 19 to Pin # 22 & Pin # 27 to Pin # 30 )
- PORTE ( Pin # 8 to Pin # 10 )
You can access any pin of any port. Ports' pins are assigned as 0,1,2,3,4,5,6,7 and 7 being the most significant bit and 0 the least so suppose I want to use PIN 3 of port B then I will write RB2. We will see it in more detail in the coding section and as it's just the hardware section I am not going into detail about this.
Timers in PIC18F452
We have a total of four built-in timers in the PIC18F452. These timers are also used as counters. We can set them to count anything or to set delays etc. For example, we want to make a digital watch on LCD using PIC, in that case, we will use timers to count. Four timers used in PIC18F452 are:
- Timer0
- Timer1
- Timer2
- Timer3
Serial Port Interfacing
PIC18F452 also supports serial interfacing using TX & RX pins. Suppose we are using any sensor and want to make a graph of its output on the PC, then we will attach the sensor to any of the input pins and then send its data to the computer using TX and RX pins. In PIC18F452:
- TX pin is pin # 25
- RX pin is pin # 26
We use the TX pin of the PIC when we want to transmit data from the PIC to the computer and RX when we want to receive data into the PIC.
Some Other Functions
These are some advanced-level functions that I will explain in the advanced section but interested readers can ask in comments or can contact me. However, sooner or later, I will post about all of them in detail.
- Interrupts in PIC18F452
- A/D converter
- EEPROM storage
- CCP and ECCP Programming
- SPI Protocol
- I2C Protocol
Getting Started with PIC Microcontrollers
In the last tutorial, we discussed Getting Started with Microcontrollers and how they work and now we are gonna have a look at Getting Started with PIC Microcontrollers. PIC microcontrollers, as I mentioned before, are manufactured by Microchip. There are many types of microcontrollers but here I am concerned with PIC18F452.So let's have a small review of PIC18F452 PIC microcontrollers.
PIC18F452 is a 40-pin microcontroller each pin has its functionality, which we will see in our next classes one by one. suppose I want to create a project on LED blinking, a simple project on PIC so what do I have to do? First of all, I need the following things so that I may use them to work with PIC. I have discussed the Functions available in the PIC18F452 Microcontroller in the next post.
Important Points
- MPLAB ---> MPLAB is a software which you can download easily from the official website of Microsoft as it's an open source software. In MPLAB you will do programming in Assembly & C Language. We will learn Assembly & C Language in our next classes.
NOTE: We will learn the Assembly & C language in our next classes. This software has already been sent to all the registered users. If you need it, then Subscribe to our Email Notification and this will be forwarded to you. Thanks.
- PIC Programmer ----> There are many PIC Programmers available in the market. You have to attach this Programmer to the PC through a serial port (Parallel Port & USB Port PIC Programmer are also available). Now Put your PIC in the 40-pin socket of the Programmer.
- PICpgm Software / PICKit software ----> This software is used to burn the program in the PIC. It's just the same as burning a movie on DVD. Now open this software and browse to your program which you have made in MPLAB and then click on program PIC and your Program will be burnt on your PIC.
- PIC Basic Circuit ---->PIC alone never works, we have to add a simple circuitry to make it work Below figure shows the simple PIC circuit. It is not very difficult and you can make it on a simple vero board with soldering. I have given its circuit below :
Now remove your PIC microcontrollers from the Programmer and add them to the hardware circuit and you will check that your PIC will give you the same results as you have programmed in it. In this tutorial, we have just taken an overview of PIC Microcontrollers. Next, we will check its Ports and the purpose of these ports. Till then take care ALLAH HAFIZ .... :))
Getting Started With Microcontrollers
Hey guys hope you all are fine and healthy. Today I am going to start a new tutorial, about PIC Microcontrollers. I will start from the very basics of PIC Microcontroller so that the beginner can also learn from it and can easily work on their projects and I will also post some projects in which I will use PIC Microcontroller and will control different modules using it.
The only thing I hate about PIC Microcontroller is the designing of its basic circuit, which we will discuss in coming tutorials, that's why I prefer to work on Arduino which is way more user-friendly than PIC Microcontroller but if look at the brighter side of PIC Microcontroller than it is much more flexible in option as compared to Arduino. Let's start today's tutorial, today I will just give an overview of what actually Microcontroller is and why to use it. So, let's begin with getting started with microcontrollers.
What is Microcontroller?
Microcontrollers are used to put the brain in your projects. Let's take an example, you have seen different light patterns at weddings or different functions where it seems like lights are walking, sometimes they show some characters glowing on and off quickly, etc. Before microcontrollers such patterns of light were very difficult you need a a lot of circuitry (serial & parallel combinations of lights) and then have to decide which light to on and which to off. A big messy thing but with the invention of the microcontroller, now you just have to add a microcontroller and put in some coding and you are done. That's the benefit of the microcontroller. and second thing in order scenario if something goes wrong then you have to change the hardware connections but in the microcontroller just change the code and you are done with no need for soldering etc.
Types of Microcontrollers
There are different microcontrollers manufactured by different companies these days. A few of them are:
- PIC
- ATMEL
- AVR
- FPGa
- Arduino (Board actually, I will explain later)
- & a lot more
but all of them have the same function. Let's look at their function.
Function of Microcontroller
A microcontroller is a simple chip (IC). We are not discussing its internal architecture as it's beyond the scope of this tutorial. We are here just concerned with its output. So a microcontroller is just a simple hardware chip. Now how to operate that chip is a question. A microcontroller has different no of pins some have 8 pins some 16 and some 40 even have 80 pins. Each pin has its function and we tell the microcontroller what function each pin will perform by adding a code in the microcontroller.
PIC Microcontrollers
PIC microcontrollers are manufactured by a company named Microchip. There is a wide variety of PIC microcontrollers. They are named PIC16F877A or PIC 18F452. The first two numbers show the series like the PIC16F series and PIC18F series. Each series has its own functions and qualities and the number of pins also varies. In my tutorial, I am gonna use the PIC18 F452 which is shown in the above figure too.
That's all for right now. I will continue it after afternoon. Stay blessed .... :))
Servo Motor Control with PIC Microcontroller
Hello friends, hope you all are healthy, wealthy and wise.
First of all, I am quite sorry about not posting for a long time, actually the load of work has really increased and I don't even have time to comb my hair.
Secondly, I have a really great news for you guys and the news is we have officially set up our office. Now, we will be more professional than ever and will respond to your queries quite fast now. I will update the photos of my new office soon INSHAHLLAH.
Let's come back to our topic. Previously, I have discussed the DC Motor control in Proteus ISIS and Stepper Motor Control in Proteus ISIS. So, now we are left with only one motor which is Servo Motor. Today's topic, as the name suggests is about the Servo Motor Control using PIC Microcontroller. The microcontroller, I am going to use in this tutorial is PIC16F877A. In this tutorial, I will design a circuit for Servo Motor Control and will also provide the code, which I have used for Servo Motor Control. If you are working on a Servo motor then you should also check Control Servo Motor with Arduino. in which I have design a servo motor control circuit using Arduino board. The code is also given there. Moreover, you should also check Angle control of Servo Motor with 555 Timer.
A Brief Intro About Servo Motor
- Servo motor is simply another motor having a much better control system already installed in it.
- The beaut of servo lies in its precise angular movement. In other words, you can move the motor at any angle you want. Like I want to move the motor to 30 degrees then I can do it quite easily in servo, which is not possible in DC or stepper.
- Moreover, it has just 3 wires to control, one is GND, one is Vcc and the third one which is usually the middle one is for controlling purposes.
- Now when you apply signal to the middle one, it starts moving. Now, how much it will move depends on the length of signal applied. If the signal applied is small, it will cover small distance.
Servo Motor Control Circuit in Proteus ISIS
- First of all select the below components from the Proteus library and add it in your workspace.
Components Used:
These components are used while designing this simulation:
- PIC16F877a.
- Servo Motor.
- Crystal Oscillator. ( 16MHz )
- Resistors. ( We need 3 resistors of 10k ohm )
- Capacitors. ( We need 2 capacitors of 33pF )
- Two Push Buttons.
Working Principle:
- Now, design your circuit as shown in the below figure:
- When I started this simulation the motor moved to the -90 degree angle. Now when I press the button, it will move in the opposite direction.
- That's how it works. Just a simple motor nothing much complicated.
PIC Microcontroller Code for Servo Motor Control
- Here's the code which I have used for controlling this servo motor. Burn this code in your PIC Microcontroller.
#define M1 PORTB.F7
#define M2 PORTB.F6
#define B1 PORTD.F0
#define B2 PORTD.F1
int a;
void main() {
TRISB=0;
TRISD=0xFF;
PORTB = 0;
a = 1;
while(1){
if((B1 == 0) && (a==1)){
PortB=0xFF;
delay_ms(100);
PortB=0x00;
delay_ms(1);
PortB=0xff;
a=0;
}
if(B2 == 0){
PortB=0x00;
}
}
}
Note:
- The code and the Proteus Simulation has already been emailed to all the subscribed members. If you are new here then subscribe to our newsletter and it will be emailed to you as well.
That's all for today. Hope I have helped you in some ways. In the next tutorial, we are gonna have a look at
Relay Simulation in Proteus ISIS. Till then, Take care, Stay Blessed.