8051 board document

23
Basic Circuit for 8051 8051 PIN Diagram: Power - Vcc, Vss Reset - RST   Crystal - XTAL[1,2]   External device interfacing – EA, ALE, PSEN, WR, RD   I/O Port – P0[7;0], P1[7:0], P2[7:0], P3  P3 is shared with control lines – Serial I/O RxD, TxD, – exter nal inter rupts IN T0, INT1 – Counter control T0, T1  P0 and P2 are multiplexed with Address and Data bus BASIC CIRCUIT -THAT MAKES 8051 WORKS.

Upload: vamsisagiraju

Post on 08-Apr-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 1/23

Basic Circuit for 8051

8051 PIN Diagram:

Power - Vcc, Vss

Reset - RST

 Crystal - XTAL[1,2]

 External device interfacing

– EA, ALE, PSEN, WR, RD

  I/O Port

– P0[7;0], P1[7:0], P2[7:0], P3

 P3 is shared with control lines

– Serial I/O RxD, TxD,– external interrupts INT0, INT1– Counter control T0, T1

 P0 and P2 are multiplexed with Address and Data bus

BASIC CIRCUIT -THAT MAKES 8051 WORKS.

Page 2: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 2/23

EA/VP PinThe EA on pin 31 is tied high to make the 8051 executes program from Internal ROM

 Reset Circuit

RESET is an active High input When RESET is set to High, 8051 goes back to the power on

state.The 8051 is reset by holding the RST high for at least two machine cycles and then returning itlow.

Power-On Reset

- Initially charging of capacitor makes RST High- When capacitor charges fully it blocks DC.

  Manual reset

-closing the switch momentarily will make RST High.

After a reset, the program counter is loaded with 0000H but the content of on-chip RAM is notaffected.

Oscillator Circuit

The 8051 uses the crystal for precisely that: to synchronize it’s operation. Effectively, the8051 operates using what are called "machine cycles." A single machine cycle is the minimumamount of time in which a single 8051 instruction can be executed. although manyinstructions take multiple cycles.

8051 has an on-chip oscillator. It needs an external crystal thats decides the operatingfrequency of the 8051.

This can be achieved in two ways,,

Page 3: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 3/23

The crystal is connected to pins 18 and 19 with stabilizing capacitors. 12 MHz(11.059MHz) crystal is often used and the capacitance ranges from 20pF to 40pF.

The oscillator can also be a TTL clock source connected with a NOT gate as shown

 How fast 8051 works ?

A cycle is, in reality, 12 pulses of the crystal. That is to say, if an instruction takes onemachine cycle to execute, it will take 12 pulses of the crystal to execute. Since we know thecrystal is pulsing 11,059,000 times per second and that one machine cycle is 12 pulses, wecan calculate how many instruction cycles the 8051 can execute per second:

11,059,000 / 12 = 921,583

Why is such an oddball crystal frequency?

11.0592 MHz crystals are often used because it can be divided to give you exact clock ratesfor most of the common baud rates for the UART, especially for the higher speeds (9600,

19200). Despite the "oddball" value, these crystals are readily available and commonly used.

Page 4: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 4/23

Serial Communication

RS-232 WAVEFORM 

TTL/CMOS Serial Logic Waveform

The diagram above, shows the expected waveform from the UART when using thecommon 8N1 format. 8N1 signifies 8 Data bits, No Parity and 1 Stop Bit. The RS-232 line,when idle is in the Mark State (Logic 1). A transmission starts with a start bit which is (Logic0). Then each bit is sent down the line, one at a time. The LSB (Least Significant Bit) is sent

first. A Stop Bit (Logic 1) is then appended to the signal to make up the transmission.

The data sent using this method, is said to be framed . That is the data is framed between aStart and Stop Bit .

RS-232 Voltage levels1. +3 to +25 volts to signify a "Space" (Logic

0)2. -3 to -25 volts for a "Mark" (logic 1).3. Any voltage in between these regions (i.e. between +3 and -3 Volts) is undefined.

The data byte is always transmitted least-significant-bit first .The bits are transmitted at specific time intervals determined by the baud rate of the serialsignal.

This is the signal present on the RS-232 Port of your computer, shown below.

RS-232 Logic Waveform

RS-232 LEVEL CONVERTER 

