16F684 Basic Functionality


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2008
    Posts
    22

    Default 16F684 Basic Functionality

    Having a few problems getting some basic functions to work properly on a 16F684, not sure if I can see the forest through the trees now. Basically I can't get the toggle function to work, works fine if I set a pin to 1 then 0. Also, if I have a SEROUT pin on the same Port as a Pin I'm manually toggling the SEROUT works but the toggle doesn't, move the SEROUT to a different port and all's fine:


    Code:
    '16f684
    
    DEFINE OSC 8 'Oscillator speed in MHz
    
    OSCCON  =   %01110111       'Page 20
    
    ANSEL   =   %00000000       
    
    TRISA   =   %00000000		
    TRISC   =   %00000000		
    
    PortA   =   %00000000
    PortC   =   %00000000
    
    WPUA    =   %00000000
    
    CMCON0  =   %00000000
    
    ADCON0  =   %00000000
    ADCON1  =   %00000000
                          
    Heart_Beat_LED  Var portC.1 'Output pin to LED for Heart Beat indication, Low is on. 
    Heart_Beat_LED  =   0
    
    Terminal_TX     var	PortC.2	'Output pin to the dumb terminal or PC program on port C
    
    Start:
    
    'Uncomment subroutine 1, 2, or 3
    
    'Goto Subroutine_1
    'Goto Subroutine_2
    'Goto Subroutine_3
    
    goto Start
    
    
    Subroutine_1:   'This works.
    
        Heart_Beat_LED = 1
        Pause 1000
        Heart_Beat_LED = 0
        Pause 1000
        Goto Start
    
    
    Subroutine_2:   'Pin is "low" and can be seen cycling between 125mV and 75mV on a scope. 
                    'both serial out's seen on terminal.
                    'If I move the Terminal_TX to PortA it works.
                    
        Heart_Beat_LED = 1
        serout Terminal_TX,6,["1-Heart_Beat_LED",13,10] 
        Pause 1000
        
        Heart_Beat_LED = 0
        serout Terminal_TX,6,["2-Heart_Beat_LED",13,10]
        Pause 1000
        Goto Start
    
    
    Subroutine_3:   'Doesn't work 
    
        Toggle Heart_Beat_LED
        Pause 1000
        Goto Start
    Last edited by munromh; - 25th September 2009 at 16:01.

  2. #2
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Strange. I have seen toggle do strange things before but cant remember what the problem was.

    Out of interest, does it work if you use the following instead of toggle:

    IF Heart_Beat_LED=0 THEN
    Heart_Beat_LED=1
    ELSE
    Heart_Beat_LED=0
    ENDIF

    PAUSE 1000
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default analog blues perhaps

    cmcon0 = 7 'Comparators off. CxIN pins are configured as<b> digital I/O</b>
    cmcon0 = 0'Comparators off. CxIN pins are configured as analog
    Last edited by Archangel; - 25th September 2009 at 19:03.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Nov 2008
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kamikaze47 View Post
    Strange. I have seen toggle do strange things before but cant remember what the problem was.
    Me too.

    IF Heart_Beat_LED=0 THEN
    Heart_Beat_LED=1
    ELSE
    Heart_Beat_LED=0
    ENDIF

    PAUSE 1000
    Nada, doesn't work. Pin stays high, don't see any change with a scope. It always sees Heart_Beat_LED = 0.

    Interestingly enough, which I left off the earlier post, if I write:

    Code:
    serout Terminal_TX,6,["1-Heart_Beat_LED = ",#Heart_Beat_LED,13,10]
    serout Terminal_TX,6,["2-Heart_Beat_LED = ",#Heart_Beat_LED,13,10]
    The value remains zero in each SEROUT.

  5. #5
    Join Date
    Nov 2008
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    cmcon0 = 7 'Comparators off. CxIN pins are configured as<b> digital I/O</b>
    Thanks Joe S., I should know better. All is fine now.

  6. #6
    Join Date
    Sep 2009
    Posts
    11


    Did you find this post helpful? Yes | No

    Default configure 16f690 for xtal osc

    Can't quite find the right place to ask this but anyway.....please bear with me..........
    Have scoured the 306 pages of the data sheet and still can't make my
    PIC16F690 oscillate at 12MHz. In PBP how do I configure it for ext crystal?
    Desperate, why do I find it so difficult? I'm only 70 yrs old.
    Cheers

  7. #7
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    External Oscillator selection is performed from the CONFIGURATION BITS of this PIC.

    See section 14 of the Datasheet (and section 3 if you're really bored)... mine's only got 304 pages, so you must have the 'Professionals' copy.

    Use your programmer to select HS OSC manually at program time if you are connecting a 12MHz Xtal.

    Alternatively, embed the appropriate device CONFIG into your program... see for example...

    http://www.picbasic.co.uk/forum/showthread.php?t=543

    Finally, don't forget to include DEFINE OSC 12 somewhere at the top of your program to tell PBP that you're running at 12MHz, otherwise it will continue to think you're at 4MHz (the default).

Similar Threads

  1. Indexer not indexing...a basic PBP problem??
    By jellis00 in forum General
    Replies: 8
    Last Post: - 24th March 2009, 16:53
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  3. using AND as an IF statement
    By dw_pic in forum mel PIC BASIC
    Replies: 27
    Last Post: - 8th June 2006, 18:05
  4. vb6 to pic basic
    By Darrenmac in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 19th December 2005, 01:56
  5. The Ultimate PIC Basic
    By picnaut in forum PBP Wish List
    Replies: 4
    Last Post: - 9th November 2004, 22:10

Members who have read this thread : 1

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