[AC2] Aula10 Part1 fixes
Signed-off-by: TiagoRG <tiago.rgarcia@ua.pt>
This commit is contained in:
parent
ddc4715b30
commit
fae75c9376
|
@ -4,7 +4,7 @@ int main() {
|
||||||
// Configure UART2:
|
// Configure UART2:
|
||||||
// 1 - Configure BaudRate Generator
|
// 1 - Configure BaudRate Generator
|
||||||
U2BRG = ((PBCLK + 8 * 115200) / (16 * 115200)) - 1;
|
U2BRG = ((PBCLK + 8 * 115200) / (16 * 115200)) - 1;
|
||||||
U2MODEbits.BRGH = 0 // 16x baud clock enabled (1 -> 4x baud clock);
|
U2MODEbits.BRGH = 0; // 16x baud clock enabled (1 -> 4x baud clock);
|
||||||
|
|
||||||
// 2 - Configure number of data bits, parity and number of stop bits
|
// 2 - Configure number of data bits, parity and number of stop bits
|
||||||
// (see U2MODE register)
|
// (see U2MODE register)
|
||||||
|
|
|
@ -21,7 +21,7 @@ int main() {
|
||||||
// Configure UART2:
|
// Configure UART2:
|
||||||
// 1 - Configure BaudRate Generator
|
// 1 - Configure BaudRate Generator
|
||||||
U2BRG = ((PBCLK + 8 * 115200) / (16 * 115200)) - 1;
|
U2BRG = ((PBCLK + 8 * 115200) / (16 * 115200)) - 1;
|
||||||
U2MODEbits.BRGH = 1; // 16x baud clock enabled (1 -> 4x baud clock)
|
U2MODEbits.BRGH = 0; // 16x baud clock enabled (1 -> 4x baud clock)
|
||||||
|
|
||||||
// 2 - Configure number of data bits, parity and number of stop bits
|
// 2 - Configure number of data bits, parity and number of stop bits
|
||||||
// (see U2MODE register)
|
// (see U2MODE register)
|
||||||
|
|
|
@ -12,12 +12,9 @@ void putc(char byte) {
|
||||||
U2TXREG = byte;
|
U2TXREG = byte;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendCounter(int counter) {
|
void putstr(char *str) {
|
||||||
while (counter != 0) {
|
// use putc() function to send each charater ('\0' should not be sent)
|
||||||
char bit = counter & 0x1;
|
while (*str != '\0') putc(*str++);
|
||||||
putc(bit);
|
|
||||||
counter >>= 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
@ -38,14 +35,25 @@ int main() {
|
||||||
// 4 - Enable UART2 (see register U2MODE)
|
// 4 - Enable UART2 (see register U2MODE)
|
||||||
U2MODEbits.ON = 1;
|
U2MODEbits.ON = 1;
|
||||||
|
|
||||||
int counter = 0;
|
int i, count = 0;
|
||||||
|
|
||||||
while (1) {
|
while(1) {
|
||||||
sendCounter(counter);
|
// Incrementa o contador módulo 10
|
||||||
delay(5000);
|
count = (count + 1) % 10;
|
||||||
counter = (counter + 1) % 10;
|
|
||||||
|
// Converte o valor do contador para binário
|
||||||
|
char binary[5];
|
||||||
|
for (i = 0; i < 4; i++) {
|
||||||
|
binary[3 - i] = (count & (1 << i)) ? '1' : '0';
|
||||||
}
|
}
|
||||||
|
binary[4] = '\0';
|
||||||
|
|
||||||
|
// Count modulo 10 em binário:
|
||||||
|
putstr(binary);
|
||||||
|
putc('\n');
|
||||||
|
|
||||||
|
delay(200); // 5hz = 200ms
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue