Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 44

Lab-1

Introduction to Keil IDE


Lab-1
• Basic features of 8051
• Assembly language
programming
• Keil IDE introduction
• Simple ASM programs
Lab-1

BASIC FEATURES OF 8051


Lab-1
• Basic features of 8051
– 8-bit CPU
– 16-bit Program Counter
– 8-bit Processor Status Word (PSW)
– 8-bit Stack Pointer
– 4KB of ROM
– Internal RAM of 128bytes
– Special Function Registers (SFRs) of 128 bytes
– 32 I/O pins arranged as four 8-bit ports (P0 - P3)
– Two 16-bit timer/counters : T0 and T1
– Two external and three internal vectored interrupts
Lab-1
• Block diagram of 8051
Lab-1
• Structure of 8-bit memory with 8-bit address
bus
8-Bit Data
0x00H D7 D6 D5 D4 D3 D2 D1 D0

0x01H D7 D6 D5 D4 D3 D2 D1 D0
Address location

0x02H D7 D6 D5 D4 D3 D2 D1 D0

. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
0xFFH D7 D6 D5 D4 D3 D2 D1 D0
Lab-1
• Structure of 8-bit memory with 16-bit address
bus
8-Bit Data
0x0000H D7 D6 D5 D4 D3 D2 D1 D0

0x0001H D7 D6 D5 D4 D3 D2 D1 D0
Address location

0x0002H D7 D6 D5 D4 D3 D2 D1 D0

. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
0xFFFFH D7 D6 D5 D4 D3 D2 D1 D0
Lab-1
8051
• AT89C51 from Atmel Corporation
• Flash (erase before write)
– ROM burner that supports flash
– A separate eraser is not needed
Lab-1

ASSEMBLY LANGUAGE
PROGRAMMING
Lab-1
• A Given Assembly language program is a
series of statements of

– Assembly language instructions: ƒTell the


CPU what to do

– Directives (or pseudo-instructions): ƒGive


directions to the assembler
Lab-1
• An Assembly language instruction consists of
four fields
[label:] Mnemonic [operands] [;comment]

Example:
REPEAT: MOV A, #50H ; Move 50H value to A
Lab-1
• Assembly language program example
Lab-1
MOV destination, source ;copy source to dest.

• The instruction tells the CPU to move (in


reality, COPY) the source operand to the
destination operand

• Source and destination can be A, R0 to R7,


direct address, direct data(#), indirect
address(@), DPTR
Lab-1
• Register are used to store information
temporarily

• The vast majority of 8051 register are 8-bit


register
Lab-1
• The most widely used registers
Lab-1
• The most widely used registers

– A (Accumulator): ƒFor all arithmetic and logic


instructions

– B, R0, R1, R2, R3, R4, R5, R6, R7: General purpose

– DPTR (data pointer), and PC (program counter)


Lab-1
• Step to assemble and running 8051 assembly
language program(asm)
Lab-1
• Sample .lst (list) file
Lab-1

ASSEMBLY LANGUAGE
PROGRAMMING
Lab-1
• Keil IDE

– It is a software platform used to provide


code editing, assembling and debugging
capability

– “Keil c51” is for 8051 microcontrollers

– “Keil MDK-Arm” for ARM devices


Lab-1
Step to run a program in Keil IDE:

1. Create a Project (.uvproj)

2. Create and write an assembly program (.a51)

3. Build your project to check errors

4. Select debug mode

5. Run your code to verify the output


Lab-1
• Step:1
1. Create a Project (.uvproj) by selecting
“Project -> New µvision Project”
2. Save your project in D: drive with your
register number as a file name
3. Select device for target as “Atmel ->
AT89C51ED2”
4. Select “No” for adding STARTUP.A51 file to
project
Lab-1
• Step to run a program in Keil IDE
Lab-1
• Step to run a program in Keil IDE
Lab-1
• Step:2
1. Create a asm file by right click on “Source
Group 1) and select “Add items to Source
group 1”
2. Then select “asm file” option and give name
for the asm file and save
3. Write the asm program on the editor and
save it
Lab-1
• Step to run a program in Keil IDE
Lab-1
• Step to run a program in Keil IDE
Lab-1
• Note on programming
Lab-1
• Step:3
1. To verify errors in the program first select
“Translate” option

2. If any error correct the error and save it


before performing Translate option again

3. If no error then click on “Build” icon to


generate supported files
Lab-1
• Step to run a program in Keil IDE
Lab-1
• Step:4
1. To run and verify your program first get into
debug mode by selecting “start/stop
debugging session” icon
Lab-1
• Step to run a program in Keil IDE
Lab-1
• Step to run a program in Keil IDE
Lab-1
• Step:5
1. To run and verify your program select run
icon or press F5
(Shows final output after executing entire
program)
2. To perform step by step execution of the
program select “step” icon or F11 (shows
output for every instruction execution)
Analyze registers and memory locations to
verify the correctness of the program
Lab-1
• Step to run a program in Keil IDE
Lab-1

SIMPLE ASM PROGRAMS


Lab-1
• Program-1
• Write a 8051 asm program to perform
– Move operation between A and data
– Move operation between Rn and data
– Move operation between A and Rn
Lab-1
Program-1
ORG 0000h
MOV A, #55H ;load 55 into A
MOV R0, #0D3H ;load D3 into R0
MOV A, R0 ; Load R0 value to A
MOV R1, A ; Load A to R1
END
Lab-1
• Program-2
• Write a 8051 asm program to perform
– Move operation between direct address and data
– Move operation between A and direct address
– Move operation between Rn and direct address
Lab-1
Program-2
ORG 0000h
MOV 55H, #0AAH ;Move AAH to address location 55H
MOV A, 55H ;Move address location value 55H to A
MOV 33H, A ; Move A to address location 33H
MOV R0, 22H ;Move address location 22H value to R0
MOV 44H, R0 ; Move R0 value to address location
44H
END

You might also like