You are on page 1of 33

REPORT: 1.

Introduction:a) Embedded system b) Microcontroller


Criteria in Choosing a Microcontroller

c) 8051 Microcontroller 2. Architecture of 8051 Microcontroller 3. Memory Map 4. Interfacing with:a) LED b) LCD c) Keypad d) Memory e) Stepper motor g) DS 1307-Real Time Clock 5. Serial communication

INTRODUCTION 1.1. Embedded system:An Embedded system means the processor is embedded into that application. An Embedded system is an application that contains at least one programmable Computer (typically in the form of a microcontroller, a microprocessor or digital Signal processor chip) and which is used by individuals who are, in the main, Unaware that the system is computer-based An Embedded system is some combination of computer hardware and software, either fixed in capability or programmable, that is specifically designed for a particular function. Industrial machines, automobiles, medical equipment, cameras, household appliances, airplanes, vending machines and toys (as well as the more obvious cellular phone and PDA) are among the myriad possible hosts of an embedded system. Embedded systems that are programmable are provided with programming interfaces, and embedded system programming is a specialized occupation.

1.2. Microcontroller:A microcontroller is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. Program memory in the form of flash or ROM is also often included on chip, as well as a typically small amount of RAM. Microcontrollers are designed for embedded applications, in contrast to the microprocessors used in personal computers or other general purpose applications. A microcontroller can be considered a self-contained system with a processor, memory and peripherals and can be used as an embedded system. Microcontrollers are used in automatically controlled products and devices, such as automobile engine control systems, implantable medical devices, remote controls, office machines, appliances, power tools, and toys. By reducing the size and cost compared to a design that uses a separate microprocessor, memory, and input/output devices, microcontrollers make it economical to digitally control even more devices and processes. Mixed signal microcontrollers are common, integrating analog components needed to control non-digital electronic systems.

Criteria in Choosing a Microcontroller:1. Meeting the computing needs of the task efficiently and cost effectively -speed, the amount of ROM and RAM, the number of I/O ports and timers, size, power consumption -easy to upgrade -cost per unit 2. Availability of software development tools -assemblers, debuggers, C compilers, emulator, simulator, technical support 3. Wide availability and reliable sources of the microcontrollers

1.3. 8051 Microcontroller:The 8051 is a Single Chip Computer or microcontroller made by Intel. It is one of the most widely used microcontroller chips in the world.

Features of 8051- 8-bit Microcontroller -Small, cheap & 40 pins. (Number of pins increases size & cost) - Harvard architecture (Separate memory space for program and data). -Internal ROM of 4Kbytes -Internal RAM of 128 bytes -External code and data memory up to 64KB -on chip oscillator - Timers 2(16-bit) - I/O pins 32 (4 ports) -Serial port 1 (UART) - Interrupt source 6 -Data memory internal 256 bytes are divided into two parts: General scratch (0x00-0x7F) and the special function register SFR (0x80-0xFF) -16 bit addresses line (0x0000-0xFFFF) and 8 bit data line (0x00-0xFF). - 8bit CPU registers - 16bit program counter & data pointer - 8bit program status word - Control registers - 4 register banks

ARCHITECTURE OF 8051 MICROCONTROLLER

Harvard architecture 4 Kb of ROM is not much at all. 128b of RAM (including SFRs) satisfies the user's basic needs. External Memory 64 Kbytes 4 ports having in total of 32 input/output lines are in most cases sufficient to make all necessary connections to peripheral environment. 2 Timers 1 Serial port input/output On chip oscillator

The whole configuration is obviously thought of as to satisfy the needs of most programmers working on development of automation devices. One of its advantages is that nothing is missing and nothing is too much. In other words, it is created exactly in accordance to the average users taste and needs. Other advantages are RAM organization, the operation of Central Processor Unit (CPU) and ports which completely use all recourses and enable further upgrade

2.1. Pin out Description:-

Pins 1-8: port 1 Each of these pins can be configured as an input or an output. Pin 9: RST A logic one on this pin disables the microcontroller and clears the contents of most registers. In other words, the positive voltage on this pin resets the microcontroller. By applying logic zero to this pin, the program starts execution from the beginning.

Pins10-17: Port 3 Similar to port 1, each of these pins can serve as general input or output. Besides, all of them have alternative functions: Pin 10: RXD Serial asynchronous communication input or Serial synchronous communication output. Pin 11: TXD Serial asynchronous communication output or Serial synchronous communication clock output. Pin 12: INT0 Interrupt 0 input. Pin 13: INT1 Interrupt 1 input. Pin 14: T0 Counter 0 clock input. Pin 15: T1 Counter 1 clock input. Pin 16: WR Write to external (additional) RAM. Pin 17: RD Read from external RAM.

Pin 18, 19: X2 , X1 Internal oscillator input and output. A quartz crystal which specifies operating frequency is usually connected to these pins. Instead of it, miniature ceramics resonators can also be used for frequency stability. Later versions of microcontrollers operate at a frequency of 0 Hz up to over 50 Hz. Pin 20: GND Ground. Pin 21-28: Port 2 If there is no intention to use external memory then these port pins are configured as general inputs/outputs. In case external memory is used, the higher address byte, i.e. addresses A8-A15 will appear on this port. Even though memory with capacity of 64Kb is not used, which means that not all eight port bits are used for its addressing, the rest of them are not available as inputs/outputs. Pin 29: PSEN If external ROM is used for storing program then a logic zero (0) appears on it every time the microcontroller reads a byte from memory. Pin 30: ALE Prior to reading from external memory, the microcontroller puts the lower address byte (A0-A7) on P0 and activates the ALE output. After receiving signal from the ALE pin, the external register (usually 74HCT373 or 74HCT375 addon chip) memorizes the state of P0 and uses it as a memory chip address. Immediately after that, the ALU pin is returned its previous logic state and P0 is now used as a Data Bus. As seen, port data multiplexing is performed by means of only one additional (and cheap) integrated circuit. In other words, this port is used for both data and address transmission. Pin 31:

EA By applying logic zero to this pin, P2 and P3 are used for data and address transmission with no regard to whether there is internal memory or not. It means that even there is a program written to the microcontroller, it will not be executed. Instead, the program written to external ROM will be executed. By applying logic one to the EA pin, the microcontroller will use both memories, first internal then external (if exists). Pin 32-39: Port 0 Similar to P2, if external memory is not used, these pins can be used as general inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE pin is driven high (1) or as data output (Data Bus) when the ALE pin is driven low (0). Pin 40: VCC +5V power supply.

MEMORY MAP
Data memory internal 256 bytes are divided into two parts: General scratch (0x00-0x7F) and the special function register SFR (0x80-0xFF) In General scratch - 4 Register Banks Each bank has 8 general purpose registers R0-R7 At a time only one bank is used. By default we can access Bank 0. Bank 0 (0x00-0x07) Bank 1 (0x08-0x0F) Bank 2 (0x10-0x17) Bank 3 (0x18-0x1F) - Bit addressable Registers(0x20-0x2F) - General purpose RAM (0x30-0x7F) It is use for general purpose data storage. Access of this area of memory is fast compare to access to the main memory and special instruction with single byte operands are used. In SFR (special function register)-It is locate in address range 0x80-0xFF within the internal memory. -All locations within this range are not defined. -Each SFR has a very specified function and an address and a name also which reflects the purpose of the SFR. - Only 21 SFR registers are defined in 8051. List of SFRs:-P 0 (port 0) -P 1(port 1) -P 2 (port 2) -P 3 (port 3) -SP (stack pointer) -DPL (data pointer low) -DPH (data pointer high) -PCON (power control) -TCON (timer control)

-TMOD (timer mode) -SCON (serial control) -SBUF (serial buffer) -IE (interrupt enable) -IP (interrupt priority) -PSW (program status word) -ACC (accumulator) -B -TL0 (timer low 0) -TL1 (timer low 1) -TH0 (timer high 0) -TH1 (timer high 1)

Fig: General purpose RAM

Fig: SFR (special function register)

INTERFACING OF DEVICES WITH MICROCONTROLLER


1. LED 2. LCD 3. KEYPAD 4. MEMORY 5. STEEPER MOTOR 6. IR SENSOR 7. RTC

4.1. LED INTERFACE:LED Light emitting diodes (LEDs) are semiconductor light sources. The light emitted from LEDs varies from visible to infrared and ultraviolet regions. They operate on low voltage and power. LEDs are one of the most common electronic components and are mostly used as indicators in circuits. They are also used for luminance and optoelectronic applications. LEDs are connected to the port P0. LEDs need approximately 10mA current to flow through them in order to glow at maximum intensity. However the output of the controller is not sufficient enough to drive the LEDs, so if the positive leg of the LED is connected to the pin and the negative to ground, the LED will not glow at full illumination. To overcome this problem LEDs are connected in the reverse order and they run on negative logic i.e., whenever 1 is given on any pin of the port, the LED will switch off and when logic 0 is provided the LED will glow at full intensity.

4.2. LCD INTERFACE:LCD LCDs can add a lot to application in terms of providing an useful interface for the user, debugging an application or just giving it a "professional" look. 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.

A very popular standard HD44780U refers to the controller chip which receives data from an external source (the 8051a and communicates directly with the LCD. The 44780 standard requires 3 control lines named EN (Enable), RS (Register Select ), RW (Read/Write ) as well as either 4 or 8 I/O lines for the data bus.

LCD pin configuration:Pin number


1 2 3 4 5 6 7-14

Function
VSS VCC VEE RS RW EN DATA

VCC, VSS and VEE: while VCC and VSS provide +5v and ground, respectively, VEE is used for controlling LCD contrast. RS, register select: if RS=0, the instruction command code register is selected, allowing the user to send a command such as clear display, cursor at home, etc. if RS = 1 the data register is selected, allowing the user to send data to be displayed on the LCD. R/W, read/write: R/W input allows the user to write information to the LCD or read information from it. R/W = 1 when reading; R/W =0 when writing. E, enable: The enable pin is wise by the LCD to latch information presented to its data pins. When data is supplied to data pins, a high to-low pulse must be applied to this pin in order for the LCD to latch in the data present at the data pins. This pulse must be a minimum of 450ns wide

D0-D7: the 8-bit data pins, D0-D7, are used to send information to the LCD or read the contents of the LCDS internal registers Instruction command codes that can be sent to the LCD to clear the display or force the cursor to the home position or blink the cursor. Table below lists the instruction command codes To send any of the commands to the LCD, make pin RS=0. for command, RW pin to 0, then send a high-to-low pulse to the E pin to enable the internal latch of the LCD. To send any of the data to the LCD, make pin RS=0. For data, make RS=1. then send a high-to-low pulse to the E pin to enable the internal latch of the LCD

Command:HEX
1 2 4 5 6 7 8 A C E F 10 14 18 1C 80 C0 38

Instruction
clear display screen return home decrement cursor shift display right increment cursor shift display left displays off, cursor off display off, cursor display on, cursor off display on, cursor blinking 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 cursor to beginning of 1st line force cursor to beginning of 2nd line 2 lines and 5x7 matrix

4.3. KEYPAD INTERFACE:Keypads are often used as a primary input device for embedded microcontrollers. The keypads actually consist of a number of switches, connected in a row or column arrangement as shown in Fig.

The 4X4 matrix connected to two ports. The rows are connected to an output port and the columns are connected to input port. If no key has been pressed reading the Input port will yield 1s for all columns since they are all connected to high (Vcc). If all the rows are grounded and a key is pressed, one of the columns will have 0 since the key pressed provides the path to the ground. It is the function of microcontroller to scan the keyboard continuously to detect and identify the key pressed To detect a pressed key, the micro-controller grounds all rows by providing 0 to the Output latch, and then it reads the columns. If the data read from the

columns is D3 -D0 =1111, no key has been pressed and the process continues until a key press is detected. However, if one of the column bit has a zero, this means that a key press has occurred. For example if D3 D0 =1101, this means that a key in the D1 column has been pressed. After a key press is detected the micro-controller will go through the process of identifying the key. Starting with the top row, the micro-controller grounds it by providing a low to row D0 only; then it reads the columns. If the data read is all 1s, no key in that row is activated and the process moved to the next row. It grounds the next row, read the columns and checks for any zero. This process continues until the row is identified. After identification of the row in which the key has been pressed, the next task is to find out which column the pressed key belongs to. This should be easy since the micro-controller knows at any time which row and the column are being accessed Following are the four major stages:1. To make sure that the preceding key has been released, 0s are output to all rows at once, and the columns are read and checked repeatedly until all the columns are high. When all columns are found to be high, the program waits for the short amount of time before it goes to the next stage of waiting for the key to be pressed. 2. To see if any key is pressed, the columns are scanned over and over in an infinite loop until one of them has a 0s on it. Remember that the output latches connected to rows still have their initial zeros making them grounded. After the key press detection the micro-controller waits 20ms for the bounce and then scans the columns again. This serves two functions: (a) It ensures that the first key press detection was not an erroneous one due to a spike noise and (b) The 20ms delay prevents the same key press from being interpreted as a multiple key press. If after the 20ms delay the key is still pressed, it goes to the next stage to detect which row it belongs to: otherwise it goes back into the loop to detect a real key press. 3. To detect which row the key press belongs to, the micro-controller grounds one row at the time, reading the columns each time. If it finds that all columns are high, this means that the key press cannot belong to that row; therefore, it

grounds the next row and continues until it finds the row the key press belongs to. Upon Finding the row that the key press belongs to, it sets up the starting address for the look-up table holding the scan codes so that row and goes to the next stage to identify the key. 4. To identify the key press, the micro-controller rotates the column bits, one bit at a time, into the carry flag and checks to see if it is low. Upon finding the zero, it pulls out the ASCII code for that key from the look-up table; otherwise it increments the pointer to point to the next element of the look-up table.

KEYPAD and LED interfacing:-

4.4. MEMORY INTERFACE: It has 4K bytes of internal Flash memory for code/program. It has 128 bytes of internal RAM Memory for data. It can access up to 64Kbytes of external data & code memory In the design of all microprocessorbased systems, semiconductor memories are used as primary storage for code and data. Semiconductor memories are directly connected to the CPU and they are the memory that the CPU first asks for the information (data and code) For this reason these memories are called as PRIMARY MEMORY. (Which are fast in responding to the CPU). The most widely used semiconductor memories are ROM and RAM. The number of bits that a semiconductor memory chip can store is called chip capacity It can be in units of Kbits, Mbits and so on.. Memory capacity of an IC chip is given in bits and of a computer system is given in bytes. E.g. if in an article says that the 16M chip has become popular it means it is of 16M bits However, if it mentions that a computer system comes with 16M memory it means 16M bytes. Memory chips are organized into number of locations within the IC. The number of bits that each location within the memory chip can hold is always equal to the number of data pins on the chip. The number of locations within the IC is given by address pins.

Speed: It is an important factor of a memory chip. To access a data, the address is presented to the address pins, the read pin is activated, and after a certain amount of elapsed time, the data show up at the data pins. The shorter this elapsed time ,the better, and consequently, the more expensive the memory chip The speed of the memory chip is commonly referred to as its ACCESS TIME.

Fig: interfacing of ROM with 8051 microcontroller

Fig: interfacing of RAM with 8051 microcontroller

Fig: Interfacing of memory (RAM and ROM) with Microcontroller

4.5. STEPPER MOTOR INTERFACE:-

A stepper motor is a brushless, synchronous electric motor that can divide a full rotation into a large number of steps, for example, 200 steps. Thus the motor can be turned to a precise angle Stepper motors operate differently from normal DC motors, which simply spin when voltage is applied to their terminals. Stepper motors, on the other hand, effectively have multiple "toothed" electromagnets arranged around a central metal gear. To make the motor shaft turn, first one electromagnet is given power, which makes the gear's teeth magnetically attracted to the electromagnet's teeth. When the gear's teeth are thus aligned to the first electromagnet, they are slightly offset from the next electromagnet So when the next electromagnet is turned on and the first is turned off, the gear rotates slightly to align with the next one, and from there the process is repeated. Each of those slight rotations is called a "step." In that way, the motor can be turned a precise angle. There are two basic arrangements for the electromagnetic coils: bipolar and unipolar.

Unipolar motor: In a unipolar stepper motor, there are four separate electromagnets. To turn the motor, first coil "1" is given current, then it's turned off and coils 2 is given current, and then coil 3, then 4, and then 1 again in a repeating pattern. Current is only sent through the coils in one direction; thus the name unipolar. A unipolar stepper motor will have 5 or 6 wires coming out of it. Four of those wires are each connected to one end of one coil. The extra wire (or 2) is called "common." To operate the motor, the "common" wire(s) is (are) connected to the supply voltage, and the other four wires are connected to ground through transistors, so the transistors control whether current flows or not.

A microcontroller or stepper motor controller is used to activate the transistors in the right order.

Bipolar motor: There are only two coils, and current must be sent through a coil first in one direction and then in the other direction; thus the name bipolar. Bipolar motors need more than 4 transistors to operate them, but they are also more powerful than a unipolar motor of the same weight. To be able to send current in both directions, engineers can use an H-bridge to control each coil or a step motor driver chip

INTERFACING To cause the stepper to rotate, we have to send a pulse to each coil in turn. The 8051 does 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.

4.6. DS 1307-Real Time Clock: Real-time clock (RTC) counts seconds, minutes, hours, date of the month, month, day of the week, and year with leap-year compensation valid up to 2100 56-byte, battery-backed, nonvolatile (NV) RAM for data storage Two-wire serial interface Programmable square wave output signal Automatic power-fail detect and switch circuitry Consumes less than 500nA in battery backup mode with oscillator running Optional industrial temperature range: -40C to +85C

VCC, GND DC power is provided to the device on these pins. VCC is the +5V input. VBAT Battery input for any standard 3V lithium cell or other energy source. Battery voltage must be held between 2.0V and 3.5V for proper operation. SDA (Serial Data Input/output) SDA is the input/output pin for the 2-wire serial interface. The SDA pin is open drain which requires an external pull-up resistor. SQW/OUT (Square Wave/Output Driver) When enabled, the SQWE bit set to 1, the SQW/OUT pin outputs one of four square wave frequencies (1Hz, 4 kHz, 8 kHz, and 32 kHz). The SQW/OUT pin is open drain and requires an external pull-up resistor. SQW/OUT will operate with either Vcc or Vbat applied. X1, X2 Connections for a standard 32.768 kHz quartz crystal

The DS1307 Serial Real-Time Clock is a low-power; full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially via a 2-wire, bi-directional bus. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with AM/PM indicator. The DS1307 has a built-in power sense circuit that detects power failures and automatically switches to the battery supply.

The DS1307 operates as a slave device on the serial bus. Access is obtained by implementing a START condition and providing a device identification code followed by a register address. Subsequent registers can be accessed sequentially until a STOP condition is executed. When VCC falls below 1.25 x VBAT the device terminates an access in progress and resets the device address counter.

When VCC falls below VBAT the device switches into a low-current battery backup mode. Upon power-up, the device switches from battery to VCC when VCC is greater than VBAT + 0.2V and recognizes inputs when VCC is greater than 1.25 x VBAT

DS 1307 address map:-

Serial communication:1. One of the 8051s many powerful features is its integrated UART (Universal asynchronous receiver/transmitter), otherwise known as a serial port. The fact that the 8051 has an integrated serial port means that you may very easily read and write values to the serial port. If it were not for the integrated serial port, writing a byte to a serial line would be a rather tedious process requiring turning on and off one of the I/O lines in rapid succession to properly "clock out" each individual bit, including start bits, stop bits, and parity bits. To allow compatibility among data communication equipment made by various manufacturers, an interfacing standard called RS232 was set by the electronics industries association (EIA) in 1960. In RS232, a 1 is represented by -3 to -25v, while a 0 bit is +3 to 25v, making 3 to +3 undefined. RS232 standard is not TTL compatible; therefore, it requires a line driver such as the MAX232 chip to convert RS232 voltage level to TTL levels, and vice versa. 8051 has two pins that are used specifically for transferring and receiving data serially. These pins are called TXD and RXD. These pins are TTL compatible; They require a line driver to make them RS232 compatible. One such driver is the MAX232 chip
9-pin 25-pin pin definition 1 8 DCD (Data Carrier Detect) 2 3 4 5 6 7 8 9 3 2 20 7 6 4 5 22 RX (Receive Data) TX (Transmit Data) GND (Signal Ground) DSR (Data Set Ready) RTS (Request To Send) CTS (Clear To Send)) RI (Ring Indicator) Direction (PC view) input input output input output input input

DTR (Data Terminal Ready) output

DB-25 female

DB-25 male

Conclusion
This project was really a very educative and enlightening experience for me. I learnt about EMBEDDED SYSTEM which was completely new for me. I realized that how a hardware synchronized by a software (program) by working on it. We learnt that how a software (program) and hardware synchronized and how a machine understands language (program). It is a demanded field in present because technology entered in every field presently and it is a very extensive field. In the end, I would once again thank all the people who made such kind of training possible for us.

Bibliography
1. EMBEDDED SYSTEM by UTL TECHNOLOGY LTD. 2. 8051 MICROCONTROLLER by Chris Braithwaite, Fred cowan and Hassan Parchizadeh. 3. Embedded C by Michal j. Pont Webs

You might also like