Code works on 16F84A but not on 16F88?


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

    Default Code works on 16F84A but not on 16F88?

    I'm working on a project using a 16F88 to read an input voltage and act when the signal drops below a certain threshold. I had the program working on a 16F84A using an RC network and the POT command to simulate the voltage input, but in order to actually build the project I needed an A to D converter.

    I got a 16F88 and can program it okay using my LABX-3 and my ICD2, my code compiles and programs, but nothing is happening on my PIC.

    To test things out, I have removed everything from the circuit except the basics - 5V supply, decoupling cap, 4 MHz xtal + 2x 22pF caps, 100k resistor from RB3 to ground, and a 470R resistor in series with an LED to ground from RB4. This is the same as the LABX-18, which is designed around the 16F88. As far as I can tell, the big differences in the two chips are the locations of the TX and RX pins connected to the MAX232. My MAX232 is out of circuit.

    Here is my code:

    Code:
    ANSEL = 0
    CMCON = 7
    
    OUTPUT PORTB.4
    
    blink:     PORTB.4 = 1
               PAUSE 500
               PORTB.4 = 0
               PAUSE 500
               GOTO blink
    
    END
    My config bits are set to:
    Oscillator = XT
    Watchdog timer, Powerup timer = OFF
    MCLR is on
    BODETECT = off
    LVP is off

    everything else is off.

    This code works fine on a 16F84A. Am I doing something wrong with the oscillator selection? I would think that I could just tell it to use the XT oscillator, right? Do I have to tell it that it has a 4MHz xtal?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    With MCLR ON, do you have a pull-up resistor on the MCLR pin?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Yes, /MCLR is pulled high. I'm using a LABX-3 development board, designed for 18 pin PICs.

    I'm certain that the problem is in the program, not the hardware. As I said earlier, the same program works on a 16F84A. Programming the 16F88 with a pre-made .hex file from another project works as well, but I can't see why my code won't work.

    I've turned off the analog peripherals, ANSEL = 0, CMCON = 7, and I'm feeding the clock input pins with a 4MHz crystal plus 2x 22pF caps. If I set the oscillator type to be HS I can see the 4MHz oscillation on my scope. The chip is working, so why isn't my program?

    I'm not an expert on the 16F88, far from it, so is there something I'm forgetting?

    If I set the oscillator to HS, do I need to tell the PIC what speed the clock is? That would be OSCCON = $60, right? I've tried that and nothing seems to work.

    Is there something wrong with how I'm setting up the port? I've tried setting it with TRISB as well, and that doesn't make my LED blink either. This is the absolute simplest program I can think of to test my setup and it's very frustrating that it works great on an '84A and not on an '88. Exact same code is working on the hardware with an '84A, so I think the hardware is OK. What's wrong with my code?

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Definitely getting somewhere. I have the PIC working, but it's blinking the wrong pin! As far as I can tell, it SHOULD be blinking RB4, pin 10, but it is actually blinking RB0, pin 6. It's also not blinking as fast as it should - it should change states every 5 ms, but it's changing about every 1 s. Is there some reason RB0 would hop up and down? It's the same on two different chips as well.

    Code:
    @ DEVICE PIC16F88, MCLR_ON, HS_OSC, WDT_OFF, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF
    
    ANSEL = 0
    CMCON = 7
    
    TRISB.4 = 0
    
    LED var	PORTB.4
    
    blink:	LED = 1
    	Pause 5
    	LED = 0
    	Pause 5
    	goto blink
    End
    This is encouraging but I've got a long way to go if I can't even get the 'F88 to blink the right port pin...
    Last edited by pharaohamps; - 6th November 2009 at 15:40.

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    With a 4MHz crystal you might want to change to XT_OSC so you're not over-driving
    your crystal.

    I don't have an X3 board to test it with, but this definitely works on a breadboard with
    a 16F88, and blinks RB4.
    Code:
    @ DEVICE PIC16F88, XT_OSC, MCLR_ON, WDT_OFF, LVP_OFF, PROTECT_OFF
    
    ANSEL = 0
    CMCON = 7
    
    OUTPUT PORTB.4
    
    blink:
      PORTB.4 = 1
      PAUSE 500
      PORTB.4 = 0
      PAUSE 500
      GOTO blink
      
      END
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Bruce, thanks for the code, but it's still not working on my PIC.

    I'm using PBP v. 2.47 with MPLAB v8.15a - are there any problems with this combo that I should know about? It seems kind of crazy to me that a PIC16F84A will work correctly with the same hardware and the same code (minus the @ DEVICE instructions.)

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


    Did you find this post helpful? Yes | No

    Default

    PBP v2.47 should work fine with MPLAB v8.15a.

    Are you 100% sure your ICD2 is programming config settings with what you expect?

    Are you programming it to run in the ICD, or just using the ICD2 as a programmer?

    Have you tried programming the PIC and dropping it on a breadboard?

    Are you compiling from within MPLAB, or are you using MicroCode Studio to compile?

    If you're using MicroCode Studio, and you're clicking the ICD Compile VS the standard
    compile button, that would explain why it doesn't work. If you click the ICD Compile
    button, and program the part, it only works when connected to a PC with the MCS ICD
    software running.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  8. #8


    Did you find this post helpful? Yes | No

    Default

    OK, I just found out that we had a copy of PBP 2.60 that had not yet been installed. I had to upgrade my install of MPLAB as well (to 8.40) but the code is now working with no changes.

    Bruce, thanks very much for all your help.

Similar Threads

  1. Can't get a 16F88 to do anything.
    By ccowley in forum General
    Replies: 14
    Last Post: - 25th August 2008, 23:42
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  3. Error code [112]/[113]
    By Dj tempo in forum General
    Replies: 3
    Last Post: - 17th June 2007, 16:15
  4. Code: Why is this code greater than 2000 words?
    By DrDreas in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 1st June 2007, 19:51
  5. Replies: 1
    Last Post: - 31st August 2005, 20: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