PIC16F676 troubles


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: PIC16F676 troubles

    I've tried several things with the registers, but no luck. I've also added a sub to make it behave the way it should:

    Code:
    #config 
        __CONFIG _CP_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT& _MCLRE_OFF
    #endconfig
    
    ADCON1 = %00000000
    ANSEL = %00000100
    CMCON = 0      
    
    TRISA = %11001100
    TRISC = %00000000
    
    LED var PORTA.1
    PUSHBUTTON var PORTA.3
    
    
    led = 1
    pause 100
    led = 0
    pause 100  
    led = 1
    pause 100
    led = 0
    
    main:
    
        if PUSHBUTTON = 0 then 
            toggle LED
            pause 25
            gosub buttonrelease
            pause 25
        endif
        
    goto main
    end
    
    buttonrelease:
    
        do until PUSHBUTTON = 1
            pause 10
        loop
        
        return
    It still does the same thing. The LED flashes on power up. The button works once. And then it locks up. And I've tried several other "lower level" ways of making the LED toggle instead of the TOGGLE statement. It's always the same. Here's something interesting, though. If I change the code to just make the LED come on when the button is pressed instead of trying to toggle it like so:

    Code:
    main:
    
           if PUSHBUTTON = 0 then
                  LED = 1
           elseif PUSHBUTTON = 1 then
                  LED = 0
           endif
    
    goto main
    end
    Everything works perfectly! So I'm assuming the problem isn't with the MCLR pin or the registries. Do I need to define the oscillator?

  2. #2
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: PIC16F676 troubles

    I think the issue is the Comparator module is still turned on.

    Your CMCON = 0 sets the comparator to Reset with RA0 and RA1 connected to the Comparator module.
    Have a look at the DS Figure 6-2 which shows the possible 8 modes of the comparator.
    You should try setting CMCON = %00000111
    Regards,
    TABSoft

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: PIC16F676 troubles

    That did the trick. Thanks, Tabsoft!

  4. #4
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: PIC16F676 troubles

    Good deal.

    I suspect with the Comparator module set to 000 whenever you perform a Toggle command this actually reads the port then writes the new value to it. This issue is that the port will always read 0 when it is configured in Reset mode.
    Last edited by Tabsoft; - 29th May 2015 at 00:06.
    Regards,
    TABSoft

Similar Threads

  1. PIC16F676 RS232 baud rate
    By jrprogrammer in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th February 2010, 15:16
  2. PIC16F676 Problem
    By Atom058 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 19th April 2007, 17:05
  3. Interfacing RTC (DS1302) with pic16F676
    By Andrew_A in forum Off Topic
    Replies: 1
    Last Post: - 14th February 2006, 09:49
  4. PIC16F676 I/O Problems.
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th March 2005, 17:37
  5. PIC16F676 Troubles
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 27th February 2005, 11:01

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts