Micro Controller Based Digital Code Lock

download Micro Controller Based Digital Code Lock

If you can't read please download the document

Transcript of Micro Controller Based Digital Code Lock

MICROCONTROLLER BASED DIGITAL CODE LOCKABSTRACTSecurity is prime concern in our day-to-day life. Every one wants to be as much as secure as to be possible. An access control systems forms a vital link in a security chain. The micro controller based digital lock presented here is an access control system that allows only authorized persons to access a restricted area. This system is best suitable for corporate offices, ATMs and home security. As a simple example, to lock our mobile phone keypad, a security code of atleast 4 digits must be entered. The system comprises a small electronic unit with a numeric keypad, which is fixed out side the entry door to control a solenoid-operated lock with the help of a stepper motor. When an authorized person enters predetermined user ID and password via the keypad, the stepper motor is operated for a limited time to unlatch the solenoid-operated lock so the door can be open. At the end of preset delay, the stepper motor is operated in reverse direction and the door gets locked again. When the code has been incorrectly entered three times in a row, the code lock will switch to block mode. This function thwarts any attempt by hackers to quickly try a large number of codes in a sequence. If the user forgets his password, the code lock can be accessed by a unique 10 digit administrator password. The secret code can be changed any time after entering the current code (Master code). A buzzer is provided for audio acknowledgment of the key impression. Whenever a key is pressed on the numeric key pad, the system acknowledges the impression by a short beep sound. This buzzer is driven by an NPN transistor. This project uses regulated 5V, 500mA power supply. 7805 three terminal voltage regulator is used for voltage regulation. Bridge type full wave rectifier is used to rectify the ac out put of secondary of 230/12V step down transformer.

BLOCK DIAGRAM

Numeric Key Pad1 4 7 2 5 8 0 3 6 9 #

Transistor Driver Circuit

Buzzer

*

8051 Micro controller

ULN Driver Circuit

Crystal 16X2 LCD Reset circuit Stepper motor

EEPROM

Contrast Control

Step down T/F

Bridge Rectifier

Filter Circuit

Regulator Power supply to all sections

Power Supply

DC power supply exists in every electronic box whether it is a computer, tv, or equipment in the laboratory. The power supply consists of ac voltage transformer, diode rectifier, ripple filter, and voltage regulator. The transformer is an ac device. It has two coil windings, the primary and the secondary, around a common magnetic core. The current flowing in the primary winding generates a time varying electromagnetic field which in turn induces an output voltage across the secondary winding. The ratio of turns in the two windings determines the ratio of the input voltage and output voltage. The higher voltage side has a thinner (high gauge) wire with more turns while the lower voltage side has thicker (low gauge) wire and fewer turns. Do not connect a transformer in the reverse direction because you could have a very high ac voltage if you connect the wall plug to the secondary winding by mistake. The rectifier is based on p-n junction. One can use a single diode forming a half-wave rectifier or four diodes forming a full-wave rectifier or a bridge rectifier. After the rectifier, the voltage signal contains both an average dc component and a time varying ac component called the ripple. To reduce or eliminate the ac component, one needs low pass filter(s). The low pass filter will pass through the dc but attenuate the ac at 60 Hz or its harmonics, i.e., 120 Hz. In the experiment, you will build a pifilter consisting of two capacitors and one resistor. To make the output voltage as constant as possible, one needs a regulator. The regulator consists of a voltage reference, e.g., a Zener diode. It can also be an IC component with voltage reference and feedback control circuit inside. Finally, you will characterize the performance of the power supply by measuring its output voltage and ripple as a function of the load current. The more the current, the higher is the ripple. Likewise, the more the current, the lower is the voltage. This is called loading.

