Convolution Calculator in MATLAB
Hello friends, hope you all are fine and having fun with your lives. In today's post, I am gonna design a Convolution Calculator in MATLAB. We all know about convolution but if you don't know then here's the wiki page for convolution which has a detailed description of Convolution. In simple words, convolution is a mathematical operation, which applies on two values say f and g and gives a third value as an output say v. In convolution, we do point to point multiplication of input functions and gets our output function.
Convolution is an important technique and is used in many simulating projects. It has a vital importance in image processing. So, today we are gonna do convolution in MATLAB and will check the output. You should also check Image Zooming with Bilinear Interpolation in MATLAB in which we have used correlation technique which is quite similar to convolution. It will give you a better idea of convolution, I recommend you to read their difference. Anyways, coming back to our today's Convolution Calculator, let's start its designing:
Convolution Calculator in MATLAB
- MATLAB has a built in command for convolution using which we can easily find the convolution of two functions.
- Syntax of this builtin convolution command is v=conv(x,h) where x and h are the input functions while v is our output.
- In my code I have used this builtin function as well as I have also design a small algorithm for calculating the convolution using its formula.
- After finding both the convolutions, I have simply compared them by plotting them on graph so that we can also verify that our result is correct.
- You can use this convolution calculator to find convolution of any two functions.
- So, first of all, copy this code and paste it in your m file and run it in your MATLAB:
clc
close all
clear all
x=input('enter the sequence, x(n)=')
h=input('enter the sequence, h(n)=')
m=length(x);
n=length(h);
subplot(4,1,1)
stem(1:m,x,'fill','r')
grid on;
title('input sequence, x(n)=')
xlabel('time n------>')
ylabel('amplitude----->')
subplot(4,1,2)
stem(1:n,h,'fill','r')
grid on;
title('impulse sequence, h(n)=')
xlabel('time n------>')
ylabel('amplitude----->')
%------linear convolution using inbuilt command------------------------%
v=conv(x,h)
l=m+n-1;
subplot(4,1,3)
stem(1:l,v,'fill','r')
grid on;
title('output sequence using inbuilt command, v(n)=')
xlabel('time n------>')
ylabel('amplitude----->')
%--------linear convolution using 'for' loop------------------------------%
X=zeros(1,l);
H=zeros(1,l);
X(1:m)=x;
H(1:n)=h;
for i=1:l
Y(i)=0;
for j=1:i
Y(i)=Y(i)+X(j)*H(i-j+1);
end
end
Y
subplot(4,1,4)
stem(1:l,Y,'fill','r')
grid on;
title('output sequence using loop, Y(n)=')
xlabel('time n------>')
ylabel('amplitude----->')
- The above code for convolution calculator is quite self explanatory but let me explain it a little.
- First of all, I am asking for inputs from user and they are saved in variables named as x and h.
- After that I am plotting them using stem function.
- In the next section, I have used the default MATLAB command for Convolution and calculated the convolution of x and h and saved it in v.
- Next I applied my simple algorithm and calculated convolution of x and h and saved it in Y and also plotted it.
- Once you run the simulation and give your input functions, you will get the below results:
- You can see in the above figure that I have given two inputs x and h and MATLAB Convolution Calculator calculated the convolution and gave us v and Y.
- v is calculated by default MATLAB command while the Y is calculated by our small convolution algorithm.
- Their graph representation is shown in the below figure:
- You can see in the above figure that we have plotted all the four signals, two inputs and two outputs and you can see both the outputs are same.
- Here's the video for this convolution calculator in MATLAB:
That's how you can design a convolution calculator in MATLAB. Let me know about your experience with this convolution calculator. I am planning to design a GUI for this calculator and will add it in this post.
MATLAB Projects
Hello friends, hope you all are fine and having fun with your lives. Today, I am going to combine all of my MATLAB Projects in this post. I have posted quite a lot of projects on MATLAB but they are not well arranged that's why are not easily accessible. So, today I finally thought to combine all my MATLAB Projects and post their links in this post so that you guys can easily access all of them in one place just like Arduino , PIC Microcontroller Projects. All these MATLAB Projects and tutorials are designed and written by our team and we have done quite a lot of work in compiling these projects as you all know MATLAB is the most difficult and vast educational tool.
Most of these MATLAB Projects are free to use and users can easily download their codes from the respective project but few of them are not free but we have placed quite small amount on them so that engineering students can buy them easily. If you got problem in any of these tutorials, then ask in comments of that respective project and I will try my best to resolve your problems as soon as possible. Moreover, I am also gonna add more MATLAB Projects in future so I will keep on adding their links in this post so that we have complete record in one place. :) As I always say, other bloggers are welcome to copy these codes but do mention our blog link in your posts and help us grow. :) So, let's get started with MATLAB Projects:
Basics of MATLAB
These are basic tutorials on MATLAB and are essential for beginner to must read them once and then move on to next tutorials. In these tutorials, I have just shown some tricks of using MATLAB, so must read them once.
MATLAB Projects - Coding
These are coding based MATLAB Projects. In these projects, I have designed algorithms in m file of MATLAB software. If you have problem in any of these projects then ask in comments and I will resolve them.
Embedded MATLAB Projects
Simulink Projects
Below are given MATLAB Projects designed in Simulink. Simulink is an awesome simulation tool available in MATLAB and is used for designing complex projects. Till now, I haven't posted much simulations but I have plans to post more simulations in near future:
Inverters Simulation
Image Processing
Image Processing is one of the best tool of MATLAB software. We can perform any kind of image processing in MATLAB. Below are given image processing projects in MATLAB software.
Speech Recognition in MATLAB using Correlation
Hello friends, hope you all are fine and having fun with your lives. Today, I am going to share a tutorial on Speech Recognition in MATLAB using Correlation. Speech recognition is used in almost every security project where you need to speak and tell your password to a computer and is also used for automation. For example, I want to turn my AC on or off using voice commands then I have to use Speech Recognition. I have to make the system recognize that whether I am saying ON or OFF. In short, speech recognition plays a vital role in voice control projects. In today's post, I am gonna show you How to do Speech Recognition in Matlab and the technique I have used in this project is known as cross correlation. You should also have a look at Eye Ball Detection in MATLAB.
Correlation is normally used in signal processing, where you need to compare two signals and need to find the similarity between them. It is also known as the dot product of those two signals. Correlation has many uses and you can read more about it on its Wiki Page. Correlation is also used for pattern recognition like you want to find some pattern in the signal then you can use Correlation. Anyways, in our project, we are using correlation to find similarities between our stored signals and the testing signal. So, let's get started with Speech Recognition in MATLAB using Correlation.
Speech Recognition in MATLAB using Correlation
- First of all, download this complete project by clicking the below button:
- Now in this package, you will find nine audio wav files.
- Five of them are the recorded sounds that are already feed in MATLAB.
- Two are test files that will be recognized by the code.
- The remaining two are success and failure files which will run if you got the recognition or not.
- Let me explain the code a bit. First of all, what we need to do is to upload the first five training audio files in the software so and then we need to test these fives files with the test files and we need to check which one is a maximum match.
- Here's the complete code:
function speechrecognition(filename)
voice=wavread(filename);
x=voice;
x=x';
x=x(1,:);
x=x';
y1=wavread('one.wav');
y1=y1';
y1=y1(1,:);
y1=y1';
z1=xcorr(x,y1);
m1=max(z1);
l1=length(z1);
t1=-((l1-1)/2):1:((l1-1)/2);
t1=t1';
%subplot(3,2,1);
plot(t1,z1);
y2=wavread('two.wav');
y2=y2';
y2=y2(1,:);
y2=y2';
z2=xcorr(x,y2);
m2=max(z2);
l2=length(z2);
t2=-((l2-1)/2):1:((l2-1)/2);
t2=t2';
%subplot(3,2,2);
figure
plot(t2,z2);
y3=wavread('three.wav');
y3=y3';
y3=y3(1,:);
y3=y3';
z3=xcorr(x,y3);
m3=max(z3);
l3=length(z3);
t3=-((l3-1)/2):1:((l3-1)/2);
t3=t3';
%subplot(3,2,3);
figure
plot(t3,z3);
y4=wavread('four.wav');
y4=y4';
y4=y4(1,:);
y4=y4';
z4=xcorr(x,y4);
m4=max(z4);
l4=length(z4);
t4=-((l4-1)/2):1:((l4-1)/2);
t4=t4';
%subplot(3,2,4);
figure
plot(t4,z4);
y5=wavread('five.wav');
y5=y5';
y5=y5(1,:);
y5=y5';
z5=xcorr(x,y5);
m5=max(z5);
l5=length(z5);
t5=-((l5-1)/2):1:((l5-1)/2);
t5=t5';
%subplot(3,2,5);
figure
plot(t5,z5);
m6=300;
a=[m1 m2 m3 m4 m5 m6];
m=max(a);
h=wavread('allow.wav');
if m<=m1
soundsc(wavread('one.wav'),50000)
soundsc(h,50000)
elseif m<=m2
soundsc(wavread('two.wav'),50000)
soundsc(h,50000)
elseif m<=m3
soundsc(wavread('three.wav'),50000)
soundsc(h,50000)
elseif m<=m4
soundsc(wavread('four.wav'),50000)
soundsc(h,50000)
elseif m<m5
soundsc(wavread('five.wav'),50000)
soundsc(h,50000)
else
{soundsc(wavread('denied.wav'),50000)}
end
- Now if you read the code from start then you can see, first of all, I uploaded the test file which I want to compare with my samples.
- After that, I uploaded all 5 samples and also get their correlation with the test sample.
- Finally, in the end, I compared the results and on the basis of it I figured out which one is the correct speech file.
- You will also get spectrum graphs of your sound files as shown in the below figure:
- It was quite an easy project and I have done it within half an hour and I hope you guys will understand.
- If you got any problems then ask in the comments and I will resolve them.
- Here's the complete video demonstration for this project and I hope it's going to help you out in understanding it.
That's all for today, and I think you have understood How to do Speech Recognition in MATLAB using Correlation. Will meet you guys in the next tutorial soon. Till then take care !!! :)
Image Zooming with Bilinear Interpolation in MATLAB
Hello friends, hope you all are fine and having fun with your lives. Today, I am going to share a simple tutorial on Image zooming with bilinear Interpolation in MATLAB. We have seen many software in which there's an option of zooming an image. For example, if you have used paint or photoshop then you have seen that you can zoom your image quite easily by clicking a button. Today's we are gonna do the same thing but in MATLAB and we will have a look at the code behind this feature.
Now, when we are zooming some image then in fact we are increasing the pixels of that image and in order to do that we have to fill those extra pixels with the color of their neighbor pixel. This thing is know as interpolation. There are many different techniques for interpolation and the one we are gonna use for this tutorial is known as Bilinear Interpolation. Bilinear interpolation is simple type of linear interpolation in which we simply apply interpolation formula on both the x and y axis. So, let's have a brief overview of Bilinear Interpolation first and then we will move on to MATLAB implementation.
What is Bilinear Interpolation ?
- As I explained earlier, Bilinear Interpolation is a simple interpolation technique in which we fill the gaps between pixels using the neighbor pixels.
- For example, we have an unknown pixel in between four pixels, and let's say the unknown pixel is f(x,y) and it is surrounded by four pixels which are:
- Q11 = (x1, y1).
- Q12 = (x1, y2).
- Q21 = (x2, y1).
- Q22 = (x2, y2).
- All these four neighbor pixels are known , now by using Bilinear Interpolation we can find the values of this unknown pixel.
- Now, first of all, we will move in the x direction only.
- The formula used for Bilinear Interpolation for x factor is:
- Now after calculating these x formulas, now we will move in y direction and the formulas are:
- Now using these formulas we can quite easily find our unknown pixel f(x,y) using Bilinear interpolation. These formulas are taken from Wiki Page of Bilinear Interpolation and you can read more details about it there.
- Now we have seen the Bilinear Interpolation so now let's move and see How to do Image Zooming using this Bilinear interpolation in MATLAB.
Image Zooming with Bilinear Interpolation in MATLAB
- You can download the complete code by clicking the below button but also read the post, as I have explained this code in this remaining post.
Download MATLAB Code for Image Zooming
- In order to do image zooming with Bilinear Interpolation in MATLAB, first of all, what you need to do is to read an image file, which I have done using this simple formula:
im0=imread('TEP.jpg');
im=cast(im0,'int16');
imshow(cast(im,'uint8'));
[h,v,d]=size(im);
- So, in this above code, what we did is , we simply read the image file which I have named as TEP.jpg
- After that I have converted this image file into int16 and then to uint8 and finally I get the size of this image file using size command.
- After that I have applied a simple algorithm and have zoomed my image using below code:
for i=1:h
for j=1:v
im1(1+(i-1)*fac,1+(j-1)*fac,:)=im(i,j,:);
end
imshow(cast(im1,'uint8'));
end
- Now in the above loop what we have done is we simply enhanced our image and named it as im1, I have used a variable fac, which is factor, its user defined like if you want to zoom image by 2 then factor will be 2.
- Now we have enhanced our image, next thing we need to do is to apply the bilinear Interpolation on this complete image and we will get the result.
- Here's the complete code for Image Zooming with Bilinear Interpolation in MATLAB.
function bilinear_zoom(fac)
im0=imread('TEP.jpg');
im=cast(im0,'int16');
imshow(cast(im,'uint8'));
[h,v,d]=size(im);
for i=1:h
for j=1:v
im1(1+(i-1)*fac,1+(j-1)*fac,:)=im(i,j,:);
end
imshow(cast(im1,'uint8'));
end
%bilinear interpolation
for i=1:1+(h-2)*fac %row number
for j=1:1+(v-2)*fac %column number
if ((rem(i-1,fac)==0) && (rem(j-1,fac)==0))
else
h00=im1( ceil(i/fac)*fac-fac+1,ceil(j/fac)*fac-fac+1,:);
h10=im1( ceil(i/fac)*fac-fac+1+fac,ceil(j/fac)*fac-fac+1,:);
h01=im1( ceil(i/fac)*fac-fac+1,ceil(j/fac)*fac-fac+1+fac,:);
h11=im1( ceil(i/fac)*fac-fac+1+fac,ceil(j/fac)*fac-fac+1+fac,:);
x=rem(i-1,fac); %coordinates of calculating pixel.
y=rem(j-1,fac);
dx=x/fac; %localizeing the pixel being calculated to the nearest four know pixels.
dy=y/fac;
b1=h00; %constants of bilinear interpolation.
b2=h10-h00;
b3=h01-h00;
b4=h00-h10-h01+h11;
im1(i,j,:)=b1+b2*dx+b3*dy+b4*dx*dy; %equation of bilinear interpolation.
end
end
imshow(cast(im1,'uint8'));
end
imshow(cast(im1,'uint8'));
imwrite(cast(im1,'uint8'),'zoomed_pic.jpg');
- Now if you check in the Bilinear Interpolation code, we have applied the same equations which we have discussed in the above section.
- The Image I have used for this code is as follows:
- Now in MATLAB window, I have given this command bilinear_zoom(2) , where fac = 2, so I am increasing my image by factor 2. So it will be zoomed by 2 times.
- Its the image from my 555 Timer post but as I have posted it recently so this image was on my desktop thats why I used it. :P
- The result obtained is as follows:
- Now you can see the image has been zoomed and is now looking big and because of Bilinear Interpolation in MATLAB we haven't lost the in between pixels.
- Here's a video for this tutorial, which will give you better idea of How to do Image Zooming with Bilinear Interpolation in MATLAB.
That's all for today, I hope you have enjoyed this post. Will meet you guys in the next tutorials soon. Till then take care. :)
Automatically Connect with Wifi SSID using Arduino YUN
Hello Friends, hope you all are fine and having fun. In today tutorial i am going to elaborate How to Automatically Connect with Wifi SSID using Arduino YUN. If you recall one of my previous tutorials named Getting started with Arduino YUN , in which i gave a brief introduction about Arduino YUN, its working and features. In that tutorial, I have explained How to connect Arduino YUN with Wifi manually. A little problem encounters while connecting Arduino manually to available wifi networks that if wifi connection drops then, then Arduino will also disconnect automatically and if wifi connection is energized again, it will still remain disconnected unless you reconnect it by yourself. This thing has very serious drawbacks in industrial projects, where data is continuously uploaded through multiple servers and if at any stage connection drops and Arduino stops working then, this thing leads to drastic outcomes.
So there is serious need to design an algorithm in which Arduino automatically connects to the available wifi connections and should enables the server to upload data through it. This whole process is a bit lengthy and much complicated. So, i will elaborate all this in the coming tutorials. In today's tutorial i am going to restrict myself only How to get Available wifi SSID using Arduino YUN. First of all lets recall the basics of Arduino YUN. Arduino YUN has 2 micro processors embedded on the same board. First is the Arduino microprocessor and the second is Atheros micro processor. Atheros supports Linux server (commonly used in Apple computers). With both these on-board micro processors, we can do anything we want to do. The beauty of Arduino board is that it has built in wifi, Ethernet port, USB host and SD card slot. We can also upload data into Arduino through wifi without physically connecting it with computer. That's why Arduino boards are the most widely used micro processors now a days, and are able to handle multitasking industrial projects. Above was a little introduction about Arduino YUN and now lets get started with our today's tutorial.
Automatically Connect with Wifi SSID using Arduino YUN
- First of all open the Arduino softeare. On toolbar click on the icon named "Tools" and a new window will open. Then go to the option "Board" and from the next opened window select the board "Arduino YUN".
NOTE:
- Remember you must download the Arduino software version 1.5.5 + instead of 1.0.3 because Arduino sketches will be only compiled in 1.5.5 version which is specifically designed for Arduino YUN.
- After selecting the board, you will load the given below code into Arduino Board.
#include <Process.h>
#include <FileIO.h>
String ESSID = "TEP";
String Pass = "Pakistan";
String Encrypt = "psk2";
void setup() {
Serial.begin(9600);
delay(5000);
FileSystem.begin();
delay(5000);
Bridge.begin();
delay(5000);
}
void loop() {
// put your main code here, to run repeatedly:
WifiAuthentication();
}
void WifiAuthentication()
{
uploadScript();
delay(1000);
runScript();
delay(20000);
}
void uploadScript()
{
File script = FileSystem.open("/tmp/setupwifi.sh", FILE_WRITE);
script.print("#!/bin/sh\n");
script.print("/sbin/uci set network.lan=interface\n");
script.print("/sbin/uci set network.lan.proto=dhcp\n");
script.print("/sbin/uci delete network.lan.ipaddr\n");
script.print("/sbin/uci delete network.lan.netmask\n");
script.print("/sbin/uci set wireless.@wifi-iface[0].mode=sta\n");
script.print("/sbin/uci set wireless.@wifi-iface[0].ssid=" + ESSID + "\n");
script.print("/sbin/uci set wireless.@wifi-iface[0].encryption=" + Encrypt + "\n");
script.print("/sbin/uci set wireless.@wifi-iface[0].key=" + Pass + "\n");
script.print("/sbin/uci commit wireless; /sbin/wifi\n");
script.print("/etc/init.d/network restart\n");
script.close();
Process chmod;
chmod.begin("chmod");
chmod.addParameter("755");
chmod.addParameter("/tmp/setupwifi.sh");
chmod.run();
}
void runScript()
{
Process myscript;
myscript.begin("/tmp/setupwifi.sh");
myscript.run();
Serial.println("Connected");
}
- The above given code is a bit complicated and it consists of many steps. Now i am going to show all the steps through a block diagram and then i will try to explain every step one by one.
- Using this code, the Arduino YUN board will automatically connected to the available SSID which is in our case is TEP. So you can give any other SSID there and it will connect to that one.
- In the above block diagram, you can see that first of all Initialize Serial Port. When you will connect Arduino YUN with your computer through cable or as i described earlier that Arduino YUN also have built-in wifi so you can also connect Arduino YUN with computer through wifi.
- Then you will load the code to Initialize Serial Port, which is the first step and also shown in the above block diagram.
- In this project we have kept Baud rate of Arduino YUN 9600.
- The next step in the block diagram is to 'Initialize File System' . In this step we will load 'File System' into our code as viewed in the code image given above.
- Now in the next step we have to initialize the Arduino YUN Bridge. The block diagram representing the internal structure of Arduino YUN is shown in the image below:
- As i stated earlier in the beginning of the tutorial that Arduino YUN has 2 on-board micro processors and Arduino YUN is the intermediate source who performs communication between both micro processors.
- The Bridge library facilitates communication between the two processors, giving Arduino sketches the ability to run shell scripts, communicate with network interfaces, and receive information from the AR 9331 processor.
- The USB Host is connected to the ATmega 32u4, while the all external interferences(like Wifi, Ethernet, SD card) are connected to Linux micro processor.
- The beauty of this board is that Bridge libraries also enables the Arduino micr processor ATmega to communicate with the other interferences, which are also connected with Linux microprocessor.
- When bridge has been activated then, Arduino YUN enables its wifi and search for the nearby available wifi connections.
- When it will get some available wifi connections in its surrounding then, from its algorithm, Arduino YUN will get the SSID from that available wifi connections.
- The next thing which we have implemented in the code is to get SSID String. It is a built in function and also available in Arduino libraries that if it gets any available wifi connection near it, then it automatically gets strings from those connections.
- When Arduino has searched for all the available wifi connections near it and after getting the SSID of available wifi connections, it sends all these SSID to serial port of Arduino YUN board.
- After that Arduino YUN will automatically connect to that wifi connection whose SSID matches with the given SSID.
- Now the end step is very important and it distinguishes Arduino YUN from all other Arduino boards, which is, After sending data to serial port it again starts the loop and got o step #4 and it again starts to search for available wifi networks.
- This phenomenon can also be verified from the above shown block diagram.
- At any stage, if wifi connection drops then the loop will again start and will search for available wifi connections, get their SSID and it will send these SSID to serial port and it will rehabilitate the connection within no time and no problem will occur at any stage of data execution.
Alright friends, that was all from today's post. It is a very basic and very important post and we have seen How to Automatically Connect with Wifi SSID using Arduino YUN. I hope you have learned something new in today's post. If you have any problem in understanding any step of this tutorial then, you can ask in the comments and i will try my best to resolve the issue. Follow us to get the codes and simulations straight in your inbox. For more tutorial and projects, stay tuned and until next tutorial Take Care !!! :)
555 Timer Projects
Hello friends, hope you all are fine and having fun with your lives. Today I am gonna post 555 Timer projects list which are already posted on our blog. Actually, I have posted many 555 Timer Projects on my blog but we don't have a list of these tutorials and they are quite scattered. So, today I thought to arrange them in a proper list so that you can find all of them in one place. All these 555 timer projects are simulated in my favorite simulating software Proteus. I have also given their simulations for download in almost all tutorials. If you feel problem in any of them then ask in comments and I will resolve them.
All these 555 Timer Projects and tutorials are written and designed completely by our team so we hold the complete ownership for these projects. Other bloggers are welcome to share them on their blogs to spread knowledge but do mention our post link as we have done a lot of work and effort in designing these tutorials and projects. :)
I will keep on updating this list in future as I am gonna add more projects on 555 Timer, I will add their links below. So, enough with the talking, let's get started with 555 Timer projects.
555 Timer Projects
I have divided these projects and tutorials in different sections depending on their complexity. Follow all these tutorials step by step and you are gonna be expert in 555 Timer real soon. I will keep on updating this list in future, whenever I am gonna add new project on 555 Timer, I will post the link here.
Basics of 555 Timer
Below tutorials will give you the basics of 555 Timer IC. So these tutorials are kind of must because if you don't know the basics of any integrated chip then how can you use it in your ciruits. So must read them once and then move to next section:
555 Timer Projects - Basics
I hope you have read the basics of 555 Timer, so now here's time to get started with 555 Timer Projects. These projects are designed in Proteus simulating software and are working perfectly. Simulations are given for download in most of these tutorials. So, lets get started:
555 Timer Projects - Advanced
Now I think you are quite expert in 555 Timer and have done the basic projects so now its time to move to the next level and design advance level projects with 555 Timer. In these projects we are gonna interface difference electronic modules with 555 Timer.
How to Generate PWM in 8051 Microcontroller
Hello everyone, hope you all are fine and having fun with your lives. In today's post, I am going to share How to generate PWM in 8051 Microcontroller. PWM is an abbreviation of Pulse Width Modulation and is used in many engineering projects. It is used in those engineering projects where you want an analog output. For example, you want to control the speed of your DC motor then you need a PWM pulse. Using PWM signal you can move your motor at any speed from 0 to its max speed. Similarly suppose you wanna dim your LED light, again you are gonna use PWM pulse. So, in short, it has numerous uses. If you are working on Arduino then you should read How to use Arduino PWM Pins.
PWM, as the name suggests, is simply a pulse width modulation. We take a pulse and then we modulate its width and make it small or big. Another term important while studying PWM is named duty cycle. The duty cycle shows the duration for which the PWM pulse remains HIGH. Now if the pulse remains high for 50% and LOW for 50% then we say that PWM pulse has a duty cycle of 50%. Similarly, if the pulse is HIGH for 70% and Low for 30% then it has a duty cycle of 70%.
Most of the microcontrollers have special pins assigned for PWM as in Arduino UNO it has 6 PWM pins on it. Similarly, PIC Microcontrollers also have PWM pins but unfortunately, the 8051 Microcontroller doesn't have this luxury means there are no special PWM pins available in 8051 Microcontroller. But PWM is necessary so we are going to manually generate the PWM pulse using Timer0 interrupt. So, before reading this tutorial you must first read How to use Timer Interrupt in 8051 Microcontroller so that you understand the functioning of Timer Interrupt. Anyways, let's get started with the generation of PWM in the 8051 Microcontroller.
Where To Buy? |
---|
No. | Components | Distributor | Link To Buy |
1 | 8051 Microcontroller | Amazon | Buy Now |
How to Generate PWM in 8051 Microcontroller ???
- You can download both the simulation and the programming code for PWM in 8051 Microcontroller by clicking the below button:
Download PWM Code & Simulation
- First of all, design a simple circuit as shown in the below figure:
- Now what we are gonna do is we are gonna generate a PWM pulse using timer0 interrupt and then we are gonna send it to P2.0.
- I have attached an oscilloscope on which we can easily monitor this PWM pulse and can check whether it's correct or not.
Code in Keil uvision 3
- Now, copy the below code and paste it into your Keil uvision software. I have used Keil uvision 3 for this code compiling.
#include<reg51.h>
// PWM_Pin
sbit PWM_Pin = P2^0; // Pin P2.0 is named as PWM_Pin
// Function declarations
void cct_init(void);
void InitTimer0(void);
void InitPWM(void);
// Global variables
unsigned char PWM = 0; // It can have a value from 0 (0% duty cycle) to 255 (100% duty cycle)
unsigned int temp = 0; // Used inside Timer0 ISR
// PWM frequency selector
/* PWM_Freq_Num can have values in between 1 to 257 only
* When PWM_Freq_Num is equal to 1, then it means highest PWM frequency
* which is approximately 1000000/(1*255) = 3.9kHz
* When PWM_Freq_Num is equal to 257, then it means lowest PWM frequency
* which is approximately 1000000/(257*255) = 15Hz
*
* So, in general you can calculate PWM frequency by using the formula
* PWM Frequency = 1000000/(PWM_Freq_Num*255)
*/
#define PWM_Freq_Num 1 // Highest possible PWM Frequency
// Main Function
int main(void)
{
cct_init(); // Make all ports zero
InitPWM(); // Start PWM
PWM = 127; // Make 50% duty cycle of PWM
while(1) // Rest is done in Timer0 interrupt
{}
}
// Init CCT function
void cct_init(void)
{
P0 = 0x00;
P1 = 0x00;
P2 = 0x00;
P3 = 0x00;
}
// Timer0 initialize
void InitTimer0(void)
{
TMOD &= 0xF0; // Clear 4bit field for timer0
TMOD |= 0x01; // Set timer0 in mode 1 = 16bit mode
TH0 = 0x00; // First time value
TL0 = 0x00; // Set arbitrarily zero
ET0 = 1; // Enable Timer0 interrupts
EA = 1; // Global interrupt enable
TR0 = 1; // Start Timer 0
}
// PWM initialize
void InitPWM(void)
{
PWM = 0; // Initialize with 0% duty cycle
InitTimer0(); // Initialize timer0 to start generating interrupts
// PWM generation code is written inside the Timer0 ISR
}
// Timer0 ISR
void Timer0_ISR (void) interrupt 1
{
TR0 = 0; // Stop Timer 0
if(PWM_Pin) // if PWM_Pin is high
{
PWM_Pin = 0;
temp = (255-PWM)*PWM_Freq_Num;
TH0 = 0xFF - (temp>>8)&0xFF;
TL0 = 0xFF - temp&0xFF;
}
else // if PWM_Pin is low
{
PWM_Pin = 1;
temp = PWM*PWM_Freq_Num;
TH0 = 0xFF - (temp>>8)&0xFF;
TL0 = 0xFF - temp&0xFF;
}
TF0 = 0; // Clear the interrupt flag
TR0 = 1; // Start Timer 0
}
- I have added the comments in the above codes so it won't be much difficult to understand. If you have a problem then ask in the comments and I will resolve them.
- Now in this code, I have used a PWM variable and I have given 127 to it as a starting value.
- PWM pulse varies from 0 to 255 as it's an 8-bit value so 127 is the mid-value which means the duty cycle will be 50%.
- You can change its value as you want it to be.
Proteus Simulation Result
- So, now when you upload the hex file and run your simulation then you will get below results:
- Now you can check in the above figure that the duration of HIGH and LOW is the same means the pulse is HIGH for 50% and LOW for the remaining 50% cycle.
- Now let's change the PWM duty cycle to 85 which is 1/3 and it will generate a PWM pulse of 33% duty cycle. Here's the result:
- Now you can easily compare the above two figures and can get the difference. In the above figure now the duty cycle has decreased as the HIGH timing of the pulse is now reduced to 1/3 and pulse is LOW for 2/3 of the total time.
That's all, for today. That's how we can generate PWM in 8051 Microcontroller. Will meet you guys in the next tutorial. Till then take care !!! :)
Interrupt Based Digital Clock with 8051 Microcontroller
Hello friends, hope you all are fine and having fun with your lives. In today's post, I am going to share Interrupt based Digital clock with 8051 Microcontroller. In the previous post, I have explained in detail How to use Timer Interrupt in 8051 Microcontroller. We have seen in that post that we can use two timers in 8051 Microcontroller which are Timer0 and Timer1. Using these timers we can easily generate interrupts. So, before going into details of this post, you must read that timer post as I am gonna use these timer interrupts in today's post.
After reading this post, you will also get the skilled hand on timer interrupt and can understand them more easily. In today's post, I am gonna design a digital clock which will increment after every one second and we will calculate this one second increment using timer interrupt. This clock will be displayed on LCD so if you are not familiar with LCD then must read Interfacing of LCD with 8051 Microcontroller. You can also implement this digital clock with any other microcontroller like Arduino or PIC Microcontroller but today we are gonna implement it on 8051 Microcontroller. The complete simulation along with code is given at the end of this post but my suggestion is to design it on your own so that you get most of it. Use our code and simulation as a guide. So, let's get started with Interrupt based Digital clock with 8051 Microcontroller. :)
Interrupt Based Digital Clock with 8051 Microcontroller
- First of all, design a circuit as shown in below figure:
- Now use the below code and get your hex file. I have designed this code in Keil uvision 3 compiler for 8051 Microcontroller.
#include<reg51.h>
//Function declarations
void cct_init(void);
void delay(int);
void lcdinit(void);
void WriteCommandToLCD(int);
void WriteDataToLCD(char);
void ClearLCDScreen(void);
void InitTimer0(void);
void UpdateTimeCounters(void);
void DisplayTimeToLCD(unsigned int,unsigned int,unsigned int);
void WebsiteLogo();
void writecmd(int);
void writedata(char);
//*******************
//Pin description
/*
P2.4 to P2.7 is data bus
P1.0 is RS
P1.1 is E
*/
//********************
// Defines Pins
sbit RS = P1^0;
sbit E = P1^1;
// Define Clock variables
unsigned int usecCounter = 0;
unsigned int msCounter = 0;
unsigned int secCounter = 0;
unsigned int minCounter = 0;
unsigned int hrCounter = 0;
// ***********************************************************
// Main program
//
void main(void)
{
cct_init(); // Make all ports zero
lcdinit(); // Initilize LCD
InitTimer0(); // Start Timer0
// WebsiteLogo();
while(1)
{
if( msCounter == 0 ) // msCounter becomes zero after exact one sec
{
DisplayTimeToLCD(hrCounter, minCounter, secCounter); // Displays time in HH:MM:SS format
}
UpdateTimeCounters(); // Update sec, min, hours counters
}
}
void writecmd(int z)
{
RS = 0; // This is command
P2 = z; //Data transfer
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
void writedata(char t)
{
RS = 1; // This is data
P2 = t; //Data transfer
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
void cct_init(void)
{
P0 = 0x00; //not used
P1 = 0x00; //not used
P2 = 0x00; //used as data port
P3 = 0x00; //used for generating E and RS
}
void InitTimer0(void)
{
TMOD &= 0xF0; // Clear 4bit field for timer0
TMOD |= 0x02; // Set timer0 in mode 2
TH0 = 0x05; // 250 usec reloading time
TL0 = 0x05; // First time value
ET0 = 1; // Enable Timer0 interrupts
EA = 1; // Global interrupt enable
TR0 = 1; // Start Timer 0
}
void Timer0_ISR (void) interrupt 1 // It is called after every 250usec
{
usecCounter = usecCounter + 250; // Count 250 usec
if(usecCounter==1000) // 1000 usec means 1msec
{
msCounter++;
usecCounter = 0;
}
TF0 = 0; // Clear the interrupt flag
}
void WebsiteLogo()
{
writecmd(0x95);
writedata('w'); //write
writedata('w'); //write
writedata('w'); //write
writedata('.'); //write
writedata('T'); //write
writedata('h'); //write
writedata('e'); //write
writedata('E'); //write
writedata('n'); //write
writedata('g'); //write
writedata('i'); //write
writedata('n'); //write
writedata('e'); //write
writedata('e'); //write
writedata('r'); //write
writedata('i'); //write
writedata('n'); //write
writedata('g'); //write
writecmd(0xd8);
writedata('P'); //write
writedata('r'); //write
writedata('o'); //write
writedata('j'); //write
writedata('e'); //write
writedata('c'); //write
writedata('t'); //write
writedata('s'); //write
writedata('.'); //write
writedata('c'); //write
writedata('o'); //write
writedata('m'); //write
writecmd(0x80);
}
void UpdateTimeCounters(void)
{
if (msCounter==1000)
{
secCounter++;
msCounter=0;
}
if(secCounter==60)
{
minCounter++;
secCounter=0;
}
if(minCounter==60)
{
hrCounter++;
minCounter=0;
}
if(hrCounter==24)
{
hrCounter = 0;
}
}
void DisplayTimeToLCD( unsigned int h, unsigned int m, unsigned int s ) // Displays time in HH:MM:SS format
{
ClearLCDScreen(); // Move cursor to zero location and clear screen
// Display Hour
WriteDataToLCD( (h/10)+0x30 );
WriteDataToLCD( (h%10)+0x30 );
//Display ':'
WriteDataToLCD(':');
//Display Minutes
WriteDataToLCD( (m/10)+0x30 );
WriteDataToLCD( (m%10)+0x30 );
//Display ':'
WriteDataToLCD(':');
//Display Seconds
WriteDataToLCD( (s/10)+0x30 );
WriteDataToLCD( (s%10)+0x30 );
}
void delay(int a)
{
int i;
for(i=0;i<a;i++); //null statement
}
void WriteDataToLCD(char t)
{
RS = 1; // This is data
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= (t&0xF0); // Write Upper nibble of data
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= ((t<<4)&0xF0);// Write Lower nibble of data
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
void WriteCommandToLCD(int z)
{
RS = 0; // This is command
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= (z&0xF0); // Write Upper nibble of data
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= ((z<<4)&0xF0);// Write Lower nibble of data
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
void lcdinit(void)
{
///////////// Reset process from datasheet /////////
delay(15000);
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= (0x30&0xF0); // Write 0x3
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
delay(4500);
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= (0x30&0xF0); // Write 0x3
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
delay(300);
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= (0x30&0xF0); // Write 0x3
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
delay(650);
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= (0x20&0xF0); // Write 0x2
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
delay(650);
/////////////////////////////////////////////////////
WriteCommandToLCD(0x28); //function set
WriteCommandToLCD(0x0c); //display on,cursor off,blink off
WriteCommandToLCD(0x01); //clear display
WriteCommandToLCD(0x06); //entry mode, set increment
}
void ClearLCDScreen(void)
{
WriteCommandToLCD(0x01); // Clear screen command
delay(1000);
}
- Now run your simulation and if everything goes fine then you will get results as shown in below figure:
- The above figure is taken after 10 seconds of start of simulation in Proteus ISIS.
- As the simulation keeps on running the clock will also keep on ticking.
- The code is self explanatory but let me explain the interrupt function.
- I have used Timer0 interrupt in this digital Clock.
- The timer interrupt function is incrementing the userCounter variable by 250 which is in micro seconds. So we need 1000us as it will become 1 second. That's why I have placed the check that when userCounter == 1000 then increment the second.
- I have added comments in the code so read it in detail and still if you stuck somewhere then ask in comments and I will resolve them.
- You can download the complete code along with Proteus Simulation by clicking the below button:
Download Proteus Simulation and Code for Digital Clock
That's all for today. Hope you have enjoyed today's project. Will meet you guys soon in the next post. Till then take care !!! :)
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!!! :)
How to use Timer Interrupt in 8051 Microcontroller
Hello friends, hope you all are fine and having fun with your lives.In today's post, we are gonna see How to use timer interrupt in 8051 Microcontroller.8051 Microcontroller comes with timer as well. They normally have two timer in them named as Timer0 and Timer1. These timers are used for counting purposes like you want to start some countdown in your project then you can use these timers or you wanna create some clock then in that case as well you need timers. So, in short there are numerous uses of timers in a project. Timers are also used for delays like you wanna create some delay of 10 sec but you dont wanna use the delay function in your project so you can use timers. You start the timer and then when it comes to 10 seconds then you can do your work. So, these are different uses of a timer and clearly we can't neglect its importance, so today we are gonna see How to use these timer interrupt in 8051 Microcontroller.
Now coming towards interrupt, interrupt is interrupt :P Yeah really, we call it interrupt because its an interrupt. In programming codes there are many things which needs to run in background and appear when its time for them to appear. Here where interrupt comes handy. Interrupt is kind of a background code which keeps on running in the background while the main code keeps on running in front but when the interrupt condition is fullfilled then it interrupts the main program and executes the functions defined in it. For Timer interrupts, suppose I wanna blink my LED after every 2 seconds then what will I do is I will start a timer for 2 seconds and when this timer completes I will generate an interrupt. So, in this way after every two seconds the led will blink. So, let's start with timers interrupt in 8051 Microcontroller and see how we are gonna do this.
How to use Timer interrupt in 8051 Microcontroller ???
As I explained earlier, we are gonna use Timer interrupt in 8051 Microcontroller. so, now before gong into the details, let me first throw some light on how we are gonna implement this. Timers count from 0 to 255 in 8 bit mode as in 8 bit 255 is the maximum value and when timer hits the 255 number then we say that our timer is overflowed. Now when timer overflows, then it sends us a indication using which we generate our intterupt. In timers, there are few registers in which they store their value. If we are talking about Timer0 then timer0 stores its value in TL0 register. Now suppose I want my timer to start counting from 10 instead 0 then I will store 10 in my TL0 register and it will count from 10 instead 0 and when it reaches 255 it will overflow. Now when Timer0 will overflow then it will make TF0 bit HIGH. TF0 is another register value, if its 1 then it means that our timer is full and if its 0 then it means our timer is still counting. So, that's how we count from our timer and check the pin TF0. Now first of all, I am gonna use Timer0 and then we will have a quick look at Timer1.
Timer0 Interrupt
- First of all, design a simple circuit as shown in below figure:
- Now upload the below code in your Keil software and get the hex file.
#include<reg51.h>
// Out Pin
sbit Out = P2^0; // Pin P2.0 is named as Out
//Function declarations
void cct_init(void);
void InitTimer0(void);
int main(void)
{
cct_init(); // Make all ports zero
InitTimer0(); // Start Timer0
while(1) // Rest is done in Timer0 interrupt
{
}
}
void cct_init(void)
{
P0 = 0x00;
P1 = 0x00;
P2 = 0x00;
P3 = 0x00;
}
void InitTimer0(void)
{
TMOD &= 0xF0; // Clear 4bit field for timer0
TMOD |= 0x02; // Set timer0 in mode 2
TH0 = 0x05; // 250 usec reloading time
TL0 = 0x05; // First time value
ET0 = 1; // Enable Timer0 interrupts
EA = 1; // Global interrupt enable
TR0 = 1; // Start Timer 0
}
void Timer0_ISR (void) interrupt 1 // It is called after every 250usec
{
Out = ~Out; // Toggle Out pin
TF0 = 0; // Clear the interrupt flag
}
- In the above code, the main function is our InitTimer0 function.
- In this function what I have done is I simply set the timer 0 to mode 2. In mode 2, it will auto reload means once the timer0 overflows then it will comes back to its original value and will start again.
- TL0 has 0x05 in it which is the initial value of timer0 and it will count for 250 micro seconds.
- TH0 also has the 0x05. On reload timer uploads the vlaue from TH0 into TL0 so thats why we have given the same value to TH0.
- After that we make ET0 bit enabled which will enable the timer, if you dont set this pin HIGH then our timer will not work.
- EA bit will enable the global interrupt. if we dont enable this pin then timer will work but it wont generate the interrupt.
- Finally after setting all configurations, we started our timer.
- Now when the Timer0 overflows after every 250 micro seconds, it will generate the interrupt and it will come to Timer0_ISR function.
- In Timer0_ISR function, I simply toggled the OUt pin which is Pin2.0 and then I again set the interrupt bit to 0 which is TF0.
- That's how our timer is working and if we check the P2.0 pin on oscilloscope then it will look something as shown in below figure:
- You can see in the above figure that our pin is toggling with an interval of 250 usec.
- One important thing to note is there's no function written in while(1) loop and still its working because its running on background and performing the interrupt routine. You can add any function in your MAin code and it will keep on working and meanwhile at the background your interrupt will also keep on generating.
- You can download this Simulation and programming code by clicking on below button.
Download Timer0 Code and Simulation
- Now, lets have a quick look on Timer1 interrupt in 8051 Microcontroller.
Timer1 Interrupt
- Now let's have a quick look on Timer1 interrupt in 8051 Microcontroller. For that, design the same simulation in Proteus as we did for Timer 0.
- Now, upload the below code in your Keil software and get the hex file.
#include<reg51.h>
// Out Pin
sbit Out = P2^0; // Pin P2.0 is named as Out
//Function declarations
void cct_init(void);
void InitTimer1(void);
int main(void)
{
cct_init(); // Make all ports zero
InitTimer1(); // Start Timer1
while(1) // Rest is done in Timer1 interrupt
{
}
}
void cct_init(void)
{
P0 = 0x00;
P1 = 0x00;
P2 = 0x00;
P3 = 0x00;
}
void InitTimer1(void)
{
TMOD &= 0x0F; // Clear 4bit field for timer1
TMOD |= 0x20; // Set timer1 in mode 2
TH1 = 0x05; // 250 usec reloading time
TL1 = 0x05; // First time value
ET1 = 1; // Enable Timer1 interrupts
EA = 1; // Global interrupt enable
TR1 = 1; // Start Timer 1
}
void Timer1_ISR (void) interrupt 3 // It is called after every 250usec
{
Out = ~Out; // Toggle Out pin
TF1 = 0; // Clear the interrupt flag
}
- Now you can see in the above code that its exactly the same as we used for Timer0 with a slight difference that now we are using registers for Timer1.
- Instead of TL0, now we are using TL1 and similarly TH1 instead of TH0 and TR1 instead of TR0.
- Rest of the code is exactly the same and hence it will give the same result as for Timer0 and is shown in below figure:
- You can download the code for Timer1 along with simulation by clicking the below button.
Download Timer1 Code and Simulation
That's all for today, I hope you guys have got something out of today's post and gonna like this one. In the coming post, I am gonna design some simple project on 8051 Microcontroller in which I will use these Timers, then you will get know more about them. So, stay tuned and subscribe us by email. Take care !!! :)