本章总结控制LED的开发流程
寄存器 -> GPIO -> 引脚 -> 编程 -> LED灯亮
第一步:了解LED物理特性
1:一正一负俩个接线点,功能是亮和不亮,两边有电压差,就会发光
2:控制LED的关键是控制寄存器,寄存器上有GPIO,一个GPIO有多个引脚第二步:读原理图,找到控制LED的引脚 如图
1:有五颗LED,其中D26的正级是接的5V (VDD_5V),其他的几颗正级接入的是VDD_IO(开发板工作电压)
2:负极: D26接入的0V,也就是常亮,D22-25通过网络连接,接入了CPU上的引脚
D22-> GPJ0_3
D23-> GPJ0_4
D24-> GPJ0_5
D25-> PWMTOUT1(通过原理图搜索,对应的是 GPD0_1,见图
第三步:查找GPIO对应的寄存器,
查询得知:There are six control registers, namely, GPJ0CON, GPJ0DAT, GPJ0PUD, GPJ0DRV, GPJ0CONPDN and GPJ0PUDPDN in the Port Group GPJ0 Control Registers.GPJ0DAT[7:0]: GPJOWhen the port is configured as input port, the corresponding bit is the pin state. When the port is configured as output port,
the pin state is the same as the corresponding bit. When the port is configured as functional pin, the undefined value will be read.GPJ0的端口0一共有8个引脚,对应的 JPJ0_0 ~ JPJ0_8,ELD用到的GPJ0Con, GPJ0DAT
第四步:并设置相对应的位,控制LEd的电压,点亮LED
0:查找寄存器对应地址
GPJ0CON:0xE020_0240
GPJ0DAT:0xE020_0244
1:控制寄存器GPJ0CON,设置为为输出模式, 如图 GPJ0CON:0xE020_0240
2:数据寄存器GPJ0DAT, 设置高电频还是低电频,1,灯熄灭,0,灯点亮, 需要控制器配合
代码如下
#define GPJ0CON 0xE0200240
#define GPJ0DAT 0xE0200244
int main(void){
int *con= (int *)GPJ0CON;
int *data = (int *)GPJ0DAT;
*con = (*con & ~(0b1111<<12)) | (0b1 <<12);
*data = (*data & ~(0b1111<<12)) | (0b1 <<12);
return 0;
}