Search Your Query

Custom Search

Monday, 30 May 2011

8051 Microcontroller port programming


There are four ports P0, P1, P2  and  P3 each  use  8 pins,  making  them 8-bit  ports. All the ports upon  RESET are configured as output, ready to be used as output ports. To use any of these ports as an input port, it must be programmed.
Pin configuration of 8051/8031 microcontroller.
Pin configuration of 8951
Pin configuration of 8951
Port 0: Port 0 occupies a total of 8 pins (pins 32-39) .It can be used for input or output. To use the pins of port 0 as both input and output ports, each pin must be connected externally to a 10K ohm pull-up resistor. This is due to the fact that P0 is an open drain, unlike P1, P2, and P3.Open drain  is a term used for MOS chips in the same way that open collector is used for TTL chips. With external pull-up resistors connected upon reset, port 0 is configured as an output port. For example, the following code will continuously send out to port 0 the alternating values 55H and AAH
MOV A,#55H
BACK:  MOV P0,A
ACALL DELAY
CPL A
SJMP BACK
Port 0 as Input : With resistors connected to port 0, in order to make it an input, the port must be programmed by writing 1 to all the bits. In the following code, port 0 is configured first as an input port by writing 1′s to it, and then data is received from the port and sent to P1.
8051 I/O Ports
8051 I/O Ports
MOV A,#0FFH         ; A = FF hex
MOV P0,A                ; make P0 an input port
BACK: MOV A,P0               ;get data from P0
MOV P1,A                ;send it to port 1
SJMP BACK
Dual role of port 0: Port 0 is also designated as AD0-AD7, allowing it to be used for both address and data. When connecting an 8051/31 to an external memory, port 0 provides both address and data. The 8051 multiplexes address and data through port 0 to save pins. ALE indicates if P0 has address or data. When ALE = 0, it provides data D0-D7, but when ALE =1 it has address and data with the help of a 74LS373 latch.
Port 1: Port 1 occupies a total of 8 pins (pins 1 through 8). It can be used as input or output. In contrast to port 0, this port does not need any pull-up resistors since it already has pull-up resistors internally. Upon reset, Port 1 is configured as an output port. For example, the following code will continuously send out to port1 the alternating values 55h  & AAh

MOV A,#55H                    ; A = 55 hex

