/* PIC serial port test http://www.captain.at/electronics/ Sends back any character received via the serial port Use with "ser": # ./ser baud=9600 baud=9600 written:ABC readport=ABC # Compile with CC5x: http://www.bknd.com/cc5x/ c:\picc\cc5x mmc.c -Ic:\picc\ -ammc.ASM -u CC5x runs nicely on Linux with "dosemu" http://www.dosemu.org/ Credit: Ported from assembler source of "The Tekatch-Welch Magnetometer" http://crocus.physics.mcmaster.ca/Magnetometer/TW/ */ #include <16F876.h> #include "int16CXX.H" #define CP_off |= 0x3F30 #define LVP |= 128 #pragma config CP_off,PWRTE=on,WDTE=off,FOSC=HS,BODEN=on,LVP #pragma origin 4 // Der folgende Code steht ab Adresse 4 interrupt myInterrupt(void) // interrupt service routine at address 4 { int_save_registers char rec; if (RCIF) // is it the serial port receive interrupt ? { while(!TXIF) { // wait for serial register to be sent, if there is still something in there nop(); } rec = RCREG; // Get the received character TXREG = rec; // write to serial register -> start transmission RCIF = 0; // reset serial port receive interrupt flag } int_restore_registers } void InitUSART() { PORTA = 0; PORTB = 0; PORTC = 0; BRGH = 1; // high speed serial port mode SPBRG=25; // Set 9600 baud for 4 MHz oscillator SYNC = 0; // Clear SYNC bit ; Set_Async_Mode; SPEN = 1; // Set serial port enable TX9 = 0; // 8-bit transmissions TXEN = 1; // Enable transmission RCIE = 1; // Rx interrupts are desired RX9 = 0; // 8-bit receptions CREN = 1; // Enable reception } void initint() { GIE = 1; // Set Global Interrupt Enable PEIE = 1; // Set Peripheral Interrupt Enable } void main(void) { InitUSART(); initint(); while(1) { nop(); nop(); } }