为什么微控制器的I/O针必须初始化

1.Briefly explain why the digital Input/Output pins on the microcontroller have to be initialized before they are used. Which line of code is responsible for the initialization of the I/O port pin?

2.The initialization in the program is “friendly”. Briefly explain why.

#include “LPC17xx.h”
void delay(volatile int value)
{
for(int i=0; i {
}
}
int main()
{
LPC_GPIO1->FIODIR |= 1< while(1)
{
LPC_GPIO1->FIOSET |= 1< delay(48000);
LPC_GPIO1->FIOCLR |= 1<<5;
delay(96000);
}
}

从代码上看,这是GPIO部分;
GPIO的针脚可以定义为输入针脚和输出针脚,不设定,单片机不知道针脚是做什么用的;
所有的外设都需要设置控制寄存器,设置完成后才能对外设进行操作。

参见《单片机原理及接口技术》