diff --git a/2ano/2semestre/ac2/aula04/part1-2.c b/2ano/2semestre/ac2/aula04/part1-2.c index d0adb19..c8b8eab 100644 --- a/2ano/2semestre/ac2/aula04/part1-2.c +++ b/2ano/2semestre/ac2/aula04/part1-2.c @@ -7,16 +7,14 @@ void delay(int ms) { int main() { // Configure RE6-RE3 as output - TRISE = TRISE & 0xFF87; + TRISE &= 0xFF87; // Initialize the counter unsigned int counter = 0; while (1) { - // Update value - LATE = (LATE & 0xFF87) // Reset bits 6-3 - | counter << 3; // Merge with counter + LATE = (LATE & 0xFF87) | counter++ << 3; + counter %= 10; delay(460); - counter = (counter + 1) % 10; } } diff --git a/2ano/2semestre/ac2/aula04/part1-3.c b/2ano/2semestre/ac2/aula04/part1-3.c index 983f017..f1154e8 100644 --- a/2ano/2semestre/ac2/aula04/part1-3.c +++ b/2ano/2semestre/ac2/aula04/part1-3.c @@ -7,16 +7,14 @@ void delay(int ms) { int main() { // Configure RE6-RE3 as output - TRISE = TRISE & 0xFF87; + TRISE &= 0xFF87; // Initialize the counter unsigned int counter = 0; while (1) { - // Update value - LATE = (LATE & 0xFF87) // Reset bits 6-3 - | counter << 3; // Merge with counter + LATE = (LATE & 0xFF87) | counter << 3; + counter = (counter + 9) % 10; delay(370); - counter = (counter + 9) % 10; } } diff --git a/2ano/2semestre/ac2/aula04/part2-1.c b/2ano/2semestre/ac2/aula04/part2-1.c new file mode 100644 index 0000000..f63e103 --- /dev/null +++ b/2ano/2semestre/ac2/aula04/part2-1.c @@ -0,0 +1,14 @@ +#include + +int main() { + // Configure ports as output + TRISB &= 0x80FF; // Use bits 14-8 + TRISD &= 0xFF9F; // Use bits 6-5 + + // Select only least significative display + LATD = (LATD & 0xFF9F) | 0x0020; + + while (1) LATB = LATB & 0x80FF | 0x0100 << (getChar() - 'a'); + + return 0; +} diff --git a/2ano/2semestre/ac2/aula04/part2-2.c b/2ano/2semestre/ac2/aula04/part2-2.c new file mode 100644 index 0000000..f3bbee3 --- /dev/null +++ b/2ano/2semestre/ac2/aula04/part2-2.c @@ -0,0 +1,26 @@ +#include + +void delay(unsigned int ms) { + resetCoreTimer(); + while(readCoreTimer() < 20000 * ms); +} + +int main() { + // Configure ports as output + TRISB &= 0x80FF; // Use bits 14-8 + TRISD &= 0xFF9F; // Use bits 6-5 + + // Select least significative display + LATD = (LATD & 0xFF9F) | 0x0020; + + while (1) { + unsigned char segment = 1; + for (; segment < (1<<7); segment <<= 1) { + LATB = (LATB & 0x80FF) | segment << 8; + delay(500); + } + LATD ^= 0x0060; + } + + return 0; +} diff --git a/2ano/2semestre/ac2/aula04/part2-5.c b/2ano/2semestre/ac2/aula04/part2-5.c new file mode 100644 index 0000000..0b9583e --- /dev/null +++ b/2ano/2semestre/ac2/aula04/part2-5.c @@ -0,0 +1,25 @@ +#include + +const unsigned int dis7Scodes[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, + 0xFD, 0x07, 0x7F, 0x6F, 0x77, 0xFC, + 0x39, 0x5E, 0xF9, 0xF1}; + +void delay(unsigned int ms) { + resetCoreTimer(); + while (readCoreTimer() < 20000 * ms); +} + +int main() { + TRISB &= 0x80FF; + TRISD &= 0xFF9F; + LATD = (LATD & 0xFF9F) | 0x0020; + + unsigned int n = 0; + while (1) { + LATB = (LATB & 0x80FF) | dis7Scodes[n++] << 8; + n %= 16; + delay(500); + } + + return 0; +}