PIC16F87 pins seem to be getting crossed over


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697

    Default PIC16F87 pins seem to be getting crossed over

    Hi, Im using a PIC16F87 and almost everything is working fine except when i send serial data i get a reply. Ive checked the code and the only way that could happen is if portb.6 changes state. It has a pull up 100K resistor so it should be 1 unless i ground it. The other weird thing is that whenever this same pin is grounded the chip wont receive serial data. Ive checked the code over and over and im 99.99% sure that its not a code problem. Ive looked in the datasheet and the pin im having problems with has some extra features. I think it might have something to do with those but even after readign the datasheet i cant figure it out.

    Ive got 3 other pins that work in the same way as this one (porta.3, portb.0 and portb.7). They all work as expected and only portb.6 has this problem

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


    Did you find this post helpful? Yes | No

    Default

    Does this happen with or without the programmer attached?
    Analog shut off?

    Without seeing the code or schematic it is hard to say.
    It is getting the time of year for spooks, so maybe that is it
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    The programmer is not attached. I have to take the chip out of the circuit to program it (Ive still not tried ICSP yet)

    Ive tried adding the 3 lines from my last thread "CMCON = 7, CVRCON = 0, CCP1CON = 0". They have no effect.

    I havn't done a schematic for this circuit but the input pin has a 100K pullup resistor and connects to an optoisolator that grounds it. The UART pins are connected to an RS485 chip along with portB.4 for driver/receiver control.

    This circuit is actually for that time of year So far there has been a problem with every circuit ive made for it this year. Im still working on the others but i might have to make some other threads soon.

  4. #4
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    642


    Did you find this post helpful? Yes | No

    Default

    Hi,

    Try a smaller pullup resistor, something like 4.7K. 100K pullup resistors might be too much. I hope this helps.

    Robert

  5. #5
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    I dont think the pullup resistor is the problem. I want a fairly weak one to make it easy to ground. 100K should be more than enough to pull up any pin on a PIC. Ive used them many times before without a problem and there are 3 others on the same circuit working fine.

  6. #6
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Theres another problem im having too. Its on a completely different circuit but using the same PIC and i wonder if it might be related. Im using portB.3 to detect a zero-crossing on AC. This pin has a pulldown resistor but always seems to be 1. Even if i completely disconnect the zero-crossing part so the pin is grounded by a 100K resistor and not connected to anything else it still says its constantly high. Just to make sure ive touched a screwdriver over it to completely short it to ground and it still shows as 1

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


    Did you find this post helpful? Yes | No

    Default

    If might help if you showed your code. Even if the code is not the problem
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Ok, Ive made a really basic version to save you looking through hundreds of lines of code. It uses the power LED to show the output (inverted) and the status LED to show the value sent by serial. My laptop sends 1 and 0 alternately.

    Code:
    '^Define_Chip: PIC16F87
    
    'Define the oscillator (20MHz)
    DEFINE OSC 20
    
    'Set the tris registers
    TRISA=%00001000
    TRISB=%11000101
    
    CMCON=7
    CVRCON=0
    CCP1CON=0
    
    'Serial port settings
    RCSTA.7=1	'Enable the serial port
    RCSTA.4=1	'Enable synchronous mode
    TXSTA.5=1	'Enable transmit
    TXSTA.2=1	'Enable high baud rate
    
    'SPBRG=10	'Baud: 115200, Error: -1.36%
    SPBRG=64	'Baud: 19200, Error: 0.16%
    
    bTemp VAR BYTE
    
    'Define output pins
    pSmoke1 VAR PORTA.2
    pSmoke2 VAR PORTA.4
    pSmoke3 VAR PORTB.1
    pSmoke4 VAR PORTB.3
    
    pPower VAR PORTA.0
    pStatus VAR PORTA.1
    
    pData VAR PORTB.4	'Switches between Master and Slave
    
    'Define input pins
    iSmoke1 VAR PORTA.3
    iSmoke2 VAR PORTB.0
    iSmoke3 VAR PORTB.7
    iSmoke4 VAR PORTB.6
    
    'Check that input pins are set to inputs
    INPUT iSmoke1
    INPUT iSmoke2
    INPUT iSmoke3
    INPUT iSmoke4
    
    'Make sure all of the outputs are off
    LOW pSmoke1
    LOW pSmoke2
    LOW pSmoke3
    LOW pSmoke4
    
    LOW pPower
    LOW pStatus
    
    LOW pData
    
    'BEGIN: Main loop
    loop:
    	
    	'Check if serial data has arrived
    	IF PIR1.5=1 THEN
    		
    		bTemp=RCREG
    		
    		pStatus=bTemp.0
    	ENDIF
    	
    	pPower=~iSmoke4
    GOTO loop
    In this example grounding the input pin makes the power LED light up as expected. When i send the alternating serial values then the status LED toggles as it should. When ground the input _and_ send serial data then the status light never comes on. Something i didnt notice before is that if the status light is already on then grounding the input turns it off. That would suggest that the grounding causes a blank byte to appear in the UART buffer.

  9. #9
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Analog

    PortB.6 has analog functions. You need to properly set your ADCON0, ADCON1, and ANSEL to turn those off for digital operation.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  10. #10
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    I tried that but i keep getting compile errors on all 3 lines saying "Symbol not previously defined"

    Edit: Ive had a look in the datasheet and it seems they should exist. Im not sure why im getting an error. The correct chip is selected
    Last edited by The Master; - 27th September 2009 at 12:24.

  11. #11
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Just quickly tried to compile your example with v2.46 without error.

    It would suggest that if these three lines...

    CMCON=7
    CVRCON=0
    CCP1CON=0

    ...are causing you problems, then you have NOT got the correct chip selected somewhere...

    And it goes to say that you have default Analog functions still enabled on your PIC.

    It's always a good idea to EXPLICITY define the start of your program with the chips CONFIG parameters along with the chip you are using... example...
    Code:
    	@ DEVICE pic10F206, WDT_OFF
    		' Watchdog Timer Disabled
    	@ DEVICE pic10F206, MCLR_OFF
    		' Master Clear Options Internal
    	@ DEVICE pic10F206, PROTECT_OFF
    		' Code Protection Disabled
    ...because if, further down the line, you inadvertantly start to compile for the wrong chip, you end up with a whole heap of errors pointing you to the fact that you've done something wrong (or have the wrong chip selected somewhere).

  12. #12
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    I never got the fuses to work from within the code. It seems like theres a few ways of doing it and i never found the right one. I did read an example somewhere that said to change an include file. Heres the line in that file

    __config _CONFIG1, _HS_OSC & _WDT_OFF & _LVP_OFF & _CP_OFF


    CMCON, CVRCON and CCP1CON are working fine. The 3 that dont work are ADCON0, ADCON1, and ANSEL. The datasheet says they should exist and i found them defined in PIC14EXT.BAS which aparently gets included for the PIC16F87. As you can see from my code the chip is defined correctly. That line gets picked up by an app i wrote that handles the compiling. Just to be on the safe side i went back to MCS and tried to compile as ive done in the past (16F87 is selected) and it still wont compile.

  13. #13
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    The Datasheet is shared between the F87 and F88. Those Registers don't exist in the F87 (first paragraph of section 12).

  14. #14
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Ok, I see that now. It does look like the 16F87 still has A/D convertors though but not as many. Should the 3 working lines have disabled those? Im not sure it matters though because the pins im having trouble with arnt marked as ANx

Similar Threads

  1. 16F877A Pullups/Pulldowns and unused pins
    By DavyJones in forum General
    Replies: 6
    Last Post: - 17th April 2009, 01:39
  2. Change On Interrupt, PIC16F884
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 14th November 2008, 17:25
  3. PIC - 8 Pins - 6 Output Pins ?
    By DanPBP in forum Off Topic
    Replies: 0
    Last Post: - 22nd October 2007, 00:23
  4. I2C Effects on other PortA pins
    By kenmac in forum General
    Replies: 2
    Last Post: - 11th July 2005, 05:36
  5. PIC PORT 'special' pins
    By barkerben in forum General
    Replies: 1
    Last Post: - 18th January 2005, 21:40

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