The power supply that we are building in this experiment is a linear power supply. In other words, the circuit functions with analog signals. In our kit, you have a small transformer which can convert 230Vac from the wall plug to 6-12 V ac. In the experiment, we are going to use the power rectifying diode, 1N4001 or IN4007. You can read from the specification sheet the characteristics of the diode. The most important thing to know is the polarity of the diode. The arrow is the p-side and the bar is the n-side. A positive voltage is needed on the p-side to make the diode conduct. IN4001 can block off large negative bias in the hundred voltage range. Another semiconductor component to be used in this experiment is a voltage regulator, 7805. 78 indicates that it is a regulator for positive voltage. There is a corresponding 79 model for negative voltage. 05 indicates that it has an output of 5 V. So, what would 7812 mean? 7805 is an integrated circuit. Just like the operational amplifier, the design engineer of the IC has optimized the circuit. You dont need to figure out your own circuit. You can just use it as a nearly ideal power supply. You shall remember though, the regulator IC requires an input voltage at least a couple of V higher than the output voltage in order to function properly. In a way, it is similar to the operational amplifier, the output is limited by the power supply voltage. Your output is always below the input. This voltage difference keeps all electronic circuits in the IC forwardly biased, hence, functioning properly in the linear regime. A word of caution for using the ac voltage. Is there a ground for the variac or transformer? There isnt any. The ac output is floating. You do not have to connect one of the output node of the transformer to ground. This is very important for the bridge, full-wave rectifier circuit. You will build two rectifiers, the half-wave rectifier and the full-wave rectifier. The half wave rectifier contains only one diode. The output goes through a load resistor to ground. Pay close attention to the power dissipation of the load resistor. This is the experiment in which many students burn their load resistors. If the load resistor is 100 Ohm, can you tell me the power dissipation? Well, it is given by voltage to the second order divided by resistance. If the voltage is 9 V and the resistance is 100 Ohm, the power dissipation would be 0.81 W. Do you still remember what is the power handling capability of those small resistors in the kit? They can only handle a quarter watt. They will heat up and burn very rapidly. You may feel the heat by touching it with your finger. When you smell something, it is already burning. Make sure you use a 1-W resistor, or you can use three 330-Ohm, quarter-Watt resistors in parallel. The waveform of the half-wave rectifier is shown in this slide. As one can see, half of the time, the rectifier generates zero output. The circuit is inexpensive but it has low efficiency and a lot of ripples. You will find this circuit in many low cost electronics, such as portable radio, clock radio, etc. The lower circuit is a full-wave rectifier. There are four diodes. They are arranged in such a way that the current always flows in the same direction through the load resistor no matter which node of the transformer is positive. You can trace the flow of the current. When the upper node of the transformer is positive, current flows through the first diode through the load, which is not shown, then it flows through the last diode to the lower node of the transformer completing the loop. When the lower node of the transformer is positive, current flows through the third diode to the load resistor then it flows through the second diode to the upper node of the transformer completing the loop. The current flows through the load resistor along the same direction all the time. How about the ground node? One needs to pay close attention. The transformer is floating. You dont need to connect the transformer to ground. This is

