0% found this document useful (0 votes)
37 views35 pages

Pdf&rendition 1

The document contains assembly language code and explanations for programs that control a 7-segment display. It includes the truth table for a BCD to 7-segment decoder that defines which segments are illuminated for each digit, as well as code samples to blink an LED, display alternating patterns on ports, and display numbers on a 7-segment display.

Uploaded by

Anuj Nikam
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)
37 views35 pages

Pdf&rendition 1

The document contains assembly language code and explanations for programs that control a 7-segment display. It includes the truth table for a BCD to 7-segment decoder that defines which segments are illuminated for each digit, as well as code samples to blink an LED, display alternating patterns on ports, and display numbers on a 7-segment display.

Uploaded by

Anuj Nikam
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/ 35

MRS. VAISHALI S.

SALUNKE
Asst. Prof. Department of Electronics
P.E. Society’s, Modern College of Arts, Science and Commerce,
Ganeshkhind,Pune-16
ASSEMBLY LANGUAGE PROGRAM

• Write a program to check the two numbers in R5 & R6


for equality. If are equal then store zero inside R7
• Algorithm
• Copy one of the register content in accumulator
• Compare it with another register content .
• Check accumulator content

P. E. SOCIETY'S, MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERCE,GANESHKHIND,PUNE-16


ASSEMBLY LANGUAGE PROGRAM
ORG 00H
MOV A,R5; Copy R5 register content in accumulator
SUB A,R6; Compare R5 register content with R6
JNZ XYZ ; If Accumulator content is not zero end the
program
MOV R7,#00H; Write 0 to R7
XYZ: END
3

P. E. SOCIETY'S, MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERCE, GANESHKHIND,PUNE-16


ASSEMBLY LANGUAGE PROGRAM
• Write a program to add 5 numbers stored in RAM starting from
address 40 H.
• Algorithm
• Initialize pointer to 40H .
• Initialize counter with count value of 5
• Add accumulator content with element of array
• Increment pointer , Decrement counter
• If Count is not zero, Go to step 3 (repeat the addition)
• Else end the program . 4

P. E. SOCIETY'S, MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERCE,GANESHKHIND,PUNE-16


ASSEMBLY LANGUAGE PROGRAM
ORG 00H
MOV R5,#40H; Initialize pointer register R5 to 40H
MOV R7,#05H ; Initialize counter Register R7
MOV A,#00H; Clear accumulator content
XYZ: ADD A,@R5; ADD elements in sequence
INC R5; Increment pointer
DJNZ R7,XYZ ; Decrement counter and check for zero value , go to step 4
END

P. E. SOCIETY'S, MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERCE, GANESHKHIND,PUNE-16


ASSEMBLY LANGUAGE PROGRAM
• Write a program to find the largest no of an array of 10 numbers stored in RAM locations
starting from address 60 H.
• Algorithm
1. Initialize pointer to 60H .
2. Initialize counter with count value of 10
3. Compare accumulator content with next element of array for equality. If are equal go to
step 6
4. If accumulator content is largest (carry=0) go to step 6
5. Otherwise take largest value inside the accumulator
6. Increment pointer , Decrement counter
7. If Count is not zero, Go to step 3 (repeat the addition)
8. Else end the program . 6
FLOW CHART
Start

Initialize Pointer ,Counter, clear register A

Compare A with next element of array

Is YES
A=
0
NO
Is YES YES
Increment Pointer and
Carry Decrement Counter
=0
NO
Is
Counter
Copy largest element in A =0 YES
NO END 7

P.E.SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16


ASSEMBLY LANGUAGE PROGRAM
ORG 00H
MOV R5,#60H; Initialize pointer register R5 to 40H
MOV R7,#10H ; Initialize counter Register R7
MOV A,#00H; Clear accumulator content
XYZ: CJNE A,@R5,NEXT ; ADD elements in sequence
JMP REPEAT
NEXT: JNC REPEAT
MOV A,@R5;
REPEAT: INC R5; Increment pointer
DJNZ R7,XYZ ; Decrement counter and check for zero value , go to step 4
END

P. E. SOCIETY'S, MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERCE, GANESHKHIND,PUNE-16


P.E.SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16 9
WRITE A PROGRAM TO BLINK LED ON P1.2

ORG 00H
CLR C
L1: CPL C
P1.2 MOV P1.2,C
CALL DELAY
8051µC
SJMP L1
END
10

P.E.SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16


ORG 00H
CLR A
L1: MOV A,#55H
MOV P1,A
CALL DELAY
MOV A,#0AAH
P1 MOV P1,A
CALL DELAY
SJMP L1
8051µC END

[A]= 55H= 0101 0101


