This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

measuring time between two pulses

Hi all,

first time posting here. Ive got a most simple goal, measure the time between a bit going low and a second bit going low.

I can only use P1, so Im assuming

loop
while p1.0 = 1

p1.0 = 0?

start a timer, could count up to 10 seconds

now loop waiting for p1.1 = 0

p1.1 = 0?

stop the timer, calculate how many seconds

display the result. Im using an HTE SDK8032 board, there is a monitor routine to display text, it interfaces to hyperterminal. if I can just get that "seconds" value, I could convert as needed and print it.

simple. what happens? nothing.

now Im trying to use C and a 32bit long as the timer int, maybe decrement, jump not zero or ?

but figuring out time from the 11.05 Mc crystal (used for baud rates) is just not making sense right now, any help is appreciated.

Parents
  • wanted to move an immediate value to a register, MOV R7, 0xF4 ; should move the hex value F4 to the register? no. I finally figured out that its MOV R7, #0xFF

    that pound sign seems to mean something to the compiler.


    Well, yes. Not to be flippant, but it means "immediate mode". MOV R7, 0F4H is the syntax for direct addressing. That is, move the contents of address 0F4H to R7. MOV R7, #0F4H is immediate addressing; move the value 0F4H to R7. Two different opcodes, AF or 7F, followed by F4.

    The compare operations are combined with jumps. Take a look at the branching section of the instruction set manual, e.g. CJNE.

    If those instructions don't suit your needs, perhaps it would be useful to note that a compare (on almost any processor) is really just a subtraction operation that doesn't keep the result, performed only for the side offect of setting the "zero" flag for later testing by a branch. Since the 8051 is accumulator-based, you can just ignore the result in the accumulator after a subtraction. (Of course, the number one thing you're likely to do after a compare is "branch if equal/not equal", which is CJNE.)

    As for the ASCII output, I'd suggest a 16-entry lookup table for the characters, for simplicity. You could test for the boundary, as you note. You just want to take the input byte value a nibble at a time. Something like:

    output(ascii[input & 0x0f]);
    input >> 4;
    output(ascii[input & 0x0f]);

    Since you're using assembly, the SWAP instruction might come in handy. You'll probably want to use an indirect addressing mode for the table lookup.

Reply
  • wanted to move an immediate value to a register, MOV R7, 0xF4 ; should move the hex value F4 to the register? no. I finally figured out that its MOV R7, #0xFF

    that pound sign seems to mean something to the compiler.


    Well, yes. Not to be flippant, but it means "immediate mode". MOV R7, 0F4H is the syntax for direct addressing. That is, move the contents of address 0F4H to R7. MOV R7, #0F4H is immediate addressing; move the value 0F4H to R7. Two different opcodes, AF or 7F, followed by F4.

    The compare operations are combined with jumps. Take a look at the branching section of the instruction set manual, e.g. CJNE.

    If those instructions don't suit your needs, perhaps it would be useful to note that a compare (on almost any processor) is really just a subtraction operation that doesn't keep the result, performed only for the side offect of setting the "zero" flag for later testing by a branch. Since the 8051 is accumulator-based, you can just ignore the result in the accumulator after a subtraction. (Of course, the number one thing you're likely to do after a compare is "branch if equal/not equal", which is CJNE.)

    As for the ASCII output, I'd suggest a 16-entry lookup table for the characters, for simplicity. You could test for the boundary, as you note. You just want to take the input byte value a nibble at a time. Something like:

    output(ascii[input & 0x0f]);
    input >> 4;
    output(ascii[input & 0x0f]);

    Since you're using assembly, the SWAP instruction might come in handy. You'll probably want to use an indirect addressing mode for the table lookup.

Children
No data