true for both the primary winding and the secondary winding. You create a ground for the lower node of the load resistor. This is the signal ground. Let me remind you again that the load resistor must have sufficient power handling capability. Otherwise, you may burn the load resistor. Please remember how to calculate the power dissipation. It is given by voltage square divided by resistance. You will know when the resistor is burning by smell, by touch, and by seeing a smoke. Please do not start a fire. That will be really bad. By the way, not only the resistor can burn, it can also melt the plastics on the prototype board. Your socket may look like melting away. That will be a permanent damage. It is to your advantage to pay attention to the amount of power dissipated by the resistor. Make sure that the power will not exceed the limit of the resistor. Now we move on to the filter. Do you still remember how to construct a low pass filter? It has a resistor in front and a capacitor across the output and ground. The ac power line runs at 60 Hz. After a half-wave rectifier, you have an average dc component. But, you also have a 60 Hz ripple. How about the full-wave rectifier? Well, I dont know whether you have noticed, the ripple is at 120 Hz. Since 120 Hz is further away from dc than 60 Hz, it is easier to filter out the ripple of the full-wave rectifier. The pi-filter consists of two capacitors and a resistor in the shape of pi. Both capacitors are large electrolytic capacitors, at least a hundred microfarad. If you have, you can use electrolytic capacitors with a thousand microfarad. Again, let me remind you electrolytic capacitors are polarized devices. Make sure to connect the negative lead to the lower voltage node and positive lead to the higher voltage node. Make sure that the voltage rating of the electrolytic capacitor is 25 V or above. An underrated capacitor may burst when the applied voltage exceeds its limit. It will spew out some fluid with a large popping sound. If this does happen, wash it from your body with water immediately. How does the pi-filter function? As a matter of fact, it is very simple. You can consider it as two low pass filters in cascade. Well, each low pass filter has a pair of resistor and capacitor. You may wonder where is the first resistor? Indeed there is one. The hidden resistor is the resistance in the secondary winding of the transformer. The resistance is very low. But, nevertheless, it is there. Combining with the first capacitor, you have the front low pass filter. The second low pass filter consists of the resistor between two capacitors and the second capacitor. The low pass filters pass through the dc and attenuate the ripple at 60 Hz or 120 Hz. In circuit operation, when the voltage generated by the transformer is higher than the capacitor voltage, the current flows through the diode charging the capacitors. At the same time, the load resistor drains current from the capacitors. When the amount of draining matches with the charging current, the voltage is stabilized. A sudden increase in load current will decrease the voltage across the capacitor. It will also increase the time period during which the diodes conduct, hence, the ripple. The resistor(s) in the pi-filter are necessary to form low pass filter(s). But, they also dissipate power themselves. Therefore, the linear power supply has limited efficiency. It is fine for low power applications but not for hundred Watt type of applications, such as the computer. The low pass filter provides better ripple filtering with large resistance and capacitance. However, the larger the resistance, the more will be the internal voltage drop and power dissipation. One must strike a balance. The resistor in the pi-filter is between 1-10 Ohm. With a 100-mA current, there is an internal voltage drop up to 1 V and a power dissipation up to 1 W. If one replaces the resistor with an inductor, you will accomplish the same filtering effect without getting into large internal voltage drop and power consumption. Unfortunately, there is no inductor in your kit.

As discussed in the p-n junction diode experiment, there is a special type of diodes called Zener diodes or avalanche diodes. They operate with a reverse bias. They allow a large change of current without much change in the junction voltage. This unique characteristic makes Zener diode a useful voltage reference in the power supply circuit. The Zener diode is connected in parallel with the load. You can treat it as a self-adjusting, variable load. When the real resistor load draws more current, the Zener diode operates at a lower current. When the load resistor draws less current, the Zeder diode increases its current. Therefore, the sum of the Zener diode current and the load current remains pretty much constant. This will maintain the power supply at a constant voltage. The design of the regulator using a Zener diode is very straight forward. It is mostly consideration of current flow, its variation, and power handling capability. One needs to pay special attention to the power handling capability of Zener diode. The junction voltage is much higher than that of the rectifying diode. Yet, the current is pretty much the same. By the way, do you still remember the junction voltage of a rectifying diode? It is of the order of 0.7 V. The Zener diode that you are using may operate at 3.3 V or 5 V. You get a five fold to seven fold increase in power dissipation. Be very careful in selecting the resistance in series with the Zener diode. The typical power handing capability of the Zener diode is 250 mW. Operating at 5 V, you want to limit the current to 50 mA. The output voltage of the pi-filter is determined by the transformer. A 9-V RMS ac signal has a maximum voltage of 12.5 V. This is the voltage of the pi-filter when there is no load attached. Now, you have a simple calculation to perform. Vout of pi-filter minus voltage of the Zener diode divided by the resistor in series with the Zener diode gives you the current. If the current is around 50 mA and the voltage difference is 12.5 - 5V, you need a resistor around 150 Ohm. The power dissipated by the Zener diode will be within the 250 mW limit. How about the power dissipation in the resistor? The voltage drop is 7.5 V and the resistance is 150 Ohm. I am sure that you can calculate the power dissipation by using V square divided by R. Make sure all components operate within their power handling capabilities. Few years ago, I purchased four computer enclosures with power supply from the same company in one batch. Do you know what happened? One went bad shortly after one year. I opened it up and saw two charred regions. The power dissipation exceeded what the components can handle. Eventually, all four failed with the same reason. I thought that I had a good deal. In the end, it was a terrible deal. Who should I blame? Of course, the circuit designer is the culprit. Will you become a good circuit designer? I hope none of you will cause any engineering disaster in your career. It is funny that they always say scientific discovery and engineering disaster. I guess science doesnt cause disaster. Only poor engineering design does. Please note that component values in the laboratory manual and in presentation slides are exemplary. They are not the exact values that you need to use. I hope that you can go through the design process and come up with your own values. This way, you can be sure that you know how the circuit functions. Now you can put it together. Here is the full picture of the linear power supply. Where is the signal ground? Remember, do not connect the ground to the transformer, neither the primary winding nor the secondary winding. Leave the transformer afloat. After completing the power supply circuit, you can now characterize it. Display the waveform at the output using the oscilloscope. Since the waveform is mostly dc with very little ac ripple, the oscilloscope may not trigger properly. Fortunately, there is a trigger source that we can use. Do you remember the line trigger? The line trigger uses the ac power line, 60 Hz signal as the trigger. Since the power supply is also based on the ac power line, this is the best time to use the external, line trigger. You

