[AC2] Add last stuff
Signed-off-by: Tiago Garcia <tiago.rgarcia@ua.pt>
This commit is contained in:
parent
a1d655693f
commit
5730b98407
|
@ -0,0 +1,21 @@
|
|||
#include <detpic32.h>
|
||||
|
||||
typedef enum { N, E, O } parity;
|
||||
void setupUART2(int baudrate, parity parity, int stopBits) {
|
||||
U2BRG = (PBCLK + 8 * baudrate) / ((baudrate <= 115200 ? 16 : 4) * baudrate) - 1;
|
||||
U2MODEbits.BRGH = baudrate <= 115200 ? 0 : 1;
|
||||
|
||||
U2MODEbits.PDSEL = parity == N ? 00 : parity == E ? 01 : 10;
|
||||
U2MODEbits.STSEL = stopBits == 1 ? 0 : 1;
|
||||
|
||||
U2STAbits.URXEN = 1;
|
||||
U2STAbits.UTXEN = 1;
|
||||
|
||||
U2MODEbits.ON = 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
setupUART2(115200, N, 1);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
#include <detpic32.h>
|
||||
|
||||
void putc(char byte) {
|
||||
// wait while UTXBF == 1
|
||||
while (U1STAbits.UTXBF == 1);
|
||||
// Copy byte to the UxTXREG register
|
||||
U1TXREG = byte;
|
||||
}
|
||||
|
||||
int main() {
|
||||
U1BRG = ((PBCLK + 8 * 115200) / (16 * 115200)) - 1;
|
||||
U1MODEbits.BRGH = 0;
|
||||
|
||||
U1MODEbits.PDSEL = 01;
|
||||
U1MODEbits.PDSEL = 0;
|
||||
|
||||
U1STAbits.UTXEN = 1;
|
||||
U1STAbits.URXEN = 0;
|
||||
|
||||
U1MODEbits.ON = 1;
|
||||
|
||||
while (1) {
|
||||
putc(0x5A);
|
||||
resetCoreTimer();
|
||||
while (readCoreTimer() < 200000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
#include <detpic32.h>
|
||||
|
||||
void putc(char c) {
|
||||
while (U2STAbits.UTXBF);
|
||||
U2TXREG = c;
|
||||
}
|
||||
|
||||
void putStr(char *c) {
|
||||
while (*c != '\0') putc(*c++);
|
||||
}
|
||||
|
||||
int main() {
|
||||
TRISDbits.TRISD11 = 0;
|
||||
|
||||
U2BRG = (PBCLK + 8 * 115200) / (16 * 115200) - 1;
|
||||
U2MODEbits.BRGH = 0;
|
||||
|
||||
U2MODEbits.PDSEL = 00;
|
||||
U2MODEbits.STSEL = 0;
|
||||
|
||||
U2STAbits.URXEN = 1;
|
||||
U2STAbits.UTXEN = 1;
|
||||
|
||||
U2MODEbits.ON = 1;
|
||||
|
||||
while (1) {
|
||||
while (!U2STAbits.TRMT);
|
||||
LATDbits.LATD11 = 1;
|
||||
putStr("12345");
|
||||
LATDbits.LATD11 = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -36,8 +36,8 @@ void _int_(32) isr_uart2rx() {
|
|||
// If OERR == 1 then reset OERR
|
||||
if (U2STAbits.OERR == 1)
|
||||
U2STAbits.OERR = 0;
|
||||
// Wait while URXDA == 0
|
||||
while (U2STAbits.URXDA == 0);
|
||||
if (!IFS1bits.U2RXIF)
|
||||
return;
|
||||
// Save U2RXREG value
|
||||
char c = U2RXREG;
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue