This article is focused for the budding engineers/hobbyists and anyone who wants to start working on 8 bit microcontroller. Al, the programs listing has been compiled on KEIL IDE and downloaded on 89V51RD2 on the Vinytics,Delhi (ET-51LS TRAINER) the picture of the kit is attached. Most of the codes that we will be considering for our learning will require only a CRO/DSO for understanding rest all the accessories required are present on the kit itself like I/O lines on 8 pin connector, keys, LEDs, LCDs, Relay & many more.
In this article we will explain you how to generate a fixed signal (clock) of 50% duty cycle. In some application we require a fixed clock signal for controlling the hardware there are 32 input/output lines on 8051 that can be programmed according to the requirement.
Let us understand the source code attached in the article.
We need to assign a constant to the port for easy understanding and readability, using sbit we can assign a constant to a pin number of port 1. The width of sbit 1, this is bit variable it can only take value of 1/0.
The declaration of pin should be done before the main loop of the source code.
sbit pin = P1^0; // decleare a variable type sbit for P1.0
We have used a long type of variable to assign the delay between the pin signal High & Low. We are declaring a counter for repeating the function C number of times to generate a clock of fixed time 300 ms.
Definitation of Long variable type is
“A signed or unsigned long integer.”
long C;
Delay 1 function is a standalone function that can be called as many times as possible in the source code. For a single call of delay 1 function you will get a delay of 300 ms.
void DELAY1()
{
for(C=0;C<450 o:p="">450>
}
This is the main source code of the program in this program we are making a super loop using the while statement we are making while (1), this statement makes the while condition always true that means the programs runs itself infinitely. We are making pin high and calling the DELAY1() sub routine to give the delay of 300 ms and then making the pin Low as result we get a clock signal of almost equal duty cycle at the port 1 _0 OR pin
main()
{
while(1)
{
pin=1; // clear port
DELAY1();
pin=0; // clear port
DELAY1();
}
}
/*program for fixed 33.33hz*/
#include // include 8051 register file
sbit pin = P1^0; // decleare a variable type sbit for P1.0
long C;
void DELAY1();
void DELAY1()
{
for(C=0;C<450 o:p="">450>
}
main()
{
while(1)
{
pin=1; // clear port
DELAY1();
pin=0; // clear port
DELAY1();
}
}
NOTE: I will add the video tutorial of working with ET-51LS on my youtube channel for this program in the coming week.
Please visit the video tutorial of Microprocessor kits on my youtube page
https://youtu.be/jjFr2Yxm3uU
No comments:
Post a Comment