Standard serial interfacing of microcontroller (TTL) with PC or any RS232C Standarddevice , requires TTL to RS232 Level converter . A MAX232 is used for this purpose. Itprovides 2-channel RS232C port and requires external 10uF capacitors.

The driver requires a single supply of +5V .

Page 5: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 5/23

MICROCONTROLLER INTERFACING WITH RS-232 STANDARD DEVICES 

• MAX232 (+5V -> +-12V converter)

• Serial port male 9 pin connector (SER)

Page 6: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 6/23

Interfacing to LCD Display

Most projects you create with the 8051 CPU require some form of display. The most

common way to accomplish this is with the LCD (Liquid Crystal Display). LCDs have become

a cheap and easy way to get text display for an embedded system Common displays are setup as 16 to 20 characters by 1 to 4 lines.

UNDERSTANDING LCD

 

Pinout

• 8 data pins D7:D0

Bi-directional data/command pins.

Alphanumeric characters are sent in ASCII format.

 

• RS: Register Select

RS = 0 -> Command Register is selected

RS = 1 -> Data Register is selected

 

• R/W: Read or Write

0 -> Write, 1 -> Read

 

• E: Enable (Latch data)

Used to latch the data present on the data pins.A high-to-low edge is needed to latch the data.

 

• VEE : contrast control

 

Page 7: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 7/23

NOTE: When writing to the display, data is transferred only on the high to low transition of this

signal. However, when reading from the display, data will become available shortly after the

low to high transition and remain available until the signal falls low again.

 

Display Data RAM (DDRAM)

Display data RAM (DDRAM) is where you send the characters (ASCII code) you want

to see on the LCD screen. It stores display data represented in 8-bit character codes. Its

capacity is 80 characters (bytes). Below you see DD RAM address layout of a 2*16 LCD.

In the above memory map, the area shaded in black is the visible display (For 16x2 display) .

For first line addresses for first 15 characters is from 00h to 0Fh. But for second line address

of first character is 40h and so on up to 4Fh for the 16th character.

 So if you want to display the text at specific positions of LCD , we require to manipulate

address and then to set cursor position accordingly .

Character Generator RAM (CGRAM)-User defined character RAM

In the character generator RAM, we can define our own character patterns by

program. CG RAM is 64 bytes ,allowing for eight 5*8 pixel, character patterns to be defined.

However how to define this and use it is out of scope of this tutorial. So I will not talk any

more about CGRAM

Registers

The HD44780 has two 8-bit registers, an instruction register (IR) and a data register

(DR). The IR stores instruction codes. The DR temporarily stores data to be written into

DDRAM or CGRAM and temporarily stores data to be read from DDRAM or CGRAM. Data

written into the DR is automatically written into DDRAM or CGRAM by an internal operation. .

These two registers can be selected by the register selector (RS) signal.

LCD Commands 

The LCD’s internal controller accept several commands and modify the display accordingly.

These commands would be things like:

– Clear screen

Page 8: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 8/23

– Return home

– Shift display right/left

 

Instruction Decimal HEX

Function set (8-bit interface, 2 lines, 5*7 Pixels) 56 38

Function set (8-bit interface, 1 line, 5*7 Pixels) 48 30

Function set (4-bit interface, 2 lines, 5*7 Pixels) 40 28

Function set (4-bit interface, 1 line, 5*7 Pixels) 32 20

Entry mode set See Below See Below

Scroll display one character right (all lines) 28 1E

Scroll display one character left (all lines) 24 18

Home (move cursor to top/left character position) 2 2

Move cursor one character left 16 10

Move cursor one character right 20 14

Turn on visible underline cursor 14 0E

Turn on visible blinking-block cursor 15 0F

Make cursor invisible 12 0C

Blank the display (without clearing) 8 08

Restore the display (with cursor hidden) 12 0C

Clear Screen 1 01

Set cursor position (DDRAM address) 128 + addr 80+ addr

Set pointer in character-generator RAM (CG RAM address) 64 + addr 40+ addr

Entry mode set

This command sets cursor move direction and display shift ON/OFF. There are 4

possible function set commands;04, 05, 06, and 07. This command changes the direction the

cursor moves by setting the address counter to increment or decrement. This command is

very important. If you do not understand it you may not see anything or what you actually

