dimanche 1 mars 2015

Code review for microcontroller 8051


I'm working with microcontroller 8051. I'm trying to simulate serial comunication on RS232 port. To do that, I need to take a single bit by bit from a number (ASCII value of a char) and put it on the port for certain amount of time.


Here is a part of my code, which might be problematic.



BITS set 60h
MOV BITS, #8
index set 0
sendDataBit:
JB 20h.index,set1
CLR T
return:
CALL waitDataBit
index set index+1
DJNZ BITS,sendDataBit


set1:
SETB T
AJMP return


I stored my ASCII number in address 20h (bit-addressable area). Now I want to access every bit of the number separately. Idealy in a loop with dynamic indexing.


The only way it work for me is to define variable index and re-define it in each loop to incremented value. But 'set' is not a instruction of the microcontroller. I'm sorry, I don't know the terminology here. And I need to precisely time whole process. With 'set' I don't know what's happening in there.


So that's why I don't like this part of my code. What do you dislike about it? Could anybody explain what is happening when running this code? What is the better solution for my problem?





Aucun commentaire:

Enregistrer un commentaire