Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

8051 timer help. thx

dadsfdadsf Member Posts: 3
hello all... im just begining doing assembler and am currently doing a reaction timer. how it works is that a light comes, u press the button then sends the time to a register. the code at the bottem is mostly part of it. turns on light, pres the button it turns off.
what i cannot get is the actual timing. how can i make it output the actual time. i can't get the actual time into the code. don't know how to do that.
also my program repeats 3 times soi can take an average of the reaction. how can i add all 3 times together..thank u all. apreciate it.


SJMP REPEAT
ORG 00040H

RAND16REG equ 0021H ;two byte random nunmber

REPEAT: MOV R7,#003H ;set number in sequence
JMP START

INIT: MOV A,#0 ;copy 0 to accumulator
MOV P0,A ;move accumulator to port 0
INC R0 ;increment the register 0
RET ;return to start for next step

GETSTART: MOV A,P1 ;move port 1 to accumulator
ANL A,#00000001B ;and imediate data with accumulator
ADD A,#0 ;add imediate data 0 to accumulator
JZ GETSTART ;
INC R1
RET

OUTGO: MOV A,#00000001B
MOV P0,A
INC R2
CALL STARTTIME
RET

GETSTOP: MOV A,P1
ANL A,#10000000B
ADD A,#0
JZ GETSTOP
INC R3
CALL STOPTIME
RET

OUTTIME: MOV A,#10000000B
MOV P0,A
INC R4
RET

STARTTIME: INC R5
RET

STOPTIME: INC R6
ret

rand16 : mov a, rand16reg
jnz rand16b
mov a, rand16reg+1
jnz rand16b
cpl a
mov rand16reg, a
mov rand16reg+1, a

rand16b : anl a, #11010000b
mov c, p
mov a, rand16reg
jnb acc.3, rand16c
cpl c

rand16c : rlc a
mov rand16reg, a
mov b, a
mov a, rand16reg+1
rlc a
mov rand16reg, a
xch a, b
ret

START: CALL INIT ;call subroutine INIT
CaLL GETSTART ;call subroutine getstart
CALL OUTGO ;call subroutine outgo
CALL GETSTOP ;call subroutine getstop
CALL OUTTIME ;call subroutine outtime
Call RAND16 ;call random number
CALL RAND16b
Call rand16c
DJNZ R7,START ;REPEAT FOR 3 TIMES

END



Comments

  • kapil.singhikapil.singhi Member Posts: 2
    1)First of all you should be sure of the time base i.e clock to be accurate may be like 12.000000Mhz.

    2)Use the timer overflow interrupt for measuring the time. Say you configur the timer which gives interrupt ever 1 ms. In ISR you have a counter to measure the no of ISR calls.

    3)Use hex to bcd conversion for for displaying the time on SEVEN segement display or LCD

    : hello all... im just begining doing assembler and am currently doing a reaction timer. how it works is that a light comes, u press the button then sends the time to a register. the code at the bottem is mostly part of it. turns on light, pres the button it turns off.
    : what i cannot get is the actual timing. how can i make it output the actual time. i can't get the actual time into the code. don't know how to do that.
    : also my program repeats 3 times soi can take an average of the reaction. how can i add all 3 times together..thank u all. apreciate it.
    :
    :
    : SJMP REPEAT
    : ORG 00040H
    :
    : RAND16REG equ 0021H ;two byte random nunmber
    :
    : REPEAT: MOV R7,#003H ;set number in sequence
    : JMP START
    :
    : INIT: MOV A,#0 ;copy 0 to accumulator
    : MOV P0,A ;move accumulator to port 0
    : INC R0 ;increment the register 0
    : RET ;return to start for next step
    :
    : GETSTART: MOV A,P1 ;move port 1 to accumulator
    : ANL A,#00000001B ;and imediate data with accumulator
    : ADD A,#0 ;add imediate data 0 to accumulator
    : JZ GETSTART ;
    : INC R1
    : RET
    :
    : OUTGO: MOV A,#00000001B
    : MOV P0,A
    : INC R2
    : CALL STARTTIME
    : RET
    :
    : GETSTOP: MOV A,P1
    : ANL A,#10000000B
    : ADD A,#0
    : JZ GETSTOP
    : INC R3
    : CALL STOPTIME
    : RET
    :
    : OUTTIME: MOV A,#10000000B
    : MOV P0,A
    : INC R4
    : RET
    :
    : STARTTIME: INC R5
    : RET
    :
    : STOPTIME: INC R6
    : ret
    :
    : rand16 : mov a, rand16reg
    : jnz rand16b
    : mov a, rand16reg+1
    : jnz rand16b
    : cpl a
    : mov rand16reg, a
    : mov rand16reg+1, a
    :
    : rand16b : anl a, #11010000b
    : mov c, p
    : mov a, rand16reg
    : jnb acc.3, rand16c
    : cpl c
    :
    : rand16c : rlc a
    : mov rand16reg, a
    : mov b, a
    : mov a, rand16reg+1
    : rlc a
    : mov rand16reg, a
    : xch a, b
    : ret
    :
    : START: CALL INIT ;call subroutine INIT
    : CaLL GETSTART ;call subroutine getstart
    : CALL OUTGO ;call subroutine outgo
    : CALL GETSTOP ;call subroutine getstop
    : CALL OUTTIME ;call subroutine outtime
    : Call RAND16 ;call random number
    : CALL RAND16b
    : Call rand16c
    : DJNZ R7,START ;REPEAT FOR 3 TIMES
    :
    : END
    :
    :
    :
    :

Sign In or Register to comment.