Fixed issue with Taster.c to disable JTAG so Pin 2 on PORTC can be used as GPIO Pin

This commit is contained in:
_N0x 2021-11-11 01:33:55 +01:00
parent 0eace5b6fe
commit 663d817b11
3 changed files with 62 additions and 43 deletions

View File

@ -2,17 +2,17 @@
void void
Led_init (void){ Led_init (void){
DDRB = 0xFF; // Set all bits in the B Data-Direction Register to output DDRB = 0xFF; /* Set all bits in the B Data-Direction Register to output */
PORTB = 0x00; // Set all bits in the PORT B Register to low to turn all LEDs off PORTB = 0x00; /* Set all bits in the PORT B Register to low to turn all LEDs off */
} }
void void
Led1_On (void){ Led1_On (void){
PORTB |= (1<<7); // Set the bit for LED_1 to hight to turn it on PORTB |= (1<<7); /* Set the bit for LED_1 to hight to turn it on */
} }
void void
Led1_Off (void){ Led1_Off (void){
PORTB &= ~(1<<7); // Set the bit for LED_1 to low to turn it off PORTB &= ~(1<<7); /* Set the bit for LED_1 to low to turn it off */
} }
void void

View File

@ -2,11 +2,20 @@
void void
Taster_init (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 */
PORTD |= (0b111<<5); // Initialize bit 5-7 of PORTD as for pull up resistor PORTD |= (0b111<<5); /* Initialize bit 5-7 of PORTD as for pull up resistor */
PORTC |= (1<<2); // Initialize bit 2 of PORTC as for pull up resistor PORTC |= (1<<PINC2); /* Initialize bit 2 of PORTC as for pull up resistor */
/** Disable JTAG so Pin 2 of PORTC can be used as a GPIO
* Command needs to be run twice - see MCU Control Register Description (23.8.1)
* Bits 7 JTD: JTAG Interface Disable
* [..] The application software must write this bit to the desired value
* twice within four cycles to change its value. [...]
*/
MCUCR |= (1<<JTD);
MCUCR |= (1<<JTD);
} }
uint8_t uint8_t

View File

@ -8,20 +8,20 @@
#include "Led.h" #include "Led.h"
#include "Taster.h" #include "Taster.h"
#include "Timer.h" #include "Timer.h"
#include <util/delay.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
#ifdef F_CPU
#define F_CPU 1000000 #define F_CPU 1000000
#endif #include <util/delay.h>
/* function declarations */ /* function declarations */
void buttonTest (void);
void task1 (void); void task1 (void);
void tast2 (void); void task2 (void);
void task3 (void);
/* global variables */ /* global variables */
volatile int g_counter = 0; volatile int g_counter = 0;
int ledStatus = 0; int g_ledStatus = 0;
uint16_t startMS; uint16_t g_startMS;
/* functions */ /* functions */
int int
@ -34,43 +34,31 @@ main (void)
Taster_init(); Taster_init();
Timer_init(); Timer_init();
g_startMS=Timer_getTick();
/* Run Task 1
while (1) while (1)
{ {
task1(); buttonTest();
}//*/ //task1();
//task2();
//task3();
/* Run Task 2 */ }
startMS=Timer_getTick();
while (1)
{
task2();
}//*/
} }
/* Task 2 (2021-10-28) */
void void
task2 () { buttonTest (void)
if(Timer_getTick()-startMS >= 1000) { /* Wait 1000ms before switching LED1 */ {
startMS=Timer_getTick(); Taster1_get() ? Led1_On() : Led1_Off();
Taster2_get() ? Led2_On() : Led2_Off();
if(ledStatus % 2 == 0){ Taster3_get() ? Led3_On() : Led3_Off();
Led1_On(); Taster4_get() ? Led4_On() : Led4_Off();
} else {
Led1_Off();
} }
ledStatus++;
}
}
/* Task 1 (2021-10-21) */ /* Task 1 (2021-10-21) */
void void
task1 () { task1 (void)
_delay_ms(50); {
_delay_ms(100);
/* Programmieren Sie ein Lauflicht. Nutzen Sie dazu die in „Led.h“ deklarierten /* Programmieren Sie ein Lauflicht. Nutzen Sie dazu die in „Led.h“ deklarierten
* Funktionen. * Funktionen.
@ -102,3 +90,25 @@ task1 () {
g_counter >= 7 ? Led7_On() : Led7_Off(); g_counter >= 7 ? Led7_On() : Led7_Off();
g_counter >= 8 ? Led8_On() : Led8_Off(); g_counter >= 8 ? Led8_On() : Led8_Off();
} }
/* Task 2 (2021-10-28) */
void
task2 (void)
{
if(Timer_getTick() - g_startMS >= 1000) { /* Wait 1000ms before switching LED1 */
g_startMS=Timer_getTick();
if(g_ledStatus % 2 == 0){
Led1_On();
} else {
Led1_Off();
}
g_ledStatus++;
}
}
void
task3 (void)
{
// beep boop
}