Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*_____________________________________________________________
- ; MTRX3700 2019 Wednesday Group 21
- ; Exercise 4a
- ; Timothy Hudson SID: 450335626
- ; Phi Nguyen SID:
- ; This program transmits a null-terminated string of ASCII
- ; characters on a 3-wire serial RS232 line at 9600 baud
- ;_____________________________________________________________*/
- // Include libraries and headers
- #include <p18f452.h>
- #include <stdio.h>
- int tx232C(unsigned char *txPtr) {
- int status = 0;
- // Loop until a null character is received
- while (*txPtr != 0) {
- TXREG = *txPtr; // Transmit character
- while (TXSTAbits.TRMT == 0); // Poll until transmit register empty
- txPtr++; // Increment pointer
- }
- }
- // Initialise serial
- void initSerial(void) {
- RCSTAbits.SPEN = 1; // Enable serial port
- SPBRG = 25; // Set baud rate to 9.6kbps
- TXSTAbits.SYNC = 0; // Enable async mode
- TXSTAbits.BRGH = 1; // Enable high speed async mode
- TXSTAbits.TXEN = 1; // Enable transmit
- }
- int int main() {
- // String to transmit
- unsigned char string[] = "A\0";
- initSerial();
- // Infinitely loop
- while(1){
- tx232C(string);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement