Prac 1 W
Prac 1 W
Theory :
What is keil?
Keil development tools for the 8051 Microcontroller Architecture support every level of software
developer from the professional applications engineer to the student just learning about embedded
software development.
The industry-standard Keil C Compilers, Macro Assemblers, Debuggers, Real-time Kernels, Single-board
Computers, and Emulators support all 8051 derivatives and help you get your projects completed on
schedule.
The 8051 Microcontroller is an 8 – bit Microcontroller i.e. it can read, write and process 8 – bit Data.
There are a bunch of manufacturers like Atmel, NXP, TI, who manufacture their own versions of 8051
Microcontroller. Irrespective of the manufacturer, the internal hardware design i.e. the 8051
Microcontroller Architecture remains more or less the same. The following image shows the 8051
Microcontroller Architecture in a block diagram style.
The block diagram of the 8051 Microcontroller Architecture shows that 8051 Microcontroller consists of a
CPU, RAM (SFRs and Data Memory), Flash (EEPROM), I/O Ports and control logic for communication
between the peripherals.
All these different peripherals inside the 8051 Microcontroller will communicate with each other via the 8
– bit Data Bus, also known as the internal data bus.
We have seen the internal architecture of the 8051 Microcontroller in the above section. Now, we will see
the features of the 8051 Microcontroller Architecture.
NOTE: Some of the features like internal ROM and RAM will vary with the specific model of the 8051
Microcontroller.
32 I/O Pins (Input / Output Pins) – Arranged as 4 Ports: P0, P1, P2 and P3.
8- bit Stack Pointer (SP) and Processor Status Word (PSW).
16 – bit Program Counter (PC) and Data Pointer (DPTR).
Two 16 – bit Timers / Counters – T0 and T1.
Control Registers – SCON, PCON, TCON, TMOD, IP and IE.
Serial Data Transmitter and Receiver for Full – Duplex Operation – SBUF.
Interrupts: Two External and Three Internal.
Oscillator and Clock Circuit.
In this tutorial, we have seen a brief note on the 8051 Microcontroller Architecture. In the next 8051
Tutorial, we will see the 8051 Memory Organization and I/O Ports.
Procedure:
2. The Figure below shows the basic names of the windows referred in this document
3. Select New μVision Project from the Project Menu.
10. Click File Menu and select New. A new window will open up in the Keil IDE.
15. Right Click on the Source Group 1 folder on your Project pane and select Add New Item to Group
'Source Group1'.
16. Selected the file and add it to the keil project.
17. After whatever you have typed out the above program to your main. A file, you can compile
the A file by pressing F7 key or by going to ' Project -> Build Target ' on the IDE menu bar.
18. If there are no errors the code will compile and you can view the output on the Build Output pane.
Hence after the compilation of code we run the program.
Applications of keil
It used for c compliers, macro assembler.
It is used for single board computers, and for emulator support for all 8051 derivatives.
Conclusion:
Hence we have studied the keil software and also know the steps of how to executed for various programs.
Practical no: 2
Aim: To understand addressing modes
Theory: To perform any operation we have to give corresponding instruction to 8051. In each instruction we have to
give 3 information.
1] Operation to be performed.
The method by which address of source of data or address of destination of result is given in the instruction called
addressing mode.
In Immediate Addressing mode, the operand, which follows the Opcode, is a constant data of either 8 or 16
bits. The name Immediate Addressing came from the fact that the constant data to be stored in the memory
The 8 or 16 bit data required for execution of instruction is directly given in the instruction, called as
immediate addressing mode. Therefore the data must be followed by a hash “#” sign.
Immediate Addressing is very fast as the data to be loaded is given in the instruction itself.
Example:
Mov a, #40h
Before Execution
After Execution
In Direct Addressing Mode, the address of the data is specified as the Operand in the
Instruction. 8 bit data required for execution of instruction is present in the internal data memory
I.e. Ram location and address of that memory location given in the instruction is called direct addressing
mode.
After Execution
In the Indirect Addressing Mode or Register Indirect Addressing Mode, the address of the Operand is
Therefore an 8 bit data required for execution of the instruction is present in memory location (internal or
external) and addressing of that memory location is pointed by pointer register which is present in the
8 bit pointer register are R0 and R1 and 16 bit pointer register is dptr.
MOV A,@R1
END
After Execution
4] Register direct addressing mode
In the 8051, Microcontroller Memory Organization Tutorial, we have seen the organization of RAM and
Therefore 8 or 16 bit data required for execution of instruction is present in register and name of the
register is mentioned in the instruction, called as register addressing mode or register direct addressing
mode.
Example:
Mov A, R5
Mov R0, B
After Execution
With Indexed Addressing Mode, the effective address of the Operand is the sum of a base register and an
offset register. If the data present in memory and address of memory location is obtained by adding 16bit
no. of given base register DPTR/PC with 8bit no. of index register accumulator, then it is called as base
Only program memory can be accessed with index addressing mode .this addressing mode is used to read
Movc A, A+@DPTR
END
After Execution
CONCLUSION:
Hence we have studied and executed the various types of addressing modes of microcontroller 8051.
Result:
An Addressing Mode is a way to locate a target Data, which is also called as Operand.
Therefore addressing modes allows flexibility in accessing the register memory locations, and it is the
methods by which address of data or address of destination of result is given in the instructions.
PRACTICAL NO: 3(a)
Theory: data transfer instruction of 8051 does not affect any of PSW flags. Except a pop or mov directly to the
psw.
Therefore various data transfer instructions are: mov, movx, movc, push, pop and exchange (XCHG).
1] General purpose.
2] Accumulator –specific.
3] address-object.
MOV: mov performs a bit or byte transfer from the source operand to the destination operand.
PUSH: push increments the SP register and then transfers a byte from the source operand to the stack
location currently addressed by sp.
Address-object transfer:
MOV DPTR, data loads 16 bits of immediate data into a pair of destination registers, DPH, DPL.
PROGRAM:
there are 79 Op-codes .flags are not affected by using data transfer instructions. Hence we have studied and
Program:
Data of 39h is
transferred to 3EH
TO BYTE(3BYTE)
0x0003 MOV 3DH,38H 85383D Data of 38Hh is
transferred to 3DH
0x0006 MOV 3CH,37H 85373C Data of 37h is
transferred to 3CH
transferred to 3BH
transferred to 3AH
transferred to 39H
transferred to 38H
transferred to 36H
transferred to 35H
AIM: EXCHANGE DATA BYTES PRESENT IN MEMORY LOACTION FROM 30H-39H TO 40H-49H
PROGRAM:
memory location
byte in memory
location 40h
0x0007 MOV A,31H E531 Load the contents of
memory location
memory location
0x000C MOV 41H,A F541 Store the product
byte in memory
location 41h
0x000E MOV A,32H E532 Load the contents of
memory location
memory location
0x0013 MOV 42H,A F542 Store the product
byte in memory
location 42h
0x0015 MOV A,33H E533 Load the contents of
memory location
memory location
0x001A MOV 43H,A F543 Store the product
byte in memory
location 43h
0x001C MOV A,34H E534 Load the contents of
memory location
memory location
0x0021 MOV 44H,A F544 Store the product
byte in memory
location 44h
0x0023 MOV A,35H E535 Load the contents of
memory location
memory location
0x0028 MOV 45H,A F545 Store the product
byte in memory
location 45h
0x002A MOV A,36H E536 Load the contents of
memory location
memory location
0x002F MOV 46H,A F546 Store the product
byte in memory
location 46h
0x0031 MOV A,37H E537 Load the contents of
memory location
memory location
0x0036 MOV 47H,A F547 Store the product
byte in memory
location 47h
0x0038 MOV A,38H E538 Load the contents of
memory location
memory location
0x003F MOV 48H,A F548 Store the product
byte in memory
location 48h
0x0041 MOV A,39H E539 Load the contents of
memory location
memory location
0x0046 MOV 49H,A F549 Store the product
byte in memory
location 49h
0x0047 END 00 End of program
CONCLUSION: HENCE THE EXCHANGE DATA BYTES PRESENT IN MEMORY LOACTION FROM 30H-39H TO
Aim: to find the largest number from the 10 bytes of data in memory location 30h-39h.store the largest
Program:
machine cycle
0x002F ORG 30H 802E Assembler directive
address
0x0030 MAIN: MOV 7809 2 byte instruction
machine cycle
0x0035 MOVX A,@DPTR E0 2byte instruction
0x0036 MOV B,A F5F0 2byte instruction
2machine cycle
0x0040 MOV R3,B ABF0 One byte instruction
cycle.
0x0042 HERE: SJMP HERE 80FE
0x0044 BACK:MOVX E0 3byte and 2
machine cycle
0X0049 MOV R5,DPH AD83 3byte and 2
machine cycle
0x004b SJMP L1 80f1
0x004d END 00 End of program
Conclusion: Thus, the program is executed for finding the largest number.
This program demonstrates that specific data parameter can be obtained by using
Conditional instructions.
Practical no: 4(A)
Theory:
Addition:
Inc : (increment adds one source operand and put the result in the operand.
ADDC: (add with carry): it adds A and the source operand and then adds 1 if CY is set and puts the result in A.
DAA (decimal adjust for bcd): corrects the sum which results from the binary addition of two, two-digit operands.
The packed bcd decimal sum formed by DA is returned to A. cy is set if bcd results greater than 99, otherwise cy is
cleared.
Subtract:
Subb: subtract with borrow: it subtracts the source operand from the first operand (the accumulator), subtracts 1
if CY is set and returns the result to A.
DEC :( DECREMENT): SUBTRACTS 1 from the source operand and returns the results to the operand.
Multiplication:
Mul performs an unsigned multiplication of register A register with B register, resulting in a two –byte result. A
receives the lower order byte and B receives the higher order byte
Division:
Div performs an unsigned division of A register by B register and returns the integer quotient to A and remainder
to the B register.
Program:
Conclusion:
The value of quotient is stored at port 1 & the value of remainder is stored at port 0.
Practical no: 4(B)
Theory:
Addition:
Inc : (increment adds one source operand and put the result in the operand.
ADDC: (add with carry): it adds A and the source operand and then adds 1 if CY is set and puts the result in A.
DAA (decimal adjust for bcd): corrects the sum which results from the binary addition of two, two-digit operands.
The packed bcd decimal sum formed by DA is returned to A. cy is set if bcd results greater than 99, otherwise cy is
cleared.
Subtract:
Subb: subtract with borrow: it subtracts the source operand from the first operand (the accumulator), subtracts 1
if CY is set and returns the result to A.
DEC :( DECREMENT): SUBTRACTS 1 from the source operand and returns the results to the operand.
Program:
Address Mnemonics opcodes explanation
0x0000 mov dptr,#1000h 901000 3 byte instruction and
2machinne cycle.
0x0003 movx a,@ dptr E0 1byte instruction, 2
machine cycle
0x0004 mov b,a F5F0 1byte instruction and
1 machine cycle.
0x0006 mov dptr,#1002h 901002 3 byte instruction and
2machinne cycle.
0x0009 movx a,@ dptr E0 1byte instruction, 2
machine cycle
0x000A add a,b 25F0 1byte instruction and
1 machine cycle.
0x000C mov dptr,#3000h 903000 3 byte instruction and
2machinne cycle
0x000F movx @ dptr ,a F0 1byte instruction, 2
machine cycle
0x0010 mov dptr,#1001h 901001 3 byte instruction and
2machinne cycle.
0x0013 movx a,@ dptr E0 1byte instruction, 2
machine cycle
0x0016 mov b,a 901003 1byte instruction and
1 machine cycle.
0x0019 mov dptr,#1003h E0 3 byte instruction and
2machinne cycle.
0x001A movx a,@ dptr 35F0 1byte instruction, 2
machine cycle
0x001C addc a,b 35F0 1byte instruction, 1
machine cycle
0x001F mov dptr,#3001h 903001 3 byte instruction and
2machinne cycle.
0x0020 movx @ dptr ,a F0 1byte instruction, 2
machine cycle
0x0022 mov a,#00h 7400 2 byte instruction ,1
machine cycle
0x0024 addc a,#00h 3400 2 byte instruction ,1
machine cycle
0x0024 mov dptr,#3002h 903002 3 byte instruction and
2machinne cycle.
0x0027 movx @ dptr,a F0 1byte instruction, 2
machine cycle
0x0028 movx @ dptr,a 901004 1byte instruction, 2
machine cycle
0x002B movx a,@ dptr E0 1byte instruction, 2
machine cycle
0x002C Mov b,a F5F0 1byte instruction, 1
machine cycle
0x002E mov dptr,#3000h 903000 3 byte instruction and
2machinne cycle.
0x0031 movx a,@ dpt E0 1byte instruction, 2
machine cycle
0x0032 subb a,b 95f0 1byte instruction,
1machine cycle
0x0034 mov dptr,#1006h 901006 3 byte instruction and
2machinne cycle.
0x0037 movx @ dptr ,a F0 1byte instruction, 2
machine cycle
Conclusion: (A+B)-C
Practical no 4: (C)
Theory :
Packed BCD:
Packed BCD Numbers are stored in two digits to a byte, in 4 bit groups referred to as nibbles. ALU is
capable of performing only binary addition and subtraction, but
by adjusting the sum or difference the correct result in packed BCD format.
Unpacked BCD:
Unpacked BCD Format: In Unpacked BCD, there is only one digit per byte and because of this,
unpacked multiplication and division can be done.
Binary operations act on single bytes and the results are adjusted. For Division, the adjustment is
done before the binary division.
Program:
Therefore, the main advantage of the Binary Coded Decimal system is that it is a fast and efficient system
to convert the decimal numbers into binary numbers as compared to the pure binary system.
Practical no 4(D)
AIM: Find 2’s complement of a number. i.e. data in 40h & find 2's comp in 41h
Theory:
1’s complement:
1’s complement of a binary number is another binary number obtained by toggling all bits in it, i.e., transforming
the 0 bit to 1 and the 1 bit to 0.
Examples:
2’s complement:
In 2’s complement of a binary number is 1 added to the 1’s complement of the binary number.
Examples:
2's complement of a binary number is 1 added to the 1's complement of the binary number.