PIC16F887 Config problem


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2005
    Location
    Cambridge UK
    Posts
    45

    Default PIC16F887 Config problem

    Hi,
    Can some one tell me where I have gone wrong with the code below please.
    Code:
     
    DEFINE OSC 8
    DEFINE ADC_BITS 10      'Defines bit resoloution
    DEFINE ADC_CLOCK 2		'Defines adc clock speed	
    DEFINE ADC_SAMPLEUS 50	'Defines sammple time of 50mS
    TRISD = %00000000
    TRISA = %11111111
    ADCON1 = %00000000   '
    ANSEL = %11111111	'All portA pins analog
    ADCON0 = %01000001	'configure A2D for Fosc/8, Channel 0 (RA0), and turn on the A2D module
    CM1CON0 = %00000000  'comparator 1 off
    CM2CON0 = %00000000  'comparator 2 off
    
    
    bar var word
    
    main:
    adcin 0,bar
    portd = bar.highbyte
    goto main
    I am using a PICkit 2 with PBP 4.47 and MPLAB v8.10. All I want to do at the moment is output the a2d0 on portc. I have set the required registers using the data sheet for the 16f887 as far as I can tell.
    Thankyou.

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


    Did you find this post helpful? Yes | No

    Default

    Seems good, you have it left justified, but you read the highbyte.. that's not the problem here. So the question are

    1) what doesn't work?
    2) Expected to work on Internal or external OSC?
    3) Config fuses?

    PS: PBP 2.47 had some issue with that PIC about ADCIN and default clock. Problem solved in 2.50. Sur we had found a workaround in here somewhere...
    Last edited by mister_e; - 13th November 2008 at 21:33.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Last edited by mister_e; - 13th November 2008 at 21:48.
    Steve

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

  4. #4
    Join Date
    Nov 2005
    Location
    Cambridge UK
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    1) what doesn't work?
    When I run the debug I can see the registers with either FF or 0 depending where the pot is, the output on portc is the same value as these viewed registers. The program acts like a comparator been left enabled on the a2d pin.

    2) Expected to work on Internal or external OSC?
    I am using the internal osc, I have tried to replicate one of the sample asm demo files to make sure I understand whats happening. I can also blink the LEDs without a problem.
    This is the code
    Code:
    TRISC = %00000000
    loop: 
    
    high portd.3
    pause 250
    high portd.2
    pause 250
    low portd.3
    pause 250
    low portd.2
    pause 250
    goto loop
    end
    3) Config fuses?
    I think this may be the problem, if I set config fuses in the code I get duplicate label errors.
    I have not set any in the code or changed them in the inc files as the blinky code above works.

  5. #5
    Join Date
    Nov 2005
    Location
    Cambridge UK
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    Mister e,
    Thanks very much for the info on that work around!!!! I had only searched the forum using pic16f887. This little test program works fine now. Its only taken me three days to sort this.
    Kind regards Nick

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


    Did you find this post helpful? Yes | No

    Default

    I see you have it working... anywho, this method is very reliable if you want to play with another way.
    http://rentron.com/PICX2.htm
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. A/D conversion with PIC18F67J50
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2009, 01:48
  2. 18F4550 Bootloader enter via eeprom setting
    By bradb in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 22nd November 2008, 23:51
  3. Error 0X0000008E when connecting a 18F2550 USB HID
    By FranciscoMartin in forum USB
    Replies: 8
    Last Post: - 16th October 2008, 17:20
  4. PortE problems (PIC18F4455)
    By RubenR in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 12th July 2006, 15:26
  5. Installation sequence
    By Demon in forum General
    Replies: 23
    Last Post: - 11th July 2006, 03:56

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