Microcontroller 8051 basics

Thread Starter

antiantianti

Joined Aug 4, 2016
45
I was reading online homeworks and now I found a question saying What is the active register bank after execution the instruction MOV PSW, #50H
the answer is RS1=1, and RS0=0 so it is Register Bank 2 . first what is RS1 and what is RS0 and why are they set to zero and one and how can you know that the answer is register bank ?
I also have another question I also saw that the P bit in psw after executing this instruction mov a,#03h A=0000 0011B so P=0 first it was difficult to know what is p bit after some research I thought it is parity bit and then you have to count the number of one bits in the result so the number of 1 bit in the result is 2 so it is an even number so P must be equal to one so why is P equal to zero here ?

I appeciate every answer
 

JohnInTX

Joined Jun 26, 2012
4,787
To add to what @AlbertHall said, MOV PSW,#50H sets the PSW bits to 01010000. The highlighted bits are RS1 and RS0 and you can see that they are 10 which selects bank 2. The ability to change the entire working register set with a simple bank switch is very useful. You can reserve one for interrupts and just switch to that bank (after pushing the PSW to save its current contents) to execute the interrupt code without having to save all of the registers individually. Just pop the PSW to restore the register context after the interrupt.

As noted, the parity bit is mostly used when sending and receiving data. For example in async comms (RS232 et al) you might set the UART to 9600 baud,7 bits, EvenParity, 1 Stop Bit. (9600,E,7,1). When you receive a character you read it into the accumulator and check the P bit to ensure it is 0. For transmitting, you would load the 7-bit data to be sent into the accumulator and examine 'P'. If it is '1' the byte in the accumulator has odd parity and you would then set the MSbit to make the parity even. After that, the accumulator is moved to the UART transmit register. Note that ODD parity is also possible, you just look for P==1 on receive and test for P==0 to see if you need to set the MSbit of the character to be transmitted. Finally, if you are using 8 bit data, you wouldn't use P at all (on an 8051 anyway..).

Have fun.

EDIT: the description of the banking is how it works in assembly language where you have to pay careful attention those things. In Keil C, you specify which register bank an interrupt routine uses in the interrupt function definition and the compiler will generate the code.
 
Last edited:
Top