Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

PIC 16f684 timer0 question

Hi,

I am a beginner at PIC programming and am trying to get timer0 to work as an event counter on external pin T0CK1.

The basic program structure is:

init:
movlw b'00110000' ; Make TMR0 a counter (pull-ups on
movwf OPTION_REG ; T0CK1 enable, falling edge, no pre-scaler

main_loop:

movf TMR0, w
movwf PORTC
delay
goto main_loop

I have a switch connected to T0CK1 that pulls the pin low when pressed and LEDS connected to PORTC to see TMR0 value. I would expect to see the LEDS increment with each button press, but instead I have to press 256 times to see TMR0 increment. Is this how timer0 is supposed to behave as an event counter on an external pin? I have tried different pre-scaler values and nothing has any effect. I am obviously missing something, can someone help me out,

regards

Dave





Comments

  • ProgramerKicoProgramerKico Posts: 2Member
    Hi,dave! I saw your post,and might I have a solution. I wrote program in
    MPLAB. It is free for download. [u]www.microchip.com[/u]

    ;----------------------------------------------------------------
    list p=16f684
    #include

    org 0x0000
    goto start

    start
    movlw b'00110000'
    movwf OPTION_REG ;TMR0 Adjusment (Prescaler 1:2)

    movlw 0x00
    movwf TRISC ;Make PORTC to OUTPUT!

    clrf PORTC ;Write 0 to portc (Turn off all diodes!)

    bsf TRISA,4 ;Make RA4 INPUT (Connect switch here)
    ;================|
    ; Main Loop =|
    ;================|
    loop
    movfw TMR0 ;Take value of TMR0 and...
    movwf PORTC ;Show on PORTC
    goto loop
    ;----------------------------------------------------------------

    That's all... You don't need "delay routine" becasuse incrementing TMR0
    is a backward process.(The only job which MCU have to work is to display value of TMR0 on leds.)
    Also,if you tired making loop's for delay,just say me and I will send you
    macrow which I wrote for 20Mhz Crystal. You just write command:
    pauzams .100 (it means: pause 100ms )

    Best wishes.

    Stefan

Sign In or Register to comment.