[A]=0AAH=1010 1010
P.E.SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16 11
P.E.SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16 12
GENERAL INFORMATION -SEVEN SEGMENT DISPLAY

Actual View Arrangement of


LED segments
COMMON ANODE 7-SEGMENT DISPLAY

• In the common anode display, all the


anode connections of the LED segments
are joined together to logic “1”.

• The individual segments are


illuminated by applying a ground,
logic “0” or “LOW” signal via a
suitable current limiting resistor to the
Cathode of the particular segment (a-
g).
COMMON CATHODE 7-SEGMENT DISPLAY
• In the common cathode display, all the
cathode connections of the LED
segments are joined together to logic
“0” or ground.
• The individual segments are
illuminated by applying “HIGH”, or
logic “1” signal via a current limiting
resistor to forward bias the individual
diode anode terminals (a-g).
ACTUAL DISPLAY OF NUMBERS AND CHARACTERS
FUNCTION TABLE :7-SEGMENT LED DISPLAY
Decimal Individual Segments Illuminated
Digit h
a b c d e f g

0 ON ON ON ON ON ON OFF OFF
1 OFF ON ON OFF OFF OFF OFF OFF
2 ON ON OFF ON ON OFF ON OFF
3 ON ON ON ON OFF OFF ON 0FF
4 OFF ON ON OFF OFF ON ON 0FF
5 ON OFF ON ON OFF ON ON 0FF
6 ON OFF ON ON ON ON ON 0FF
7 ON ON ON OFF OFF OFF OFF OFF
8 ON ON ON ON ON ON ON OFF
9 ON ON ON OFF OFF ON ON OFF
TRUTH TABLE BCD TO 7-SEGMENT(COMMON CATHODE ) DECODER

BCD INPUT 7-SEGMENT OUTPUT Hex Equivalent


D C B A a b c d e f g h
0 0 0 0 1 1 1 1 1 1 0 0 FC
0 0 0 1 0 1 1 0 0 0 0 0 60
0 0 1 0 1 1 0 1 1 0 1 0 DA
0 0 1 1 1 1 1 1 0 0 1 0 F2
0 1 0 0 0 1 1 0 0 1 1 0 66
0 1 0 1 1 0 1 1 0 1 1 0 B6
0 1 1 0 1 0 0 1 1 1 1 0 9E
0 1 1 1 1 1 1 0 0 0 0 0 E0
1 0 0 0 1 1 1 1 1 1 1 0 FE
1 0 0 1 1 1 1 0 0 1 1 0 E6
ORG 00H
7SEGDATA DB
0FC,60,0DA,0F2,66,0B6,9E,0E0
,0FE,0E6
END
ORG 00H
• P1.7-a
MOV R1,#7SEGDATA;
• MOV R2,#10;
P1
P1.6-b

• P1.5 c
CLR A;
• P1.4-d
REPEAT: MOV A,@R1
8051µC • P1.3-e
MOV P1,A
• P1.2-f

• P1.1-g ACALL DELAY


• P1.0-h INC R1;
DJNZ R2,REPEAT; 19

END
SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16
Input Device ORG 00H
P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 7SEGDATA
P2.1 P2.0 DB
D C B A 0 0 1 0 1 0 0FC,60,0DA,0F2,66,0B6,9E,0
0 0
E0,0FE,0E6
P2.3 P2.2 P2.1 P2.0 END
ORG 00H
MOV P2,#0FFH
• P1.7-a
MOV A,P2
• AND A,#0FH
P1
P1.6-b

• P1.5 c ADD A,#7SEGDATA


• P1.4-d
MOV R1,A
8051µC • P1.3-e
CLR A
• P1.2-f

• P1.1-g MOV A,@R1


• P1.0-h MOV P1,A
END 20

SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16


P.E.SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16 21
EMBEDDED ‘C’ PROGRAMMING ASSEMBLY LANGUAGE PROGRAMMING

• Programming in ‘C’ is Easy and less • Programming in ASSEMBLY language


time Consuming is tedious and time Consuming
• Easy to modify and update existing • Existing programs Can not be Easily
programs . modified and updated.
• Variety of library functions are • No library/ready to use functions
available to use in the programs . are available to use in the programs .
• It is Microcontroller independent and • It is Microcontroller/platform
therefore portable from system to dependent and therefore not
system with less or no modifications. portable from system to system
• More user friendly • Machine friendly 22

P. E. SOCIETY'S, MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16


DATA TYPES IN EMBEDDED ‘C’
• Unsigned character : 8-bit(0-255) . Uses single location of memory.
• Signed character : Out of 8-bit, M.S.B. BIT indicates sign
• Data Range (-128-to +127) .
Uses single location of memory
• Unsigned int : 16-bit DATA range (0-65535).
Occupies two memory locations.
• Signed int: 16 bit DATA . M.S.B. bit indicates sign.
Data Range (-32768-0-+ 32767) .
Uses two location of memory
23

P.E.SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16


DATA DECLARATION
• sbit : Allows to use single pin out of any bit accessible SFR in 8051 microcontroller .
For example- sbit LED=P1^2
• bit: Allows access to single bits of bit addressable RAM area20H to 2F H (Address
range 00H - FFH ). bit SWITCH = 02H
• sfr : To access entire byte of special function register. sfr OUT =P0
• Array declaration:
Unsigned char num[ ]=“ABCDEF”, declares array of 6 char elements
Unsigned int AR[10] = , , , , ..............., , declares array of 10 integer type
elements

P.E.SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16 24


LOGIC OPERATORS

Operation Operator
AND &
OR I
XOR ^
Inverter ~
P.E.SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16 25
BITWISE SHIFT OPERATORS

Operation Operator
Shift Right >>
Shift Left <<

P.E.SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16 26


Write a 8051 C program to toggle bits of P1
continuously with some time delay

P.E.SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16 27


ASSEMBLY PROGRAM
# include <reg51.h> ORG 00H
void main (void) CLR A
{ L1: MOV A,#55H
while(1) MOV P1,A

{ CALL DELAY

char x; MOV A,#0AAH

P2=0X55; MOV P1,A


CALL DELAY
for (X=0;X<=255;X++);
SJMP L1
P2=0XAA;
END
for (X=0;X<=255;X++);
}
[A]= 55H= 0101 0101
}
[A]=0AAH=1010 1010 28

P.E.SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16


TIME DELAY GENERATION IN EMBEDDED ‘C’ PROGRAM
• Use simple for loop
• Use timers in 8051
➢Factors affecting the accuracy of time delays generated using
FOR loop in 8051 ‘C’ program
1.Version of 8051 microcontroller
2. Frequency of the Crystal connected externally
3. Compiler used for converting C program to assembly program
29

P.E.SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16


RUN THE FOLLOWING PROGRAM AND EXAMINE THE RESULTS

• # include <reg51.h> 1. P0=0X35 & 0X0F; 3. P2= 0X54 ^ 0x78;


35H= 0011 0101 54 = 0101 0100
void main void &
0FH = 0000 1111 ^
{ P0=0X35 & 0X0F; 78 = 0111 1000
0000 0101= 05H
0010 1100= 2CH
P1= 0X04 | 0X68; 2. P1= 0X04 | 0X68;
4. P3= ~ 0x55;
P2= 0X54 ^ 0x78; 04H = 0000 0100
| 55 = 0101 0101
68H = 0110 1000
P3= ~ 0x55;
0110 1100= 6CH~55 = 1010 1010= AAH
}
30

P.E.SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16


Program 1. Write a C program to read P2.3 , complement and send it to P2.7

# include <reg51.h>
sbit input=P2^3;
sbit output=P2^7;
bit membit=0x02;
void main (main)
{
While(1)
{
membit==input;
output=~membit; }
} 31

P.E.SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16


Program 2: # include <reg51.h>
sbit SW=P2^7;
Write a C program to void main (main)
monitor P2.7. {
While(1)
When it is high send 55H { while (SW==0);
to P1 P1=0x55;
}
}

P.E.SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16


Program 3: # include <reg51.h>
sbit SW=P1^4;
A switch is connected to void main (main)
pin P1.4 . {
While(1)
Write a C program to
{ if (SW==0)
Out data 00h on port 2 P2=0x00;
for switch condition is else
OFF and FFH for switch P2=0XFF;
}
condition is ON.
}

P.E.SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16


# includeInput Device
<reg51.h>
ORG 00H
unsigned char 7SEGDATA DB
D C B A
SSDdata [ ]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0x9e, 0FC,60,0DA,0F2,66,0B6,9E,0
0xe0,0xfe,0xe6} E0,0FE,0E6
P2.3 P2.2 P2.1 P2.0

Unsigned char LOCATE; END


ORG 00H
void main (main) MOV P2,#0FFH
{ While(1) • P1.7-a MOV A,P2
{ P2=0XFF;

P1
P1.6-b
P1=0X00; AND A,#0FH
• P1.5 c
ADD A,#7SEGDATA
LOCATE=SSDdata+(P2&0X0F);
• P1.4-d

8051µC • P1.3-e MOV R1,A


P1=SSDdata[locate]; • P1.2-f CLR A
} • P1.1-g
MOV A,@R1

}
P1.0-h
MOV P1,A
END 34

P.E.SOCIETY'S,MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16


THANK YOU

P. E. SOCIETY‘S, MODERN COLLEGE OF ARTS ,SCIENCE AND COMMERECE,GANESHKHIND,PUNE-16 35

You might also like