wanted to see on LCD screen. I have created 4 animated gifs to demonstrate what the

function set command is all about.

Set cursor position (DDRAM address)

As said earlier if we want to display the text at specific positions of LCD , we require to

manipulate address and then to set cursor position accordingly.

I want to display "MAHESH" in message "Hi MAHESH" at the right corner of first line then I

should start from 10th character.

So referring to table 80h+0Ah= 8Ah.

Page 9: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 9/23

INTERFACING LCD TO 8051

The 44780 standard requires 3 control lines as well as either 4 or 8 I/O lines for thedata bus. The user may select whether the LCD is to operate with a 4-bit data bus or an 8-bitdata bus.

If a 4-bit data bus is used, the LCD will require a total of 7 data lines.If an 8-bit data bus is used, the LCD will require a total of 11 data lines.

The three control lines are EN, RS, and RW.

Note that the EN line must be raised/lowered before/after each instruction sent to the LCDregardless of whether that instruction is read or write, text or instruction. In short, you must

always manipulate EN when communicating with the LCD. EN is the LCD's way of knowing thatyou are talking to it. If you don't raise/lower EN, the LCD doesn't know you're talking to it onthe other lines.

Page 10: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 10/23

Stepper Motor

BASICS OF STEPPER MOTOR

Of all motors, step motor is the easiest to control. It's handling simplicity is really hard

to deny - all there is to do is to bring the sequence of rectangle impulses to one input of step

controller and direction information to another input. Direction information is very simple and

comes down to "left" for logical one on that pin and "right" for logical zero. Motor control is

also very simple - every impulse makes the motor operating for one step and if there is no

impulse the motor won't start. Pause between impulses can be shorter or longer and it defines

revolution rate. This rate cannot be infinite because the motor won't be able to "catch up" with

all the impulses (documentation on specific motor should contain such information). The

picture below represents the scheme for connecting the step motor to microcontroller and

appropriate program code follows.

The key to driving a stepper is realizing how the motor is constructed. A diagram

shows the representation of a 4 coil motor, so named because 4 coils are used to cause the

revolution of the drive shaft. Each coil must be energized in the correct order for the motor to

spin.

In Figure 3.3, as in Figure 3.1, boxes are used to represent switches; a control unit,

not shown, is responsible for providing the control signals to open and close the switches at

the appropriate times in order to spin the motors. The control unit is commonly a computer or

programmable interface controller, with software directly generating the outputs needed to

control the switches.

As with drive circuitry for variable reluctance motors, we must deal with the inductive

kick produced when each of these switches is turned off. Again, we may shunt the inductive

kick using diodes, but now, 4 diodes are required, as shown in Figure 3.4:

Page 11: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 11/23

 

Step angle

It is angle through which motor shaft rotates in one step. step angle is different for

different motor . selection of motor according to step angle depends on the application ,

simply if you require small increments in rottion choose motor having smaller step angle. No

of steps require to rotate one complete rotation = 360 deg. / step angle in deg.

Steps/second

The relation between RPM and steps per sec. is given by ,steps or impulses /sec.

=(RPM X Steps /revolution ) /60 Pause between impulses can be shorter or longer and it

defines revolution rate. This rate cannot be infinite because the motor won't be able to "catch

up" with all the impulses (documentation on specific motor should contain such information).

So referring to RPM value in datasheet you can calculate steps/sec and from it delay or pause

between impulses

INTERFACING TO 8051.

Page 12: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 12/23

To cause the stepper to rotate, we have to send a pulse to each coil in turn. The 8051does not have sufficient drive capability on its output to drive each coil, so there are a number

of ways to drive a stepper,

Stepper motors are usually controlled by transistor or driver IC like

ULN2003. 

Driving current for each coil is then needed about 60mA at +5V supply. A Darlington transistor

array, ULN2003 is used to increase driving capacity of the 2051 chip. Four 4.7k resistors help

the 2051 to provide more sourcing current from the +5V supply.

Coil A Coil B Coil C Coil D Step

0 1 1 0 1

0 0 1 1 2

1 0 0 1 3

1 1 0 0 4

 

Page 13: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 13/23

Sensors Interfacing

Transducer is a device capable of being actuated by an an energizing input from oneor more transmission media and in turn generating a related signal to one or moretransmission systems. It provides a usable output in response to specified input measurand ,which may be in the form physical, chemical, Mechanical or optical....

For eg. temperature transducer transduces temp. changes to equivalent resistancechanges which can further converted into electrical signal (voltage) for measurements.

TEMPERATURE

1. LM35 Precision temperature sensor 

• LM34 series are precision integration-circuit temperature sensors whose output voltage is

linearly proportional to the Fahrenheit temperature.

• LM35 series are precision integration-circuit temperature sensors whose output voltage is

linearly proportional to the Celsius temperature.

Page 14: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 14/23

 

P/NTemperature

Range (oC)Accuracy (oC) Output (mv/oC)

LM35A -55 to 150 1.0 10

LM35 -55to 150 1.5 10LM35CA -40 to 110 1.0 10

LM35C -40 to 110 1.5 10

LM35D 0 to 100 2.0 10

 I am using LM35DT package to operate over a 0° to +100°C temperature range

R5 and C3 are used for capacitive load compensation.

INTERFACING TO MICROCONTROLLER USING ADC804

• The ADC804 has 8-bit resolution with a maximum of 256 steps and the LM35 produces

10mV for every degree of temperature change.

•We will do calibration such that ,

for temperature range of 0 to 100°C , voltage in at the input of ADC will be 0 to 2.56 v.

•we need to set Vref/2 = 1.28V

so step size will be 2560mv/256 = 10mv

also for every degree change in temp. LM35 output changes by 10mv ,so every degree

change in temp. will produce 1 unit change in digital out of ADC

Page 15: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 15/23

 

•Thus resolution of our system will be 1deg C , which is Smallest temp. that we can measure

with this system.

ADC-DAC Interfacing

Analog signals are very common inputs to embedded systems .Most transducers and

sensors such as temperature ,pressure ,velocity ,humidity are analog. Therefore we need to

convert these analog signals in to digital so that 8051 can read it.

 ANALOG DIGITAL TO CONVERTER - ADC

Commonly used ADC device – ADC804

 ABOUT IC

Page 16: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 16/23

PinOut

 • CS – Chip Select , active low

• RD – Read Digital data from ADC, H-L edge triggered

• WR -- Start conversion, L-H pulse edge triggered

• INTR -- end of conversion, Goes low to indicate conversion done

• Data bits -- D0-D7

• CLK IN & CLK R

– CLK IN is an input pin connected to an external clock source when an external clock is used

for timing. However, ADC804 has an internal clock

generator.

To use the internal clock generator of the ADC804, the CLK IN and CLK R pins are connected

to a capacitor and a resistor. In that case, the

clock frequency is determined by the equation.

 

f = 1/1.1RC

R=10K and C=150pF f=606Hz

the conversion time is 110us.

Input Voltage range

• Default 0-5V. Can be changed by setting

different value for Vref/2 pin.

Vin=Vin(+) – Vin (-)

Vref/2(Volts)

Vin(Volts)

Step size (mV)

Open (2.5) 0 to 5 5/256 = 19.53

2.56 0 to 5.12 5.12/256 =20

1.28 0 to 2.56 2.56/256 = 10

0.5 0 to 1 1/256=3.90

Page 17: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 17/23

• Range = 0 to 2x Vref/2.

for Vin = 2x Vref/2. we get 256 as a digital output on D0-D7. (Refer Table)

•Step Size a Smallest change

– (2 x Vref/2)/ 256 for ADC804

for eg for step size 10mv ,digital output on D0-D7 changes by one count for every 10mv

change of the input analog voltage.

 Data Out

Dout = Vin / Step Size

for input vtg. of 2.56 volts (Vref=1.28 volts) and stepsize of 10mv Dout =2560/10 =256 or

FF that is full scale output.

Conversion Time Greater than 110us for ADC804

Resolution

 8 bits for ADC804

INTERFACING ADC804 TO 8051

Signals to be interfaced (on the ADC804)– D0-D7, RD, WR, INTR, CS

Can do both Memory mapping and IO mapping

Memory Mapping (timing is critical)

– Connect D0-D7 of ADC804 to the data bus of the 8051 system

– Connect RD, WR of the ADC804 to the 8051 system (ensure polarity)

