serial_hardware

USART hardware control

Author Stef Mientki, Copyright (c) 2002..2006, all rights reserved.
Adapted-by Sebastien Lelong.
Compiler >=2.4g

Description

USART hardware control.
Routines for sending and receiving through the PIC-usart,
both RS232 and SPI are supported (for SPI see spi_hardware.jal)
Baudrate can simply be set through a human constant,
because the baudrate depending registers are calculated by this unit.
Baudrate is calculated, starting at the high baudrate flag,
which will ensure the highest possible accuracy.
SPI routines are setup for more SPI-devices,
in which case CS should be controled outside this unit.


Dependencies

No dependency found



Summary

Global variables/contants

Procedures

Private

Functions


API details

Global variables/contants

Procedures

  • serial_hw_data'put(byte in data)

    Here Serial read and write are definied as pseudo variables
    so you use them as normal vars, like
     * wait for character being received,
     * then echo the inverted character
    {{{
    serial_hw_data = ! serial_hw_data
    }}}
    
    these procedures will wait till they can perform their action
    therefore it's better to use to following construct
    {{{
     if charater received, echo the inverted character
    if  serial_hw_data_available then
        serial_hw_data = ! serial_hw_data
    end if
     do other things
    }}}
    
    

  • serial_hw_init()

    Initializes the RS232 port, calculates baudrate registers.
    

  • serial_hw_write_word(word in data)

    like Serial_H_write, but then with a word as input
    The MSB is outputed first
    

  • serial_hw_write(byte in data)

    Asynchronuous RS232 send routine, using the TX pin
    Sends byte X (8 bit with no parity) to the serial port
    First checks (and waits if necessary) if transmit buffer is empty
    
    remark: PIR1-register (containing _TXIF-flag) must be in bank0 !!
    

  • serial_hw_data_raw'put(byte in data)

    These are real raw procedures, declared as pseudo variables
    the user is totally responsible for testing the transmit/receive
    flag before using these functions
    

  • serial_hw_enable()

    Enables USART (wether used as RS232 or SPI),
    

  • serial_hw_disable()

    Disables USART (wether used as RS232 or SPI),
    so ports can be used (temporary) for other purposes.
    USART can be enabled again by calling serial_hw_enable()
    

Private
  • _calculate_and_set_baudrate()

    internal function, calculates and sets baudrate divider
    and stores it in the appropiate register.
    the high-speed / low-speed bit is not stored but returned as the result
    
    Special attention is payed to the highest and lowest baudrates,
    a deviation of 5% is accepted in these cases
    
    Asynchronous baudrate settings (see also page 74/75 of DS40300B):
    {{{
    if TXSTA_BRGH = 0 (low speed)
     SPBRG = ( Fosc / ( 64 * Baudrate ) ) -1
    
    if TXSTA_BRGH = 1 (high speed)
     SPBRG = ( Fosc / ( 16 * Baudrate ) ) -1
    }}}
    
    Synchronous baudrate settings:
     * TXSTA_BRGH = 0 (low speed)
     * SPBRG = ( Fosc / ( 4 * Baudrate ) ) -1
    
    


Functions


Related samples

Here are the list of samples which use this library:

sample16f876a_t6603.jal
sample16f877a_print_serial_numbers.jal
sample16f877a_co2_t6603.jal
sample16f877a_serial_hardware.jal
sample16f648a_i2c_sw_l1.jal
sample16f877a_serial_print.jal
sample16f877a_i2c_sw_l1.jal
sample16f648a_serial_print.jal
sample16f88_serial_print.jal
sample16f648a_serial_hardware.jal
sample16f88_serial_hardware.jal
sample16f88_print_serial_numbers.jal
sample16f88_serial_hw_echo.jal
sample16f88_remember_me.jal
sample16f88_i2c_sw_l1.jal
sample16f88_delay_basic.jal
sample16f88_adc_lowres.jal