Fixed wrong register in Taster.c and cleand up main.c
This commit is contained in:
parent
48ea8062c0
commit
8cd2a63ce5
@ -4,8 +4,8 @@ void Taster_init(void){
|
|||||||
DDRD &= ~(0b111<<5); // Set bit 5-7 of Data Direction Register D as input
|
DDRD &= ~(0b111<<5); // Set bit 5-7 of Data Direction Register D as input
|
||||||
DDRC &= ~(1<<2); // Set bit 2 of Data Direction Register C as input
|
DDRC &= ~(1<<2); // Set bit 2 of Data Direction Register C as input
|
||||||
|
|
||||||
PIND &= ~(0b111<<5); // Initialize bit 5-7 of PORTD as low
|
PORTD |= (0b111<<5); // Initialize bit 5-7 of PORTD as for pull up resistor
|
||||||
PINC &= ~(1<<2); // Initialize bit 2 of PORTC as low
|
PORTC |= (1<<2); // Initialize bit 2 of PORTC as for pull up resistor
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Taster1_get(void){
|
uint8_t Taster1_get(void){
|
||||||
|
@ -12,17 +12,31 @@
|
|||||||
#define F_CPU 1000000
|
#define F_CPU 1000000
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(void)
|
/* function declarations */
|
||||||
|
void task1 ();
|
||||||
|
|
||||||
|
/* global variables */
|
||||||
|
int g_counter = 0;
|
||||||
|
|
||||||
|
/* functions */
|
||||||
|
int
|
||||||
|
main (void)
|
||||||
{
|
{
|
||||||
// Initialize the LEDs and Buttons
|
// Initialize the LEDs and Buttons
|
||||||
Led_init();
|
Led_init();
|
||||||
Taster_init();
|
Taster_init();
|
||||||
|
|
||||||
|
|
||||||
int counter = 0;
|
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
// Run Task 1
|
||||||
|
task1();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Tast 1 (2021-10-21) */
|
||||||
|
void
|
||||||
|
task1 () {
|
||||||
_delay_ms(50);
|
_delay_ms(50);
|
||||||
|
|
||||||
/* Programmieren Sie ein Lauflicht. Nutzen Sie dazu die in „Led.h“ deklarierten
|
/* Programmieren Sie ein Lauflicht. Nutzen Sie dazu die in „Led.h“ deklarierten
|
||||||
@ -37,22 +51,21 @@ int main(void)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Check if counter needs to be incremented
|
// Check if counter needs to be incremented
|
||||||
if (Taster1_get()) counter++;
|
if (Taster1_get()) g_counter++;
|
||||||
|
|
||||||
// Check if counter needs to be decremented
|
// Check if counter needs to be decremented
|
||||||
if (Taster2_get()) counter--;
|
if (Taster2_get()) g_counter--;
|
||||||
|
|
||||||
// Keep counter within boundaries (0-8)
|
// Keep counter within boundaries (0-8)
|
||||||
counter = (counter + 9) % 9;
|
g_counter = (g_counter + 9) % 9;
|
||||||
|
|
||||||
// Set the LEDs according to the counter
|
// Set the LEDs according to the counter
|
||||||
counter >= 1 ? Led1_On() : Led1_Off();
|
g_counter >= 1 ? Led1_On() : Led1_Off();
|
||||||
counter >= 2 ? Led2_On() : Led2_Off();
|
g_counter >= 2 ? Led2_On() : Led2_Off();
|
||||||
counter >= 3 ? Led3_On() : Led3_Off();
|
g_counter >= 3 ? Led3_On() : Led3_Off();
|
||||||
counter >= 4 ? Led4_On() : Led4_Off();
|
g_counter >= 4 ? Led4_On() : Led4_Off();
|
||||||
counter >= 5 ? Led5_On() : Led5_Off();
|
g_counter >= 5 ? Led5_On() : Led5_Off();
|
||||||
counter >= 6 ? Led6_On() : Led6_Off();
|
g_counter >= 6 ? Led6_On() : Led6_Off();
|
||||||
counter >= 7 ? Led7_On() : Led7_Off();
|
g_counter >= 7 ? Led7_On() : Led7_Off();
|
||||||
counter >= 8 ? Led8_On() : Led8_Off();
|
g_counter >= 8 ? Led8_On() : Led8_Off();
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user