8051

absf

Joined Dec 29, 2010
1,968
I can use Subb command only to determine result is positive or negative? for positive, carry=0, for negative, carry=1
or it also tell us whether number is greater or less than other.
Subb A,11 ; carry=1 if A<11
I think that would depends on how you define negative numbers. You can have a look on this thread for some ideas.

http://forum.allaboutcircuits.com/threads/help-on-the-nature-of-negative-binary-numbers.108690/

Second problem i am facing is:
for 5ms delay using timer and mode 1, i use the procedure as explained in last two lines of post#15, but for 200ms or 400ms, the value is much greater than that for 16 bit as mode 1 is for 16 bit.Now, i am confused how to calculate the delay? whether i should have to use nested loop without timer or there is anyother technique to resolve this using timer and mode?
I am not too sure about this. Been too long not using 8051. Have to dig out my notes to find out.
May be @cmartinez can help here ........

Allen
 

cmartinez

Joined Jan 17, 2007
8,257
I think that would depends on how you define negative numbers. You can have a look on this thread for some ideas.

http://forum.allaboutcircuits.com/threads/help-on-the-nature-of-negative-binary-numbers.108690/



I am not too sure about this. Been too long not using 8051. Have to dig out my notes to find out.
May be @cmartinez can help here ........

Allen
Sure I can help... but I'll look into it tomorrow morning. Down here it's 12:20 AM and I gotta go whisper to my pillow...
 

cmartinez

Joined Jan 17, 2007
8,257
Ok I'm back... rested and refreshed.. :)
To accurately generate a delay loop in an 8051 MCU, you have to know exactly how many clock cycles each instruction takes. This is normally documented in the manufacturer's datasheet.
For instance, I normally use the AT89LP4052, and each instruction normally lasts only 1/12th of what a classic 8051 would take.
If you're going to generate delay loops in the range of several hundred ms, I'd suggest you wrote code for a routine that would generate a 1 ms delay when called.

Here's an example of a routine that generates a Useconds µs delay:

Code:
********************************************************************************************************
;  Wait routine
;  number of microseconds waited = 1.01725 * Useconds
;  Keeping in mind that we're working with a 14.7456MHZ oscillator, and that the AT89LP4052 takes
;  one clock cycle per machine cycle, then each machine cycle takes 0.000 000 067816840277... sec,
;  that is 0.0678µs, and that means that we need 14.7456 machine cycles in order to spend 1µs
;  VERY IMPORTANT: THE MINIMUM VALUE THAT THE Useconds VARIABLE CAN HAVE IS #3D !!!!
;********************************************************************************************************
WAIT:            ;calling wait takes 3/4 cycles \
  PUSH Useconds  ;2 cycles  > Total of 8 cycles
  PUSH R0        ;2 cycles  /

  MOV R0, #3D  ;2 cycles \
  MOV R0, #3D  ;2 cycles |
  MOV R0, #3D  ;2 cycles  > dummy instructions, totaling 10 cycles
  MOV R0, #3D  ;2 cycles |
  MOV R0, #3D  ;2 cycles /

  ;The total number of cycles of all the instructions, including the DEC's applied to the Useconds
  ;variable, and considering the exception of those included in the wait loop, is 30 cycles, which is
  ;approx 2 microseconds. That is why we're decreasing the Useconds variable by 2, so that in the end
  ;we get the number of approximately desired microseconds.
  ;This means that for this routine to work, the minimum value for Useconds has to be #3D

  DEC Useconds  ;2 cycles  \ Total of
  DEC Useconds  ;2 cycles  / 4 cycles

  WAIT_LOOP:
  MOV R0, #3D  ;2 cycles                 \  R0 = 3, therefore the total number of cycles is
  DJNZ R0, $  ;3 cycles                   \ 3*3+6=15 cycles per loop, which will be a little over 1µs
  DJNZ Useconds, WAIT_LOOP  ;4 cycles     / in the end the number of total waited µs will be
  ;                                      /  1.01725 µs per executed loop

  POP R0  ;2 cycles       \
  POP Useconds  ;2 cycles  > Total of 8 cycles
RET  ;4 cycles            /
 

absf

Joined Dec 29, 2010
1,968
I found a good 8051 timer calculator here.

http://www.8051projects.net/download-d115-8051-time-delaytimer-routine-calculator.html

You may download it and run it and enter the time delay (S, mS, uS) that you want. The program will calculate and even write the program in .asm for you; so you can just insert the code into your program.

If you use the vanila 8051 running at 12 MHz, the longest time delay you can get is around 65mS using 16 bit timer. So just generate 50mS delay and call it multiple times.

Unfortunately there is no provision for making time delay using wasting time method by counting variables/registers/DJNZ combinations. I'd link it here if I find one.

In case you're using fast single clock cycle mcu like the one mentioned by cmartinez, then you have to adjust the division factors in the program in order to get the correct timing.

Allen
 

Thread Starter

Ameer ul haq

Joined Mar 19, 2015
11
Hello #absf and cmartinez!
Can you help me that max232 serial communication in 8051, when we give input from PC, how the serial communication circuit knows that it is Alphabet or letter etc.If the input is alphabet, reply the word with that alphabet.Can you explain it well.
 
Last edited:
Top