GPS Project: PIC18F26K22 or PIC18F46K22


Closed Thread
Results 1 to 40 of 69

Hybrid View

  1. #1
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Quote Originally Posted by richard View Post
    Code:
    TRISB = %10000000   'use TRISB to specify which pin is (1 = input) and which (0 = output)  (RB7 PORTB.7 is the RX input pin of the EUART, the rest are output)
    TRISC = %10000000   'use TRISC to specify which pin is (1 = input) and which (0 = output)  (RC7 PORTC.7 is the RX input pin of the EUART, the rest are output)
                        'in PORTC the RC3 attached is an LED.
    setting the tris incorrectly will stop the eusarts from working


    from data sheet

    Setting the TXEN bit of the TXSTAx register enables thetransmitter circuitry of the EUSART. Clearing the SYNC
    bit of the TXSTAx register configures the EUSART for
    asynchronous operation. Setting the SPEN bit of the
    RCSTAx register enables the EUSART and
    automatically configures the TXx/CKx I/O pin as an
    output. If the TXx/CKx pin is shared with an analog
    peripheral the analog I/O function must be disabled by
    clearing the corresponding ANSEL bit.
    To be honest i didnt really understand the statement. I understand that it is not necessary to set a TRIS register at TX bit as automatically the TX configured as an output.....

    Code:
    TRISB = %10000000   'use TRISB to specify which pin is (1 = input) and which (0 = output)  (RB7 PORTB.7 is the RX input pin of the EUART, the rest are output)
    TRISC = %10000000   'use TRISC to specify which pin is (1 = input) and which (0 = output)  (RC7 PORTC.7 is the RX input pin of the EUART, the rest are output)
                        'in PORTC the RC3 attached is an LED.
    as we have already stated and configured the EUSART with the following:

    Code:
    '*-----------------------------------------------------------------------------|
    '*                        |  --------------------- |                           |
    '*----------------------- | EUART 1 Configuration  | --------------------------|
    '*                        |  --------------------- |                           |
    '*-----------------------------------------------------------------------------|
    
            DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
            DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
            DEFINE HSER_CLROERR 1 ' Clear overflow automatically
            DEFINE HSER_SPBRG 160 ' 38400 Baud @ 64MHz, -0,08%
            SPBRGH = 1
            BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
            
    '*-----------------------------------------------------------------------------|
    '*                        |  --------------------- |                           |
    '*----------------------- | EUART 2 Configuration  | --------------------------|
    '*                        |  --------------------- |                           |
    '*-----------------------------------------------------------------------------|
    
            DEFINE HSER2_RCSTA 90h ' Enable serial port & continuous receive
            DEFINE HSER2_TXSTA 24h ' Enable transmit, BRGH = 1
            DEFINE HSER2_CLROERR 1 ' Clear overflow automatically
            DEFINE HSER2_SPBRG 160 ' 38400 Baud @ 64MHz, -0,08%
            SPBRGH2 = 1
            BAUDCON2.3 = 1         ' Enable 16 bit baudrate generator
            
    '*-----------------------------------------------------------------------------|
    '*-----------------------------------------------------------------------------|
    How Do we configure the rest of the TRIS bits?

    Code:
    TRISB = %1X000000   'use TRISB to specify which pin is (1 = input) and which (0 = output)  (RB7 PORTB.7 is the RX input pin of the EUART, the rest are output)
    TRISC = %1X000000   'use TRISC to specify which pin is (1 = input) and which (0 = output)  (RC7 PORTC.7 is the RX input pin of the EUART, the rest are output)
                        'in PORTC the RC3 attached is an LED.
    Last edited by astanapane; - 3rd July 2018 at 07:03.

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,653


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    How Do we configure the rest of the TRIS bits?
    when you read
    Setting the SPEN bit of the
    RCSTAx register enables the EUSART and
    automatically configures the TXx/CKx I/O pin as an
    output.
    in the eusart section it means its unnecessary to clear the tris bit for the tx pin, keep in mind that on some chips clearing the tx pin tris bit
    will stop the eusart from working . I prefer to form good habits ,although the 18f26k22 does not seem to object and functions either way .
    Warning I'm not a teacher

  3. #3
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Richard, bardon me. Still im confused from your answer.

    I understand the part of setting up the EUSART, automatically we make the TX port as an output.

    My question is, what do we do with the rest of the TRISB and TRISC bits apart from the RX/TX.

    Code:
    TRISA = %00000000   'use TRISA to specify which pin is (1 = input) and which (0 = output)  (ALL pins are output)
    TRISB = %10000000   'use TRISB to specify which pin is (1 = input) and which (0 = output)  (RB7 PORTB.7 is the RX input pin of the EUART, the rest are output)
    TRISC = %10000000   'use TRISC to specify which pin is (1 = input) and which (0 = output)  (RC7 PORTC.7 is the RX input pin of the EUART, the rest are output)
                        'in PORTC the RC3 attached is an LED. 
    
    '           --------------- TRIS A-B-C ---------------
    '------------------------------------------------------------------------|
    ' PORTA.7  PORTA.6  PORTA.5  PORTA.4  PORTA.3  PORTA.2  PORTA.1  PORTA.0 |
    '  bit7     bit6     bit5     bit4     bit3     bit2     bit1     bit0   |
    '   0        0        0        0        0        0        0        0     |
    '------------------------------------------------------------------------|
    '------------------------------------------------------------------------|
    ' PORTB.7  PORTB.6  PORTB.5  PORTB.4  PORTB.3  PORTB.2  PORTB.1  PORTB.0 |
    '  bit7     bit6     bit5     bit4     bit3     bit2     bit1     bit0   |
    '   1        0        0        0        0        0        0        0     |
    '------------------------------------------------------------------------|
    '------------------------------------------------------------------------|
    ' PORTC.7  PORTC.6  PORTC.5  PORTC.4  PORTC.3  PORTC.2  PORTC.1  PORTC.0 |
    '  bit7     bit6     bit5     bit4     bit3     bit2     bit1     bit0   |
    '   1        0        0        0        0        0        0        0     |
    '------------------------------------------------------------------------|
    I feel like i'm missing something. Sorry for my questions, but i would like to be sure i understand every part of the code. And when i configure the ports as an input or outputs, or Digital/Analogue, i need to know exactly what am i doing.

    In our case as we want to configure the EUSART, as you stated from the manual -datasheet, we have automatically the TX pin as an output. But dont we continue to specify the other pins with the TRIS command?

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,653


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    My question is, what do we do with the rest of the TRISB and TRISC bits apart from the RX/TX
    .
    that would depend entirely on what you want do with each pin , if and only if you need it to be an output clear the corresponding tris bit
    Warning I'm not a teacher

  5. #5
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Quote Originally Posted by richard View Post
    .
    that would depend entirely on what you want do with each pin , if and only if you need it to be an output clear the corresponding tris bit
    Thanks a lot for your answer. I guess we cant leave unassigned the bits. Normally as far as i have learned from what i have read in this forum, it is better to configure the bits of each port and give an Input or Output direction in addition to high or low stage.

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,653


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    I guess we cant leave unassigned the bits
    there is no such state , pins are either inputs or outputs or analog inputs , outputs can only be high or low
    if you have no reason to use a pin as an output then leave as an input , if you have no reason to use a pin as a digital input you can leave it analog
    the pic chip won't care. the pic chip does not care if outputs are high or low its only what they connect to that cares , it up to you to initialise the pins
    in use to the correct type/state and direction to match the requirement of what they connect to and then make sure they stay that way.
    Warning I'm not a teacher

  7. #7
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    Quote Originally Posted by richard View Post
    there is no such state , pins are either inputs or outputs or analog inputs , outputs can only be high or low
    if you have no reason to use a pin as an output then leave as an input , if you have no reason to use a pin as a digital input you can leave it analog
    the pic chip won't care. the pic chip does not care if outputs are high or low its only what they connect to that cares , it up to you to initialise the pins
    in use to the correct type/state and direction to match the requirement of what they connect to and then make sure they stay that way.
    now it is clear. Really appreciate your help.

    Thanks a lot Richard.

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,139


    Did you find this post helpful? Yes | No

    Default Re: GPS Project: PIC18F26K22 or PIC18F46K22

    I have my doubts on leaving inputs floating.

    Usually if I have any unused ports, I turn them as outputs and clear them.

    If they are inputs, maybe enable the pull ups if any or tie them to ground.

    A floating pin can cause troubles in certain cases.

    Ioannis

Similar Threads

  1. PIC18F46K22 config issue
    By LGabrielson in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th September 2012, 03:20
  2. Replies: 1
    Last Post: - 27th July 2008, 06:14
  3. Pic GPS project Demo
    By Art in forum GPS
    Replies: 0
    Last Post: - 28th October 2007, 03:05
  4. GPS project question
    By mjp130 in forum GPS
    Replies: 6
    Last Post: - 4th July 2007, 20:09
  5. gps project
    By chuckad in forum GPS
    Replies: 2
    Last Post: - 9th February 2007, 02:52

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