This is the second part of 8051 Tutorial Series. you can also check first part and second part of series
Types of Memory:
As you know generally memory categorised as RAM and ROM But it can be also categories as internal and external. For 8051 we generally talk about three type of memory is- On chip memory (RAM and ROM)
- External Code memory (ROM memory) and
- External RAM memory.
External RAM and ROM:
On Chip Memory:
8051 have on chip RAM and ROM , but in general we only talk about on chip RAM. The on chip RAM is also two types- Internal RAM ( specified by manufactuar )
- Special Function Register (SFR) memory
Register bank: all four register bank cover 32byte of RAM and they can be used as R0,R1...R7 by setting Register bank or directly by their address of RAM. it is addressed from 00h to 1Fh
.
Example 1
++++++++++++++++++++Register Bank+++++++++++++++++++++ SETB PSW.3 ;Selecting register bank 1 MOV R1, #23H ;mov 23h on register R! or 1st bank ----or---- MOV 09H,#23H ;09h is addr of R1 of reg.bank 1 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
Bit Addressable RAM: This part of RAM is bit addressable, that means you can excess individual bit of this RAM by bit operation like SETB, CLR, CPL, JB etc and bit address.
Each bit has a address and addressed from 00-127 in decimal and 00-7Fh in hex. Advantage of this RAM is that you can define bool variable in this RAM. In RAM map it is addressed from 20H to 2FH
Example 2
++++++++++++++Bit Addressable RAM++++++++++++++++++++++ SETB 00H ;set bit 00h CLR 70H ;clear bit 70h CPL 12H ;complement bit 12h +++++++++++++++++++++++++++++++++++++++++++++++++++++++
Scratch Pad RAM: This is the remaining RAM after register bank and bit addressable RAM and size of it depend on type of controller. If your code has more variable or need to store data then this ram is used.
8051 Data Type and Directives:
There is only one data type for 8051 which is 8 bit data type. All variable you define is 8bit wide and can hold value 0-255 or -128 to 127.Let you define a variable (counter) then you need to take of overflow of counter by writing code, because after reaching counter to 255 it not go to 256 instead it reset to 00. while in other languages like c, you don't need to checking overflow of variable.
DB (Define Byte): DB is used to define 8 bit data in Internal ROM memory. It can be used as
Example 3
+++++++++++++++++++++DB (define byte)+++++++++++++++++++ DATA 1: DB 45 ;define a decimal data DATA 2: DB 01001011B ;define a binary data DATA 3: DB 37H ;define a hex data DATA 4: DB "1223" ;ASCII number DATA 5: DB "It is Tentuts.com" ; define a string ++++++++++++++++++++++++++++++++++++++++++++++++++++++++H after hex value and B after binary value necessary but you can drop D from decimal values. ASCII and string automatically converted in hex by assembler
Some directives are:
ORG (Origin) : It show the beginning address of the program. When you define a ORG for a segment of program then that code if burned in ROM memory at that memory address.
Example 4
++++++++++++++++++++++++ORG (Origin)++++++++++++++++++++ ORG 00H ;code burned after 00h memory MOV R0,30H ADD A,R0 --and-- ORG 300H ;code burned after 300h memory DB: 34h,32h ;300h contain 34h and 301h contain 32h ;because we define two byte data ++++++++++++++++++++++++++++++++++++++++++++++++++++++++EQU (equate): It define a constant without occupying memory. This makes task very simple by giving a name to memory location or constant value
Example 5
++++++++++++++++++++++++EQU (Equate)++++++++++++++++++++ COUNT EQU 25 MOV R0, #COUNT ;mov 25 to r0 ;it is value because of #sign --similar to-- MOV R0, #25 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++END: It tells to assembler that this is the end of assembly program. so a program may look like this after use of all directive
++++++++++++++++++++++++SAMPLE PROGRAM++++++++++++++++++ ;perform addition of three numbers ORG 00H CONST EQU 30H ;define a constant STORE EQU 46H ;define memory address to ;store data after addition ADD A,#DATA1 ;add data to reg A. ADD A,#DATA2 ;add data ADD A,#CONST ;add const "# sign is used" MOV STORE,A ;STORE as address because no #sing ORG 330H DATA1: DB 23H ;define 23h at 330h DATA2: DB 34H ;define 34h at 331h END ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Directive has no effect on program and no hex is generated for them. they are used for assembler and programmer to make program less complex and readableHope you enjoy the tutorial. In next part we cover JUMP, LOOPs and CALL instructions and use them.
if you like this tutorial please share to others and follow us.
Comments
Post a Comment