Embedded C Programming With Keil Language
Embedded C Programming With Keil Language
Language
Embedded C is most popular programming language in software field for
developing electronic gadgets. Each processor used in electronic system is
associated with embedded software.
Embedded C programming plays a key role in performing specific function
by the processor. In day-to-day life we used many electronic devices such
as mobile phone, washing machine, digital camera, etc. These all device
working is based on microcontroller that are programmed by embedded C.
Let's see the block diagram representation of embedded system
programming:
The Embedded C code written in above block diagram is used for blinking
the LED connected with Port0 of microcontroller.
33.1M
603
History of Java
we need to install keil micro version 5 software from it’s official site
click on keil software for download purpose setup file is no much big i.e. only 94 mb
After successful installation of software we need to create our new project so for that click on project Tab
and select New microvision project
After the selection of this file we need to give name for the project file
Create new project
file in keil software
we know that it is possible to write code in embedded c as well as assembly language so if we want to
write code in assembly language then we are click on No Tab if write this code in embedded c then click
on yes tab.
In this article we click on Yes because we are use here assembly language
Next step is Add New Item group in keil software so for that click right on Source group 1 and select Add
New Item to group ‘source Group 1’
Following windows are open after the Add New Item group in keil software so select C file (.c) and give
the name for this file . in below file we give simplepro name and add this file to source group.
At the left hand side we see created different Target file so for write embedded code click on file and click
on new.
after the write source code we need to compile this program so click on build program menu . then
compiler execute our program one by one line and show result as like below pop-up window
For debug purpose we can use Start/ Stop debug section Tab
Summary :
In this article we saw how to write and run embedded c program in keil software so about this article you
have any query then free to ask me
Keil Programs
• Simulator
• Debugger
Keil Software provides you with software development tools for the 8051 family of
microcontrollers. With these tools, you can generate embedded applications for the
multitude of 8051 derivatives. Keil provides following tools for 8051 development
4. Source-Level Debugger/Simulator,
main()
}
#include<reg51.h>
sbit D1 = P0^1;
sbit D2 = P0^2;
sbit D3 = P0^3;
sbit D4 = P0^4;
sbit D5 = P0^5;
sbit D6 = P0^6;
sbit D7 = P0^7;
sbit S1 = P1^1;
sbit S2 = P1^2;
main()
first ip
second ip
}
#include<reg51.h>
sbit D1 = P1^1;
sbit D2 = P1^2;
sbit D3 = P1^3;
sbit D4 = P1^4;
sbit D5 = P1^5;
sbit D6 = P1^6;
sbit D7 = P1^7;
int i;
void delay(void); // 1 ms delay
main()
{
{
D1 = D2;
D2 = D3;
D3 = D4;
D4 = D5;
D5 = D6;
D6 = D7;
}
}
void delay()
{
int k
for(k=0;k<1000;k++);
}
Simultaneous Transmission & Reception
of Data
Example-4: write a program to simultaneously transmit and receive data.
#include <reg51.h>
main()
{
#include<reg51.h>
delay();
op1=1;
delay();
op2=1;
int x;
for(x=0;x<10000;x++);
}
void main()
}
#include<reg51.h>
{
{
}
}
void main()
{
TL1=0xAF;
}
SONAR
Example 7: send ultrasonic wave through P1.0 and receive its echo through P3.2.
#include <reg51.h>
{
TF0=0; // clear timer flag
}
{
}
main()
{
while(1);
}
Counting Number of 1s in input
Example 8: take input from P0. Count no of 1 in input
#include <reg51.h>
sbit D1 = B^1;
sbit D2 = B^2;
sbit D3 = B^3;
sbit D4 = B^4;
sbit D5 = B^5;
sbit D6 = B^6;
sbit D7 = B^7;
void main()
{
b=0;
{ // 8 times
b=D7;
D7=D6;
D6=D5;
D5=D4;
D4=D3;
D3=D2;
D2=D1;
D1=D0;
}
}
#include<reg51.h>
{
{
c=0; // reset it to 0 and
}
}
void main(void)
{
{
break;
P0=0xA4;
break;
P0=0xB0;
break;
P0=0x99;
break;
case 5:
P0=0x92;
break;
P0=0x82;
break;
P0=0xF8;
break;
P0=0x80;
break;
P0=0x90;
break;
}
}
#include<reg51.h>
void main(void)
{
{
break;
P0=0xA4;
break;
P0=0xB0;
break;
P0=0x99;
break;
P0=0x92;
break;
P0=0x82;
break;
P0=0xF8;
break;
P0=0x80;
break;
}
}