– Connect CS of ADC804 to an appropriate address decoder output

– Connect INTR of ADC804 to an external interrupt Pin on the 8051 (INT0 or INT1)

IO Mapping (easiest - I prefer )

– Connect D0-D7, RD, WR, CS, INTR to some port bits on the 8051 (12 in all).

 

Algorithm

• Make CS=0 and send a low-to-high to pin WR to start the conversion.

• Keep monitoring INTR

Page 18: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 18/23

– If INTR =0, the conversion is finished and we can go to the next step.

– If INTR=1, keep polling until it goes low.

• After INTR=0, we make CS=0 and send a high-to-low pulse to RD to get the data out of the

ADC804 chip.

ASSEMBLY LANGUEGE  (A51)

ADC_IO:

mov P1, #0xff ; To configure as input

 

AGAIN

clr p3.7 ;Chip select

setb P3.6 ;RD=1

clr P3.5 ;WR=0

setb P3.5 ;WR=1- low to high transition

WAIT:

jb P3.4, WAIT ;wait for INTR

clr p3.7 ;generate cs to ADC

clr P3.6 ;RD=0 -High to low transition

mov A, P1 ;read digital o/p

sjmp AGAIN

DIGITAL TO ANALOG CONVERTER - DAC

 Commonly used DAC808 (MC1408)

– R/2R ladder

– Iout = Iref (D7/2 + D6/4 + D5/8 + …… + D0/256)

– Iout converted to voltage by a resistive load or op-amp based isolator (Rf from Vout to V-

and V+ to GND)

 

PinOut

– D0-D7 à Connected to the Processor’s IO port

– Vref+, Vref-, Vee

 

Usage:

– Just write a byte to the IO port and the DAC converts it to an

analog value

Some 8051 clones have ADCs and DACs in built

Page 19: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 19/23

7 Segment DisplayINTRODUCTION

 For the seven segment display you can use the LT-541 or LSD5061-11 chip. Each of the

segments of the display is connected to a pin on the 8051 (the schematic shows how to do

this). In order to light up a segment on the the pin must be set to 0V. To turn a segment off 

the corresponding pin must be set to 5V. This is simply done by setting the pins on the 8051

to '1' or '0'.

 LED displays are

• Power-hungry (10ma per LED)

• Pin-hungry (8 pins per 7-seg display)

 But they are cheaper than LCD display

Page 20: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 20/23

7-SEG Display are available in two types -1. Common anode & 2. common cathode , but

command anode display are most suitable for interfacing with 8051 since 8051 port pins can

sink current better than sourcing it.

CREATING DIGIT PATTERN:

For displaying Digit say 7 we need to light segments -a ,b, c. Since we are usingCommon anode display , to do so we have to to provide Logic -0 (0 v) at anode of thesesegments. so need to clear pins- P1.0 ,P1.1,P1.2. that is 1 1 1 1 1 0 0 0 -->F8h .

Connection

Segment number 8051 pin number

A P1.0

B P1.1

C P1.2

D P1.3E P1.4

F P1.5

G p1.6

h(dp) P1.7

Page 21: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 21/23

Hex Code

Digit Seg. h Seg. g Seg. f Seg. e Seg. d Seg. c Seg. b Seg. a HEX

0 1 1 0 0 0 0 0 0 C0

1 0 0 0 0 0 1 1 0 06

2 1 0 1 0 0 1 0 0 A4

3 1 0 1 1 0 0 0 0 B0

4 1 0 0 1 1 0 0 1 99

You can also do this for some characters like A ,E .. but not for D or B because it will be same

as that of 0 & 8 . So this is one of limitation of 7-seg display.

Since we can Enable only one 7-seg display at a time ,we need to scan these display at fast

rate .The scanning frequency should be high enough to be flicker-free. At least 30HZ

.Therefore – time one digit is ON is 1/30 seconds

INTERFACING

Note that I am using Common Anode display. so the common Anode pin is tied to

5v .The cathode pins are connected to port 1 through 330 Ohm resistance (current limiting).

Common Anode display

Example: To display 03 value…….

Page 22: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 22/23

All Interfacing Circuit Design:

Page 23: 8051 Board Document

8/7/2019 8051 Board Document

http://slidepdf.com/reader/full/8051-board-document 23/23