Sei sulla pagina 1di 138

1. MICROCONTROLLER General description The P89V51RD2 is an 80C51 microcontroller with 64 kB Flash and 1024 bytes of data RAM.

A key feature of the P89V51RD2 is its X2 mode option. The design engineer can choose to run the application with the conventional 80C51 clock rate (12 clocks per machine cycle) or select the X2 mode (6 clocks per machine cycle) to achieve twice the throughput at the same clock frequency. Another way to benet from this feature is to keep the same performance by reducing the clock frequency by half, thus dramatically reducing the EMI. The Flash program memory supports both parallel programming and in serial In-System Programming (ISP). Parallel programming mode offers gang-programming at high speed, reducing programming costs and time to market. ISP allows a device to be reprogrammed in the end product under software control. The capability to eld/update the application rmware makes a wide range of applications possible. The P89V51RD2 is also In-Application Programmable (IAP), allowing the Flash program memory to be recongured even while the application is running. Features 80C51 Central Processing Unit 5 V Operating voltage from 0 to 40 MHz 64 kB of on-chip Flash program memory with ISP (In-System Programming) and IAP (In-Application Programming) Supports 12-clock (default) or 6-clock mode selection via software or ISP SPI (Serial Peripheral Interface) and enhanced UART PCA (Programmable Counter Array) with PWM and Capture/Compare functions Four 8-bit I/O ports with three high-current Port 1 pins (16 mA each) Three 16-bit timers/counters Programmable Watchdog timer (WDT) Eight interrupt sources with four priority levels Second DPTR register Low EMI mode (ALE inhibit) TTL- and CMOS-compatible logic levels

Pin diagram

Figure 1.1 Pin diagram of 8051

P89V51RD2 pin description Symbol: P0.0 toP0.7 Pin : 39-32 I/O Port 0: Port 0 is an 8-bit open drain bi-directional I/O port. Port 0 pins that have 1s written to them float, and in this state can be used as high-impedance inputs. Port 0 is also the multiplexed low-order address and data bus during accesses to external code and data memory. It uses strong internal pull-ups when transitioning to 1s External pull-ups is required during program verification or as a general purpose I/O port. Symbol: P1.0 toP1.7 Pin : 40-44 I/O Port 1: Port 1 is an 8-bit bi-directional I/O port with internal pull-ups. The Port 1 pins are pulled high by the internal pull-ups when 1s are written to them and can be used as inputs in this state. As inputs, Port 1 pins that are externally pulled LOW will source current (IIL)because of the internal pull-ups. Port 1 also receives the low-order address bytes during the external host mode programming and verification. P1.0 I/O T2: External count input to Timer/Counter 2 or Clock-out from Timer/Counter 2 P1.1 I T2EX: Timer/Counter 2 capture/reload trigger and direction control P1.2 I ECI: External clock input. This signal is the external clock input for the PCA. P1.3 I/O CEX0: Capture/compare external I/O for PCA Module 0.Each capture/compare module connects to a Port 1 pin for external I/O. When not used by the PCA, this pin can handle standard I/O. P1.4 I/O SS: Slave port select input for SPI CEX1: Capture/compare external I/O for PCA Module 1 P1.5 I/O MOSI: Master Output Slave Input for SPI CEX2: Capture/compare external I/O for PCA Module 2 P1.6 I/O MISO: Master Input Slave Output for SPI CEX3: Capture/compare external I/O for PCA Module 3 P1.7 I/O SCK: Master Output Slave Input for SPI CEX4: Capture/compare external I/O for PCA Module 4 Symbol: P2.0 toP2.7 PIN : 21-28(I/O with internal pull-up) Port 2: Port 2 is an 8-bit bi-directional I/O port with internal pull-ups. Port 2 pins are pulled HIGH by the internal pull-ups when 1s are written to them and can be used as inputs in this state. As inputs, Port 2 pins that are externally pulled LOW will source current (IIL) because of the internal pull-ups. It uses strong internal pull-ups when transitioning to 1s. Port 2 also receives some control signals and a partial of high-order address bits during the external host mode programming and verification. Symbol: P3.0 toP3.7 Pin : 11-17(I/O with internal pull-up) Port 3: Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. Port 3 pins are pulled HIGH by the internal pull-ups when 1s are written to them and can be used as inputs in this state. As inputs, Port 3 pins that are externally pulled LOW will source current (IIL)because

of the internal pull-ups. Port 3 also receives some control signals and a partial of high-order address bits during the external host mode programming and verification. P3.0 RXD: serial input port P3.1TXD: serial output port P3.2 INT0: external interrupt 0 input P3.3 INT1: external interrupt 1 input P3.4 T0: external count input to Timer/Counter 0 P3.5 T1: external count input to Timer/Counter 1 P3.6 WR : external data memory write strobe P3.7 RD : external data memory read strobe PSEN29 I/O Program Store Enable: PSEN is the read strobe for external program memory. When the device is executing from internal program memory, PSEN is in active(HIGH). When the device is executing code from external program memory, PSEN is activated twice each machine cycle, except that two PSEN activations are skipped during each access to external data memory. A forced HIGH-to-LOW input transition on the PSEN pin while the RST input is continually held HIGH for more than 10 machine cycles will cause the device to enter external host mode programming. RST 9 I Reset: While the oscillator is running, a HIGH logic state on this pin for two machine cycles will reset the device. If the PSEN pin is driven by a HIGH-to-LOW input transition while the RST input pin is held HIGH, the device will enter the external host mode; otherwise the device will enter the normal operation mode EA31 I External Access Enable: EA must be connected to VSS in order to enable the device to fetch code from the external program memory. EA must be strapped to VDD for internal program execution. However, Security lock level 4 will disable EA, and program execution is only possible from internal program memory. The EA pin can tolerate a high voltage of 12 V.

ALE/PROG30 I/O Address Latch Enable: ALE is the output signal for latching the low byte of the address during an access to external memory. This pin is also the programming pulse input (PROG) for flash programming. Normally the ALE is emitted at a constant rate of 1/6 the crystal Frequency and can be used for external timing and clocking. One ALE pulse is skipped during each access to external data memory. However, if AO is set to 1, ALE is disabled. XTAL1 19 I Crystal 1: Input to the inverting oscillator amplifier and input to the internal clock generator circuits. XTAL2 18 O Crystal 2: Output from the inverting oscillator amplifier. VDD 40 I Power supply VSS20 I Ground

2. KEIL Keil software is used to write the microcontroller code and to simulate it on the computer itself. It is also used to generate the hex code for the code written in ALP or C. User Vs machine (microcontroller): as the microcontroller know only about the digital value (i.e. either logic zero or one), so we need to convert the written code in the sets of zero n one. The KEIL environment provide us the facility to convert the code written in C or ALP to sets of zero n one (i.e. called hex code). How to use the keil Create a new project To create a new project go to project option then click the new project option. It will ask to save the project in the desired folder. All the project is saved in the Uv2 format with the extension of Uv2. Selecting the device After saving the project the window will appear which will ask for selecting the device, then select the company PHILIPS or NXP and then select the device number P89V51RD2.

Figure 2.1 selecting device

After selection of device, one more window will appear to copy the start up code .After clicking ok option the project format is ready to simulate the code. Writing Code click the new file in the FILE menu. Then a new file will appear in which code must be written in any programming language like C or ALP. The window will appear as shown below

Figure 2.2 writing code in editor window

Saving the code Code written in C should be saved with the extension .c (i.e. the file is stored as filename.c). The code written in ALP(assembly language programming) has to save with the extension of .a. Adding the code file in the project Right click on source group 1 ,the option Add files to group source group1 will appear.

Figure 2.3 Adding files to group

Simulating code and checking Click the debug option and click start/stop debug session then the the window will appear as follows:

Figure 2.4 Starting debug session

The keil we use having limitation to simulate the maximum code size 2KB.this window is just for a warning message, so, just press ok for that option. After that the project is ready to run. The microcontroller is having 4 ports. Each port is having 8 pins. Each port can be used either as input or output port. By using KEIL integrated development environment, we can check all the input and output on computer itself. For that when your project is ready to run then click the option peripheral then go to I/O ports and then select the ports which all are required.

Figure 2.5 Testing of code Testing of code Code can be tested on computer itself. After selecting the port, just press run on the window and give the input to the port and the corresponding output will automatically appear on other port.

Figure 2.6 Simulation

Compilation Compilation can be done by clicking translate current file and then building by clicking built target.It will generate the hex code .But before that settings must be changed, for that project option selected and then Options for Target target 1must be clicked.

Figure 2.7 To select target

A new window will appear as shown below, here we need to change the Xtal (MHz):

Figure 2.8 To set Xtal(MHZ)

Here,the frequency of crystal which we are going to use must be filled. For that Use On -chip ROM(0x0-0xFFFF)option must be clicked. Then the option output must be clicked and the option Create HEX Filemust be selected. Then build target will generate the HEX code automatically.

3. ISIS PROTEUS ISIS incorporates a number of features which aid in the management of large designs. It is used to produce designs containing many thousands of components. ISIS provides the means to enter the design in the first place, the architecture for real time interactive simulation and a system for managing the source and object code associated with each project. In addition, a number of graph objects can be placed on the schematic to enable conventional time, frequency and swept variable simulation to be performed. FEATURES The simulator runs on Windows 98/Me/2k/XP and later. It allows automatic wire routing and dot placement/removal. It contains powerful tools for selecting objects and assigning their properties. It ensures full support for buses including component pins, inter-sheet terminals, module ports and wires. It includes bill of materials and electrical rules check reports. Net list outputs to suit all popular PCB layout tools. ISIS AND NETWORKS ISIS is fully network compatible. The library files can be set to Read Only. This prevents users from messing with symbols or devices that may be used by others. Since the registry determines the location of library files, it follows that users can have individual USERDVC.LIB files in their personal or group directories. DESCRIPTIONS ISIS program must be started.The start button must be clicked. Along the top of the screen is the menu bar. The largest area of the screen is called the editing window, and it acts as a window on the drawing - this is where the wire-up components can be placed. The smaller area at the top right of the screen is called the overview window. In normal use the overview window displays an overview of the entire drawing - the blue box shows the edge of the current sheet and the green box shows the area of the sheet currently displayed in the editing window. However, when a new object is selected from the object selector the overview window is used to preview the selected object. The area of the drawing is displayed in the editing window to simply 'pan' the editing window up, down, left or right, position of the mouse pointer over the desired part of the editing window and the F5 key is pressed. The SHIFT key is pressed and the mouse is bumped against the edges of the editing window to pan up, down, left or right.F8 key is pressed to display the whole drawing. The SHIFT key is pressed down and dragged out a box around the area to zoom in to .Zoom In, Zoom Out, Zoom Full or Zoom Area icons on the toolbar also can be used for zooming. Below the Overview Window is the Object Selector which is used to select devices, symbols and other library objects. STEPS TO DRAW THE DESIGN The p button at the top left corner of the object selector is selected. Clicking left causes the device selector dialogue box to appear and select the various devices from the libraries.The objects selector displays all the parts in the currently selected library according to the settings

in the extensions selector. Click left once on a part to browse or double-click a part to pick it in to the design. The browser displays the last selected part in the parts selector as a means of browsing the contents of the library. Whenever a device is selected in the device selector, the selected device is previewed in the overview window. By clicking left or right on the Rotation and/or Mirror icons, the device is redrawn to preview the new orientation. The preview remains until the device is placed or until another command or action is performed. It should be ensured that the device is selected and the mouse pointer is moved into the middle of the editing window. The left mouse button must be pressed down. An outline of the device will appear which can be moved around by dragging the mouse. When the button is released, the component will be placed and is drawn in full. The rotation of the last object tagged can be adjusted in this way; the mirror icon can similarly be used to reflect the last object tagged. ISIS senses a component pin and deduces that a wire is needed to connect from it. To signify this, it displays a green line which goes from the pin to the pointer. Manually a wire can be routed by simply clicking left on the first pin, clicking left at each point along the required route and then finished by clicking left on the second pin. To complete this section of the drawing, place the two generic and one ground terminals and wired. To do this, the terminal icon is selected. The object selector changes to a list of the terminal types available. The ground terminal is selected and placed it. Work must be saved at any time by means of the Save command on the File menu. Save as option also allows saving it with a different filename to run the program, the play button must be clicked and to terminate the program, the stop button is clicked.

4. FLASHMAGIC Flash Magic is a PC tool for programming flash based microcontrollers from NXP using a serial or Ethernet protocol while in the target hardware. There are five simple steps to erase and programme a device and setting key options. It programs Intel Hex Files. There is Automatic verifying option after programming. MAIN WINDOW After flashmagic software start-up, the main window will be as shown below:

Figure 4.1 Main window Communication For this select device by selecting select and select P89v51RD2device Then specify COM1 in COMPORT row. Specify the baud rate as 9600 Fill interface row as NONE(ISP). Specify operator frequency as 12MHz.

Erase Enable the Erase block used by HEX file, as shown below:

Figure 4.2 Erasing blocks used by Hex file Hex File selection Select the required/generated hex file by pressing Browse button, as shown below:

Figure 4.3 Choosing Hex file

Then select hex file and its path specified in the Hex File. Options Go to options menu from that select Advanced option and in that press Hardware Config Here, Enable the use DTR to control RST which is normally disabled as shown below:

Figure 4.4 Hardware configure Then press ok Press the start button from main window as shown below:

Figure 4.6 Start dumping into specified IC So by pressing start button the hex file will be start dumping into the specified

5. UNIVERSAL PROGRAMMER-TOPWIN6 The TOP3100 programmer has compact size, lower power consumption, and high reliability. This is an universal equipment especially designed for MCU and EPROMs programming. USB universal serial port is used to connect with the PC, communications, support 2000/xp//Vista/Win7, software upgrades and flexible. Features Full driving with 48 pin(Vpp/Vcc/GND/TTL), good for future upgrading. Support 2.5V to 6.5V device. Selectable to use USB or external 5V power supplier to supply power. Transmission speed is 12MHz/s. Suitable to work with Desktop and Laptop. With current protection function, effectively protects the programmer and devices. Automatic Pin status detection. 48 pins self-lock sockets. Support operation system: WINDOWS7/vista/2000/2003/XP; Plastic cabinet, small size and light weight. Auto detects company and type of the IC. Software support: TopWin ver6.0 or newer.

Specifications Software: Topwin6 (forWindows7/Vista/2003/2000//xp) Actual tested Speed(PIII/800M, Windows98se,USB1.1):28F320 write and check 104 seconds,29LF320 write and check 112 seconds, p89c58 write and check 5 seconds. Size: 155mm*110mm*26mm Weight for the programmer only : 275g Power: < 2.5W (5V/500mA) 48 Pin self-lock socket (Changeable)

This auction includes New Top3100 USB Universal programmer; Software: TopWin6 (for Windows7/Vista/xp); USB cable.

Main window: After TopWin start-up, Main window of topwin6 will be showed on the screen as follows:

Figure 5.1 Main window Select device by multiple list Choose "Run" ,and from that select select chip then appeared the dialog box as follows:

Figure 5.2 Select chip Select device Select "Type of Device" in the "Type" menusuch as "MPU". Select a manufacturer from the list of "Manufacturer", like "PHILIPS". Select a device type from the list of "Device", like select"P89V51RD2". Then dialog box appears as follows:

Figure 5.3 Select P89v51RD2

Erasing previous content: To erase the previous content from buffer, go to Run menu and from that select Erase, as shown in the dialog box:

Figure 5.4 Erase before loading Now after erasing it is ready to load the new data. After being erased the device shows "FF".

Loading file to buffer Window under the buffer will show "data from xxxx to xxxx".The function is helping you to write in the correct address. Loading step is the same with "Open file". Select the empty device before setup. To load the new data go to File menu and select Load Data option, as shown in the below dialog box:

Figure 5.5 Select load data Then select the required/generated hex file with filename.hex extension from the library and open it, as shown below:

Figure 5.6 Choosing the Hex file

1Choose the file format in "project file", for example a hexadecimal file, .HEX 2. Choose byte. Many devices should set byte while shown the dialog. 3Select the way to fill, if it is 00, then the buffer zone so if it is FF, so is the blank or No clear fill mode. 4Select the address of buffer zone. Normally starting address will be o.

Figure 5.7 Select the address of buffer zone

Operation Operation box on the left hand beside buffer will spring the five functions of the device. Select the function which is needed, then press[Go], programmer will operate "Erase" "Blank" "Write code" "Verify" "Config Secure are the operation done by pressing start and GO buttons as shown below:

Figure 5.8 Select start and go

The verify menu is selected by choosing secure from Run and is chiefly used to test the common static storage SRAM. Press "Start"[Go], and the programmer test each byte of memory to ensure the test is performed stably, as shown below.

Figure 5.9 To verify

Ex. No : 1 Date :

ARITHMETIC OPERATIONS USING 8051


AIM: To design and implement arithmetic operations by interfacing KEYPAD and LCD using 8051 microcontroller. HARDWARE REQUIRED: 1. VSM DLL model keypad. 2. 16X2 Line LCD (LM016L). 3. PHILIPS P89C51RD2XX. 4. TOP2048 Programmer kit. 5. Power supply(5v). 6. Connecting wires. SOFTWARE REQUIRED: 1. Keil uvision 3. 2. ISIS Proteus Professional 7. 3. Topwin VER5.49.

ALGORITHM: 1. Initialize the ports using cct_init() function. 2. Initialize the Port1 for input interfacing with keypad.(Rows are assigned to P1.0,P1.1,P1.2,P1.3& columns are assigned to P1.4,P1.5,P1.6&P1.7) 3. Initialize the Port2 for data pins of LCD. 4. Initialize the P3.6 for enable and P3.7 for RS of LCD. 5. Get the key value and store it in num1 using get_key() function. 6. Check the num1 with all cases in get_num() if not display wrong input using DispError() function. 7. Display the num1 on LCD using writedata(). 8. Get the operator using get_func(); 9. Check the operator with all cases in get_func() if not display wrong input using DispError() function. 10. Similarly for num2. 11. Press= key and perform the operation . 12. Check whether num less than zero then perform the operation and display the number with signed value.

FLOWCHART:
START

Initialize the ports using cct_init()

Initialize the P1 for input interfacing with keypad

Initialize the P2 for data pins of LCD

Initialize the P3.6 for E & P3.7 for RS of LCD

Get the key value

Store the num1 using get_key()

NO

Check num1 in get_num() Display wrong input using disp error()

YES Display the num1 on LCD using write data()

Get the operator using get_fun()

NO

Check operator in get_fun()

Display wrong function using Disp error() YES

store the num2 using get_key()

NO

YES

Check num2 in get_fun()

Display wrong input using Disp error()

Press = key & perform the operation

Check the num < 0 YES

NO Display the number with signed value

Display the result

Stop

Fig 1.2 Arithmetic Operation Using 8051 Microcontroller

Program: #include<reg51.h> #include<string.h> #define Error 13 void cct_init(void); void delay(int); void lcdinit(void); void writecmd(int); void writedata(char); void writeline(char[]); void ReturnHome(void); char READ_SWITCHES(void); char get_key(void); int get_num(char); char get_func(char); void DispError(int); void disp_num(int); sbit RowA = P1^0; sbit RowB = P1^1; sbit RowC = P1^2; sbit RowD = P1^3; sbit C1 = P1^4; sbit C2 = P1^5; sbit C3 = P1^6; sbit C4 = P1^7; sbit E = P3^6; sbit RS = P3^7; int main(void) { char key; int num1 = 0; char func = '+'; int num2 = 0; cct_init(); lcdinit(); while(1) { key = get_key(); writecmd(0x01); writedata(key); num1 = get_num(key); if(num1!=Error) { key = get_key(); writedata(key);

func = get_func(key); if(func!='e') { key = get_key(); writedata(key); num2 = get_num(key); if(num2!=Error) { key = get_key(); writedata(key); if(key == '=') { switch(func) { case '+': disp_num(num1+num2); break; case '-': disp_num(num1-num2); break; case 'x': disp_num(num1*num2); break; case '/': disp_num(num1/num2); break; } } else { if(key == 'C') writecmd(0x01); else DispError(0); } } } } } }