BACK: MOV P1,A                        ;send it to Port 1
ACALL DELAY                  ;call delay routine
CPL A                               ;make A=0
SJMP BACK
Port 1 as input: To make port1 an input port, it must programmed as such by writing 1 to all its bits. In the following code port1 is configured first as an input port by writing 1’s to it, then data is received from the port and saved in R7 ,R6 & R5.
MOV A,#0FFH   ;A=FF HEX
MOV P1,A         ;make P1 an input port by writing all 1’s to it
MOV A,P1         ;get data from P1
MOV R7,A         ;save it in register R7
ACALL DELAY   ;wait
MOV  A,P1        ;get another data from P1
MOV R6,A         ;save it in register R6
ACALL DELAY   ;wait
MOV  A,P1        ;get another data from P1
MOV R5,A         ;save it in register R5
Port 2 : Port 2 occupies a total of 8 pins (pins 21- 28). It can be used as input or output. Just like P1, P2 does not need any pull-up resistors since it already has pull-up resistors internally. Upon reset,Port 2 is configured as an output port. For example, the following code will send out continuously to port 2 the alternating values 55h and AAH. That is all the bits of port 2 toggle continuously.
MOV A,#55H                    ; A = 55 hex
BACK:  MOV P2,A                        ;send it to Port 2
ACALL DELAY                  ;call delay routine
CPL A                               ;make A=0
SJMP BACK
Port 2 as input : To make port 2 an input, it must programmed as such by writing 1 to all its bits. In the following code, port 2 is configured first as an input port by writing 1’s to it. Then data is received from that port and is sent to P1 continuously.
MOV A,#0FFH         ;A=FF hex
MOV P2,A                ;make P2 an input port by writing all 1’s to it
BACK: MOV A,P2     ;get data from P2
MOV P1,A                ;send it to Port1
SJMP BACK             ;keep doing that
Dual role of port 2 : In systems based on the 8751, 8951, and DS5000, P2 is used as simple I/O. However, in 8031-based systems, port 2 must be used along with P0 to provide the 16-bit address for the external memory. As shown in pin configuration 8051, port 2 is also designed as A8-A15, indicating the dual function. Since an 8031 is capable of accessing 64K bytes of external memory, it needs a path for the 16 bits of the address. While P0 provides the lower 8 bits via A0-A7, it is the job of P2 to provide bits A8-A15 of the address. In other words, when 8031 is connected to external memory, P2 is used for the upper 8 bits of the 16 bit address, and it cannot be used for I/O.
Port 3 : Port 3 occupies a total of 8 pins, pins 10 through 17. It can be used as input or output. P3 does not need any pull-up resistors, the same as P1 and P2 did not. Although port 3 is configured as an output port upon reset. Port 3 has the additional function of providing some extremely important signals such as interrupts. This information applies both 8051 and 8031 chips.
Functions of port 3
Functions of port 3
P3.0 and P3.1 are used for the RxD and TxD serial communications signals. Bits P3.2 and P3.3 are set aside for external interrupts. Bits P3.4 and P3.5 are used for timers 0 and 1. Finally P3.6 and P3.7 are used to provide the WR and RD signals of external memories connected in 8031 based systems.
Read-modify-write feature : The ports in the 8051 can be accessed by the read-modify-write technique. This feature saves many lines of code by combining in a single instruction all three action of (1) reading the port, (2) modifying it, and (3) writing to the port. The following code first places 01010101 (binary) into port 1. Next, the instruction “XLR P1,#0FFH” performs an XOR logic operation on P1 with 1111 1111 (binary), and then writes the result back into P1.
MOV P1,#55H      ;P1=01010101
AGAIN: XLR P1,#0FFH     ;EX-OR P1 with 1111 1111
ACALL DELAY
SJMP AGAIN
Notice that XOR of 55H and FFH gives AAH. Likewise, the XOR of AAH and FFH gives 55H.
Single bit  addressability of ports:  There are times that we need to access only 1 or 2 bits of the port instead of the entire 8 bits. A powerful feature of 8051 I/O ports is their capability to access individual bits of the port without altering the rest of the bits in that port.
For example, the following code toggles the bit p1.2 continuously.
BACK:  CPL P1.2                   ;complement p1.2 only
ACALL DELAY
SJMP BACK
Notice that P1.2 is the third bit of P1, since the first bit is P1.0, the second bit is P1.1, and so on. Notices in example of those unused portions of port1 are undisturbed. Table bellow shows the bits of 8051 I/O ports. This single bit addressability of I/O ports is one of the features of the 8051 microcontroller.
Addressing bits

Interfacing 7-Segment Display using lookup table


The Light Emitting Diode (LED), finds its place in many applications in this modern electronic fields. One of them is the Seven Segment Display. Seven-segment displays contains the arrangement of the LEDs in “Eight” (8) passion, and a Dot (.) with a common electrode, lead (Anode or Cathode). The purpose of arranging it in that passion is that we can make any number out of that by switching ON and OFF the particular LED’s. Here is the block diagram of the Seven Segment LED arrangement.
Pin configuration of a seven segment display:
7 segment pin configuration
LED’s are basically of two types:
  1. Common Cathode (CC)
    All the 8 anode legs uses only one cathode,  which is common.
  2. Common Anode (CA)
    The common leg for all the cathode is of Anode type.
For the discussion purpose, we use CC LED, where by just reversing the logical voltages we can implement the same for CA LED also.
In a CC LED, all the 8 legs (‘a’ through ‘h’) are of anode type and the common cathode will be connected to the GND of the supply. By energizing any of the legs with +5 Volts will lead to switch the correspondent segment ON. In the microprocessor binary system, 0Volts will be considered as Binary 0, and 5Volts will be considered as Binary1. Considering these two condition, we can make an arrangement as the microcontroller gives OUT the 0s and 1s through its ports, which is connected to the 8 legs of the LED. Of course, we can control the Port Output; implicitly we can Switch-ON required legs of the display.
There 2 methods of interfacing LED with the Microcontroller Intel 8051/8951.
  1. Using lookup table. This uses 7 output pins of microcontroller
  2. Using 7447 decoder. This method uses 4 output pins of microcontroller
