transmit

=transmit functions (transmit_setup, transmit, transchar, TX interrupt code)= Owner: Michael

Purpose and Documentation
The function //transmit(string)// copies //string// into a large circular buffer, and starts transmission. //transchar// copies the next character into the transmit shift register TXREG. The transmit interrupt calls //transchar// again to send the next character. //transchar// stops transmission by disabling the interrupt when the insertion and removal indices from the large buffer match up. Will add more to this later.

Syntax
void transmit_setup(void); void transmit(char* string); void transchar(void); void lowISR(void); - only a relevant fragment of the overall low ISR

Usage
As described above, call //transmit(string)// to send null-terminated string //string// out via serial.

transmit

 * Input**: char* string. A string that will be transmitted out by serial.
 * Output**: void.
 * Return**: void.

**transchar, transmit_setup**
Input: void.
 * Output**: void.
 * Return:** void.

Operation
Describe in very general terms how the function fulfills its purpose. This should be reflected in the code.

**Globals**
code // transmit system globals char transbuf[TRANSBUFSIZE] = "";   //transmit buffer char transbufi = 0;            // buffer insertion index from string char transbufr = 0;            // buffer removal index to transmit shift register code
 * 1) define TRANSBUFSIZE 256

void transmit_setup(void);
code void transmit_setup(void) //Setup function, or parameters to include in a central setup function { TRISCbits.TRISC7 = 1;// PortC 7 is output TRISCbits.TRISC6 = 0; //PortC 6 is input TXSTAbits.SYNC = 0;// asynchronous mode TXSTAbits.BRGH = 1; //high baud rate SPBRG = 25;// for baud rate 9600 TXSTAbits.TX9 = 0; //8-bit transmission TXSTAbits.TXEN = 1;// enable transmission RCSTAbits.SPEN = 1; //Enable serial port INTCONbits.GIEH = 1;// (IPEN = 1) -> enable high-priority interrupts globally INTCONbits.GIEL = 1; //(IPEN = 1) -> enable low-priority peripheral interrupts } code

void transmit(char* string);
code void transmit(char* trans_string) // Transmit function, writes string into buffer and starts sending { char i = 0; while(transbuf[transbufi] != '\0')       // until null termination of string reached { transbuf[transbufi] = trans_string[i];       // copy string into transmit buffer transbufi++; if(transbufi >= TRANSBUFSIZE) { transbufi = 0; }           // catch insertion index overflow i++; } PIE1bits.TXIE = 1;                // enable transmit interrupt transchar;                    // transmit first character } code

void transchar(void);
code void transchar(void) // Transmit function, sends next char to TXREG as long as transmission buffer has more material to write { TXREG = transbuf[transbufr];        // load character into transmit shift register

transbufr++;               // increment removal index if(transbufr >= MAXSIZE) { transbufr = 0; }        // catch removal index overflow

if (transbufr == transbufi)         // if removal index catches insertion index, end of transmission { PIE1bits.TXIE = 0; }        // disable transmit interrupt } code

void lowISR(void); - only a relevant fragment of the overall low ISR
code void lowISR(void) { INTCONbits.GIEL = 0; low priority interrupt disable if(PIR1bits.TXIF == 1 && PIE1bits.TXIE == 1) //transmit enabled, transmit shift register empty { transchar; }// transmit next character INTCONbits.GIEL = 1; // low priority interrupt enable }

code

**Versions**
[|serial_transmit_14Oct.txt] - may have some errors.