A Brief Introduction To 8051 Microcontroller

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 26

A

BRIEF

INTRODUCTION

TO 8051

MICROCONTROLLER

When we have to learn about a new computer we have to familiarize about the machine capability we are using, and we can do it by studying the internal hardware design (devices architecture), and also to know about the size, number and the size of the registers.A microcontroller is a single chip that contains the processor (the CPU), non-volatile memory for the program (ROM or flash), volatile memory for input and output (RAM), a clock and an I/O control unit. Also called a "computer on a chip," billions of microcontroller units (MCUs) are embedded each year in a myriad of products from toys to appliances to automobiles. For example, a single vehicle can use 70 or more microcontrollers. The following picture describes a general block diagram of microcontroller.89s52: The AT89S52 is a low-power, highperformance CMOS 8-bit microcontroller with 8K bytes of in-system programmable Flash memory. The device is manufactured using Atmels high-density non-volatile memory technology and is compatible with the industry-standard 80C51 instruction set and pin out. The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional non volatile memory programmer. By combining a versatile 8-bit CPU with in-system programmable Flash on a monolithic chip, the Atmel's AT89S52 is a powerful microcontroller which provides a highly-flexible and cost-effective solution to many embedded control applications. The AT89S52 provides the following standard features: 8K bytes of Flash, 256 bytes of RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit timer/counters, a six-vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator, and clock circuitry. In addition, the AT89S52 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port, and interrupt system to continue functioning. The Power-down mode saves the RAM con-tents but freezes the oscillator, disabling all other chip functions until the next interrupt. The hardware is driven by a set of program instructions, or software. Once familiar with hardware and software, the user can then apply the microcontroller to the problems easily. The pin diagram of the 8051 shows all of the input/output pins unique to microcontrollers: The following are some of the capabilities of 8051 microcontroller.

Internal ROM and RAM I/O ports with programmable pins Timers and counters Serial data communication

INTRODUCTION
A microcontroller is a computer-on-a-chip built for specific tasks such as displaying/receiving information through LEDs or remote controlled devices. 8051 introduced the world to the most revolutionary set of microcontrollers. Apart from 8051, 8052 and 8031 complete the 8051 family. The 8052 microcontroller has 256 bytes of RAM and 3 timers. Programs written for 8051 projects can be used for 8052 as well. The 8031 has all features of 8051 except that it is ROM-less. An external ROM that is as large as 64 k bytes can be programmed and added to this chip for execution. The main disadvantage of adding external ROM is that 2 out of 4 ports are used up leaving less for I/O operations. The different types of memory used in 8051 are: i. Internal RAM Located from address 0 to 0xff. ii. Special Function Registers (SFR) Located from address 0x80 to 0Xff. iii. Program Memory Located at address 0. Uses 16 bit Special Function Register DPTR, to save the tables of constants. iv. External Data Memory Located at address 0. Uses MOVX (Move External) to access the external data memory. 8051s history dates back to when Intel Corporation first built the 8 bit microcontroller in 1981. This microcontroller was referred as system on a chip because it had 128 bytes of RAM, 4 Kbytes of ROM, 2 Timers, 1 Serial port, and four ports on a single chip. Intel permitted other microcontroller manufacturers to fabricate different versions of 8051 with the condition that code compatibility should be maintained. The advantage of this is that when the program is written, it can be used for any version of 8051 irrespective of manufacturer.

8051 BLOCK DIAGRAM

8051 Microcontroller Block Diagram Explanation:


CPU (Central Processor Unit): As you may be familiar that Central Processor Unit or CPU is the mind of any processing machine. It scrutinizes and manages all processes that are carried out in the Microcontroller. User has no power over the functioning of CPU. It interprets program printed in storage space (ROM) and carries out all of them and do the projected duty. Interrupts: As the heading put forward, Interrupt is a sub-routine call that reads the Microcontrollers key function or job and helps it to perform some other program which is extra important at that point of time. The characteristic of Interrupt is extremely constructive as it aids in emergency cases. Interrupts provides us a