can easily obtain a stable waveform no matter how small the ripple is. You just need to push few buttons to select the external trigger and use the line source as the external trigger. Please note that you dont need to connect anything to the external trigger input. The power cord provides this line trigger. Remember that the input of the oscilloscope can be ac coupled or dc coupled. In order to see the ripple, you need to pick ac coupling. The ripple can easily be examined in details by increasing the sensitivity. Measure the frequency of the ripple. Is it 120 Hz? Measure the peak-to-peak variation of the ripple. At the same time, use a dc voltage meter to monitor the dc voltage and a current meter in series with the load resistor to monitor the current. Change the load resistance so that the load current is varied from few mA to 100 mA. Find the correlation between the load current to ripple and to the output voltage. You can expect that the output voltage drops as the load current increases while the ripple increases at the same time. A good power supply should have as little the dc voltage drop and not much increase in ripple as the load current increases. The specifications of the dc power supply include the output voltage, the current and power ratings. For example, your computer power supply can provide a number of voltages, such as, 5 V, 3.3 V, 12 V, -5 V and -12 V. It has a power rating of 300-500 W. The combined current of the 5 V and 3.3 V supply should not be above 25-30 A. The ripple is often specified as percentage, e.g., 1.5% ripple. The most prominent effect of ripple is on audio circuits. If you hear a low frequency humming noise, it indicates that there is a ripple. This humming noise is also quite pronounced when you have a ground loop somewhere. Try your computer with an external microphone. You will know what I mean by the humming sound. The performance of the dc power supply can be further enhanced by using a regulator IC. The regulator IC is very easy to connect. You need a crude dc power supply, such as the output of the pi-filter. The circuit is connected as shown in the slide. You only need to attach two moderate capacitors, one at the input and the other at the output. Their values are quite flexible, usually a fraction of microfarad. The only requirement is that the input voltage should be 2-3 V higher than the output voltage. The additional voltage will bias the transistors inside to operate in the linear regime. 7805 with a proper heat sink can handle quite a bit of current. The regulator IC has an internal voltage reference. It also has extensive feedback control. A small deviation at the output triggers an internal adjustment to cancel out any external disturbances such as a transient increase in load current. It is extremely effective in controlling the output voltage. If time permits, you can also take data from the output of the regulator IC using an oscilloscope and changing load resistance. The main purpose of the regulator IC is to provide as stable a dc output voltage as possible with as little residual ac ripple as possible. The output voltage and ripple are pretty much independent of the load current. In other words, there is almost no loading effect. This is accomplished by advanced circuit design. If you ever need a power supply less than 1 A, you should use the regulator IC. It is very easy to use and has superb performance. By the way, 7805 is quite flexible. Using a divider to sense a portion of the output voltage, you can obtain output at 6 V, 9 V, etc. In addition to linear dc power supply, you can find many other power circuits. One is the switching power supply. The switching power supply has a high efficiency approaching 90%. It is widely used by computers. The power supply of computers nowadays can handle 300-500 W. High efficiency can keep it cool. What is inside of the switching power supply? In short, it uses switching circuits running at high

