Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 1 Guest are viewing this topic.
/* ** Tranmission.C ** UART2 RS232 asynchronous communication demonstration code ** */ // configuration bit settings, Fcy=72MHz, Fpb=36MHz #pragma config POSCMOD=XT, FNOSC=PRIPLL #pragma config FPLLIDIV=DIV_2, FPLLMUL=MUL_18, FPLLODIV=DIV_1 #pragma config FPBDIV=DIV_2, FWDTEN=OFF, CP=OFF, BWP=OFF #define FCY 72000000L #define FPB 36000000L #include <p32xxxx.h> // I/O definitions for the Explorer16 #define CTS _RF12 // Cleart To Send, input #define RTS _RF13 // Request To Send, output #define TRTS TRISFbits.TRISF13 // tris control for RTS pin // timing and baud rate calculations #define BRATE (FPB/4/9600)-1 // 9600 baud #define U_ENABLE 0x8008 // enable UART (BREGH=1) #define U_TX 0x0400 // enable transmission // initialize the UART2 serial port void initU2( void) { U2BRG = BRATE; U2MODE = U_ENABLE; U2STA = U_TX; TRTS = 0; // make RTS output RTS = 1; // set RTS default status } // initU2 // send a character to the UART2 serial port void putU2( int c) { while ( U2STAbits.UTXBF); // wait while Tx buffer full U2TXREG = c; } // putU2 main() { char c[16],b; int i=0; c="Welcome To Pic32"; initU2(); while(1) { b=c putU2( b); i++; if i=15 { i=0; } }
// 3.2 echo the character putU2( c);
putU2("h");putU2("e");putU2("l");putU2("l");putU2("o");
putU2("hello world!");
while(1) { b=c putU2( b); i++; if i=15 { i=0; } }