Académique Documents
Professionnel Documents
Culture Documents
Microcontrollers as the name suggests are small controllers. They are like single chip computers that are often embedded into other systems to function as
processing/controlling unit. For example the remote control you are using probably has microcontrollers inside that do decoding and other controlling functions. They are also used in automobiles, washing machines, microwave ovens, toys ... etc, where automation is needed. Embedded system means the processor is embedded into the required application. An embedded product uses a microprocessor or microcontroller to do one task only. In an embedded system, there is only one application software that is typically burned into ROM. Example: printer, keyboard, video game player . Microprocessor - A single chip that contains the CPU or most of the computer Microcontroller - A single chip used to control other devices The microcontroller incorporates all the features that are found in microprocessor. The microcontroller has built in ROM, RAM, Input Output ports, Serial Port, timers, interrupts and clock circuit. A microcontroller is an entire computer manufactured on a single chip. Microcontrollers are usually dedicated devices embedded within an application. For example, microcontrollers are used as engine controllers in automobiles and as exposure and focus controllers in cameras. In order to serve these applications, they have a high concentration of on-chip facilities such as serial ports, parallel input output ports, timers, counters, interrupt control, analog-to-digital converters, random access memory, read only memory, etc. The I/O, memory, and on-chip peripherals of a microcontroller are selected depending on the specifics of the target application. Since microcontrollers are powerful digital processors, the degree of control and programmability they provide significantly enhances the effectiveness of the application.
~ 14 ~
~ 15 ~
Microcontroller Vs Microprocessor:-
It is very clear from figure that in microprocessor we have to interface additional circuitry for providing the function of memory and ports, for example we have to interface external RAM for data storage, ROM for program storage, programmable peripheral interface (PPI) 8255 for the Input Output ports, 8253 for timers, USART for serial port. While in the microcontroller RAM, ROM, I/O ports, timers and serial communication ports are in built. Because of this it is called as system onchip. So in micro-controller there is no necessity of additional circuitry which is interfaced in the microprocessor because memory and input output ports are inbuilt in the microcontroller. Microcontroller gives the satisfactory performance for small applications. But for large applications the memory requirement is limited because only 64 KB memory is available for program storage. So for large applications we prefer microprocessor than microcontroller due to its high processing speed.
~ 16 ~
Architecture of 8051:It is 8-bit microcontroller, means MC 8051 can Read, Write and Process 8 bit data. This is mostly used microcontroller in the robotics, home appliances like mp3 player, washing machines, electronic iron and industries. Mostly used blocks in the architecture of 8051 are as follows:
~ 17 ~
used for user space which is normally Register banks and stack. But other 128 byte RAM which consists of SFRs.
b. 4KB ROM
In 8051, 4KB read only memory (ROM) is available for program storage. This is used for permanent data storage. Or the data which is not changed during the processing like the program or algorithm for specific applications. This is volatile memory; the data saved in this memory does not disappear after power failure. We can interface up to 64KB ROM memory externally if the application is large. These sizes are specified different by their companies. Address Range of PC: Address range of PC means program counter (which points the next instruction to be executing) can be moved between these locations or we can save the program from this location to this location.
~ 18 ~
available for delay generation. These hardware pins can be also used for counting some external events. How much times a number is repeated in the given table is calculated by the counter. In MC8051, two timer pins are available T0 and T1, by these timers we can give the delay of particular time if we use these in timer mode. We can count external pulses at these pins if we use these pins in counter mode. 16 bits timers are available. Means we can generate delay between 0000H to FFFFH. TMOD, TCON registers are used for controlling timer operation.
~ 19 ~
Power Supply pins 8051 c works with +5V DC source applied to Vcc and 0V to Gnd input pin. It has an onchip crystal clock generator. As such it must be supported externally by connecting a crystal across crystal input XTAL1, XTAL2. It has active hign reset input pin. As such the controller is said to be reset upon application of active hign pulse.
~ 20 ~
Port 0 and Port 2: If input pin is grounded then port 0 acts as lower order
8bit address data bus where as port 2 acts as higher order 8 bit address bus.
Port 3: Each and every pin in this port offer some separate functionality
irrespective of level at input pin.
External Access Control pins (External Access): If is connected to +5V then the
microcontroller fetches code from internal or inbuilt program memory. If it is cnneected to 0V then the microcontroller fetches code from external program memory.
~ 21 ~
(Program Store Enable) This is an output pin. For opcode fetch operation,
microcontroller asserts output pin as low which can be used for selecting the external program memory chip. This can also be used as ROM read control signal
1
to the inverting oscillator amplifier and input to the interanal clock operating circuit.
XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier which can be configured for use as an on-chip oscillator, as shown in Figure 1. Either a quartz crystal or ceramic resonator may be used. To drive the device from an external clock source, XTAL2 should be left unconnected while XTAL1 is driven as shown in Figure 2. There are no requirements on the duty cycle of the external clock signal, since the input to the internal clocking circuitry is through a divide-by-two flip-flop, but minimum and maximum voltage high and low time specifications must be observed.
~ 22 ~
INTERFACING OF 8051
1) LED Interfacing(PORT as o/p):
Port as output: In this topic we study how we send the values on ports and how we observe that value on ports. The microcontroller always loads the binary equivalent of value on the ports. For example we send 0x0A. Here 0x shows the value is in hexadecimal. The binary equivalent of 0x0A is 00001010. So if we send 0x0A the equivalent binary is observed on the port. The LSB is observed on the LSB pins of port and MSB observed on the MSB pins of port. Now how we observe the 0 and ones physically. There is specific voltage level concerned with 0 and 1. These levels are TTL compatible.
Logic 0 1
~ 23 ~
So we can verify the loaded value by checking voltage level using multimeter or by driving led from this voltage.
Example Program Of LED interfacing With 8051 WAP to interface 8 leds and glow them for some instance and then put it off. #include<reg51.h> Void delay(); Void main() { P1=0xff; Delay(500); P1=0x00; } Void delay(int itime) { Int i,j; For(i=0;i<itime;i++) For(j=0;j<1275;j++) }
~ 24 ~
2) LCD Interfacing On most displays, the pins are numbered on the LCDs printed circuit board, but if not, it is quit easy to locate pin1. Since the pin is connected to ground, it often has a thicker PCB track connected to it, and it is generally connected to the metal work at some point. The function of each of the connections is shown in the table below:Pins 1 & 2 are the power supply lines, Vss & Vdd. The Vdd pin should be connected to the positive supply & Vss to the 0V supply or ground. supplies of 6V & 4.5V both work well, and even 3V is sufficient for some modules. Consequently, these modules can be effectively and economically powered by batteries. Pin 3 is a control pin, Vee, which is used to alter the contrast of the display. Ideally, these pin should be connected to a variable voltage supply. A preset potentiometer connected between the power supply lines, with its wiper connected to the contrast pin is suitable in many cases, but be aware that some modules may require a negative potential; as low as 7V in some cases. For absolute simplicity, connecting this pin to 0V will often suffice. Pin 4 is register select (RS) line. PIN NO. 1 2 3 4 5 6 7 8 9 10 11 NAME Vss Vdd Vee RS R/W E D0 D1 D2 D3 D4 FUNCTION Ground +ve supply Contrast Register select Read/Write Enable Data Bit 0 Data Bit 1 Data Bit 2 Data Bit 3 Data Bit 4
~ 25 ~
12 13 14
D5 D6 D7
Three command control inputs. When this line is low, data bytes transferred to the display are treated as commands, and data bytes read from the display indicate its status. By setting the RS line high, character data can be transferred to and from the module. Pin 5 is (R/W) line. This line is pulled low in order to write commands or character data to the module, or pulled high to read character data or status information from its registers. Pin 6 is Enable (E) line. This input is used to initiate the actual transfer of commands or character data between the module and the data lines. 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. Pins 7 to 14 are the eight data bus lines (D0 to D7). Data can be transferred to and from the display, either as a single 8-bit byte or as two 4-bit nibbles. In the latter case, only the upper four data lines (D4 to D7) are used. This 4-bit mode is beneficial when using a microcontroller, as fewer I/O lines are required.
~ 26 ~
Example Program of LCD interfacing with 8051 WAP to Display ECE ROCKS On LCD #include<reg51.h> #define lcdport P3
sbit rs=P2^0;
~ 27 ~
void main() { P3=0x00; P2=0x00; lcdport=0x38; cmd(); lcdport=0x0e; cmd(); lcdport=0x01; cmd(); lcdport='E'; dat(); lcdport='C'; dat(); lcdport='E'; dat(); lcdport='R'; dat(); lcdport='O'; dat(); lcdport='c'; dat(); lcdport='k'; dat();
~ 28 ~
lcdport='s'; dat(); } void delay(int itime) { int i,j; for(i=0;i<itime;i++) for(j=0;j<1275;j++); } void cmd() { rs=0; rw=0; en=1; delay(100); en=0; } void dat() { rs=1; rw=0; en=1; delay(100); en=0; }
~ 29 ~
3) SEVEN SEGMENT DISPLAY 7 segment LED display is very popular and it can display digits from 0 to 9 and quite a few characters like A, b, C, ., H, E, e, F, n, o,t,u,y, etc. Knowledge about how to interface a seven segment display to a micro controller is very essential in designing embedded systems. A seven segment display consists of seven LEDs arranged in the form of a squarish 8 slightly inclined to the right and a single LED as the dot character. Different characters can be displayed by selectively glowing the required LED segments. Seven segment displays are of two types,common cathode and common anode. In common cathode type , the cathode of all LEDs are tied together to a single terminal which is usually labeled as com and the anode of all LEDs are left alone as individual pins labeled as a, b, c, d, e, f, g & h (or dot) . In common anode type, the anode of all LEDs are tied together as a single terminal and cathodes are left alone as individual pins. The pin out scheme and picture of a typical 7 segment LED display is shown in the image below.
Digit drive pattern of a seven segment LED display is simply the different logic combinations of its terminalsa to h in order to display different digits and characters. The common digit drive patterns (0 to 9) of a seven segment display are shown in the table below.
~ 30 ~
Digit 0 1 2 3 4 5 6 7 8 9
a 1 0 1 1 0 1 1 1 1 1
b 1 1 1 1 1 0 0 1 1 1
c 1 1 0 1 1 1 1 1 1 1
d 1 0 1 1 0 1 1 0 1 1
e 1 0 1 0 0 0 1 0 1 0
f 1 0 0 0 1 1 1 0 1 1
g 0 0 1 1 1 1 1 0 1 1
#include<reg51.h> void delay(int); void main() { char i,arr[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0xfd,0x07,0x7f,0x6f}; for(i=0;i<10;i++) { P1=arr[i]; delay(100); } } void delay(int itime) { int i,j; for(i=0;i<itime;i++) for(j=0;j<1275;j++); }
~ 31 ~
~ 32 ~