The difference between the two main methods is simple and clear. In both the cases, microcontroller communicates with external world through its ports. But, in the 1st case, we connect all the 8 pins of the port directly to the LED and control the voltage through the ports manually to display the desired number.  But, in the second case, we send the BCD of the number that we wanted to display to a middleware IC 7447, the BCD to LED code converter, which by itself gives out the correspondent 7 segment codes to the LED.
Here we explain using lookup table. Click here for the method “using 7447 decoder”
Using Lookup Table:
As we discussed, this method uses the port of the microcontroller to display the desired number. The common cathode pin is connected to GND by external wire, if it is the CC LED and in the case of the common Anode LED, the Anode pin is connected to +Vcc. Here, other pins of the LED are connected to Port 2 of 8951. A table will be prepared which relates the BCD code to the LED display code (pattern). We call it as Lookup table. The table below explains how we construct the Lookup table. Circuit diagram is given below.
Circuit diagram for Common Anode 7-Segment Display:

7 segment circuit comon anode
Circuit diagram for Common Cathode 7-Segment Display:

7 segment circuit comon cathode
























Calculation of lookup table as follows:
The lookup table contains the input pattern for the LED legs, to display the corresponding digits.
The table shows the seven segment requirement pattern to display the Hex number, with the Seven segment conversion.
For example, Let us consider the display of the number 0, where we need to switch ON all the LEDs which are there at the boundary. i.e. for a CC LED, we  should supply 5 volts to these LEDs. The 6 LEDs (‘a’ through ‘f’) should get binary 1, the dot and the (middle) hyphen segment should get 0Volts or the binary Zero. Effectively the Seven segment pattern code will be (0011 1111) 3Fh. That is what we OUT through the port pins.
For a Common Anode LED, the display pattern will be the complement of that of Common Cathode pattern.
For Common Cathode :
Common Cathode Lookup Table
For common Anode:
Common Anode Lookup Table
ASM program:
This program displays characters 0 through 9 on seven-segment display connected directly to the port 2 of the microcontroller Intel8951.
Here, the look up table is stored from the memory location 19H of the microcontroller. The first set is the pattern code for common anode followed by the common cathode.

//Look up table for common Anode
 
org 0000
mov r0,#19h
mov @r0,#0c0fh // Code for the digit 0
inc r0
mov @r0,#0f9h // Code for the digit 1
inc r0
mov @r0,#0a4h // Code for the digit 2
inc r0
mov @r0,#0b0h // Code for the digit 3
inc r0
mov @r0,#099h // Code for the digit 4
inc r0
mov @r0,#092h // Code for the digit 5
inc r0
mov @r0,#082h // Code for the digit 6
inc r0
mov @r0,#0f8h // Code for the digit 7
inc r0
mov @r0,#0f0h // Code for the digit 8
inc r0
mov @r0,#98h // Code for the digit 9
 
//Look up table for common Cathode
 
org 0000
mov r0,#19h
mov @r0,#0bfh
inc r0
mov @r0,#86h
inc r0
mov @r0,#0dbh
inc r0
mov @r0,#0cfh
inc r0
mov @r0,#0e6h
inc r0
mov @r0,#0edh
inc r0
mov @r0,#fdh
inc r0
mov @r0,#87h
inc r0
mov @r0,#0ffh
inc r0
mov @r0,#0e7h
 
again: mov a,#00h ; Start form zero
up: mov r2,a
mov r0,#19h ; Load starting address of luck up table
add a,r0
mov r0,a
mov a,@r0 ; Get the LED equivalent
mov p2,a ; Move to Port 2
 
mov r3,#255 ; Delay
D1: mov r1,#255
D: djnz r1,D
djnz r3,D1
mov a,r2
inc a
cjne a,#0ah,up
sjmp again

To find the sum of digits