void cct_init(void) { P0 = 0x00; P1 = 0xf0; P2 = 0x00; P3 = 0x00; } void delay(int a) {

int i; for(i=0;i<a;i++); } void writedata(char t) { RS = 1; P2 = t; E = 1; delay(150); E = 0; delay(150); }

void writecmd(int z) { RS = 0; P2 = z; E = 1; delay(150); E = 0; delay(150); } void lcdinit(void) { delay(15000); writecmd(0x30); delay(4500); writecmd(0x30); delay(300); writecmd(0x30); delay(650); writecmd(0x38); writecmd(0x0c); writecmd(0x01); writecmd(0x06); } void ReturnHome(void) { writecmd(0x02); delay(1500); }

void writeline(char Line[]) { int i; for(i=0;i<strlen(Line);i++) { writedata(Line[i]); } ReturnHome(); } char READ_SWITCHES(void) { RowA = 0; RowB = 1; RowC = 1; RowD = 1; if (C1 == 0) { delay(10000); while (C1==0); return '7'; } if (C2 == 0) { delay(10000); while (C2==0); return '8'; } if (C3 == 0) { delay(10000); while (C3==0); return '9'; } if (C4 == 0) { delay(10000); while (C4==0); return '/'; } RowA = 1; RowB = 0; RowC = 1; RowD = 1; if (C1 == 0) { delay(10000); while (C1==0); return '4'; } if (C2 == 0) { delay(10000); while (C2==0); return '5'; } if (C3 == 0) { delay(10000); while (C3==0); return '6'; } if (C4 == 0) { delay(10000); while (C4==0); return 'x'; } RowA = 1; RowB = 1; RowC = 0; RowD = 1; if (C1 == 0) { delay(10000); while (C1==0); return '1'; } if (C2 == 0) { delay(10000); while (C2==0); return '2'; } if (C3 == 0) { delay(10000); while (C3==0); return '3'; } if (C4 == 0) { delay(10000); while (C4==0); return '-'; } RowA = 1; RowB = 1; RowC = 1; RowD = 0; if (C1 == 0) { delay(10000); while (C1==0); return 'C'; } if (C2 == 0) { delay(10000); while (C2==0); return '0'; } if (C3 == 0) { delay(10000); while (C3==0); return '='; } if (C4 == 0) { delay(10000); while (C4==0); return '+'; } return 'n'; } char get_key(void)

{ char key = 'n'; while(key=='n') key = READ_SWITCHES(); return key; } int get_num(char ch) { switch(ch) { case '0': return 0; break; case '1': return 1; break; case '2': return 2; break; case '3': return 3; break; case '4': return 4; break; case '5': return 5; break; case '6': return 6; break; case '7': return 7; break; case '8': return 8; break; case '9': return 9; break; case 'C': writecmd(0x01); return Error; break; default: DispError(0); return Error; break; } } char get_func(char chf) { if(chf=='C') { writecmd(0x01); return 'e'; } if( chf!='+' && chf!='-' && chf!='x' && chf!='/' ) { DispError(1); return 'e'; } return chf; }

void DispError(int numb) { writecmd(0x01); switch(numb) { case 0: writeline("Wrong Input"); break; case 1: writeline("Wrong Function"); break; default: writeline("Wrong Input"); break; } } void disp_num(int numb) { unsigned char UnitDigit = 0; unsigned char TenthDigit = 0; if(numb<0) { numb = -1*numb; writedata('-'); } TenthDigit = (numb/10); if( TenthDigit != 0) writedata(TenthDigit+0x30); UnitDigit = numb - TenthDigit*10; writedata(UnitDigit+0x30); }

Circuit diagram:
LCD LM016L

VSM DLL model keypad

P89C51RD2

Fig. 1.3 8051 Microcontroller interfacing with LCD & Keypad Connection

Output:

Fig 1.4 Sample Output for Addition

Fig 1.5 Sample Output for Subtraction

Fig 1.6 Sample Output for Multiplication

Fig 1.7 Sample Output for Division Hardware Diagram:

Fig 1.8 Hardware Setup for Arithmetic Operation

Result: Therefore, arithmetic operations by interfacing keypad and lcd using 8051 microcontroller has been executed successfully.

EX NO: 2 DATE: SERIAL COMMUNICATION WITH UART OF 8051: AIM To establish serial communication with UART of 8051 and simulate the output through Kiel software. COMPONENTS REQUIRED Microcontroller IC P89V51RD2FN Max 232 IC & 9 pin RS232 female connector. Bread board & connecting wires. Resistors 1K,8.2k,10k -10nos Crystal Oscillator 11.0592 MHz Capacitor 1f, 10f, 33pf, 0.1f,150pf-6nos

BLOCK DIAGRAM

Figure 2.1 Block Diagram-Serial Communication

SERIAL COMMUNICATION PC/compatible computers (Pentium) microprocessors normally have two COM ports Both ports have RS232-type connectors COM ports are designated as COM 1 and COM 2 (replaced by USB ports) Serial communication is often used either to control or to receive data from an embedded microprocessor. Serial communication is a form of I/O in which the bits of a byte begin transferred appear one after the other in a timed sequence on a single wire. Serial communication has become the standard for inter-computer communication. In this lab, we'll try to build a serial link between 8051 and PC using RS232 and MAX 232 to make it TTL compatible.

MAX-232 Converts from RS232 voltage levels to TTL voltage levels Uses a +5 V power source MAX232 has two sets of line drivers for transferring and receiving data Line drivers used for TxD are called T1 and T2 Line drivers for RxD are designated as R1 and R2 T1 and R1 are used together for TxD and RxD of the 8051 Second set is left unused

(a) Inside MAX232

b) its Connection to the 8051 (Null Modem) Figure 2.2 - MAX-232

RS232 STANDARDS Most widely used serial I/O interfacing standard Input and output voltage levels are not TTL compatible 1 bit is represented by -3 to -25 V 0 bit is +3 to +25 V -3 to +3 is undefined To connect RS232 to a microcontroller system must use voltage converters such as MAX232 to convert the TTL logic levels to the RS232 voltage levels, and vice versa

9 PIN RS232 FEMALE CONNECTOR Data communication classification DTE (data terminal equipment) DCE (data communication equipment) DTE - Terminals and computers that send and receive data DCE - Communication equipment responsible for transferring the data Simplest connection between a PC and microcontroller requires a minimum of three pins, TxD, RxD, and ground

Figure 2.3 PC/compatible computers (Pentium) microprocessors normally have two COM ports both ports have RS232-type connectors COM ports are designated as COM 1 and COM 2 (replaced by USB ports) can connect the 8051 serial port to the COM 2 port

9 PIN RS232

Figure 2.4- RS232 DB9 Female Connector

DESCRIPTION PROGRAMMING 8051 TO TRANSFER DATA SERIALLY: 1) The TMOD register is loaded with the value 20H, indicating the use of timer1 in mode2 to set the baud rate. 2) The TH1 is loaded with one of the baud rate values for serial data transfer. 3) The SCON register is loaded with value 50H, indicating serial mode1,where an 8-bit data is framed with start and stop bits 4) TR1 is set to 1 to start timer1 5) TI is cleared by the CLR TI instruction 6) The character byte to be transferred serially as written into the SBUF register 7) The TI flag bit is monitored with the use of instruction JNB TI, XX to see if the character has been transferred completely 8) To transfer the next character, go to step 5.

CODING MOV TMOD,#20H MOV TH1,#-3 MOV SCON,#50H SETB TR1 MOV A,#"H" ACALL TRANS MOV A,#"I" ACALL TRANS MOV A,#" " ACALL TRANS MOV A,#"H" ACALL TRANS MOV A,#"O" ACALL TRANS MOV A,#"W" ACALL TRANS MOV A,#" " ACALL TRANS MOV A,#"A" ACALL TRANS MOV A,#"R" ACALL TRANS MOV A,#"E" ACALL TRANS MOV A,#" " ACALL TRANS ;Timer 1 mode 2(auto reload) ;9600 baud rate ;serial mode 1,REN enabled ;to start timer 1 ;transfer H to A ;call subroutine ;transfer I to A ;call subroutine ;transfer to A ;call subroutine ;transfer H to A ;call subroutine ;transfer O to A ;call subroutine ;transfer W to A ;call subroutine ;transfer to A ;call subroutine ;transfer A to A ;call subroutine ;transfer R to A ;call subroutine ;transfer E to A ;call subroutine ;transfer to A ;call subroutine

MOV A,#"Y" ACALL TRANS MOV A,#"O" ACALL TRANS MOV A,#"U" ACALL TRANS MOV A, #"?" ACALL TRANS

;transfer Y to A ;call subroutine ;transfer O to A ;call subroutine ;transfer U to A ;call subroutine ;transfer ? to A ;call subroutine

AGAIN:SJMP AGAIN ;be in this loop always TRANS: MOV SBUF,A ;transfer contents of A serially HERE: JNB TI,HERE ; wait for transmission to be over CLR TI RET ;clear TI for next transmission ;go back to next instruction

CIRCUIT DIAGRAM

Figure 2.5 Circuit Diagram

FLOW CHART
Start

Set TMOD for mode selection

Set TH1 to set baud rate

Load the value to SCON register

Start the timer TR1

Transfer data to SBUF register

Check TI flag

Transfer current data

Send next data to be transmitted

Stop

Figure 2.6 Flow Chart

SIMULATION OUTPUT

Figure 2.7 Simulation Output

HYPER-TERMINAL OUTPUT

Figure 2.8 Hyper terminal Output

HARDWARE SETUP

Figure 2.9 Hardware Setup

RESULT Thus the Serial Transmission of data from Microcontroller to HyperTerminal was set by using RS 232 Cable

EXNO:3 DATE: TRAFFIC CONTROL IMPLEMENTATION USING 8051 MICROCONTROLLER AIM To implement traffic control using 8051 microcontroller interfacing seven segment display. COMPONENTS REQUIRED: Microcontroller (P89V51RD2) Seven segment display (anode)- 2 Development board Universal programmer connecting wires ALGORITHM Include the header file using the comment #include<reg51.h> Define RED led, YELLOW led, GREEN led,RED1 led,YELLOW1 led,GREEN1 led for the port P1 ,pin 0,pin 1,pin 2,pin 5,pin 6,pin 7 respectively Declare function call display1(), display(),delay() In the main program give input to RED led (port1^0) and GREEN1 led(port1^7) and other all led is off Call the display function to decrement the counter from 9 to 0 >declare the 7 segment code in array.The code is written for common anode. >call the delay function to execute the delay by the timer between the decrement TMOD=0x01 TH0=0xa0 TL0=0x30 TR0=1 set timer 1 and mode 1 of 8 bit microcontroller load the timer higher 8 bit with the value a0 load the timer lower 8 bit with the value 30 turn on T0

while(TF0==0) wait for TF0 to roll over TR0=0 TF0=0 turn OFF T0 clear TF0

Display function executed the program returns to the main program, Give input to YELLOW led(port P1^1) call for msdelay for 10 secs. and simultaneously RED1 led (port P1^5) is ON. YELLOW led goes low. GREEN led (port P1^2) is ON .Now Display1 function is called for display the counter value from 9-0

Display1 function has different time delay from display function since YELLOW led goes from low to high. The loop continues to ON the led in the sequence RED -GREEN1-YELLOWRED1-GREEN-YELLOW1-GREEN1-RED with the counter decrement from 9 to 0.

FLOW CHART

START

INITIALIZE DISPLAY,DISPLAY1, DELAY, MSDELAY FUNCTION

SET PORT PIN FOR RED,RED1,YELLOW, YELLOW1,GREEN,GREEN1 LED

WHILE(1)

GIVE INPUT TO RED ,GREEN1 LED & CALL DISPLAY FUNCTION

COUNTER DECREMENT FUNCTION

DELAY FUNCTION

YELLOW LED =1 & CALLS MSDELAY FUNCTION

GREEN =1 & RED1=1 & CALL DISPLAY1 FUNCTION

COUNTER DECREMENT FUNCTION

DELAY FUNCTION

Fig 3.1 Flowchart of Traffic Control Implementation using 8051 Microcontroller

CIRCUIT DIAGRAM

Seven segment display

Fig 3.2 Circuit Diagram of Traffic Control Implementation Using 8051 Microcontroller

CODING #include<reg51.h> sbit rlight=P1^0; sbit ylight=P1^1; sbit glight=P1^2; sbit r1light=P1^5; sbit y1light=P1^6; sbit g1light=P1^7; void display1(); void display(); void delay(); void msdelay(unsigned int); void main() { unsigned char i; while(1) { ylight=0; r1light=0; y1light=0; glight=0; rlight=1; g1light=1; display(); rlight=0; glight=0; g1light=0; r1light=1; display1(); r1light=0; glight=0; ylight=0; rlight=1; y1light=1; for(i=0;i<5;i++) msdelay(30); }} void display() { code unsigned char pattern[10]={ 0x98,0x80,0Xf8,0X02,0X12, 0X99,0Xb0,0Xa4,0Xf9,0Xc0}; { unsigned int n,i; for(n=0;n<=9;n++) { P2=pattern[n]; P3=pattern[n]; for(i=0;i<=50;i++) delay();

} } } void display1() code unsigned char pattern[10 ]={0x98,0x80,0Xf8,0X02,0X12, 0X99,0Xb0,0Xa4,0Xf9,0Xc0}; unsigned int n,i; ylight=1; for(i=0;i<5;i++) msdelay(30); ylight=0; glight=1; { for(n=0;n<=9;n++) { P2=pattern[n]; P3=pattern[n]; for(i=0;i<=55;i++) delay(); } }} void delay() { TMOD=0x01; TH0=0xa0; TL0=0x30; TR0=1; while(TF0==0); TR0=0; TF0=0; } void msdelay (unsigned int value) { unsigned int x,y; for(x=0;x<value;x++) for(y=0;y<1275;y++) }

ISIS STIMULATION OUTPUT

Fig 3.3 ISIS Stimulation of Traffic Control Implementation with 8051 Microcontroller HARDWARE OUTPUT

Fig3.4 Hardware Output of Traffic Control Implementation with 8051 Microcontroller

RESULT Traffic control using 8051 microcontroller with seven segment display is implemented and output is verified.

EX NO: 4 DATE:

COUNTER PROGRAMMING WITH TIMERS IN 8051 MICROCONTROLLER AIM To establish and develop an counter application for P89v51RD2FN microcontroller, by programming in keil with timers using delay. COMPONENTS REQUIRED Microcontroller (P89V51RD2) Led-4(Yellow) Development board Universal programmer Connecting wires

ALGORITHM Include the header file and declare the delay function. Assign the characters x and i Initialize the port 1 as output by assigning port 1=x. Initialize for loop with x=0 and the count increment for x<15. Within infinite while loop the count will increment continuosly for x<15. Call timer delay function Configure timer mode by passing the hex value into the TMOD register Load the initial values in the Timer low TL1 and high TH1. Start the Timer by setting TR1 bit. Wait while the Timer flag TF1 is raised. Clear the Timer flag. Stop the Timer by clearing TR1 bit. Repeat the above until i<20 to generate a delay of half second (500ms).

FLOWCHART
start

Define the delay function (T1M1Delay)

Initialize Unsigned character(x=0,i=0)

While (1)

If x<=15

No

Assign (P1=x)

Yes

If i<20 ii

No

Output display in led (0000-1111)

Yes
T1M1Delay ( )

Increment i

Increment(X++)

Figure 4.1 Upcounter Implementation Using 8051 Microcontroller

CIRCUIT DIAGRAM

Figure 4.2 Circuit Diagram for Upcounter Implementetion

CODING #include<reg51.h> void T1M1delay(void); void main() { unsigned char x,i; while(1) { for(x=0;x<=15;x++) { P1=x; for(i=0;i<20;i++); T1M1delay(); }}} Void T1M1delay(void) { TMOD=0x10; TL1=0xFE; TH1=0xA5; TR1=1; while(TF1==0); TR1=0; TF1=0; }

0-OFF 1-ON

UPCOUNT LED 4 LED 3 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1

LED 2 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1

LED 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1

Table 4.1 Truth Table of Upcounter Implementation

RESULT Thus the upcounter application with timer using delay was successfully executed and verified.

ISIS SIMULATION OUTPUT

Figure 4.3 ISIS Stimulation of Upcounter Implementation Using 8051 Microcontroller

HARDWARE OUTPUT

Figure 4.4 Hardware Output of Upcounter Implementation Using 8051 Microcontroller

4.1 KEYPAD INTERFACING USING 8051 MICROCONTROLLER

CIRCUIT DIAGRAM

Figure 4.1.1 Circuit Diagram of Keypad Interfacing

CODING
#include<reg51.h> sbit led0=P1^0; sbit led1=P1^1; sbit led2=P1^2; sbit led3=P1^3; sbit led4=P1^4; sbit led5=P1^5; sbit led6=P1^6; sbit led7=P1^7; sbit col1=P3^0; sbit col2=P3^1;

sbit col3=P3^2; sbit row1=P2^0; sbit row2=P2^1; sbit row3=P2^2; void delay(unsigned int msec) //Time delay function { int i,j ; for(i=0;i<msec;i++) for(j=0;j<1275;j++); } void display(int a) //Display functon for LCD { switch(a) { case 1: led0=1; delay(100); led0=0; break; case 2:led0=1; delay(100); led1=1; delay(100); led0=led1=0; delay(100); break; case 3: led0=1;

delay(100); led1=1; delay(100); led2=1; delay(100); led0=led1=led2=0; delay(100); break; case 4: led0=1; delay(100); led1=1; delay(100); led2=1; delay(100); led3=1; delay(100); led0=led1=led2=led3=0; delay(100); break; case 5: led0=1; delay(100); led1=1; delay(100); led2=1; delay(100); led3=1;

delay(100); led4=1; delay(100); led0=led1=led2=led3=led4=0; break; case 6: led0=1; delay(100); led1=1; delay(100); led2=1; delay(100); led3=1; delay(100); led4=1; delay(100); led5=1; delay(100); led0=led1=led2=led3=led4=led5=0; break; case 7:led0=1; delay(100); led1=1; delay(100); led2=1; delay(100); led3=1; delay(100);

led4=1; delay(100); led5=1; delay(100); led6=1; delay(100); led0=led1=led2=led3=led4=led5=led6=0; break; case 8: led0=1; delay(100); led1=1; delay(100); led2=1; delay(100); led3=1; delay(100); led4=1; delay(100); led5=1; delay(100); led6=1; delay(100); led7=1; delay(100); led0=led1=led2=led3=led4=led5=led6=led7=0; break; }

} void check_col1() //Function for checking column one { row1=row2=row3=1; row1=0; if(col1==0) display(1); row1=1; row2=0; if(col1==0) display(2); row2=1; row3=0; if(col1==0) display(3); } void check_col2() //Function for checking column two { row1=row2=row3=1; row1=0; if(col2==0) display(4); row1=1; row2=0; if(col2==0) display(5); row2=1; row3=0;

if(col2==0) display(6); } void check_col3() //Function for checking column three { row1=row2=row3=1; row1=0; if(col3==0) display(7); row1=1; row2=0; if(col3==0) display(8); } void main() { P1=0x00; col1=col2=col3=1; //Input Port while(1) {

if(col1==0) check_col1(); else if(col2==0) check_col2(); else if(col3==0) check_col3(); } }

ISIS SIMULATION OUTPUT

Figure 4.1.2 ISIS Simulation of Keypad Interfacing With LED

EX:NO: 5 DATE:

DISPLAYING THE POSITION OF KEY PRESSED USING 7 SEGMENT DISPLAY AIM To display the position of the key pressed using 7 segment display in the microcontroller COMPONENTS REQUIRED Microcontroller P89V51RD2-1 Development board Bread board Universal programmer connecting wires Keypad-1 BCD to 7 segment Decoder, IC 7447-2 7 Segment display(common anode type)-2 AND 74LS21-1

ALGORITHM Initializing port 2 as output port and port 1 as input port by giving P1=0x0F External interrupt pin is enabled. When the interrupt occurred is detected by pressing the key, external interrupt is disabled, in order to avoid any interrupt until the key press is detected Flag is also set (flag=0xff) to indicate that there is an external interrupt Now scanning of keypad starts to detect the position of key pressed Initially scancode value is given as 0xef and this value is assigned to port1 and keycode

The following two conditions are checked if scancode value is not equal to 0xff; a) ((keycode&0x0f)!=0x0f); if this condition is true, no change in the keycode value and detects the column value b) else the following operation is done scancode=(keycode<<1)|0x0f; to detect the row value Scanned code output is given to port2. With the decoder, the corresponding decimal value of keycode(port2) is displayed in the 7 segment. Again the port 1 is set as 0x0f and the flag is resetted(flag=0x00) External interrupt is set (EX1=1) and waits for the next interrupt.

FLOWCHART START

Initialize IE=0; EX1=1; EA=1 P2=0XFF, P1=0X0F NO

If key press YES p Flag=0xff

YES
INT1

=1

NO
EX1=0,Scancode=0XEF

If scancode!= 0xXFF

NO

YES
P1=Scancode Keycode=p1

(keycode&0x0f) !=0x0f 0000

YES

scancode=(keycode>1)|0x0f

NO

Keycode=~keycode P2=keycode

P1=0x0F

NO
INT1==1

YES
Flag=~flag

NO
Flag==0

YES
EXT=1

END

Figure 5.1: Flowchart to scan the position of key pressed by making keypad as external interrupt

CIRCUIT DIAGRAM

Figure 5.2: Circuit diagram to display the position of key pressed using 7 segment displays

CODING #include <reg51.h> #include <stdio.h> #define byte unsigned char //Interrupt service routine Void keyinterrupt() interrupt 2 { int t; byte keycode, scancode, flag=0xff; t=5000; while(t--); if(INT1==1) return; EX1=0; scancode=0xef; while (scancode!=0xff) { P1=scancode; Keycode=P1; if((keycode&0x0f)!=0x0f) break; scancode=(keycode<<1)|0x0f; } keycode=~keycode; P2=keycode;

P1=0X0F; while(1) { if(INT1==1) { flag=~flag; if(flag==0) break; } t=10000; while(t--); } EX1=1; return; } Void main(void) { IE=0; EX1=1; EA=1; P2=0XFF; P1=0X0F; while(1) { }}

ISIS SIMULATON OUTPUT

Figure 5.3: ISIS simulation output for displaying the position of key pressed using the seven segment display

RESULT Thus, keypad is used as the external interrupt and the position of the key pressed is displayed using two 7 segment display and verified

EX.NO: 6 DATE: CONTROL FOUR LED USING SWITCH IN 8051 MICROCONTROLLER AIM To control four LED in different sequence using switch in microcontroller P89V51RD2. COMPONENTS REQUIRED Microcontroller P89V51RD2 Universal programmer LED-4 Switch-1 Connecting wires

ALGORITHM Initialize port1 as output port by assigning 0 to port1 Initialize pin3.4(T0-timer0 input) of port3 as input port by assigning 1 to pin3.4 TMOD(Timer/counter mode control register) is an 8-bit register, both timers 0 and 1 use the same register to set various timer operation mode. Set TMOD with value 0x16. Timer0 is used as counter with mode2 8-bit auto-reload.Mode2 is an 8-bit timer it allows only values of 00 to FFH to be loaded into the timers register TH0.After TH0 is loaded with the 8-bit value the 8051 gives a copy of it to TL0. Set values in Timer0 (16-bit register) as (timer0 low byte register )TL0=0x0FB and( high byte register)TH0=0x0FB and set TR0=1(Timer0 run control bit) to start the counter Within infinite while loop different sequence for each input count(TL0) is defined using switch case. Each value in each sequence is assigned to output port1 with a delay of 2 seconds. Timer1 is used as timer with mode1 (16-bit timer) for generating delay. Initiate for loop with i=0. Set values in Timer1(16-bit register) as TL1=0x0A5 and TH1=0x0FE.start Timer1 by setting TR1=1(Timer1 run control bit is ON) and continuously monitor timer1 overflow flag (TF1).If TF1==1 then, clear by setting TF1=0 and TR1=0(Timer1 run control bit is OFF)and, increment i in for loop. Repeat the aboveuntil i<80 to generate a delay of 2 seconds elsereturn to where it is called to execute the next value in the sequence. After reaching value FF incounter(TL0) the 8-bit auto reload mode reloads the value from TH0 to TL0 and monitors TL0and switch the case accordingly.

FLOWCHART
Start

Initialize port1 as output P1=0x0000; Initialize pin3.4 (T0) as input T0=1; Initialize TMOD=0x016, TL0=0xFB, TH0=0xFB and, set TR0=1to start counter Interrupt using switch connected to T0 P1=0x01;delay(); P1=0x03;delay(); P1=0x05;delay() P1=0x09; delay(); P1=0x02;delay(); P1=0x03;delay(); P1=0x06;delay(); P1=0x0A; delay(); P1=0x04;delay(); P1=0x05;delay(); P1=0x06;delay();P1=0x 0C; delay();

Yes if(TL0==0Xfc) NO Yes if(TL0==0Xfd)

NO Yes if(TL0==0Xfe) NO NO if(TL0==0Xff) Yes

P1=0x08;delay(); P1=0x09;delay(); P1=0x0A;delay(); P1=0x0C;delay();

Figure 6.1 flowchart for controlling four LED using switch in microcontroller

Start

i=0

Set TL1=0x0A5 and TH1=0x0FE Set TR1=1

Yes while(TF1==0); No TR1=0; TF1=0; increment i; Yes

i<80 No Return

Figure 6.2 Flowchart for delay

CIRCUIT DIAGRAM

Figure 6.3 Circuit diagram to control four LED using switch in microcontroller

CODING #include <REG51F.H> void delay(); void main(void) { P1=0X00; T0=1; TMOD=0x16; TL0=0xFB; TH0=0xFB; TR0=1; while(1) { switch(TL0) { case 0xfc: P1=0x01; delay(); P1=0x03; delay(); P1=0x05; delay(); P1=0x09; delay(); break; case 0xfd: P1=0x02; delay(); P1=0x03; delay(); P1=0x06; delay(); P1=0x0A; delay(); break; case 0xfe: P1=0x04; delay(); P1=0x05; delay(); P1=0x06; delay(); P1=0x0C; delay(); break; case 0xff: P1=0x08; delay(); P1=0x09;

delay(); P1=0x0A; delay(); P1=0x0C; delay(); break; } } } void delay() { inti; for(i=0;i<80;i++) { TH1=0xA5; TL1=0xFE; TR1=1; while(TF1==0); TR1=0; TF1=0; } }

SAMPLE OUTPUT

Figure 6.4 ISIS simulation output control four led using switch in 8051 microcontroller HARDWARE OUTPUT

Figure 6.5 Hardware Implementation of Control four led using Switch in 8051 Microcontroller

SAMPLE OUTPUT TL0=0XFC TL0=0XFD

LED 1 1 1 1 1 2 0 1 0 0 3 0 0 1 0 4 0 0 0 1 1 0 1 0 0 2 1 1 1 1

LED 3 0 0 1 0 4 0 0 0 1

TL0=0XFE

TL0=0XFF

LED 1 0 1 0 0 2 0 0 1 0 3 1 1 1 1 4 0 0 0 1 1 0 1 0 0 2 0 0 1 0

LED 3 0 0 0 1 4 1 1 1 1

RESULT Thus four LEDs in different sequence using switch in microcontroller P89V51RD2 was implemented and verified.

EXNO:7 DATE: INTERFACING STEPPER MOTOR WITH 8051 AIM To write a Program to Interface a stepper motor with 8051c and to rotate in clockwise and anti-clockwise direction using keil software.

HARDWARE REQUIRED

Microcontroller IC P89C51RD2XX PHILIPS 1No Crystal Oscillator 11.0592 MHz Capacitor 1f, 10f, 33pf, 0.1f,150pf-6nos Bread board & connecting wires. Resistors 1K,8.2k,10k,4.7k-10nos Micro Switch 1 Pin ULN2003-1 No Stepper motor

SOFTWARE REQUIRED Keil vision 3 ISIS Proteus Professional 7 Topwin VER5.49

ALGORITHM Define the delay function. Initialize the switch, SW. Making the condition as an infinite loop. If SW = 0, motor get rotates step by step in a clockwise direction with a delay of 100 ms. If SW = 1, motor get rotates step by step in a counter-clockwise direction with a delay of 100 ms. This process gets repeated until the power off.

FLOWCHART
Start

Define delay function (MSDelay)

Set port pin for switch (SW)

Initialize switch, SW=1

While(1)

Assign P1=0x06 MSDelay(100) Assign P1=0xcc MSDelay(100)

Yes

If SW==0

No

Assign P1=0x06 MSDelay(100)

Assign P1=0x33 MSDelay(100)

Assign P1=0x99 MSDelay(100)

Assign P1=0x99 MSDelay(100)

Assign P1=0x33 MSDelay(100)

Assign P1=0xcc MSDelay(100)

Figure 7.1 Flow Chart

CIRCUIT DIAGRAM

To ULN2003 5V

4.7K

Fig 7.7:STEPPER MOTOR INTERFACE

Figure 7.2 Circuit Diagram of Stepper Motor Interface

PROCEDURE 1. Write the stepper motor coding for (clock wise rotation) in keil software and generate a hex code. 2. Dump the hex code in the controller chip using flash magic software. 3. Give the circuit connections as given above. 4. Interface the 8051 controller, ULN2003 and the stepper motor. 5. Switch on the power supply and view the clock-wise rotation of stepper motor. 6. Repeat the steps 1-5 for anti-clock-wise rotation of the motor.

STEP SEQUENCES Normal 4-Step Sequence (90)

CLOCK WISE

Step # 1 2 3 4

Winding A 1 1 0 0

Winding B 0 1 1 0

Winding C 0 0 1 1

Winding D 1 0 0 1

Counter Clockwise

Table 7.1 4-Step Sequence

STEP ANGLE Step angle 0.72 1.8 2.0 2.5 5.0 7.5 15 Steps per revolution 500 200 180 144 72 48 24

Table 7.2 Step Angle

CODING #include<reg51.h> void MSDelay(unsigned int value); sbit SW=P2^7; void main() { SW=1; while(1) { if(SW==0) { P1=0x06; MSDelay(100); P1=0x0c; MSDelay(100); P1=0x09; MSDelay(100); P1=0x03; MSDelay(100); } else { P1=0x06; MSDelay(100); P1=0x03; MSDelay(100); P1=0x09; MSDelay(100); P1=0x0c; MSDelay(100); } } } void MSDelay(unsigned int value) { unsigned int x,y; for(x=0;x<1275;x++) for(y=0;y<value;y++); }

ISIS SIMULATION OUTPUT

Figure 7.3 Simulation of Stepper Motor Interfacing

HARDWARE SNAP SHOT

Figure 7.4 Interfacing Stepper Motor

RESULT Thus the program is written to interface stepper motor with 8051c was verified and executed.

Ex No:8 Date: INTERFACING ADC0804 WITH TEMPERATURE SENSOR AIM To design and verify the ADC 0804 conversion of data given, using Philips AT89C5 Microcontroller with temperature sensing as a parameter.

COMPONENTS REQUIRED Philips AT89C51RD2XX Microcontroller ADC 0804 LM 35 Temperature sensor Resistor - 10 K ohm Capacitor- 150 Pico farad LCD Display Kiel Simulator ISIS Emulator

BLOCK DIAGRAM

Figure 8.1 Block Diagram of the Experiment

CIRCUIT DIAGRAM

Figure 8.2 Circuit Diagram

ALGORITHM 1. START 2. Select the specific ports of microcontroller. 3. Initialize the interrupts. 4. Move the 8-bit data into ACC and store the data from accumulator into any register 5. Write the commands of LCD display for output data. 6. Move again data from register to accumulator for division operation. 7. Convert the data from ASCII values. 8. Display the data through ADC output pins. 9. Generate delay where ever necessary. 10. STOP ALGORITHM BETWEEN THE DATA FROM LM35 AND ADC0804 1. START 2. Temperature sensors LM35 sense the output temperature. 3. Initialize the CS=0 pin and low to high transition, to enable the data to be write to ADC, which starts the conversion. 4. Keep the INTR pin always low to ensure that process of conversion is finished. 5. Initialize the CS=1 pin and pass high to low transition, to read the data at output of ADC. 6. STOP

CODING #include<reg51.h> //#define port P3 #define adc_input P1 //#define dataport P0 #define sec 100 sbit rs = P3^0; sbit rw = P3^1; sbit e = P3^2; sbit wr= P3^3; sbit rd= P3^4; sbit intr= P3^5; int a,b,c; void delay(unsigned int msec ); void lcd_cmd(unsigned int item); void lcd_data(unsigned int item); void lcd_data_string(unsigned char *str); void delay(unsigned int msec) { int i ,j ; for(i=0;i<msec;i++)

for(j=0; j<1275; j++); } void lcd_cmd(unsigned int item) //Function to send command to LCD { P2 = item; rs= 0; rw=0; e=1; delay(1); e=0; return; } /*void lcd_data_string(unsigned char *str) // Function to send string to LCD { int i=0; while(str[i]!='\0') { lcd_data(str[i]); i++; delay(10); } }*/ void lcd_data(unsigned char item) //Function to send data to LCD

{ P2 = item; rs= 1; rw=0; e=1; delay(1); e=0; //delay(100); return; } void main() { //adc_input=0xff; lcd_cmd(0x38); lcd_cmd(0x0E); //Display On, Cursor Blinking lcd_cmd(0x01); // Clear Screen lcd_cmd(0x06); lcd_cmd(0x80);

rd=1; wr=0; wr=1; while(intr==1);

rd=0; a=adc_input; delay(1); intr=1; b=0x30+(a/0x0A); c=0x30+(a%0x0A); lcd_data(b); lcd_data(c); }

FLOW CHART

Figure 8.3 Implementation of Interfacing ADC with Temperature Sensor

PROTOTYPE ISIS OUTPUT

Figure 8.5 Screen Shot of ISIS Emulator

INTERFACING LCD

Figure 8.4 Prototype of Experiment

RESULT
Thus the Analog-Digital conversion using 8051 was successfully completed and the analog datas were converted to its digital values.

EX.NO:9 DATE:

DIGITAL CLOCK AIM To implement digital clock using seven segment display in microcontrollerP89V51RD2. COMPONENTS REQUIRED
MicrocontrollerP89V51RD2 Universal programmer Seven segment display-6 Switch-2 4x4 Keypad Connecting wires

ALGORITHM Initialize Port 2(P2.0-P2.5) as enablepins to 6 seven segments. Set Port3 for keypad scanning. Initialize P2.6 and P2.7 as input which is used as switch for set mode and run mode Initialize timer0 and timer1 in timer mode. Set TL0=0X99 & TH0=0X0f1 to generate 0.004 second and set IE=0x82 to enable timer0 interrupt and start timer0(TR0=1) If run=0;within infinite loop clock starts running from 00:00:00 If set=0;enter second, minute, hour using keypad and assigned to s0,s1,m0,m1,h0 and h1. Within infinite loop clock starts running from the value i.e., set via keypad Set TL1=0X0FD & TH1=0X4B to generate 50ms and repeat using for loop for about 20 times to generate one second Each value in second is incremented with time delay of one second using timer1 When timer0 overflow ,it set TF0=1 which is raised as interrupt then executes interrupt routine

Within interrupt routine, again reload TL0=0x36 & TH0=0x0F6 and post increment count variable Then depending upon count ,it enable one of the 6 seven segment and display the content in s/m/h variable

FLOWCHART
START

Initialize P2.0-P2.5 as enable pins to 6 seven segments.Set Port3 for keypad scanning. Initialize P2.6 and P2.7 as input connected to switch for set mode and run mode Initialize timer0 and timer1 in timer modeSet TL0=0X99 & TH0=0X0f1set IE=0x82 and set TR0=1
if (run=0) NO YES Start from 00:00:00 callclockdelay() & increment if (set=0) YES Enter s0, s1, m0, m1, h0, h1 using keypad and set values in for loop and starts from set value callclockdelay() & increment

NO

Figure9.1 Flowchart for digital clock

Start ISR

Set TL0=0X99 & TH0=0X0f1 and initialize P1=0xff


Set P2.0 toP2.5 as zero. Count++ Count=count%6 YES If count=0 NO If count=1 NO If count=2 NO If count=3 NO If count=4 NO If count=5 YES YES YES P1=digi[s0]; P2.0 = 1; break; P1=digi[s1]; P2.1 = 1; break;

YES

P1=digi[m0]; P2.2 = 1; break; P1=digi[m1]; P2.3 = 1; break; P1=digi[h0]; P2.4 = 1; break;

YES

P1=digi[h1]; P2.5 = 1; break;

Return

Figure9.2 Flowchart for display

START clockdelay

i=0

Set TL1=0x0FD and TH1=0x4B Set TR1=1

Yes while(TF1==0); No TR1=0; TF1=0; increment i; Yes

i<20 No Return

Figure9.3 Flowchart for one second delay

CIRCUIT DIAGRAM

Figure9.4 Digital clock circuit diagram

