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

Timer 0 as counter

Can anyone please send me the code for counting pulses using timer 0 as counter in 'C'language.

Parents
  • The assembly code is
    MOV TMOD,#25h
    MOV TH0,#00h
    MOV TL0,#00h
    SETB P3.4
    AGAIN:SETB TR0
    MOV R3,TL0
    MOV R4,TH0
    Back: JNB TF0,Back
    CLR TR0
    CLR TF0
    SJMP AGAIN

    The c code is

    void main()
    { unsigned int pulsecount,Fpulse_count; while(1) { TH0=0x00; TL0=0x00; P3=0xFF; TR0=1; /* Start the timer for counting pulses*/ if(TF0!=1) { Fpulse_count++; } pulsecount=TH0*256+TL0; TR0=0; TF0=0; }
    }

Reply
  • The assembly code is
    MOV TMOD,#25h
    MOV TH0,#00h
    MOV TL0,#00h
    SETB P3.4
    AGAIN:SETB TR0
    MOV R3,TL0
    MOV R4,TH0
    Back: JNB TF0,Back
    CLR TR0
    CLR TF0
    SJMP AGAIN

    The c code is

    void main()
    { unsigned int pulsecount,Fpulse_count; while(1) { TH0=0x00; TL0=0x00; P3=0xFF; TR0=1; /* Start the timer for counting pulses*/ if(TF0!=1) { Fpulse_count++; } pulsecount=TH0*256+TL0; TR0=0; TF0=0; }
    }

Children