Help in trying to set pins functions


Closed Thread
Results 1 to 4 of 4
  1. #1

    Default Help in trying to set pins functions

    I'm trying to set the pins functions of 16F723. As I'm total green to PICs I'm finding it hard to understand the datasheet, I've been trying to find info on how to read and understand the datasheet but with no luck, can anyone point me to such info.
    I would like to set all the Ports to digital, pull-ups on Port B and internal oscillator running at 4MHz.

    The settings I'm using are the following:
    OSCCON = %01100000 ' Sets the internal oscillator register to 4 MHz
    ADCON1=%00000111 ' All Ports Digital
    OPTION_REG.7 = 0 ' Enable Port B pull-ups

    TRISB = %11111111 ' Port B input
    TRISA = %00000000 ' Port A output
    TRISC = %11111100 ' Port C inputs C.2 to C.7 inputs Port C.0 and C.1 outputs

    Can you let me know if the settings any right or explane what is wrong.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Help in trying to set pins functions

    Hi,
    OSCCON = %01100000 ' Sets the internal oscillator register to 4 MHz
    Nope, the two most significant bits are not used so that can't be right. OSCCON = %00010000 would be 4MHz IF the PLL is enabled (which you do with the CONFIG bits). If the PLL is not enabled you'd get 125kHz.

    ADCON1=%00000111 ' All Ports Digital
    Nope, ADCON1 basically controls the clock to the ADC and from where it gets its references. To set which pins are analog vs digital you use ANSELA, ANSELB, ANSELE

    OPTION_REG.7 = 0 ' Enable Port B pull-ups
    Yes and no. This "turns on" the pullups but you also need to select WHICH of the 8 pullups to be enabled - you do that thru the WPUB register.

    TRISB = %11111111 ' Port B input
    TRISA = %00000000 ' Port A output
    TRISC = %11111100 ' Port C inputs C.2 to C.7 inputs Port C.0 and C.1 outputs
    Yep, that seems right.

    Always use the datasheet for the correct device. Just because it's done one way with one device for which you may see some code on the 'net doesn't mean it's the same for another device - that would just be TOO easy ;-)

    As for "how to read the datasheet" I don'r have any good advice really. It's just a matter of reading thru the section pertaining to the specific peripheral you're using. Oh, one tip though, at the end of each section there's a list of registers which, in one way or another, relates to the specific peripheral. If something doesn't work the way you expect go thru that list and make sure you haven't missed something.

    /Henrik.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Help in trying to set pins functions

    Thanks for the input, I do not understand CONFIG bits and PLL is enabling, where can I find how to do this? I have look at lots of basic code and have not seen any reference to CONFIG bits so don't know where to start. I still can not workout how to set all the ports to digital when I try to use ANSELA, ANSELB, ANSELE I can not get the code to compile just get the following errors C:\PBP\PBPPIC14.LIB 463 : Symbol not previously defined (ANSEL) and Error[113] C:\PBP\PBPPIC14.LIB 449 : Symbol not previously defined (ANSELH)...

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Help in trying to set pins functions

    My bad perhaps, ANSELE is not implemented in the 28pin devices (722, 723, 726), only in the larger variants in the family. ANSELA and ANSELB should work though.

    PBP has a default CONFIG for each device which it uses if you don't tell it otherwise. You can either override the CONFIG in your programmer software or put the changes in your code (recommended). If you have PBP3 the open the manual and look at the #CONFIG directive, that's what you use to override the defaults. If you have an older version you need to either edit/change the default config OR comment it out and add your own in your code. For more info on that, take a look at this thread.

    /Henrik.

Similar Threads

  1. String types and functions AND Functions with arguments
    By PickyBiker in forum PBP Wish List
    Replies: 3
    Last Post: - 1st January 2015, 09:00
  2. functions
    By Charles Linquis in forum PBP Wish List
    Replies: 2
    Last Post: - 9th November 2009, 04:13
  3. FUNCTIONS in PBP
    By Mostafa in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 29th June 2007, 08:20
  4. functions
    By BigWumpus in forum PBP Wish List
    Replies: 1
    Last Post: - 13th June 2006, 17:05
  5. Functions
    By AndyP in forum PBP Wish List
    Replies: 4
    Last Post: - 6th May 2005, 12:00

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