|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools |
Rating:
|
Display Modes |
|
#10
|
|||
|
|||
|
Re: New C18 3.0+ Compatible FRC Code
Kevin:
Here are some change that I made to your serial routine to set the baudrate correctly for any processor speed. in serial_port.c #ifdef ENABLE_SERIAL_PORT_ONE void Init_Serial_Port_One(void) { // Start by initializing the serial port with code // common to receive and transmit functions // SPBRG = BAUD_38400 ; // baud rate generator register [251] SPBRG = SPBRG_VAL_1; // defined in hardware.h // #ifdef USART1_USE_BRGH_LOW TXSTAbits.BRGH = 0; // high baud rate select bit (asynchronous mode only) [248] #else // 0: low speed TXSTAbits.BRGH = 1; // high baud rate select bit (asynchronous mode only) [248] // 1: high speed #endif // 1: high speed .................................................. .................................................. .................................................. ...... #ifdef ENABLE_SERIAL_PORT_TWO void Init_Serial_Port_Two(void) { // Start by initializing the serial port with code // common to receive and transmit functions // SPBRG2 = BAUD_9600; // baud rate generator register [251] SPBRG2 = SPBRG_VAL_2; // defined in hardware.h // #ifdef USART2_USE_BRGH_LOW TXSTA2bits.BRGH = 0; // high baud rate select bit (asynchronous mode only) [248] #else // 0: low speed TXSTA2bits.BRGH = 1; // high baud rate select bit (asynchronous mode only) [248] // 1: high speed #endif // 1: high speed ------------------------------------------------------------------------------------------------------------------------------------------------------------ in the hardware set up routines... // Define system xtal/clock frequency // #define CLOCK_FREQ (40000000) // Frequency in Hz #if defined(__18CXX) // All PIC18 processors #include <p18cxxx.h> #define INSTR_FREQ (CLOCK_FREQ/4) // PIC18 clock divider #else #error Unknown processor or processor not defined #endif // Set up serial port(s) baud rate // #define BAUD_RATE_1 (38400) // Serial port 1, bps #define BAUD_RATE_2 (38400) // Serial Port 2, bps // set as needed... //#define USART1_USE_BRGH_LOW // for most lower baud rates //#define USART2_USE_BRGH_LOW // for most lower baud rates #if defined(USART1_USE_BRGH_LOW) #define SPBRG_VAL_1 ( ((CLOCK_FREQ/BAUD_RATE_1)/64) - 1) #else #define SPBRG_VAL_1 ( ((CLOCK_FREQ/BAUD_RATE_1)/16) - 1) #endif #if defined(USART2_USE_BRGH_LOW) #define SPBRG_VAL_2 ( ((CLOCK_FREQ/BAUD_RATE_2)/64) - 1) #else #define SPBRG_VAL_2 ( ((CLOCK_FREQ/BAUD_RATE_2)/16) - 1) #endif #if ((SPBRG_VAL_1 > 255) || (SPBRG_VAL_2 > 255)) #error "Calculated SPBRG value is out of range for current CLOCK_FREQ." #endif Last edited by Lafleur : 04-01-2008 at 11:14. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Does the camera code suits to all versions of MPLAB and C18? | razer | Programming | 3 | 04-01-2007 14:50 |
| Trying to follow C18 interrupt context code... | dcbrown | Programming | 5 | 21-12-2006 09:01 |
| Error w/ FRC code | JamesBrown | Programming | 2 | 08-01-2005 16:17 |
| Programming code Fix FRC | Ferazel2001 | Programming | 6 | 08-02-2004 02:46 |
| FRC default code | hedgehogger | Programming | 2 | 21-01-2004 18:41 |