16F688 port puzzle


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Location
    Isle of Man
    Posts
    32

    Cool 16F688 port puzzle

    I am using a 16F688, with internal clock enabled and only 2 port connections: to LED1 and LED2 on PortC.

    This trivial program shows a problem I have found with the Port addressing:


    CMCON0=%0000111 'Comparators off
    OSCCON.3=1 'Use internal clock
    TRISC=0 'PortC is all output

    LED1 Var PortC.3
    LED2 Var PortC.5
    Timer Var WORD

    Timer=0

    Loop: Pause 20 'Delay makes LED flash at about 1Hz
    Timer=Timer+1
    IF Timer.4=1 then
    LED1=1
    LED2=1
    ENDIF
    IF Timer.4=0 then
    LED1=0
    LED2=0
    ENDIF
    GOTO Loop

    END

    Using this program only LED2 will flash. However, if the statements LED2=1 and LED2=0 are removed, then LED1 will flash. It is not possible to make both flash together!

    Any ideas? I am completely mystified.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Seems to be an analog port related stuff...

    let's open the 16F688 datasheet... mmm i see...

    what about if you add...
    Code:
    ANSEL = 0
    at the top of your code?
    Last edited by mister_e; - 1st October 2007 at 22:08.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Feb 2006
    Location
    Isle of Man
    Posts
    32


    Did you find this post helpful? Yes | No

    Default 16F688 port puzzle - solved

    Yup, that solved the problem!

    Now I realy must try to understand what ANSEL actually does ....

    A BIG thanks again to Mister_E!

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    In that datasheet, ANSEL is not really well documented like most other PIC registers. You need to read between the line. Open the PDF and search for ANSEL, you'll find few hits.

    Basically each bit of ANSEL is assigned to a ADC channel. Bit 0 to AN0, Bit 1 to AN1 and so on. POR value is 255, %11111111. If a specific bit is set, the corresponding channel will be set as analog, if it's clear, it's digital. ANSEL=0 will obviously set every channel to digital.

    EDIT: erm... ok it's documented... Register 4-3, PDF page 36. It's just not in the ADC section... as it 'should be'. Why??? Because
    Last edited by mister_e; - 1st October 2007 at 22:48.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Feb 2006
    Location
    Isle of Man
    Posts
    32


    Did you find this post helpful? Yes | No

    Cool 16F688 Port puzzle

    Yes, I also did a search for ANSEL in the datsheet and found nothing of much use.

    Although it works in this example, I am still unclear why ANSEL has any effect on the behaviour of LEDs on PortC.3 and PortC.5 which are not configurable for analogue.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Miip! C.3 is also AN7...

    In theory ANSEL.7=0 should also work.

    PS: Read again post 4, i changed it while you replied.

    Using a analog port as digital output will do weird things...
    Last edited by mister_e; - 1st October 2007 at 22:56.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. DS1820 with 16f688
    By jessey in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 23rd May 2009, 05:07
  2. Change On Interrupt, PIC16F884
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 14th November 2008, 17:25
  3. port config.
    By tamertokgoz in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th July 2008, 12:25
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. STATUS re-curtain W
    By zugvogel1 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 13th February 2005, 15:21

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