0
votes

I am trying to solve this problem with 8051 in Assembly language. So, here is the question: There is 8-bit data comes from the Computer with 9600 baudrate. Each data gets parity check with 8051 microcontroller. If data parity is 1, R0 increases. If it's zero, R1 increases. After 10 data, if the data with parity 1 is greater than data with parity 0, then P1.0 led lights up. Else, P1.1 led lights up. Write to program for this. ( Crystal 11.059MHz )

I wrote this, but how do I get the data parity?

MOV TMOD,#00100000B
MOV SCON,#11001000B
MOV TH1,#-3
SETB TR1
MOV R0,#0 
MOV R1,#0
MOV R2,#10 
MAIN:
JNB RI,$
CLR RI
MOV A,SBUF
MOV C,RB8
MOV P,C
JB P,PARITY1 
PARITY0: 
INC R1 
SJMP DONGU
PARITY1:
INC R0
DONGU: 
DJNZ R2,MAIN
MOV A,R0
SUBB A,R1
JC LEDB
LEDA: 
CPL P1.0
SJMP DONE
LEDB:
CPL P1.1
DONE: NOP
END  

I think this part is nonsense for this problem, what should do?

MOV C,RB8
MOV P,C

Thank you for your help.

1
Welcome to Stack Overflow. Please edit your question to improve its quality and focus: (1) Which part of parity calculation are you struggling with - how to calculate it, or how to program it in assembler? In both cases, you should boil down the question to a minimal problem. (2) The question&answer are not only meant for you, but they will be saved so that others will find them and can reuse both. Therefore, please make use of newline and other formatting, and check spelling.HelpingHand

1 Answers

0
votes

The general idea seems to get the parity bit of the incoming data from the special bit RB8 located in SCON register (http://www.keil.com/support/man/docs/is51/is51_ov_cpupsw.htm), which is the register of the serial port.

Basing on it, one of two branches (PARITY0 and PARITY1) is taken.

The only strange thing is that the incoming parity bit, RB8, gets moved to the P bit, which is useless; one could load RB8 in the carry and perform a jc/jnc. The P bit is useful to know the parity of the byte loaded in the accumulator, it is non sense to try to write to it.

For some more information, you can look here: https://openlabpro.com/guide/uart-8051/ to see a general overview of the 8051 serial port.