16f887 44 pin demo board code problem?


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default

    Hello,
    I was wondering if someone could suggest why this code below doesn't work to change the oscillator speed of the Internal Oscillator while the program is running but the other code block below does work? Another thing I was pondering is, shouldn't I be setting bit 0 of the OSCCON register to 1? The datasheet for the 16f887 says this about bit 0:
    1 = Internal oscillator is used for system clock
    0 = Clock source defined by FOSC<2:0> of the CONFIG1 register.

    Code:
    'this doesn't work
       IF Push_Button = Is_Pressed THEN 
          IF OSCCON = %01100000 THEN 
             OSCCON = %01110000  
          ELSE 
             OSCCON = %01100000 
          ENDIF 
          WHILE Push_Button = Is_Pressed  
               PORTD = %10000001 ' Show that button press has stopped the code here
          WEND 
       ENDIF
    Code:
    'this works
       IF Push_Button = Is_Pressed THEN
          IF B = 0 THEN 
             B = 1 
          ELSE 
             B = 0
          ENDIF
          WHILE Push_Button = Is_Pressed  
               PORTD = %10000001 ' Show that button press has stopped the code here
          WEND
       ENDIF 
       IF B = 0 THEN OSCCON = %01110000 ' 8 MHz 
       IF B = 1 THEN OSCCON = %01100000 ' 4 MHz
    Thanks
    jessey

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Lightbulb

    hi,

    I think it is "not so good" to change osc settings WHILE you touch the button ( debounce issue guaranteed !!! ...PORTD can show anything but truth !!! )

    good reason for #2 to work better ... ONLY better.

    I ( it's me ...) Would look for button state CHANGES instead of simply the button state ...

    Alain
    Last edited by Acetronics2; - 7th December 2008 at 13:23.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Another thing I was pondering is, shouldn't I be setting bit 0 of the OSCCON register to 1? The datasheet for the 16f887 says this about bit 0:
    1 = Internal oscillator is used for system clock
    0 = Clock source defined by FOSC<2:0> of the CONFIG1 register.
    See post #4
    You have the OSC set for internal at the start. In the config settings. You do not need to change the source.
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  3. Help with 18F4520 on PICDEM 2 Plus Demo Board 2006
    By kennYy in forum mel PIC BASIC
    Replies: 2
    Last Post: - 28th April 2008, 16:12
  4. 7 segment digit problem (using Mister E's code)
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 9th September 2005, 20:25
  5. SRF04 Range Finder 16F628 R18iXL Board
    By Spindle in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th June 2005, 02:08

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