![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| Hi all, I am using PIC18F2423 to encode some command input and controlling perpherals. the input will be from computer and transmitted to PIC over a wireless link. i am using a low power digital radio system (ER400TRS) for wireless link. the receiver 'serial data out' pin will be connected to PIC rc7 which is TX/DT pin. i am using CCS C compiler. i am confused about the coding. how to initialize the TX pin and USART operation. i read compiler help file and was unable to find out the appropiate command to get the data. should i use '#use rs232(baud=9600,rcv=PIN_r7)' that command? pls help me with your valuable advice. with regards mhasan | |
| |
| | (permalink) | |
| If I remember correctly, you should use something like: Quote:
You also have to pass your oscillator value for it to work correctly. | ||
| |
| | (permalink) |
| The #use RS232 statement has been clearly explained in CCS Help File. Anyways here it is for your reference. Code: #USE RS232 -------------------------------------------------------------------------------- Syntax: #use rs232 (options) Elements: Options are separated by commas and may be: STREAM=id Associates a stream identifier with this RS232 port. The identifier may then be used in functions like fputc. BAUD=x Set baud rate to x XMIT=pin Set transmit pin RCV=pin Set receive pin FORCE_SW Will generate software serial I/O routines even when the UART pins are specified. BRGH1OK Allow bad baud rates on chips that have baud rate problems. ENABLE=pin The specified pin will be high during transmit. This may be used to enable 485 transmit. DEBUGGER Indicates this stream is used to send/receive data though a CCS ICD unit. The default pin used in B3, use XMIT= and RCV= to change the pin used. Both should be the same pin. RESTART_WDT Will cause GETC() to clear the WDT as it waits for a character. INVERT Invert the polarity of the serial pins (normally not needed when level converter, such as the MAX232). May not be used with the internal UART. PARITY=X Where x is N, E, or O. BITS =X Where x is 5-9 (5-7 may not be used with the SCI). FLOAT_HIGH The line is not driven high. This is used for open collector outputs. Bit 6 in RS232_ERRORS is set if the pin is not high at the end of the bit time. ERRORS Used to cause the compiler to keep receive errors in the variable RS232_ERRORS and to reset errors when they occur. SAMPLE_EARLY A getc() normally samples data in the middle of a bit time. This option causes the sample to be at the start of a bit time. May not be used with the UART. RETURN=pin For FLOAT_HIGH and MULTI_MASTER this is the pin used to read the signal back. The default for FLOAT_HIGH is the XMIT pin and for MULTI_MASTER the RCV pin. MULTI_MASTER Uses the RETURN pin to determine if another master on the bus is transmitting at the same time. If a collision is detected bit 6 is set in RS232_ERRORS and all future PUTC's are ignored until bit 6 is cleared. The signal is checked at the start and end of a bit time. May not be used with the UART. LONG_DATA Makes getc() return an int16 and putc accept an int16. This is for 9 bit data formats. DISABLE_INTS Will cause interrupts to be disabled when the routines get or put a character. This prevents character distortion for software implemented I/O and prevents interaction between I/O in interrupt handlers and the main program when using the UART. STOP=X To set the number of stop bits (default is 1). This works for both UART and non-UART ports. TIMEOUT=X To set the time getc() waits for a byte in milliseconds. If no character comes in within this time the RS232_ERRORS is set to 0 as well as the return value form getc(). This works for both UART and non-UART ports. SYNC_SLAVE Makes the RS232 line a synchronous slave, making the receive pin a clock in, and the data pin the data in/out. SYNC_MASTER Makes the RS232 line a synchronous master, making the receive pin a clock out, and the data pin the data in/out. SYNC_MATER_CONT Makes the RS232 line a synchronous master mode in continuous receive mode. The receive pin is set as a clock out, and the data pin is set as the data in/out. UART1 Sets the XMIT= and RCV= to the chips first hardware UART. UART2 Sets the XMIT= and RCV= to the chips second hardware UART. Purpose: This directive tells the compiler the baud rate and pins used for serial I/O. This directive takes effect until another RS232 directive is encountered. The #USE DELAY directive must appear before this directive can be used. This directive enables use of built-in functions such as GETC, PUTC, and PRINTF. The functions created with this directive are exported when using multiple compilation units. To access the correct function use the stream identifier. When using parts with built-in SCI and the SCI pins are specified, the SCI will be used. If a baud rate cannot be achieved within 3% of the desired value using the current clock rate, an error will be generated. The definition of the RS232_ERRORS is as follows: No UART: · Bit 7 is 9th bit for 9 bit data mode (get and put). · Bit 6 set to one indicates a put failed in float high mode. With a UART: · Used only by get: · Copy of RCSTA register except: · Bit 0 is used to indicate a parity error. Warning: The PIC UART will shut down on overflow (3 characters received by the hardware with a GETC() call). The "ERRORS" option prevents the shutdown by detecting the condition and resetting the UART. Examples: #use rs232(baud=9600, xmit=PIN_A2,rcv=PIN_A3)
__________________ "There is no way to peace, peace is the way!" | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| Most Common and Best PIC? | LiquidOrb24 | Micro Controllers | 13 | 12th February 2007 03:42 AM |
| Good Pic Book Recomendations | BackFire1 | Micro Controllers | 13 | 5th February 2007 11:20 PM |
| PIC 16F628A UART Coding Problem | Gayan Soyza | Micro Controllers | 11 | 1st February 2007 12:59 PM |
| i need clarity on a pic 16f877 | ZIGGY_DAN | Micro Controllers | 3 | 27th January 2007 12:30 PM |
| Usart to Usart? | Eclipsed | General Electronics Chat | 7 | 23rd October 2003 05:07 PM |