method to postpone or delay the current process, carry out a sub-routine task and then all over again restart standard program implementation. The Micro-controller 8051 can be assembled in such a manner that it momentarily stops or break the core program at the happening of interrupt. When sub-routine task is finished then the implementation of core program initiates automatically as usual. There are 5 interrupt supplies in 8051 Microcontroller, two out of five are peripheral interrupts, two are timer interrupts and one is serial port interrupt. Memory: Micro-controller needs a program which is a set of commands. This program enlightens Microcontroller to perform precise tasks. These programs need a storage space on which they can be accumulated and interpret by Microcontroller to act upon any specific process. The memory which is brought into play to accumulate the program of Microcontroller is recognized as Program memory or code memory. In common language its also known as Read Only Memory or ROM. Micro-controller also needs a memory to amass data or operands for the short term. The storage space which is employed to momentarily data storage for functioning is acknowledged as Data Memory and we employ Random Access Memory or RAM for this principle reason. Microcontroller 8051 contains code memory or program memory 4K so that is has 4KB Rom and it also comprise of data memory (RAM) of 128 bytes. Bus: Fundamentally Bus is a group of wires which functions as a communication canal or mean for the transfer Data. These buses comprise of 8, 16 or more cables. As a result, a bus can bear 8 bits, 16 bits all together. There are two types of buses: 1. Address Bus: Microcontroller 8051 consists of 16 bit address bus. It is brought into play to address memory positions. It is also utilized to transmit the address from Central Processing Unit to Memory. 2. Data Bus: Microcontroller 8051 comprise of 8 bits data bus. It is employed to cart data. Oscillator: As we all make out that Microcontroller is a digital circuit piece of equipment, thus it needs timer for its function. For this function, Microcontroller 8051 consists of an on-chip oscillator which toils as a time source for CPU (Central Processing Unit). As the productivity thumps of oscillator are steady as a result, it facilitates harmonized employment of all pieces of 8051 Microcontroller. Input/output Port: As we are acquainted with that Microcontroller is employed in embedded systems to manage the functions of devices. Thus to gather it to other machinery, gadgets or peripherals we need I/O (input/output) interfacing ports in Micro-controller. For this function Micro-controller 8051 consists of 4 input/output ports to unite it to other peripherals. Timers/Counters: Micro-controller 8051 is incorporated with two 16 bit counters & timers. The counters are separated into 8 bit registers. The timers are utilized for measuring the intervals, to find out pulse width etc.

8051 Architecture
16 bit PC &data pointer (DPTR) 8 bit program status word (PSW) 8 bit stack pointer (SP) Internal ROM 4k Internal RAM of 128 bytes. 4 register banks, each containing 8 registers 80 bits of general purpose data memory 32 input/output pins arranged as four 8 bit ports P0-P3 Two 16 bit timer/counters: T0-T1 Two external and three internal interrupt sources Oscillator and clock circuits

For any electronics project the power supply plays a very important role in its proper functioning. In this project we are using external A.C supply (220 v) as input, this high voltage is converted into 12 Volts A.C by step down transformer, then we use voltage regulators and filters with bridge rectifier to convert the A.C into D.C voltage. For voltage regulation we are using LM 7805 and 7812 to produce ripple free 5 and 12 Volts D.C constant supply.

A circuit breaker capable of microcontroller-based fault detection having a backup circuit for causing the circuit to trip in response to a microcontroller fault or a failure of a regulated power supply powering the microcontroller. The circuit breaker includes an RC circuit connected to an SCR. The resistor of the RC circuit is connected between the anode and gate of the SCR, and the capacitor is connected between the gate and cathode of the SCR. The microcontroller has a first pin coupled to the RC circuit, which is initially in a high input impedance state. In the event of a microcontroller fault or power supply failure, the capacitor will

charge to a voltage sufficient to activate the SCR and trip the breaker. If the microcontroller start-up routine is successful, the pin is configured as an output and is pulled low, shorting out the capacitor.

DESCRIPTION OF 8051INTERFACINGS
It is very important to keep a track of the working of almost all the automated and semi-automated devices, be it a washing machine, an autonomous robot or anything else. This is achieved by displaying their status on a small display module. LCD (Liquid Crystal Display) screen is such a display module and a 16x2 LCD module is very commonly used. These modules are replacing seven segments and other multi segment LEDs for these purposes. The reasons being: LCDs are economical, easily programmable, have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on. LCD can be easily interfaced with a microcontroller to display a message or status of a device. This topic explains the basics of a 16x2 LCD and how it can be interfaced with AT89C51 to display a character.

LCD
LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments and other multi segment LEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of displaying special & even custom characters (Unlike in seven segments), animations and so on.

A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command and Data. The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position,

controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD. Click to learn more about internal structure of a LCD.

PinDiagram:

Pin Description: Pin No 1 2 3 Function Ground (0V) Supply voltage; 5V (4.7V 5.3V) Contrast adjustment; through a variable resistor Name Ground Vcc VEE

4 5 6 7 8 9 10 11 12 13 14 15 16

Selects command register when low; and data register when high Low to write to the register; High to read from the register Sends data to data pins when a high to low pulse is given

Register Select Read/write Enable DB0 DB1 DB2 DB3

8-bit data pins DB4 DB5 DB6 DB7 Backlight VCC (5V) Backlight Ground (0V) Led+ Led-

SEVEN SEGMENT

A seven segment display is the most basic electronic display device that can display digits from 0-9. They find wide application in devices that display numeric information like digital clocks, radio, microwave ovens, electronic meters etc. The most common configuration has an array of eight LEDs arranged in a special pattern to display these digits. They are laid out as a squared-off figure 8. Every LED is assigned a name from 'a' to 'h' and is identified by its name. Seven LEDs 'a' to 'g' are used to display the numerals while eighth LED 'h' is used to display the dot/decimal.

A seven segment is generally available in ten pin package. While eight pins correspond to the eight LEDs, the remaining two pins (at middle) are common and internally shorted. These segments come in two configurations, namely, Common cathode (CC) and Common anode (CA). In CC configuration, the negative terminals of all LEDs are connected to the common pins. The common is connected to ground and a

particular LED glows when its corresponding pin is given high. In CA arrangement, the common pin is given a high logic and the LED pins are given low to display a number

AT89C51 MICROCONTROLLER
AT89C51 is an 8-bit microcontroller and belongs to Atmel's 8051 family. ATMEL 89C51 has 4KB of Flash programmable and erasable read only memory (PEROM) and 128 bytes of RAM. It can be erased and program to a maximum of 1000 times. In 40 pin AT89C51, there are four ports designated as P1, P2, P3 and P0. All these ports are 8-bit bidirectional ports, i.e., they can be used as both input and output ports. Except P0 which needs external pullups, rest of the ports have internal pull-ups. When 1s are written to these port pins, they are pulled high by the internal pull-ups and can be used as inputs. These ports are also bit addressable and so their bits can also be accessed individually.

Port P0 and P2 are also used to provide low byte and high byte addresses, respectively, when connected to an external memory. Port 3 has multiplexed pins for special functions like serial communication, hardware interrupts, timer inputs and read/write operation from external memory. AT89C51 has an inbuilt UART for serial communication. It can be programmed to operate at different baud rates. Including two timers & hardware interrupts, it has a total of six interrupts.

Pin Diagram:

Pin Description:

Pin No 1 2 3 4

Function

Name

P1.0 P1.1 P1.2 P1.3 8 bit input/output port (P1) pins P1.4 P1.5 P1.6 P1.7 Reset pin; Active high Input (receiver) for serial Reset

5 6 7 8 9

10

communication Output (transmitter) for serial

RxD

P3.0

11

communication External interrupt 1 External interrupt 2 Timer1 external input Timer2 external input Write to external data memory

TxD 8 input/output bit

P3.1

12 13 14 15 16

Int0 Int1 T0 T1 Write

P3.2 P3.3 P3.4 P3.5 P3.6

port (P3) pins

17 18

Read from external data memory

Read

P3.7 Crystal 2

Quartz crystal oscillator (up to 24 MHz) 19 20 21 22 23 24 25 26 27 28 29 Program store enable; Read from external program memory Address Latch Enable 30 Program pulse input during Flash programming External Access Enable; Vcc for internal program executions 31 Programming enable voltage; 12V (during Flash programming) 32 33 34 35 36 37 Low-order address bits when interfacing with external memory 8 bit input/output port (P0) pins Vpp P0.7/ AD7 P0.6/ AD6 P0.5/ AD5 P0.4/ AD4 P0.3/ AD3 P0.2/ AD2 Prog EA 8 bit input/output port (P2) pins / High-order address bits when interfacing with external memory Ground (0V) Crystal 1 Ground P2.0/ A8 P2.1/ A9 P2.2/ A10 P2.3/ A11 P2.4/ A12 P2.5/ A13 P2.6/ A14 P2.7/ A15 PSEN ALE

38 39 40 Supply voltage; 5V (up to 6.6V)

P0.1/ AD1 P0.0/ AD0 Vcc

PROJECT TOPIC DESCRIPTION It is very important to keep a track of the working of almost all the automated and semi-automated devices, be it a washing machine, an autonomous robot or anything else. This is achieved by displaying their status on a small display module. LCD (Liquid Crystal Display) screen is such a display module and a 16x2 LCD module is very commonly used. These modules are replacing seven segments and other multi segment LEDs for these purposes. The reasons being: LCDs are economical, easily programmable, have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on. LCD can be easily interfaced with a microcontroller to display a message or status of a device. This topic explains the basics of a 16x2 LCD and how it can be interfaced DESCRIPTION A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers. 1. Command/Instruction Register- stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing, clearing the screen, setting the cursor position, controlling display etc. 2. Data Register- stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD. This project has following function: It displays a dynamic message with certain animated effects (left shifting and displaying again after a certain time delay) on a 162 LCD screen interfaced by an Atmel AT89C51Microcontroller. Components Required: Microcontroller (Atmel AT89C51) 162 LCD Rheostat (10 kohm) Crystal Oscillator (12 MHz) 1 Pcs. 1 Pcs. 1 Pcs. 1 Pcs.

Resistor (10 k ohm) Capacitor (10F/25V) Jumper Wires

1 Pcs. 1 Pcs. As per requirement

Softwares Used: o o o o Microsoft Word 07 Keil vision 2.0 Proteus(Isis) 7 Super Pro L++

A string or message can be displayed on LCD by sending its characters to data register after configuring the command register of LCD. To create dynamic effects, a specific command instruction is sent to LCD via microcontroller AT89C51.

CODE LOGIC
Hex Code 1 2 4 6 5 7 8 A C E 10 14 18 1C 80 C0 38 Command to LCD Instruction Register Clear screen display Return home Decrement cursor Increment cursor Shift display right Shift display left Display OFF, cursor OFF Display OFF, cursor ON Display ON, cursor OFF Display ON, cursor blinking Shift cursor position to left Shift cursor position to right Shift the entire display to the left Shift the entire display to the right Force the cursor to the beginning of the 1st line Force cursor to the beginning of the 2nd line Use 2 lines and 5x7 matrix

To create a particular effect, any of these code(s) can be used in a pattern. For example, shifting the entire display right (5H) in a loop will keep moving the text to right. To create oscillating text, first keep shifting the string to right (for say, 8 positions) and then shift it to left. This left-right shifting can be done in an infinite loop.

Here P2 is used as output port of the 8051 microcontroller (AT89C51) which sends the data byte to data pins of the LCD. The control pins (pin 4, 5 & 6) are connected to pins 0, 1 & 6, respectively, of P3 port of the microcontroller. Pin 3 is connected to a preset of 10k to adjust the contrast on LCD screen.

CODE (ASSEMBLE PROGRAMME OR C PROGRAMME)


// Program to display dynamic text on LCD

#include<reg51.h> #define msec 50 sbit rs=P3^0; //Register select (RS) sbit rw=P3^1; //Read write (RW) pin sbit en=P3^6; //Enable (EN) pin unsigned char commands[]={0x38,0x0E,0x01,0x06,'\0'}; //Command to be sent to LCD char name[]={"ECE Rocks"}; //String to be displayed on LCD

void delay(unsigned int time) //Time delay function { unsigned int i,j; for(i=0;i<time;i++) for(j=0;j<1275;j++);

void lcdcmd(unsigned char value) //Function for sending values to the command register of LCD { P2=value; rs=0; rw=0; en=1; delay(1); en=0; return; }

void display(unsigned char value) //Function for sending values to the data register of LCD { P2=value; rs=1; rw=0; en=1; delay(1); en=0; return; }

void main() { int i,j; for(i=0;commands[i]!='\0';i++) //Sending string to LCD { lcdcmd(commands[i]); delay(msec); } for(j=0;name[j]!='\0';j++) { display(name[j]); delay(msec); } while(1) { lcdcmd(0x1C); //Shift the entire display to right delay(75); } }

PROTEUS DESIGNED CIRCUIT DIAGRAM

RESULT (SCREEN SHOTS OF RUNNING PROJECT)

CONCLUSION
The project was easy to make. The designing and coding of the project was not also much difficult. However, the components are not readily available in electronics market. The LCD was run short in market and finally found from old stock of a shop. Most of the microcontrollers available in market are out of order and there is no replace offered by shop keeper of it. Therefore, we wasted our money for 4 microcontrollers and finally the fifth one we purchase was a good microcontroller. One thing that we got from our experience is that simulation made on proteus is not accurate. When we simulated the circuit on proteus, the time delay observed was approx. 8 sec. However, practically it is 0.5 sec. Once the microcontroller is programmed, then the Connections on bread board were not difficult to make. However initially the LCD didnt show any display. We checked all the components. The components were in perfect order. After much thought we changed the value of resistance on rheostat which changed the brightness of LCD. Hence finally the string is displayed and then it moved dynamically to left. In nut

shell, the project is accomplished after a little difficulty in the end and the HEX file is executed well such that the cursor appears on LCD screen, the cursor increments further such that the string Welcome to RCET appears. After the string appeared, it moves to left. After a delay of 0.5 sec., the string blinks again and then move to right and then there comes another delay. This routine continues for an infinite span of time unless the power supplied to the circuit is disconnected.

APPLICATIONS:
The project have many applications we may see in our daily life. Some of them are as follows: The ticket booth LCD counters of banks. Advertisement boards. News displaying LCD boards installed on traffic signals. Digital Clocks. Flight timing displaying boardson airports.

REFERENCE
http://www.engineersgarage.com en.wikipedia.org http://vediktronics.blogspot.in http://vj86.hubpages.com http://www.slideshare.net http://www.slideshare.net

The 8051 Microcontroller And Embedded Systems Using Assembly And C, 2/E by mazidi

You might also like