Professional Documents
Culture Documents
System Bus
Observe Temperature
(Input) Sensor
Processor
mem
6
EMBEDDED DESIGN
1. Core hardware
2. Firmware tools
3. Programming tools
4. Hardware tools
• AVR Microcontroller
• ARDUINO (UNO,MEGA,NANO)
2. Firmware tools
3. Programming tools
4. Hardware tools
Advance Tech. India Pvt Ltd
FIRMWARE TOOLS
• 8051- KEIL Compiler, IAR, Eclipse
2. Firmware tools
KEIL
A microcontroller (sometimes
abbreviated µC or MCU) is a small
computer on a single IC containing
a processor core, memory, and
programmable input/output
peripherals.
PROGRAMMER
RESET
LCD
MOTOR MD ROM
MAX CPU`
COMP BUZZER
232
SWITCH
RAM
INTERRUPT
8051 LED
O
GND S
C
8051 Microcontroller Programing
Input file
For
MCU
8051
Microcontroller
Transferring file Compiling &
Using
Suitable medium
Building
Like USB or Of the Code
RS-232cable
Source Code
In
C- Language
Let’s check how to put brain in our
device
8051 BASIC
COMPONENT
4K bytes internal ROM
128 bytes internal RAM
Four 8-bit I/O ports (P0 - P3).
Two upto16-bit timers/counters
One serial interface.
5 interrupts.
COMPARISON
ROM 4k 8k 0k
TIMERS 2 3 2
I/O PORT 32 32 32
SERIAL PORT 1 1 1
INTERRUPT 5 8 6
PIN P1.0 1 40 Vcc
P1.1 2 39 P0.0(AD0)
DISCRIPTION P1.2 3 38 P0.1(AD1)
OF P1.3
P1.4
4
5
37
36
P0.2(AD2)
P0.3(AD3)
8051 P1.5 6 35 P0.4(AD4)
P1.6 7 34 P0.5(AD5)
P1.7 8 8051 33 P0.6(AD6)
RST 9 (8031) 32 P0.7(AD7)
(RXD)P3.0 10 (8751) 31 EA
(TXD)P3.1 11 30 ALE
(8951)
(INT0)P3.2 12 29 PSEN
(INT1)P3.3 13 28 P2.7(A15)
(T0)P3.4 14 27 P2.6(A14)
(T1)P3.5 15 26 P2.5(A13)
(WR)P3.6 16 25 P2.4(A12)
(RD)P3.7 17 24 P2.3(A11)
XTAL2 18 23 P2.2(A10)
XTAL1 19 22 P2.1(A9)
GND 20 21 P2.0(A8)
PINS OF 8051
VCC(pin 40):
– VCC provides supply voltage to the chip.
– The voltage source is +5V.
GND(pin 20):ground
XTAL1 and XTAL2(pins 19,18):
– These 2 pins provide external clock.
– XTAL 1:Input to the inverting oscillator amplifier and
input to the internal clock generator circuits
– XTAL 2:Output from the inverting oscillator amplifier
C2
XTAL2
30pF
C1
XTAL1
30pF
GND
Solution:
RST(pin 9):reset
– It is an input pin and is active high
(normally low).
• The high pulse must be high at
least 2 machine cycles.
• Upon applying a high pulse to
RST, the microcontroller will
reset and all values in registers
will be lost.
TB1
Read pin
8051 IC
WRITING “0” TO OUTPUT PIN P1.X
TB1
Read pin
8051 IC
PINS OF 8051
/EA(pin 31):external access
– There is no on-chip ROM in 8031 and 8032 .
– The /EA pin is connected to GND to indicate the code is stored
externally.
– /PSEN & ALE are used for external ROM.
– For 8051, /EA pin is connected to VCC.
/PSEN(pin 29):program store enable
– This is the read pin for external program memory. When the
device is executing from internal program memory, /PSEN is
inactive (HIGH). When the device is executing code from
external program memory, PSEN is activated (low).
– This is an output pin and is connected to the OE pin of the
ROM.
Circuit symbol:
A switch generates a
high to low pulse.
The pulse acts as
input to
microcontroller.
Microcontroller
senses the transition
and perform
appropriate task.
#include<reg51.h>
sbit sw=P2^0;
sbit led=P1^0;
void main()
{
sw=0;
led=0;
while(1)
{
if(sw==1) led=1;
else led=0;
}}
Interfacing
#include<reg51.h>
char arr[10]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
void delay(void)
{
int f;
for(f=0;f<30000;f++);
}
void main(void)
{ int a;
for(a=0;a<10;a++)
{
P2=arr[a];
delay();
}}
PROGRAM COUNT 00 TO 99
#include<reg51.h>
char arr[10]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
void delay(void)
{
int f;
for(f=0;f<10000;f++);
}
void main(void)
{
int a,b,c;
for(a=0;a<10;a++)
{ for(b=0;b<10;b++)
{ for(c=0;c<30;c++)
{
P3=0x40;
P0=arr[b];
delay();
P3=0x80;
P0=arr[a];
delay();} }}}}}
Interfacing
of 8051
with LCD
4. Clear display:
Send 01H to clear display and return cursor to home
position.
Hex values
0x00
0x04
0x02
0x1F
0x02
0x04
0x00
0x00
void main(void)
{
CODE
P2=0x38; instwrt(); delay();
#include<reg51.h> P2=0x0E; instwrt(); delay();
sbit RS =P1 ^ 0; P2=0x01; instwrt(); delay();
sbit E =P1 ^ 1; P2=0x06; instwrt(); delay();
void delay(void) P2=0x40; instwrt(); delay();
{unsigned int i;
for(i=0;i<=20000;i++); P2=0x00; datawrt();
} P2=0x04; datawrt();
void instwrt(void) P2=0x02; datawrt();
{ P2=0x1f; datawrt();
RS=0; P2=0x02; datawrt();
E=1; delay(); E=0; P2=0x14; datawrt();
} P2=0x00; datawrt();
void datawrt(void) P2=0x00; datawrt();
{ while(1)
RS=1; {
E=1; delay(); E=0; P2=0x80; instwrt(); delay();
} P2=0; datawrt(); delay();
}
}
INTERFACING WITH
EXTERNAL ADC
Calculating Dout
The data we get at the D0 - D7 depends
upon the step size & the Input voltage
i.e. Vin.
Address Latch Enable (ALE) - The address is latched on the Low – High
transition of ALE.
· Output Enable - Whenever data has to be read from the ADC, Output Enable
pin has to be pulled high thus enabling the TRI-STATE outputs, allowing data to
be read from the data pins D0-D7.
·End of Conversion (EOC) - This pin becomes High when the conversion has
ended, so the controller comes to know that the data can now be read from the
data pins.
·Clock - External clock pulses are to be given to the ADC; this can be given
either from LM 555 in Astable mode or the controller can also be used to give the
pulses.
· D0 – D7 - D0- D7 are the digital data output pins since ADC0808 is a parallel
ADC chip.. To calculate the output voltage, we can use following formula
ALGORITHM
1.Start.
2.Select the channel.
3.A Low – High transition on ALE to latch in the address.
4.A Low – High transition on Start to reset the ADC’s SAR.
5.A High – Low transition on ALE.
6.A High – Low transition on start to start the conversion.
7.Wait for End of cycle (EOC) pin to become high.
8.Make Output Enable pin High.
9.Take Data from the ADC’s output
10.Make Output Enable pin Low.
11.Stop
PROGRAM
while(1)
{
#include<reg51.h> ALE=1;
#include"delay.h" SOC=1;
#include"lcd.h" clock();
sbit ALE=P3^2; ALE=0;
sbit SOC=P3^3; SOC=0;
sbit OE=P3^5; clock();
sbit EOC=P3^4; while(!EOC);
sbit CLOCK=P3^6; OE=1;
unsigned char adc_val; adc_val=P1;
unsigned char temp[5]; dummy=P1;
void clock(void); cmd_lcd(0xc3);
void main(void) number_lcd(dummy);}}
{ void clock(void)
int i; {
int dummy; int a,b;
init_lcd(); for(b=0;b<=1000;b++)
cmd_lcd(0x83); {
cmd_lcd(0x01); for(a=0;a<30;a++);
lcd_string("LDR VALUE") ; CLOCK=~CLOCK;}}
Serial
Communication
1.Parallel
2.Serial
11.0592 MHz
Machine cycle 28800 Hz
XTAL frequency ÷ 32
÷ 12 Timer 1
oscillator 921.6 kHz By UART To timer 1
To set the
Advance Tech. India Pvt Ltd Baud rate
Baud Rates in the 8051
• SCON.4
• Set/cleared by software to enable/disable
reception.
– REN=1
• If we want the 8051 to both transfer and
receive data, REN must be set to 1.
– REN=0
• The receiver is disabled.
• The 8051 can not receive data.
Advance Tech. India Pvt Ltd
Transfer Data with the TI flag
• The following sequence is the steps that the
8051 goes through in transmitting a
character via TxD:
1. The byte character to be transmitted is written into
the SBUF register.
2. It transfers the start bit.
3. The 8-bit character is transferred one bit at a
time.
4. The stop bit is transferred.
SBUF
8-bit char
bit by bit
TI UART TxD
Advance Tech. India Pvt Ltd
Steps to transmit data
from 8051 to pc
1.Load SCON register.
2.Laod TMOD register(select timer1 mode 2).
3. Load baud rate in TH1.
4. Start the timer.
5. Place character in SBUF.
6. Monitor TI flag.
7. Clear TI flag.
#include<reg51.h>
void main ()
{
while(1)
{
TMOD=0x20;// timer1 in mode 2
SCON=0x50;// scon register for reciver enable
TH1=0xfd;// baudrate 9600
TR1=1; // start the timer
SBUF='A';// data that has to be sent put in sbuf
while(TI==0);// monitor the transmit flag
TI=0; // clear the timer 1 flag after transmit
}
}
PROGRAM TO TRANSMIT DATA
TO PC
#include<reg51.h>
unsigned char arr[]={“Ankit Mohan”};
void serial_init()
{
void main ()
TMOD=0x20;
{
SCON=0x50;
Int i;
TH1=0xfd;
serial_init();
TR1=1; while(1)
} {
void serial_trans(unsigned char trans) for(i=0;i<=11;i++)
{
{
serial_trans(arr[i]);
SBUF=trans; }
while(TI==0); }
TI=0;
Advance Tech. India Pvt Ltd
}
PROGRAM TO RECEIVED DATA FORM
PC
#include<reg51.h>
void serial_init()
{
void main ()
TMOD=0x20;
SCON=0x50; {
TH1=0xfd; serial_init();
TR1=1; while(1)
TI=0; {
} P1=serial_rec();
unsigned char serial_rec() }
{
while(RI==0);
}
RI=0;
return(SBUF);
}
void main()
{ int i;
init_lcd();
init_serial(9600);
while(1)