0% found this document useful (0 votes)
6 views11 pages

Source Program:: 2. Traffic Light Control

The document contains various assembly language programs for an 8085 microprocessor, including counting bits, controlling traffic lights, separating even numbers, calculating squares and square roots, finding two's complement, counting positive/negative numbers, calculating factorials, and converting HEX to decimal and binary. Each program is accompanied by a source code and a brief description of its functionality. Additionally, there are hardware interfacing details for the traffic light control system.

Uploaded by

VidhyaVishali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views11 pages

Source Program:: 2. Traffic Light Control

The document contains various assembly language programs for an 8085 microprocessor, including counting bits, controlling traffic lights, separating even numbers, calculating squares and square roots, finding two's complement, counting positive/negative numbers, calculating factorials, and converting HEX to decimal and binary. Each program is accompanied by a source code and a brief description of its functionality. Additionally, there are hardware interfacing details for the traffic light control system.

Uploaded by

VidhyaVishali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

1.

Write a program to count number of l's in the contents of D register and store the count
in the B register.
(2200H) = 04
(2201H) = 34H
(2202H) = A9H
(2203H) = 78H
(2204H) =56H
Result = (2202H) = A9H

Source program :
· MVI B, 00H
· MVI C, 08H
· MOV A, D
· BACK: RAR
· JNC SKIP
· INR B
· SKIP: DCR C
· JNZ BACK
· HLT

2. Traffic Light Control


Statement: Design a microprocessor system to control traffic lights. The traffic light
arrangement is as shown in Fig. The traffic should be controlled in the following manner.
1) Allow traffic from W to E and E to W transition for 20 seconds. 2) Give transition period
of 5 seconds (Yellow bulbs ON) 3) Allow traffic from N to 5 and 5 to N for 20 seconds 4)
Give transition period of 5 seconds (Yellow bulbs ON) 5) Repeat the process.

HARDWARE FOR TRAFFIC LIGHT CONTROL

Fig. shows the interfacing diagram to control 12 electric bulbs. Port A is used to control
lights on N-S road and Port B is used to control lights on W-E road. Actual pin connections
are listed in Table 1 below.

The electric bulbs are controlled by relays. The 8255 pins are used to control relay on-off
action with the help of relay driver circuits. The driver circuit includes 12 transistors to
drive 12 relays. Fig. also shows the interfacing of 8255 to the system.

INTERFACING DIAGRAM
SOFTWARE FOR TRAFFIC LIGHT CONTROL

Source Program 1:
· MVI A, 80H : Initialize 8255, port A and port B
· OUT 83H (CR) : in output mode
· START: MVI A, 09H
· OUT 80H (PA) : Send data on PA to glow R1 and R2
· MVI A, 24H
· OUT 81H (PB) : Send data on PB to glow G3 and G4
· MVI C, 28H : Load multiplier count (40ıο) for delay
· CALL DELAY : Call delay subroutine
· MVI A, 12H
· OUT (81H) PA : Send data on Port A to glow Y1 and Y2
· OUT (81H) PB : Send data on port B to glow Y3 and Y4
· MVI C, 0AH : Load multiplier count (10ıο) for delay
· CALL: DELAY : Call delay subroutine
· MVI A, 24H
· OUT (80H) PA : Send data on port A to glow G1 and G2
· MVI A, 09H
· OUT (81H) PB : Send data on port B to glow R3 and R4
· MVI C, 28H : Load multiplier count (40ıο) for delay
· CALL DELAY : Call delay subroutine
· MVI A, 12H
· OUT PA : Send data on port A to glow Y1 and Y2
· OUT PB : Send data on port B to glow Y3 and Y4
· MVI C, 0AH : Load multiplier count (10ıο) for delay
· CALL DELAY : Call delay subroutine
· JMP START

Delay Subroutine:
· DELAY: LXI D, Count : Load count to give 0.5 sec delay
· BACK: DCX D : Decrement counter
· MOV A, D
· ORA E : Check whether count is 0
· JNZ BACK : If not zero, repeat
· DCR C : Check if multiplier zero, otherwise repeat
· JNZ DELAY
RET : Return to main program
Separate even numbers from given numbers
Statement: Write an assembly language program to separate even numbers from the
given list of 50 numbers and store them in the another list starting from 2300H. Assume
starting address of 50 number list is 2200H.

Source program :
· LXI H, 2200H : Initialize memory pointer l
· LXI D, 2300H : Initialize memory pointer2
· MVI C, 32H : Initialize counter
· BACK:MOV A, M : Get the number
· ANI 0lH : Check for even number
· JNZ SKIP : If ODD, don't store
· MOV A, M : Get the number
· STAX D : Store the number in result list
· INX D : Increment pointer 2
· SKIP: INX H : Increment pointer l
· DCR C : Decrement counter
· HLT : Stop

Find the square of given number


2200H = 4H
2201H= 9AH
2202H= 52H
2203H= 89H
2204H= 3FH
Result = 89H + 3FH = C8H
2300H= H Lower byte
2301H = H Higher byte
· LXI H, 6200H : Initialize lookup table pointer
· LXI D, 6100H : Initialize source memory pointer
· LXI B, 7000H : Initialize destination memory pointer
· BACK: LDAX D : Get the number
· MOV L, A : A point to the square
· MOV A, M : Get the square
· STAX B : Store the result at destination memory location
· INX D : Increment source memory pointer
· INX B : Increment destination memory pointer
· MOV A, C
· CPI 05H : Check for last number
· JNZ BACK : If not repeat
· HLT : Terminate program execution

Find the Square Root of a given number


· LDA 4200H : Get the given data(Y) in A register
· MOV B,A : Save the data in B register
· MVI C,02H : Call the divisor(02H) in C register
· CALL DIV : Call division subroutine to get initial value(X) in D-reg
· REP: MOV E,D : Save the initial value in E-reg
· MOV A,B : Get the dividend(Y) in A-reg
· MOV C,D : Get the divisor(X) in C-reg
· CALL DIV : Call division subroutine to get initial value(Y/X) in D-reg
· MOV A, D : Move Y/X in A-reg
· ADD E : Get the((Y/X) + X) in A-reg
· MVI C, 02H : Get the divisor(02H) in C-reg
· CALL DIV : Call division subroutine to get ((Y/X) + X)/2 in D-reg.This is
XNEW
· MOV A, E : Get Xin A-reg
· CMP D : Compare X and XNEW
· JNZ REP : If XNEW is not equal to X, then repeat
· STA 4201H : Save the square root in memory
· HLT : Terminate program execution

Subroutine Program:
· DIV: MVI D, 00H : Clear D-reg for Quotient
· NEXT:SUB C : Subtract the divisor from dividend
· INR D : Increment the quotient
· CMP C : Repeat subtraction until the
· JNC NEXT : divisor is less than dividend
· RET : Return to main program
Note: The square root can be taken by an iterative technique. First, an initial value is
assumed. Here, the initial value of square root is taken as half the value of given number.
The new value of square root is computed by using an expression XNEW = (X + Y/X)/2
where, X is the initial value of square root and Y is the given number. Then, XNEW is
compared with initial value. If they are not equal then the above process is repeated until X
is equal to XNEW after taking XNEW as initial value. (i.e., X ←XNEW)

Finding Two's complement of a number


Sample problem:
(4200H) = 55H
Result = (4300H) = AAH + 1 = ABH

Source program:
LDA 4200H : Get the number
CMA : Complement the number
ADI, 01 H : Add one in the number
STA 4300H : Store the result
HLT : Terminate program execution

Count number of one's in a number

(2200H) = 04
(2201H) = 34H
(2202H) = A9H
(2203H) = 78H
(2204H) =56H
Result = (2202H) = A9H
Source program :
· MVI B, 00H
· MVI C, 08H
· MOV A, D
· BACK: RAR
· JNC SKIP
· INR B
· SKIP: DCR C
· JNZ BACK
· HLT

Find the number of negative, zero and positive numbers


Statement: A list of 50 numbers is stored in memory, starting at 6000H. Find number
of negative, zero and positive numbers from this list and store these results in memory
locations 7000H, 7001H, and 7002H respectively.

