Introduction
Hello friend,
Welcome
to embedded c projects tutorial. If you have very much interest in embedded c
programming for 8051 microcontroller then this tutorial may help you in several
aspects of microcontroller
programming in embedded c.
Target
Audience
This
tutorial is written to help student, faculties, embedded engineers (software
programmer and hardware engineers). Who require some basic concept of
programming in embedded c. To know, ”how to apply logic for programming in
embedded c?” One should have knowledge of peripherals available on 8051
microcontroller .These are timer/counters,interrupts,uart,i2c,Analog to Digital
Converter, Digital to Analog Converter, PWM
and Watchdog etc..
Embedded System
Computing
Systems has so many uses in our daily life. These are everywhere in different
appliances. There are millions of computer system, laptop, workstations and
servers built every year. Those have build for different purposes. Embedded system is nearly computer system
other then desktop.
Embedded system has different uses like as follows:
1. Consumer
Electronics (Cell Phones , Digital Cameras, Portable Video Game, Camcorders, Video Cassette, Pagers
and Calculator)
2. Business
Equipments (Card Reader, Cash Register, Curbside Check-In, Alarm System,
Automated Teller Machine (ATM))
3. Home Appliances (Answering
Machine, Microwave Ovens, Thermostats, Home Security Systems, Washing Machine)
4. Office Automation(
Fax Machines, Printers, Scanner, Copier)
Microcontroller
Microcontroller differ from the Computer as,” CPU on chip”
is Microcomputer and “Computer on chip” is microcontroller. 8051 Microcontroller
was designed by intel in 1980s.The block of 8051 microcontroller is as follows:
Block Diagram of 8051 Microcontroller
The description of each part of block diagram is as follows:
1.
CPU (central
processing unit): It is the brain of any microcontroller. Which control and
monitors any operation performed by Microcontroller .It reads the program
written in ROM (Read Only Memory) and executes the program to perform task.
2.
Interrupts:
Interrupt is a subroutine which is more
important than any other program running at that time. It helps in emergency
operations. Interrupt gives mechanism to hold ongoing operation, To execute the
subroutine and then again resume operation. Vectored interrupts are as follows:
INT0
INT1
TF0
TF1
R1/T1
Interrupt INT0, INT1 are negative edge triggered. When all
these interrupts are active corresponding flag is set except for serial
interrupt. Two of them are external Interrupt, two of them are timer interrupts
and one is serial port interrupt.
3.
Memory
: Microcontroller Require Program To Perform Task. So Microcontroller Has
Internal Memory ROM (of 4K) and RAM (of 128K). Memory which stores the program
of microcontroller is known as program memory or ROM. Memory which have data
for temporary is known as RAM.
4.
BUS:
Microcontroller has two types of buses as follows:
Address
Bus: this bus is 16 bit long. It is used for address memory and location to
Transfer the address from CPU to memory of microcontroller.
Data
bus: it is 8bit long. It is used for Data transfer.
5.
Oscillator:
Microcontroller has on chip oscillator. Which is used to generate clock to CPU.
Output pulse of oscillator is stable.
6.
input/output ports: microcontroller has four i/o ports as follows:
Port 0
– External memory access .low address byte/data.
Port 1 – General purpose i/o. pin 0,1
for timer/counter 2.
Port
2 – External memory access. high address byte.
Port 3 -
0-RxD: serial i/p
1-TxD: serial o/p
2-INT0: external interrupt
3-INT1:external interrupt
4-T0 :timer/counter 0 external interrupt
5- T1 :timer/counter 1 external interrupt
6-WR: external data memory write strobe
7 RD: external data memory read
strobe
Application of 8051
Microcontroller
Microcontroller is used in various
applications. Some of them are listed below:
Defence application
Automobile application
Medical electronics
Security systems (smart cards, e-commerce)
Aeronautics
Space
Mobile
communication
Rail transport
Industrial processing
Robotics
Remote
sensing
Some examples of embedded c Projects
1.
LED glow
Embedded C code for LED glow:
#include<reg51.h>
// special function register declarations
void
Delay(void); // Function
prototype declaration
void main (void)
{
while(1) //
infinite loop
{
P2=0x00; // LED ON
Delay();
P2=0xFF; // LED OFF
Delay();
}
}
void
Delay(void)
{
int j;
int i;
for(i=0;i<40;i++)
{
for(j=0;j<1275;j++)
{
}
}
}
2. 00 to 99 Decimal counter
Embedded C code for 00to 99 counter
#include<reg51.h>
void Delay(int ms);
void main(void)
{
unsigned long timer=0;
unsigned char
num[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0xFF,0xEF};
unsigned int l,k,n;
int
turn=1;
while(1)
{
for(k=0;k<=99;k++)
{
l=k/10;
n=k%10;
P2=num[n];
P3=0x02;
Delay(25);
P2=num[l];
P3=0x01;
Delay(30);
}
if(timer==100)
{
timer=0;
timer++;
}
}}
void
Delay(int m)
{
int j,i;
for(i=0;i<m;i++)
{
for(j=0;j<1275;j++)
{
}
}
}



No comments:
Post a Comment