18f14k22 portb.5 always high using hserout


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

    Question 18f14k22 portb.5 always high using hserout

    Oops - - Should be 18f14k22

    Hi

    I cannot figure out why, when using HSEROUT, on PORTB.7, PORTB.5 is high
    no matter what I try.

    Making PORTB = 0 on the first line has no effect either

    Actually, when bit 5 on TRISB is set to an input, the port is not
    always high then - - that makes sense. Problem is, I need it as an output.

    I need to use HSEROUT for my Serial LCD, since I am using interrupts,
    and the data is corrupted otherwise.

    I am using PBP 2.60A
    The manual states on page 93 that "On devices with two serial ports,
    HSEROUT will only use the first port."

    My circuit board is etched, assembled, and everything works, but I need
    to use PORTB.5 as another output.

    Here is a simple program to show the problem. When the HSEROUT line
    is enabled, PORTB.5 is always high.

    If the HSEROUT line is commented out, PORTB.5 works just fine.





    Code:
               DEFINE OSC 16      
               OSCCON = %11110110  ' 16 MHZ INTERNAL OSCILLATOR
               
               TRISB = %00000000
               
               DEFINE HSER_BAUD 9600      ' FOR 4 LINE BY 20 CHARACTER LCD
    '                                      USES PORTB.7 - - DEDICATED HARDWARE SERIAL PORT
             DEFINE HSER_TXSTA 20H
         
               HERE:
               
               PAUSE    100
               
               HSEROUT  [254,128,"TEST TEST"]
                         
               GOTO HERE
               
               ''''''''''Cant get much simpler than this . . . .
    Last edited by ozarkshermit; - 4th March 2015 at 19:43. Reason: wrong title

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


    Did you find this post helpful? Yes | No

    Default Re: 18f14k22 portb.5 always high using hserout

    There are threads in this forum which have addressed this, worth a search, that said HSERIN idles the input pin at high logic level. To switch it to an i/o port you need to turn it off before you try to use it. Look at pp184 of the data sheet as it addresses RCSTA register.

    push goes to shove you might use Debug instead of HSER commands, it's pretty lean for bit bang serial port.
    Last edited by Archangel; - 5th March 2015 at 09:06.
    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.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: 18f14k22 portb.5 always high using hserout

    When you enable the (E)USART (which HSERIN does of course) it takes control of the TX/RX pins, thus you can't use the as normal I/O.

    /Henrik.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: 18f14k22 portb.5 always high using hserout

    Thanks

    I found a "work-around" for this - I needed one output to pulse an LED as a "heart-beat", so I changed that to PORTB.5.
    In the program I change TRISB.5 from a 0 to 1 and back to a 0 to flash the LED. Therefore freed up the other output. From what I see it has no other effect on the program.

    Ken

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: 18f14k22 portb.5 always high using hserout

    Another approach is to enable/disable the hardware port in your program. For the 16f1826 I use RCSTA.7 = 0 to disable the port when I'm done using it.

Similar Threads

  1. Problem reading 24FC1025 EEPROM with 18f14k22
    By JimAvanti in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 31st May 2013, 20:55
  2. High byte lost in HSEROUT a Word variable
    By Demon in forum General
    Replies: 2
    Last Post: - 7th October 2012, 22:30
  3. Replies: 6
    Last Post: - 12th March 2011, 14:11
  4. PortB pins will not initialize LOW, only HIGH?
    By ronbowalker in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th December 2009, 20:27
  5. 18F14k22 eTouch
    By warrier in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 28th July 2009, 06:20

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