16F887 - PORT pins interfere with each other when set high/low


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default 16F887 - PORT pins interfere with each other when set high/low

    Hello.

    Run into strange problem. I have button connected to PORTA.0 (pulled up to 5v via 10k resistor) and buzzer to PORTB.7 Below is the shortened code.

    Code:
    OSCCON=%01110101  'SET INTOSC TO 8MHZ
    ANSEL=%00000000
    ANSELH=%00000000 'disable ADC
    
    
    TRISC=%00000000 'set PORTC as output all
    TRISD=%00000000 'set PORTD as output all
    TRISB=%00000000 'set PORTB as output all
    TRISA=%00000001 'set PORTA 0 as input, others as output
    TRISE=%00000000 'same here
    BUZ var PORTB.7
    BUTN var PORTA.0 
    
    
    
    DEFINE OSC 8   'OSC SPEED
    'turn off all digits
    
    
    PORTA=0: PORTB=0: PORTC=0: PORTD=0 : PORTE=0 'turn off all outputs
    
    CYCLER:
    if BUTN=0 then
    high BUZ
    pause 100
    low BUZ
    pause 100
    endif
    goto CYCLER
    A simple code, when you press the button and keep it pressed, buzzer should rapidly beep. But it does not exactly works. It makes 5 normal length beeps and then 5 silent - When looked with scope, feels like first PAUSE 100 statement is being skipped - only a small impulse appears on scope on buzzer pin. After these 5 silent (short) pulses, there will come trail of 5 normal length pulses and so on. The first thoughts might be that button is faulty. But I've removed it, soldered porta.0 pin directly to GND - no change. If I remove reading of BUTN, and just leave high buz pause 100 low buz pause 100 code, it all works just fine. So it might appear that PORTA is doing something. So I changed code to the following

    Code:
    CYCLER:
    IF BUTN=0 then
    high PORTB.7
    TRISB.7=1
    pause 100
    TRISB.7=0
    pause 100
    goto CYCLER:
    It works fine.

    It may appear that problem is solved. But wait, fun just begins. Let's slightly modify the code and add flashing led, connected to say PORTB.4

    Code:
    CYCLER:
    IF BUTN=0 then
    high PORTB.7
    TRISB.7=1
    TRISB.4=1
    pause 100
    TRISB.7=0
    TRISB.4=0
    pause 100
    goto CYCLER:
    We run into same problem. Led flashes as it should, but buzzer is outputting 5 long and 5 short pulses in the loop. If I remove "IF BUTN=0" then buzzer works again fine.

    I thought that this might be Pickit 3 interfering with ports and tried to unplug it - nothing helps.

    Any ideas?

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: 16F887 - PORT pins interfere with each other when set high/low

    I don't understand why you make the portb.7 input (since it should be an output to buzzer), wait 100ms and then output again.

    Ioannis

  3. #3
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: 16F887 - PORT pins interfere with each other when set high/low

    As far as I understand PBP manual and in practice before, HIGH PORTX.Y makes that pin high and LOW PORTX.Y makes that pin low.

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: 16F887 - PORT pins interfere with each other when set high/low

    TRISB.7=1 makes portb.7 an input

    TRISB4.=1 makes portb.4 an input

    TRISB.7=0 makes portb.7 an output

    TRISB4.=0 makes portb.4 an output

    Is this really what you want?

    Ioannis

  5. #5
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: 16F887 - PORT pins interfere with each other when set high/low

    No. I want to make PORTB.7 output logical "1" and then logical "0". PBP statements like HIGH PORTB.7 work, but only if I do not read PORTA.0 as input.

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: 16F887 - PORT pins interfere with each other when set high/low

    So, why in your loop, you use TRIS to make the ports input then output? You should use High Portb.7 or Low Portb.7 and not TRIS. TRIS is only to define the input or output operation.

    Ioannis

Similar Threads

  1. Replies: 10
    Last Post: - 14th April 2014, 20:47
  2. 16F887 PORTC.7 high
    By Neosec in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 31st March 2013, 22:39
  3. Help in trying to set pins functions
    By MinesCoffee in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th December 2012, 18:03
  4. PortB pins will not initialize LOW, only HIGH?
    By ronbowalker in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th December 2009, 19:27
  5. Replies: 0
    Last Post: - 25th May 2005, 10:35

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