CODING #include <REG51F.H> voidclockdelay(); unsigned char count=0; sbit enable_1 = P2^0; sbit enable_2 = P2^1; sbit enable_3 = P2^2; sbit enable_4 = P2^3; sbit enable_5 = P2^4; sbit enable_6 = P2^5; sbit set = P2^6; sbit run = P2^7; sbit r1 = P3^0; sbit r2 = P3^1; sbit r3 = P3^2; sbit r4 = P3^3; sbit c1 = P3^4; sbit c2 = P3^5; sbit c3 = P3^6; sbit C4 = P3^7; voiddisp(int ); int keypad(void); intgetkey(); unsigned char digi[]={0x0c0,0x0f9,0x64,0x70,0x59,0x52,0x42,0x0f8,0x40,0x50,0x46};

int s0,s1,m0,m1,h0,h1; inta,b,c,d,e,f; int flag=0; void main() { TMOD=0x11; TL0=0x99; TH0=0x0f1; IE=0x82; TR0=1; if(set==0) { while(set==0); do{ flag=0; a=getkey(); if(a>=10) { a=10;flag=1;} s0=a; }while(flag==1);

do{ flag=0; b=getkey();

if(b>5) { b=10;flag=1;} s1=b; }while(flag==1);

do{ flag=0; c=getkey(); if(c>=10) { c=10;flag=1;} m0=c; }while(flag==1);

do{ flag=0; d=getkey(); if(d>5) {d=10;flag=1;} m1=d; }while(flag==1);

do{ flag=0; e=getkey();

if(e>=10) {e=10;flag=1;} h0=e; }while(flag==1);

do{ flag=0; f=getkey(); if(e>3&&e<10) { if(f>=2) { f=10;flag=1;} } if(e<=3) { if(f>2) {f=10;flag=1;} } h1=f; }while(flag==1); while(1) {for(h1=f;h1<2;h1++) { for(h0=e;h0<10;h0++) { for(m1=d;m1<=5;m1++) {for(m0=c;m0<10;m0++)

{for(s1=b;s1<=5;s1++) { for(s0=a;s0<10;s0++) { } a=0; } b=0; } c=0; } d=0; } e=0; } f=0; clockdelay();

if(h1==2) { for(h0=e;h0<=3;h0++) { for(m1=d;m1<=5;m1++) {for(m0=c;m0<10;m0++)

{ for(s1=b;s1<=5;s1++) { for(s0=a;s0<10;s0++) { } a=0; } b=0; } c=0; clockdelay();

} d=0; } e=0; h1=0; } } } if(run==0) { while(1) { for(h1=0;h1<2;h1++)

{ for(h0=0;h0<10;h0++) { for(m1=0;m1<=5;m1++) { for(m0=0;m0<10;m0++) { for(s1=0;s1<=5;s1++) { for(s0=0;s0<10;s0++) { } } } } } } clockdelay();

if(h1==2) { for(h0=0;h0<=3;h0++) { for(m1=0;m1<=5;m1++)

{ for(m0=0;m0<10;m0++) { for(s1=0;s1<=5;s1++) { for(s0=0;s0<10;s0++) { } } } } } } } } voidclockdelay() { inti; for(i=1;i<=20;i++) { TMOD=0X11; TL1=0X0FD; TH1=0X4B; TR1=1; clockdelay(); }

while(TF1==0); TR1=0; TF1=0; } }

voidclockdisp() interrupt 1 { TL0=0x99; TH0=0xf1; P1=0xff; enable_1 = enable_2 = enable_3 = enable_4 = enable_5 = enable_6 = 0; count++; count=count%6; switch(count) { case 0: P1=digi[s0]; enable_1 = 1; break; case 1: P1=digi[s1]; enable_2 = 1; break;

case 2: P1=digi[m0]; enable_3 = 1; break;

case 3: P1=digi[m1]; enable_4 = 1; break;

case 4: P1=digi[h0]; enable_5 = 1; break;

case 5: P1=digi[h1]; enable_6 = 1; break; } } intgetkey() { int key=99; while(key==99)

key=keypad(); return(key); } int keypad(void) { r1=0; r2=1;r3=1; r4=1; if(c1==0){ while(c1==0); return 7; } if(c2==0){ while(c2==0); return 8; } if(c3==0){ while(c3==0); return 9; } r1=1; r2=0; r3=1; r4=1; if(c1==0){ while(c1==0); return 4;} if(c2==0){ while(c2==0); return 5;} if(c3==0){ while(c3==0); return 6;} r1=1;r2=1;r3=0;r4=1; if(c1==0){ while(c1==0); return 1;} if(c2==0){ while(c2==0); return 2;} if(c3==0){ while(c3==0); return 3;} r1=1;r2=1;r3=1;r4=0; if(c2==0){ while(c2==0); return 0;} return 99; }

SAMPLE OUTPUT

Figure 9.5 ISIS simulation output

RESULT Thus digital clock using seven segment display in microcontroller P89V51RD2 was simulated using ISIS and verified

EX. NO:10 DATE : OBSTACLE DETECTOR USING IR SENSOR

AIM: To design and implement obstacle detection by interfacing LCD and IR sensor using 8051 microcontroller. Hardware Required: 16X2 Line LCD (LM016L). IR Sensor. PHILIPS P89v51RD2XX. TOP2048 Programmer kit. Power supply(5v). Connecting wires. Software Required: Keil uvision 3. ISIS Proteus Professional 7. Topwin VER5.49.

IR (Infrared) Sensor The basic concept of IR(infrared) obstacle detection is to transmit the IR signal(radiation) in a direction and a signal is received at the IR receiver when the IR radiation bounces back from a surface of the object. Here in the figure the object can be any thing which has certain shape and size, the IR LED transmits the IR signal on to the object and the signal is reflected back from the surface of the object. The reflected signals is received by an IR receiver. The IR receiver can be a photodiode / phototransistor or a ready made module which decodes the signal.

Fig 10.1 IR Sensor

IR Transmitter In general, the basic building block of any IR transmitter is modulation of the information signal with carrier signal, because the receiver modules which are available off-the-shelf are made for a particular carrier frequency. So it is clear that when you chose a particular IR receiver module, you also need to transmit the the modulated wave with the same carrier frequency of that of a IR receiver module. IR Receiver It is quite simple to construct a IR receiver with readily available off-the-shelf modules. These modules are nothing but the IC packages, referred as TSOP(Thin small-outline package). In this document, the receiver is designed for 38 kHz carrier signal, hence the IC selected should work for the same frequency. The IC TSOP4838 will serve as a receiver module, which is compatible with both TTL and CMOS logic. This means that we can directly get digital signal from the receiver module and then connect it to the microcontroller.

ALGORITHM:

Initialize the Port1 for data pins of LCD. Initialize the P2.4 for RS ,P2.5 for enable and P2.6 for RW pins of LCD. Initialize the Port 2.7 for output pin of IR SENSOR. Declare function delay(), lcdcmd(), lcddata(), lcddata_string() and IRSENSOR(). Call the command function lcdcmd() to send the commands to LCD Call the IRSENSOR() function to check the obstacle present If any obstacle present means the IR (P 2.7 ) output will be high signal and then lcddata_string() will be called to display obstacle in LCD Else the IR (P 2.7 ) output will be low signal and then lcddata_string() will be called to display no obstacle in LCD

Flow chart

Start

Initialize the Port1 for data pins of LCD

Initialize the P2.4 for RS ,P2.5 for enable and P2.6 for RW

Initialize the Port 2.7 for output pin of IR SENSOR

Call the command function lcdcmd()

Call the IRSENSOR()

YES

If output is high?

Display Obstacle in LCD

NO

Display no Obstacle in LCD

Stop

Fig 10.2 IR Sensor Using 8051 Microcontroller

Program: #include<reg51.h> #define cmdport P2 #define dataport P1

sbit rs = cmdport^4; //register select pin sbit rw = cmdport^6; // read write pin sbit e = cmdport^5; //enable pin sbit IR = cmdport^7; void IRSENSOR();

void delay(unsigned int msec) // Function to provide time delay in msec. { int i,j ; for(i=0;i<msec;i++) for(j=0;j<275;j++); }

void lcdcmd(unsigned char item) //Function to send command to LCD { dataport = item; rs= 0; rw=0; e=1; delay(1); e=0; }

void lcddata(unsigned char item) //Function to send data to LCD { dataport = item; rs= 1; rw=0; e=1; delay(1); e=0; } void lcddata_string(unsigned char *str) // Function to send string to LCD { int i=0; while(str[i]!='\0') { lcddata(str[i]); i++; delay(1); } }

void main() { lcdcmd(0x38); // for using 8-bit 2 row mode of LCD delay(100); lcdcmd(0x0E); // turn display ON for cursor blinking delay(10);

lcdcmd(0x01); //clear screen delay(10); lcdcmd(0x06); //display ON delay(10); lcdcmd(0x80); // bring cursor to position 6 of line 1 delay(100); IRSENSOR(); }

void IRSENSOR () {

if(IR==0) { lcddata_string("no obstacle"); } else { lcddata_string("obstacle "); } }

CIRCUIT DIAGRAM:

Fig 10.3 IR Sensor Using 8051 Microcontroller SAMPLE OUTPUT:

Fig 10.4 Output of IR Sensor when no obstacle present

Fig 10.5 Output of IR Sensor when obstacle present

RESULT: Therefore, obstacle detection by interfacing LCD and IR sensor using 8051 microcontroller. has been executed successfully.

EX NO:11 DATE: INTERFACING LED WITH AVR AIM To write a program for interfacing LED with AVR microcontroller to Blink by using AVR studio. COMPONENTS REQUIRED Microcontroller IC Atmega 16 Max 232 IC & 9 pin RS232 Female connector Bread board and connecting wires Resistors 1K ohm, Crystal oscillator 8 MHz Capacitor 1F, 10 F, 33pF LED 3mm - 8

THEORY AVR MICROCONTROLLER The AVR is a modified Harvard architecture 8-bit RISC single chip. The AVR was one of the first microcontroller families to use on-chip flash memory for program storage, as opposed to one-time programmable ROM, EPROM, or EEPROM used by other microcontrollers at the time. Among the first of the AVR line was the AT90S8515, which in a 40-pin DIP package has the same pin out as an 8051 microcontroller, including the external multiplexed address and data bus. The polarity of the RESET line was opposite (8051's having an active-high RESET, while the AVR has an active-low RESET) but other than that, the pin out was identical.

PIN DIAGRAM

FIG 11.1 Pin Diagram of ATMEGA16S PIN DESCRIPTION ATmega16 Microcontroller Pin Description Pin 40Vcc Vcc provides supply voltage to the chip. The voltage source is +5V. Pin 20Ground Pins 19,18 : XTAL1 and XTAL Pin 9Reset It is an input pin and is active high (normally low . The high pulse must be high at least 2 machine cycles.

FIG 11.2 Crystal Oscillator

CIRCUIT DIAGRAM
ATmega16

FIG 11.3 Interfacing LEDS with ATMEGA16

CIRCUIT CONNECTION Give the Vcc (5V) supply to the 40th pin and ground to the 20th pin of microcontroller. Give the reset pin connections (reset switch, 10uF and 10k resistor) to the 9th pin of the controller as per the circuit diagram. Give the oscillator connections (8 MHz crystal oscillator and two 33pF capacitors) as per the circuit diagram. Connect the pins PB0 - PB7 to data line

PROGRAM #include <avr/io.h> int main(void) { int a=0xFF, i=0; DDRB=0xFF; while(1) { for(int j=0; j<20000; j++) PORTB =0x00; for(int j=0; j<20000; j++) PORTB =0xFF; }}

PROCEDURE Write the seven segment coding for display in AVR Studio software and generate a hex code. Give the circuit connections as given above. Interface the AVR microcontroller and LED. Switch on the power supply and view the LED blinking.

ISIS EMULATION

FIG 11.4 Simulation Result of LED Interfacing

RESULT Thus the program is written to interface LED with AVR microcontroller is verified and executed.

EX NO: 12 DATE: PROGRAMMING WITH ANALOG COMPARATOR OF AVR AIM To implement Analog Comparator of AVR. DESCRIPTION The Analog Comparator compares the input values on the positive pin AIN0 and negative pin AIN1. When the voltage on the positive pin AIN0 is higher than the voltage on the negative pin AIN1, the Analog Comparator Output, ACO, is set. The comparators output can be set to trigger the Timer/Counter1 Input Capture function. In addition, the comparator can trigger a separate interrupt, exclusive to the Analog Comparator. The user can select Interrupt triggering on comparator output rise, fall or toggle.

FIG 12.1 Block Diagram of Analog Comparator

SPECIAL FUNCTION IO REGISTER

FIG 12.2 SFIOR Bit 3 ACME: Analog Comparator Multiplexer Enable When this bit is written logic one and the ADC is switched off (ADEN in ADCSRA is zero), the ADC multiplexer selects the negative input to the Analog Comparator. When this bit is written logic zero, AIN1 is applied to the negative input of the Analog Comparator. ANALOG COMPARATOR CONTROL AND STATUS REGISTER

FIG12.3 ACSR Bit 7 ACD: Analog Comparator Disable When this bit is written logic one, the power to the Analog Comparator is switched off. This bit can be set at any time to turn off the Analog Comparator. This will reduce power consumption in active and Idle mode. When changing the ACD bit, the Analog Comparator Interrupt must be disabled by clearing the ACIE bit in ACSR. Otherwise an interrupt can occur when the bit is changed. Bit 6 ACBG: Analog Comparator Bandgap Select When this bit is set, a fixed bandgap reference voltage replaces the positive input to the Analog Comparator. When this bit is cleared, AIN0 is applied to the positive input of the Analog Comparator. Bit 5 ACO: Analog Comparator Output The output of the Analog Comparator is synchronized and then directly connected to ACO. The synchronization introduces a delay of 1 - 2 clock cycles. Bit 4 ACI: Analog Comparator Interrupt Flag This bit is set by hardware when a comparator output event triggers the interrupt mode defined by ACIS1 and ACIS0. The Analog Comparator Interrupt routine is executed if the ACIE bit is set and the I-bit in SREG is set. ACI is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, ACI is cleared by writing a logic one to the flag.

Bit 3 ACIE: Analog Comparator Interrupt Enable When the ACIE bit is written logic one and the I-bit in the Status Register is set, the Analog Comparator Interrupt is activated. When written logic zero, the interrupt is disabled. Bit 2 ACIC: Analog Comparator Input Capture Enable When written logic one, this bit enables the Input Capture function in Timer/Counter1 to be triggered by the Analog Comparator. The comparator output is in this case directly connected to the Input Capture front-end logic, making the comparator utilize the noise canceller and edge select features of the Timer/Counter1 Input Capture interrupt. When written logic zero, no connection between the Analog Comparator and the Input Capture function exists. To make the comparator trigger the Timer/Counter1 Input Capture interrupt, the TICIE1 bit in the Timer Interrupt Mask Register (TIMSK) must be set. Bits 1, 0 ACIS1, ACIS0: Analog Comparator Interrupt Mode Select These bits determine which comparator events that trigger the Analog Comparator interrupt.

TABLE 12.1 ACIS0/ACIS1 SETTING

ANALOG COMPARATOR MULTIPLEXED INPUT It is possible to select any of the ADC7..0 pins to replace the negative input to the Analog Comparator. The ADC multiplexer is used to select this input, and consequently, the ADC must be switched off to utilize this feature. If the Analog Comparator Multiplexer Enable bit (ACME in SFIOR) is set and the ADC is switched off (ADEN in ADCSRA is zero), MUX2..0 in ADMUX select the input pin to replace the negative input to the Analog Comparator. If ACME is cleared or ADEN is set, AIN1 is applied to the negative input to the Analog Comparator.

Table 12.2 Analog Comparator Multiplexed Input

PROGRAM #include <avr\io.h> // Most basic include files #include <avr\interrupt.h> // Add the necessary ones #include <avr\signal.h> // here // Define here the global static variables int My_global; // Interrupt handler example for INT0 // SIGNAL(SIG_INTERRUPT0) { } // It is recommended to use this coding style to // follow better the mixed C-assembly code in the // Program Memory window // void my_function(void) { // Put the open brace '{' here asm("nop"); } // *********************************************************** // Main program // *********************************************************** // Inline assembly example

int main(void) { DDRD=0X00; // ANI0,1 AS I/P DDRB=0X01; //PB0 AS O/P ACSR=0X00; while(1) { // REFLECT ACO BIT STATUS IN PB0 if(ACSR&(1<<ACO)) PORTB|=1; //SET pb0 else PORTB=0X00; //CLR PB0 }}

VM SIMULATION

FIG 12.4 Control Panel

FIG 12.4 Output of Analog Comparator RESULT The Analog Comparator of AVR is analyzed.

EX NO: 13 DATE: INTERFACING SEVEN SEGMENT DISPLAY WITH AVR AIM To write a program for interfacing seven segment display with AVR microcontroller to display the numerical value and non numerical characters by using AVR studio.

COMPONENTS REQUIRED Microcontroller IC Atmega 16 Max 232 IC & 9 pin RS232 Female connector Bread board and connecting wires Resistors 1K ohm, Crystal oscillator 8 MHz Capacitor 1F, 10 F, 33pF Seven segment display 4

THEORY SEVEN SEGMENT DISPLAY A seven-segment display (SSD), or seven-segment indicator, is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dotmatrix displays. Seven-segment displays are widely used in digital clocks, electronic meters, and other electronic devices for displaying numerical information. A seven segment display, as its name indicates, is composed of seven elements. Individually on or off, they can be combined to produce simplified representations of thearabic numerals. Often the seven segments are arranged in an oblique (slanted) arrangement, which aids readability. In most applications, the seven segments are of nearly uniform shape and size (usually elongated hexagons, though trapezoids and rectangles can also be used), though in the case of adding machines, the vertical segments are longer and more oddly shaped at the ends in an effort to further enhance readability.

FIG13.1 Individual Segment for Seven Segment Display

CIRCUIT DIAGRAM

FIG 13.2 Interfacing Seven-Segment Display with ATMEGA16S

CIRCUIT CONNECTION Give the Vcc (5V) supply to the 40th pin and ground to the 20th pin of microcontroller. Give the reset pin connections (reset switch, 10uF and 10k resistor) to the 9 th pin of the controller as per the circuit diagram. Give the oscillator connections (8 MHz crystal oscillator and two 33pF capacitors) as per the circuit diagram. Connect the pins PB0 - PB7 to data line and PD0 PD3 to control line of the seven segment display.

PROGRAM #include <avr\io.h> // Most basic include files #include <avr\interrupt.h> // Add the necessary ones #include <avr\signal.h> // here #include<util/delay.h> int DATA[4]={0x60,0xda,0xf2,0x66}; unsigned char i,j=0x01; SIGNAL(SIG_INTERRUPT0) { } // Main program int main(void) {

DDRB=0XFF; DDRD=0XFF; while(1) { // Infinite loop; for(i=0;i<4;i++) { PORTB=DATA[i]; PORTD=~(j<<i); _delay_ms(500); } } }

PROCEDURE Write the seven segment coding for display in AVR Studio software and generate a hex code. Give the circuit connections as given above. Interface the AVR microcontroller and seven segment displays. Switch on the power supply and view the seven segment display.

ISIS EMULATION

FIG 13.3 Simulating Seven-Segment Display in ISIS

RESULT Thus the program is written to interface seven segment displays with AVR microcontroller is verified and executed.

Potrebbero piacerti anche