diff --git a/2ano/2semestre/ac2/aula10/addicional.c b/2ano/2semestre/ac2/aula10/addicional.c new file mode 100644 index 0000000..250f36a --- /dev/null +++ b/2ano/2semestre/ac2/aula10/addicional.c @@ -0,0 +1,21 @@ +#include + +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; +} diff --git a/2ano/2semestre/ac2/aula10/part2.c b/2ano/2semestre/ac2/aula10/part2.c new file mode 100644 index 0000000..dfb5e27 --- /dev/null +++ b/2ano/2semestre/ac2/aula10/part2.c @@ -0,0 +1,30 @@ +#include + +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; +} + diff --git a/2ano/2semestre/ac2/aula10/part3.c b/2ano/2semestre/ac2/aula10/part3.c new file mode 100644 index 0000000..5cbe866 --- /dev/null +++ b/2ano/2semestre/ac2/aula10/part3.c @@ -0,0 +1,34 @@ +#include + +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; +} diff --git a/2ano/2semestre/ac2/aula11/part1.c b/2ano/2semestre/ac2/aula11/part1.c index 9dbb187..1354197 100644 --- a/2ano/2semestre/ac2/aula11/part1.c +++ b/2ano/2semestre/ac2/aula11/part1.c @@ -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; diff --git a/2ano/2semestre/ac2/slides/AC2-T-Aula14.pdf b/2ano/2semestre/ac2/slides/AC2-T-Aula14.pdf new file mode 100644 index 0000000..d72f900 Binary files /dev/null and b/2ano/2semestre/ac2/slides/AC2-T-Aula14.pdf differ diff --git a/2ano/2semestre/ac2/slides/AC2-T-Aula16.pdf b/2ano/2semestre/ac2/slides/AC2-T-Aula16.pdf new file mode 100644 index 0000000..e6aaa5d Binary files /dev/null and b/2ano/2semestre/ac2/slides/AC2-T-Aula16.pdf differ diff --git a/2ano/2semestre/ac2/slides/AC2-T-Aula17.pdf b/2ano/2semestre/ac2/slides/AC2-T-Aula17.pdf new file mode 100644 index 0000000..8fa7236 Binary files /dev/null and b/2ano/2semestre/ac2/slides/AC2-T-Aula17.pdf differ diff --git a/2ano/2semestre/ac2/slides/AC2-T-Aula18_19.pdf b/2ano/2semestre/ac2/slides/AC2-T-Aula18_19.pdf new file mode 100644 index 0000000..1b3244f Binary files /dev/null and b/2ano/2semestre/ac2/slides/AC2-T-Aula18_19.pdf differ diff --git a/2ano/2semestre/ac2/slides/AC2-T-Aula20_21.pdf b/2ano/2semestre/ac2/slides/AC2-T-Aula20_21.pdf new file mode 100644 index 0000000..a597d54 Binary files /dev/null and b/2ano/2semestre/ac2/slides/AC2-T-Aula20_21.pdf differ diff --git a/2ano/2semestre/ac2/slides/AC2-T-Aula22_23_24.pdf b/2ano/2semestre/ac2/slides/AC2-T-Aula22_23_24.pdf new file mode 100644 index 0000000..ccbe1d0 Binary files /dev/null and b/2ano/2semestre/ac2/slides/AC2-T-Aula22_23_24.pdf differ