Since the task is to set a certain pin as output, the first thing you need to do is to check the board schematics to find out which microcontroller port and pin that “pin 12” corresponds to. Microcontroller ports often have a 1 letter name such as PORTA, PORTB etc. This is also the case for AVR.
Once you have found out which port that’s the correct one, you also have to figure out which bit in that port register to set. There will be 8 pins per port, since each port on this MCU corresponds to 8 bit registers.
Since you want this pin to be an output, you have to configure a “data direction register” to make it such. On AVR (and most Motorola-flavoured MCUs), these registers are called DDRx, where x is the port letter. See the AVR manual, GPIO section. You set the DDR register as output by writing a one to the bit corresponding to the pin.
Once that is done, you can set the relevant bit in actual port register to 1 or 0, depending on if you want a high or low signal. These are called PORTx on AVR.
To create a 5 second delay, it is likely enough for hobbyist/student purposes to call a “busy wait” function. The Arduino libs has the delay()
function that should suffice. Simply wait 5000ms. In professional/real-world applications, busy-wait delays should be avoided and then you’d rather use the on-chip hardware peripheral timers instead, to set a flag when the timer has elapsed.
1
solved Using the Programming Language C to test the pins of Arduino Board [closed]