Source program :
· LXI H, 6000H : Initialize memory pointer
· MVI C, 00H : Initialize number counter
· MVI B, 00H : Initialize negative number counter
· MVI E, 00H : Initialize zero number counter
· BEGIN:MOV A, M : Get the number
· CPI 00H : If number = 0
· JZ ZERONUM : Goto zeronum
· ANI 80H : If MSB of number = 1i.e. if
· JNZ NEGNUM number is negative goto NEGNUM
· INR D : otherwise increment positive number counter
· JMP LAST
· ZERONUM:INR E : Increment zero number counter
· JMP LAST
· NEGNUM:INR B : Increment negative number counter
· LAST:INX H : Increment memory pointer
· INR C : Increment number counter
· MOV A, C
· CPI 32H : If number counter = 5010 then
· JNZ BEGIN : Store otherwise check next number
· LXI H, 7000 : Initialize memory pointer.
· MOV M, B : Store negative number.
· INX H
· MOV M, E : Store zero number.
· INX H
· MOV M, D : Store positive number.
· HLT : Terminate execution

Find the factorial of a number


Statement: Program to calculate the factorial of a number between 0 to 8
Source program :
· LXI SP, 27FFH ; Initialize stack pointer
· LDA 2200H ; Get the number
· CPI 02H ; Check if number is greater than 1
· JC LAST
· MVI D, 00H ; Load number as a result
· MOV E, A
· DCR A
· MOV C,A ; Load counter one less than number
· CALL FACTO ; Call subroutine FACTO
· XCHG ; Get the result in HL
· SHLD 2201H ; Store result in the memory
· JMP END
· LAST: LXI H, 000lH ; Store result = 01
· END: SHLD 2201H
· HLT

Subroutine Program:
· FACTO:LXI H, 0000H
· MOV B, C ; Load counter
· BACK: DAD D
· DCR B
· JNZ BACK ; Multiply by successive addition
· XCHG ; Store result in DE
· DCR C ; Decrement counter
· CNZ FACTO ; Call subroutine FACTO
· RET ; Return to main program

HEX to Decimal conversion


Statement: Convert the HEX number in memory to its equivalent decimal number
Source program :
· LXI H, 4150 ; Point to data
· LXI B, 0000 ; Initialize hundreds= 0, Tens=0
· MOV A, M ; Get hex data to A
· LOOP: SUI 64
· JC LOOP 1
· INR B ; hundreds= hundreds+1
· JMP LOOP
· LOOP 1: ADI 64 ; if subtracted extra, add it clear carry flag
· LOOP 2: SUI 0A
· JC LOOP 3
· INR C ; Tens=tens+1
· JMP LOOP 2
· LOOP 3: ADI 0A ; If subtracted extra, add it again
· INX H ; A = Units
· MOV M, B ; store hundreds
· MOV B, A ; Combine Tens in C &
· MOV A, C ; Units in A to form a
· RLC ; Single 8-bit number
· RLC
· RLC
· RLC
· ADD B
· INX H
· MOV M, A ; Store tens & Units
· HLT

Note: In this experiment the number is converted to its equivalent decimal number using
the following logic. First count the number of hundreds, the number of tens & units
present in that hex number. Then add up to get the equivalent decimal number.
Converting A9 we get:
A9 /64=45 Hundreds = 01
Since 64(100 decimal) cannot be subtracted from 45 no. of hundreds = 01. Now count tens
45/0A=3B Tens = 01 Now from 09, 0A cannot be subtracted. Hence tens = 06 the decimal
equivalent of A9 is 169.

HEX to binary conversion


Statement:Convert an 8 bit hex no to its binary form & store in memory
Source Program:
· LXI H, 4150 : Initialize memory pointer
· MVI B, 08 : count for 8-bit
· MVI A, 54
· LOOP : RRC
· JC LOOP1
· MVI M, 00 : store zero it no carry
· JMP COMMON
· LOOP2: MVI M, 01 : store one if there is a carry
· COMMON: INX H
· DCR B : check for carry
· JNZ LOOP
· HLT : Terminate the program

LINK : http://www.8085projects.info/page/free-programs-for-8085-microprocessor.aspx

You might also like