frequency. The switching circuit like CMOS is highly energy efficient. The high operating frequency makes all capacitors and inductors small. If your computer were to have a linear power supply, it would be at least twice as heavy. What else you can find on power sources? There are dc to dc converters offering flexible voltages on the mainboard. As you know, modern cpu can operate anywhere from 0.8 V to 1.5 V. These voltages are derived on the mainboard from the power supply which provides 5 V and 3.3 V by the dc to dc converter. Finally, there are dc to ac inverters. You can connect an inverter to the cigarette lighter in your car to obtain 117 V ac. Do you know that your notebook computer has an inverter inside? Where do you need ac power in your notebook computer? Make a guess. Well, it is the backlight of the LED panel. There is a cold cathode fluorescence tube inside. It may require a couple hundred volts to start and to operate. It runs on an inverter. After finishing the experiment, I encourage you to go through the review. Just describe each circuit, its function, and characteristics. Review is the best way to ensure that you have learned all the essentials.

MICROCONTROLLER 89C52PIN DIAGRAM AND ITS DESCRIPTION:The microcontroller generic part number actually includes a whole family of microcontrollers that have numbers ranging from 8031to 8751 and are available in NChannel Metal Oxide Silicon (NMOS) and Complementary Metal Oxide Silicon (CMOS) construction in a variety of package types.

PIN DIAGRAM:

With 4Kbytes of Flash Programmable and Erasable Read Only Memory (PEROM). The device is manufactured using Atmels high density nonvolatile memory technology and is compatible with the industry standard MCS-51 instruction set and pinout. The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory programmer. By combining a versatile 8-bit CPU with Flash on a monolithic chip, the Atmel AT89C52 is a powerful microcomputer which provides a highly flexible and cost effective solution to many embedded control applications. The AT89C52 provides the following standard features: 4 Kbytes of Flash, 256 bytes of RAM, 32 I/O lines, two 16-bit timer/counters, a five vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator and clock circuitry.

In addition, the AT89C52 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port and interrupt system to continue functioning. The Power Down Mode saves the RAM contents but freezes the oscillator disabling all other chip functions until the next hardware reset.

ARCHITECTURE OF 89C52:

Architecture of 89C52

Port 0:Port 0 is an 8-bit open drain bidirectional I/O port. As an output port each pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as

high-impedance inputs. Port 0 may also be configured to be the multiplexed low order address/data bus during accesses to external program and data memory. In this mode P0 has internal pull-ups. Port 0 also receives the code bytes during Flash programming, and outputs the code bytes during program verification. External pullups are required during program verification

Port 1:Port 1 is an 8-bit bi-directional I/O port with internal pull-ups. The Port 1 output buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins they are pulled high by the internal pull-ups and can be used as inputs. As inputs, Port 1 pins that are externally being pulled low will source current (IIL) because of the internal pull-ups. Port 1 also receives the low-order address bytes during Flash programming and program verification.

Alternate functions of port 1

Port 2:Port 2 is an 8-bit bidirectional I/O port with internal pull ups. The Port 2 output buffers can sink/source four TTL inputs. When 1s are written to Port 2 pins they are pulled high by the internal pull-ups and can be used as inputs. As inputs, Port 2 pins that are externally being pulled low will source current (IIL) because of the internal pull ups. Port 2 emits the high-order address byte during fetches from external program memory and during accesses to external data memory that use 16-bit

addresses (MOVX A,@DPTR). In this application it uses strong internal pull-ups when emitting 1s. During accesses to external data memory that uses 8-bit addresses (MOVX A,@RI), Port 2 emits the contents of the P2 Special Function Register. Port 2 also receives the high-order address bits and some control signals during Flash programming and verification.

Port 3:Port 3 is an 8-bit bidirectional I/O port with internal pull ups. The Port 3 output buffers can sink/source four TTL inputs. When 1s are written to Port 3 pins they are pulled high by the internal pull ups and can be used as inputs. As inputs, Port 3 pins that are externally being pulled low will source current (IIL) because of the pull ups. Port 3 also serves the functions of various special features of the AT89C52 as listed below:

Alternate functions of port 3

RST:RST means RESET; 89C52 uses an active high reset pin. It must go high for two machine cycles. The simple RC circuit used here will supply voltage (Vcc) to reset pin until capacitance begins to charge. At a threshold of about 2.5V, reset input reaches a low level and system begin to run.

Reset Connection

ALE/PROG:Address Latch Enable output pulse for latching the low byte of the address during accesses to external memory. This pin is also the program pulse input (PROG) during Flash programming. In normal operation ALE is emitted at a constant rate of 1/6 the oscillator frequency, and may be used for external timing or clocking purposes. Note, however, that one ALE pulse is skipped during each access to external Data Memory. If desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-disable bit has no effect if the microcontroller is in external execution mode.

THE ON-CHIP OSCILLATORS:Pins XTAL1 and XTAL2 are provided for connecting a resonant network to form an oscillator. The crystal frequency is basic internal clock frequency. The maximum and minimum frequencies are specified from 1to 24MHZ. Program instructions may require one, two or four machine cycles to be executed depending on type of instructions. To calculate the time any particular instructions will take to be executed, the number of cycles C, T = C*12d / Crystal frequency Here, we chose frequency as 11.0592MHZ. This is because,

baud= 2*clock frequency/(32d. 12d[256d-TH1]).The oscillator is chosen to help generate both standard and nonstandard baud rates. If standard baud rates are desired, an 11.0592MHZ crystal should be selected. From our desired standard rate, TH1 can be calculated. The internally implemented value of capacitance is 33 pf.

On-Chip Oscillators

INTERFACING LCD TO THE ICROCONTROLER:This is the first interfacing example for the parallel port. We will star with something simple. This example does not use the Bi-directional feature found on newer ports, thus it should work with most, if no all Parallel Ports. It however does not show the use of the status port as an input. So what are we interfacing? A 16 Character X 2 Line LCD Module to the Parallel Port. These LCD Modules are very common these days, and are quite simple to work with, as all the logic required running them is on board.

Features: Interface with either 4-bit or 8-bit microprocessor. Display data RAM Character generator ROM Display data RAM and character generator RAM may be Accessed by the microprocessor.

Numerous instructions Clear Display, Cursor Home, Display ON/OFF, Cursor Built-in reset circuit is triggered at power ON.

Alphanumeric LCD:

A general purpose alphanumeric LCD, with two lines of 16 characters.

Pin diagram:

In the above table Vcc and Vss are supply pins and VEE (Pin no.3) is used for controlling LCD contrast. Pin No.4 is Rs pin for selecting the register, there are two very important registers are there in side the LCD. The RS pin is used for their selection as follows. If RS=0, the instruction command code register is selected, allowing the user to send data to be displayed on the LCD. R/W is a read or writes Pin, which allows the user to write information to the LCD or read information from it. R/W=1 when reading R/W=0 when writing. The LCD to latch information presented to its data pins uses the enable (E) pin. The 8-bit data pins, D0-D7, are used to send information to the LCD or read the contents of the LCDs internal registers. To display letters and numbers, we must send ASCII codes for the letters A-Z, and number 0 -9 to these pins while making RS=1.

MICRO CONTROLLER FEATURES: Compatible with MCS-51 Products.

8K Bytes of In-System Reprogrammable Flash Memory. Endurance: 1,000 Write/Erase Cycles. Fully Static Operation: 0 Hz to 24 MHz. Three-level Program Memory Lock. 256 x 8-Bit Internal RAM. Three 16-bit Timer/Counters. Eight Interrupt Sources. Programmable Serial Channel. Low Power Idle and Power Down Modes

Basic concept for KeilIntroductionThis tutorial will assist you in writing your first 8051 Assembly language program using the popular Keil Compiler. Keil offers an evaluation package that will allow the assembly and debugging of files 2K or less. This package is freely available at their web site. Keils website address is www.keil.com. The sample program included in the tutorial toggles Ports 1 and 2 on the 8051. The compiled program has been tested using the 8051 board from MicroDigitalEd.com. The program also works with other systems that have Port 1 and 2 available.

Basic Keil Tutorial

1. Open Keil from the Start menu 2. The Figure below shows the basic names of the windows referred in this document

Starting a new Assembler Project1. Select New Project from the Project Menu.

2. Name the project Toggle.a51 3. Click on the Save Button. 4. The device window will be displayed. 5. Select the part you will be using to test with.

6. Double Click on the Dallas Semiconductor. 7. Scroll down and select the DS89C420 Part 8. Click OK

Creating Source File1. Click File Menu and select New.

2. A new window will open up in the Keil IDE.

3. Copy the example to the Right into the new window. This file will toggle Ports 1 and 2 with a delay. 4. Click on File menu and select Save As ORG 0H MOV A, #55H AGAIN: MOV P1, A MOV P2, A ACALL DELAY

CPL A SJMP AGAIN DELAY: MOV R3, #200 OUTER: MOV R2, #0255 INNER: DJNZ R2, INNER DJNZ R3, OUTER RET END

5. Name the file Toggle.a51 6. Click the Save Button

Adding File to the Project1. Expand Target 1 in the Tree Menu

2. Click on Project and select Targets, Groups, Files

3. Click on Groups/Add Files tab 4. Under Available Groups select Source Group 1 5. Click Add Files to Group button

6. Change file type to Asm Source file(*.a*; *.src) 7. Click on toggle.a51 8. Click Add button 9. Click Close Button 10. Click OK button when you return to Target, Groups, Files dialog box

11. Expand the Source Group 1 in the Tree menu to ensure that the file was added to the project.

Creating HEX for the Part1. Click on Target 1 in Tree menu

2. Click on Project Menu and select Options for Target 1 3. Select Target Tab

4. 5. 6. 7.

Change Xtal (Mhz) from 50.0 to 11.0592 Select Output Tab Click on Create Hex File check box Click OK Button

8. Click on Project Menu and select Rebuild all Target Files 9. In the Build Window it should report 0 Errors (s), 0 Warnings 10. You are now ready to Program your Part

Testing Program in Debugger1. Comment out line ACALL DELAY by placing a Semicolon at the beginning. This will allow you to see the port change immediately. 2. Click on the File Menu and select Save

3. Click on Project Menu and select Rebuild all Target Files 4. In the Build Window it should report 0 Errors (s), 0 Warnings

5. Click on Debug Menu and Select Start/Stop Debug Session

Running the Keil Debugger1. The Keil Debugger should be now be Running.

2. Click on Peripherals. Select I/O Ports, Select Port 1

3. A new window should port will pop up. This represent the Port and Pins

4. Step through the code by pressing F11 on the Keyboard. The Parallel Port 1 Box should hange

you completely step through the code. 5. To exit out, Click on Debug Menu and Select Start/Stop Debug Session