Download as pdf or txt
Download as pdf or txt
You are on page 1of 38

Chapter 3

Bit Addressable Area

By DeccanRobots
What is Bit Addressable Area?
FFh
General purpose
Memory Area

2Fh
Bit Addressable
Memory
20h Memory Area
from 20H to
Registers
2FH is Bit
00h addressable
Data Memory Area.
For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India
What is Bit Addressable Area?
FFh This memory area can be accessed
as a byte as well as a bit.

Part of Bit addressable Memory area shown here


2Fh 25h
24h
23h
20h
22h
13 09 21h
00h 04 03 02 01 00 20h
Data Memory
For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India
What is Bit Addressable Area?
FFh e.g. MOV 20h,#55h will copy 55h
value to 20h Memory Area. This is
Byte level access
Part of Bit addressable Memory area shown here
2Fh 25h
24h
23h
20h
22h
13 09 21h
00h 04 03 02 01 00 20h
Data Memory
For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India
What is Bit Addressable Area?
FFh e.g. SETB 00h will copy Binary 1
value to Bit address 00. This is Bit
level access
Part of Bit addressable Memory area shown here
2Fh 25h
24h
23h
20h
22h
13 09 21h
00h 04 03 02 01 00 20h
Data Memory
For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India
What is Bit Addressable Area?
This bit is named as 00h
This bit is named as 01h
This bit is named as 02h
25h
24h
23h
22h
This bit is named as 0Dh 13 09 21h
which is 13th Bit in bit 04 03 02 01 00 20h
addressable area
For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India
What is Bit Addressable Area?

 Question for you:


 SETB 20h
code will 25h
24h
copy 23h
Binary 1 at 22h
which 13 09 21h
Location? 04 03 02 01 00 20h

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India


What is Bit Addressable Area?

 SETB command is used to copy Binary


1 at address provided in command

 SETB 12h will copy Binary 1 at 12h


location in Bit addressable area

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India


What is Bit Addressable Area?

 CLR command is used to copy Binary 0


at address provided in command

 CLR 12h will copy Binary 0 at 12h


location in Bit addressable area

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India


What is Bit Addressable Area?

 Similarly All ports P0, P1, P2, P3 are bit


addressable.
 In other words we can access all 8
bits(1 Byte) of any port at a time or we
can access single bit individually.

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India


What is Bit Addressable Area?

 MOV P2,#55h will change all 8 bits of


P2
 SETB P2.3 will make 3rd Bit of P2 ( Pin
number 24 of Controller to 1 state)
 CLR P2.0 will make 0th Bit of P2 ( Pin
number 21 of Controller to 0 state)

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India


What is Bit Addressable Area?

 Hence we understand that section of


data memory can be accessed as Byte
and as Bit too.
 Each bit has its own address like 00h,
01h, 02h etc.
 SETB or CLR command can be used to
modify values of any Bit.

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India


What is Bit Addressable Area?

 MOV 00h,#00h Are you able to make


difference between
 CLR 00h these two commands?

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India


What is Bit Addressable Area?

 MOV 00h,#00h Are you able to make


difference between
 CLR 00h these two commands?

Remember:
CLR Command is always used for a BIT.

Hence CLR 00h command will copy Binary


0 to bit addressable area’s 00h location

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India


What is Bit Addressable Area?
Remember:
CLR Command is always used for a BIT.
Hence CLR 00h 25h
command will 24h
23h
copy Binary 0
22h
to bit addressable 13 09 21h
area’s 00h location 04 03 02 01 00 20h

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India


What is Bit Addressable Area?
0 0 0 0 0 0 0 0 FFh
 MOV 00h,#00h
Will copy value 00h
To memory location
00h i.e. R0

0 0 0 0 0 0 0 0 02h
0 0 0 0 0 0 0 0 01h
0 0 0 0 0 0 0 0 00h
For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India
What is Bit Addressable Area?

 MOV 00h,#00h Are you able to make


difference between
 CLR 00h these two commands?

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India


Second Application:
Toggle LED using Micro Switch

 Use one Micro switch and 1 LED


provided on Interfacing board.
 Initially LED will be OFF
 Press Switch once to make it ON
 Press it again to make it OFF
 Press it again to make it ON
 This will continue….
For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India
Toggle LED using Micro Switch
 Refer “Application 1.2” from Book
 Refer Circuit diagram
 Make connection accordingly and send
program to 89S52.

LED Micro Switch

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India


Toggle LED using Micro Switch
Make LED OFF
SETB P2.0
Loop: Wait till Switch is
not pressed
JB P1.0, Loop
CPL P2.0 Change State of
LED
Debounce:
JNB P1.0, Debounce
Wait till Switch is
SJMP Loop fully released
Code is Explained on Next Slide
For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India
Toggle LED using Micro Switch
Make LED OFF
SETB P2.0
Loop: JB Command is used
JB P1.0, Loop to jump to label specified
if bit is 1
Here if P1.0 is 1 then program will jump to
Loop.
Label
In other words, if switch is not pressed, P1.0
will remain to 1 state, and program will remain
in Loop
For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India
Toggle LED using Micro Switch
Make LED OFF
SETB P2.0
Loop: JB Command is used
JB P1.0, Loop to jump to label specified
CPL P2.0 if bit is 1

Complement P2.0
Label
CPL is complement, which will change
state of P2.0 to 0 if it is 1 OR will make
it 1 if it is 0
For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India
Toggle LED using Micro Switch

SETB P2.0 JNB command is used to


Jump to label if bit is 0.
Loop:
If bit is 1 then it will continue
JB P1.0, Loop program to next line
CPL P2.0
Debounce:
JNB P1.0, Debounce
SJMP Loop Program will jump to
Loop
For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India
Toggle LED using Micro Switch
Commands you have learnt till now:

MOV SETB CLR CPL JB JNB SJMP

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India


What is SFR?
 Special Function Register
 These are 1 byte or 2 bytes memory
locations.
 SFR is not part of data memory.
 Microcontroller has a separate memory
area allocated for all SFRs.

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India


What is SFR?
 E.g. P0, P1, P2 and P3 (All ports) are
SFRs.
 Another SFR commonly used in BIT
operations is PSW.
 Address of P0 is 80h
 Address of P1 is 90h
 Address of P2 is A0h
 Address of P3 is B0h
 Address of PSW is D0h
For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India
What is SFR?

 Hence following code will have same


effect because A0 is address of P2
MOV 0A0h,#55h Make sure to
OR add 0 (Zero)
MOV P2,#55h before hex value,
if hex value is starting
with a character
For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India
What is SFR?

 PSW Register

D0

7th 0th
bit bit
It is used to store result
CARRY FLAG of most of the Boolean
Known as “C” Operations

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India


What is SFR?

 7th Bit of PSW is Known as “C”


 C is used in many commands to store
operation done over bit.

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India


Back to Bits……..

ANL C,bit-address
ANL C,03h
This command will AND value of C with
value of address 03h.

Move to next slide to understand it in


detail.
For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India
Back to Bits.. Logical Operation

SETB C Location C=1


CLR 03h Location 03h=0
ANL C, 03h 1 AND 0 = 0
Result of this operation is
always stored in Left Operand.
Here it will be stored in C
Finally value of C will be 0
For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India
Logical Operation for Bits

 Similarly:  E.g.

ORL C,bit-address ORL C,03h


CPL bit-address CPL 03h
CLR bit-address CLR 03h
CPL C CPL C
CLR C CLR C
For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India
Logical Operation for Bits

Next Instruction is:


ANL C,/bit-address
e.g.
SETB C
CLR 03h
Slash ( / ) indicate
ANL C,/03h complement
AND operation between C and Complemented value of
03h will be executed. Value of 03h is never changed.
For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India
Logical Operation for Bits

 Similarly:
ORL C,/bit-address

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India


Logical Operation for Bits
Commands you have learnt till now:

MOV SETB CLR CPL JB JNB SJMP ANL


ORL

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India


How to Practice More?

To practice more, write code in 8051IDE,


assemble your program and use F11 key
to execute in steps on computer.
Use PORT, Registers window to check
results and changes in values.
These windows can be opened from Menu
“View-Registers” or “View-Ports” in
8051IDE as shown in next slide.
For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India
How to Practice More?

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India


End of Chapter 3

 This is END of 3rd Chapter


 Open 4th Chapter to interface Stepper
Motors and DC Motors.

For Microcontroller Development Boards --- www.EmbeddedMarket.com -- India

You might also like