Here is the program to find the sum of the digits of the entered number. Main idea in this program is to slice down the given number into digits and to operate on them.
Logic : The program asks the user to enter the number, to find out the sum of its digits. Sets the flag ‘sum’ to zero, implies that sum till now is Nil. Stores the entered number as Num. The while loop slices the number into digits. In each iteration, the current digit gets added up to the flag ‘Sum’ . Finally it prints out the number.
The same logic can be implemented for other programs too, where the situation comes to slice up the given number, as in the case of  Reversing the number.
#include<stdio.h>
#include<math.h>
void main()
{
long int num,sum = 0,dig;
clrscr();
printf(“nnt ENTER A NUMBER…: “);
scanf(“%ld”,&num);
while(num>0)
{
dig = num % 10;
sum = sum + dig;
num = num / 10;
}
printf(“nt SUM OF DIGITS IS…: %ld”, sum);
getch();
}

Digital Code lock using AT89C2051


Here is a project called ‘Digital Code Lock using AT89C2051′. LCD is used for display and a keyboard is used to input  the keys. This project source code is written in C. Both the C files and hex files are given for download.
A Brief Description:
This a simple project with efficient hacking prevention from Brute Force etc. The basic user lock is of 5 Digits and Master Lock is of 10 digits so its not easy for an intruder to break the lock unless you keep the code simple.
The input is taken from a 4×3 Keypad (please see the schematic for more information) and Display the user input on a 2×16 LCD. A pin is assigned as output for activating and deactivating the lock. For demonstration i have connected an LED to that pin.
From user side:
The user has two options either he/she can use its own 5 digit code or use the default 5 digit code. If user has to do setup his own code, then he has to enter “12345″ and press ‘#’. After this.. controller will ask for 10 Digit master password which is preprogrammed in the controller. Entering master lock, user can enter the new 5 digit code for the lock and press ‘#’ to save it.
Using the Keypad:
Keypad has 12 keys (4×3) starting from 1,2,3,4,5,6,7,8,9,*,0,# (please see the schematic for layout). Numeric keys are used for entering numbers. ‘*’ is used as the Cancel key and ‘#’ is used as the Enter key.
Circuit Diagram:
Circuit diagram of Digital Code lock using AT89C2051
Circuit diagram of Digital Code lock using AT89C2051
Download File Information:
  1. LCD.C – 4-Bit LCD Drivers
  2. LCD.H – LCD function prototypes and other declerations
  3. Lock.C – code for lock functioning
  4. LOCK.H – lock function declarations
  5. KEYPAD.C – Keypad drivers
  6. KEYPAD.H – Function declarations
  7. DELAY.C – Delay Functions
  8. DELAY.H – Function Prototypes only
  9. MAIN.C – Main function!
  10. Digital Code Lock Schematic – PDF file of orcad schematic
Download the source codes by clicking here

Programmable number lock system


Programmable number lock system is a high security number lock system that can be used to lock electronic devices. The present system is very user friendly. This system is a combination of software and hardware at its best. We have used a 8051 microcontroller kit for interfacing our system.
In the present design we can activate or deactivate 9 devices. Each device is locked using a 4 digit code (password). The code can be set as per the user’s desire, hence the name ‘ PROGRAMMABLE ‘. For the device to be activated (unlocked), the user should enter the code that had been entered when the device was locked. In case the user enters the wrong code a silent alarm will be activated.
Introduction to Programmable number lock system:
The system has three units, namely:
  1. Keyboard unit.
  2. Display unit.
  3. Control unit.
The keyboard unit consists of 9 number keys, 1 unlock key and 1 lock key. These are all push button switches. This unit is used to select the desired device and to enter the codes into the system. It is also used to request the system to lock/unlock the selected device.
The display section contains 5 seven segment display. This unit displays the device number and the code entered. This section is detachable. If detached it does not affect the working of the whole system. This unit also contains password reset button and an LED to indicate the error when the device is   already locked and user wants to lock the device again. The error indicator also indicates an error when the system is already unlocked and the user tries to unlock the same.
The control unit  is the heart of our system. It contains the necessary circuitry for the control of the device .This unit controls 9 devices, which is lock/unlock  by selecting it using the keyboard and entering the password. If the code entered to unlock the device is wrong, then a silent alarm is triggered .The keyboard unit and the display unit are connected to this unit.
All these three units are merged together to form the whole system.
Model of Programmable number lock system
Model of Programmable number lock system
Block diagram of Programmable number lock system:
 Block diagram of Programmable number lock system:
Block diagram of Programmable number lock system:
Working of the system:
When the system  is initially installed the reset button is pressed. This key is present in the control unit. This unlocks all the devices. This is to avoid undesired functioning of the system.
To lock a particular device the device number is selected using the keyboard. Once the device is selected the user has to press the lock key present in the keyboard. Now the device waits for the user to enter the the code. The user can enter a 4 digit number using the keyboard as per his desire. Once all the 4 digits are entered the system electronically locks the selected device.
In the same manner to unlock a particular device, the device number is entered using the keyboard. Once the device number is selected the code for the selected device is entered. If the entered code matches the code that had been entered while that particular device was locked then the selected device will be activated (unlocked). If the codes do not match each other a silent alarm will be triggered (a LED placed in the control section. Shown in figure 3).An error indicator (placed in the display section) is provided if any user tries to lock a device which has already been locked or vice versa.
If the user is half way entering the code or has done an error while entering the code and wants to start over all again then a reset button is provided in the display section. By pressing this button the user can start from entering the device number and so on.
The number of devices which the system can control can be increased by addition of a few components in the control unit. More security can be achieved by increasing the number of digits in the code. This can be done by minor changes in the program. The system uses the internal RAM of the 8051 to store the code and hence puts a lower limit to the number of digits in the code and also the number of devices the system can control. Once the system is installed only the display unit and keyboard unit will be accessible to the user. Access to the control unit should be provided only to an official personal since it contains the system  reset button.
System:
In this section we will be explaining the hardware design these units individually. Each unit description is accompanied by its circuit diagram.
KEYBOARD UNIT :
The keyboard used in this system is an encoder type. It uses IC 74147 priority encoder to convert the entered the digits to its corresponding binary codes. IC 74147 has a active low inputs as well as active low outputs (for more details please refer the corresponding data sheets). Each of the pins are activated using push to on switches. These switches ground the encoder inputs to activate that particular number giving the equivalent BCD code. This is then given as input to IC 7404 which is an inverter. To avoid loading of 7404 by the later stages transistor switches are provided to each of its outputs. The circuit diagram of the keyboard is as given in the next section.
Circuit diagram of Keyboard section
Circuit diagram of Keyboard section
DISPLAY UNIT :
The logic used here is shift and display i.e. when the next number is entered the previous number is shifted to the left by one unit and then the next number is displayed. To achieve this we have used IC 7496 which is a 5–bit shift register (for more details please refer the corresponding data sheets). The data lines from control section are given serially to the registers as shown in the circuit. The clock to these registers is given by the program every time a button on the keyboard is pressed. The shifting used here is parallel shifting. The outputs of the registers are given to CD4511 BCD to seven segment decoder. The seven segment display used are common cathode type since the output of the decoder is high when activated. This section consists of a reset switch which is used to reset the display.
Circuit diagram of Keyboard section
Circuit diagram of Keyboard section
Control unit:
Circuit diagram of Control Unit
Circuit diagram of Control Unit
The program codes for this project is given in the next page
APPLICATION:
The ‘Electronic device number lock’ system is a high security system.The main application kept in mind during the design of this system is to secure expensive electronic devices and machinery. The access to such devices can be restricted to particular users only. The system is highly secured since the code can be changed every time the user locks it.
This can also be used an physical lock by using solenoid and thus can be used to lock safes in banks or other institutions.
Regular electronic number lock available in the market can lock/unlock just one device, but this design can lock/unlock up to nine devices.
The program used for the operation of this system is as follows :
;***************************************************************;
PROCEDURE OF WAIT
;***************************************************************
org 8500h
wait:  push dph
push dpl
push r0
push r1
mov dptr,#2042h     ;input data from PORT C
wi:     movx a,@dptr
mov r2,a
anl a,#20h
jz cont                      ;check for interrupt from display unit
jmp start
cont:  mov a,r2
anl a,#0fh                ;to check whether any key is pressed
jz wi
mov r0,#75
lcall 6798h
mov dptr,#2042h
here:  movx a,@dptr          ;wait for the key to be realesed
jnz here
mov dptr,#2040h     ;sending a pulse to the display section
mov a,r2
movx @dptr,a
mov a,#00h
mov dptr,#2041h
movx @dptr,a
mov a,#40h
movx @dptr,a
mov a,r2
mov r0,#75
lcall 6798h
pop r1
pop r0
pop dpl
pop dph
ret
;***************************************************************;
STORING  AND RETRIVING OF PASS WORD
;***************************************************************
org 8550h
scan:  mov r0,#04h
mov dptr,#2042h
one:  movx a,@dptr      ;check for lock or unlock buttons
anl a,#0c0h
jz one
ret
lock:  lcall  wait             ;storing of pass word in given location
mov @r1,a
inc r1
djnz r0,lock
lcall out
ret
unlock: clr 0ah
call wait
mov a,@r1
xrl a,r2                 ;comparing the entered and the stored code
jz match
setb 0ah              ;in case of mismatch set error bit
match: inc r1
djnz r0,unlock
jnb 0ah,go
mov a,#20h
push dptr
mov dptr,#2040h
movx @dptr,a
push r0
push r1
mov r0,#ffh
lcall 6798h
pop r1
pop r0
mov a,#00h
movx @dptr,a
pop dptr
jmp not
go:    lcall out
not:   ret
;***************************************************************;
TO ACCEPT THE DEVICE NUMBER
;***************************************************************
org 9000h
mov sp,#05fh
main:  clr 01h                        ;clearing all the device flags
clr 02h
clr 03h
clr 04h
clr 05h
clr 06h
clr 07h
clr 08h
clr 09h
setb ie.7
setb ie.2
start: mov a,#89h                ;C as ip,A and B as op
mov dptr,#2043h
movx @dptr,a
mov r7,#05h               ;clearing the display section
rss:   mov dptr,#2040h
mov a,#00h
movx @dptr,a
mov a,#00h
mov dptr,#2041h
movx @dptr,a
mov a,#40h
movx @dptr,a
djnz r7,rss
lcall wait
cjne a,#01h,nxt2
jmp dev1
nxt2: cjne a,#02h,nxt3
jmp dev2
nxt3: cjne a,#03h,nxt4
jmp dev3
nxt4: cjne a,#04h,nxt5
jmp dev4
nxt5: cjne a,#05h,nxt6
jmp dev5
nxt6: cjne a,#06h,nxt7
jmp dev6
nxt7: cjne a,#07h,nxt8
jmp dev7
nxt8: cjne a,#08h,nxt9
jmp dev8
nxt9: cjne a,#09h,start
jmp dev9
;***************************************************************;
SELECTED DEVICE ACTIVATION
;***************************************************************
org 9200h
dev1: mov r1,#30h               ;Loading the address of the password
mov r3,#01h                ;device no. used to give to the decoder
lcall scan
cjne a,#80h,unlock1    ;check for the lockunlock pressed
jmp lock1
unlock1: jnb 01h,error1         ;generating error if the selected device is already
;activated
lcall unlock
jb 0ah,hr1
clr 01h                          ;clear lockunlock flag
hr1:   jmp start
lock1: jb 01h,error1
lcall lock
setb 01h                       ;set lockunlock flag
jmp start
error1: mov a,#40h              ;activating the error LED
mov dptr,#2040h
movx @dptr,a
push dptr
push r0
push r1
mov r0,#ffh
lcall 6798h
pop r1
pop r0
pop dptr
jmp start
;***************************************************************
dev2: mov r1,#035h
mov r3,#02h
lcall scan
cjne a,#80h,unlock2
jmp lock2
unlock2: jnb 02h,error2
lcall unlock
jb 0ah,hr2
clr 02h
hr2:   jmp start
lock2: jb 02h,error2
lcall lock
setb 02h
jmp start
error2: mov a,#40h
mov dptr,#2040h
movx @dptr,a
push dptr
push r0
push r1
mov r0,#ffh
lcall 6798h
pop r1
pop r0
pop dptr
jmp start
;***************************************************************
dev3: mov r1,#03ah
mov r3,#03h
lcall scan
cjne a,#80h,unlock3
jmp lock3
unlock3:jnb 03h,error3
lcall unlock
jb 0ah,hr3
clr 03h
hr3: jmp start
lock3:jb 03h,error3
lcall lock
setb 03h
jmp start
error3: mov a,#40h
mov dptr,#2040h
movx @dptr,a
push dptr
push r0
push r1
mov r0,#ffh
lcall 6798h
pop r1
pop r0
pop dptr
jmp start
;***************************************************************
dev4: mov r1,#040h
mov r3,#04
lcall scan
cjne a,#80h,unlock4
jmp lock4
unlock4:jnb 04h,error4
lcall unlock
jb 0ah,hr4
clr 04h
hr4:   jmp start
lock4:jb 04h,error4
lcall lock
setb 04h
jmp start
error4: mov a,#40h
mov dptr,#2040h
movx @dptr,a
push dptr
push r0
push r1
mov r0,#ffh
lcall 6798h
pop r1
pop r0
pop dptr
jmp start
;***************************************************************
dev5: mov r1,#045h
mov r3,#05h
lcall scan
cjne a,#80h,unlock5
jmp lock5
unlock5:jnb 05h,error5
lcall unlock
jb 0ah,hr5
clr 05h
hr5:   jmp start
lock5:jb 05h,error5
lcall lock
setb 05h
jmp start
error5: mov a,#40h
mov dptr,#2040h
movx @dptr,a
push dptr
push r0
push r1
mov r0,#ffh
lcall 6798h
pop r1
pop r0
pop dptr
jmp start
;***************************************************************
dev6: mov r1,#04ah
mov r3,#06h
lcall scan
cjne a,#80h,unlock6
jmp lock6
unlock6:jnb 06h,error6
lcall unlock
jb 0ah,hr6
clr 06h
hr6:   jmp start
lock6:jb 06h,error6
lcall lock
setb 06h
jmp start
error6: mov a,#40h
mov dptr,#2040h
movx @dptr,a
push dptr
push r0
push r1
mov r0,#ffh
lcall 6798h
pop r1
pop r0
pop dptr
jmp start
;**************************************************************
dev7: mov r1,#050h
mov r3,#07h
lcall scan
cjne a,#80h,unlock7
jmp lock7
unlock7:jnb 07h,error7
lcall unlock
jb 0ah,hr7
clr 07h
hr7:jmp start
lock7:jb 07h,error7
lcall lock
setb 07h
jmp start
error7: mov a,#40h
mov dptr,#2040h
movx @dptr,a
push dptr
push r0
push r1
mov r0,#ffh
lcall 6798h
pop r1
pop r0
pop dptr
jmp start
;***********************************************************
dev8: mov r1,#055h
mov r3,#08h
lcall scan
cjne a,#80h,unlock8
jmp lock8
unlock8:jnb 08h,error8
lcall unlock
jb 0ah,hr8
clr 08h
hr8:   jmp start
lock8:jb 08h,error8
lcall lock
setb 08h
jmp start
error8: mov a,#40h
mov dptr,#2040h
movx @dptr,a
push dptr
push r0
push r1
mov r0,#ffh
lcall 6798h
pop r1
pop r0
pop dptr
jmp start
;***********************************************************
dev9: mov r1,#05ah
mov r3,#09h
lcall scan
cjne a,#80h,unlock9
jmp lock9
unlock9:jnb 09h,error9
lcall unlock
jb 0ah,hr9
clr 09h
hr9: jmp start
lock9:jb 09h,error9
lcall lock
setb 09h
jmp start
error9: mov a,#40h
mov dptr,#2040h
movx @dptr,a
push dptr
push r0
push r1
mov r0,#ffh
lcall 6798h
pop r1
pop r0
pop dptr
jmp start
;***********************************************************
;                    OUTPUT SECTION
;***********************************************************
org 0a000h
out:   mov a,r3         ;loading the device number
mov dptr,#2041h
movx @dptr,a
ret
;***********************************************************
This program is assembled using DASM assembler and the hex file is downloaded to the 8051 microcontroller kit.

Related Posts Plugin for WordPress, Blogger...