##初学嵌入式,请多指教
keil MDK5 编写的代码
无法点亮灯,下面是电路图
![
|
int main()
{
while(1)
{
*((int*)(0x40021000 + 0x18)) = 0x00000010;//打开时钟RCC_APB2ENR
*(int*)(0x40011000 + 0x00) = 0x00000001;//GPIOC_CRL是配置0-7引脚号
*(int*)(0x40011000 + 0x0c) = 0x00000001;//配置输出高电平GPIOC_ODR
}
}//PC0端口点亮led
void SystemInit()
{
}
解决方案,代码问题
int main()
{
while(1)
{
*((int*)(0x40021000 + 0x18)) |=1<<4;//打开时钟RCC_APB2ENR
*(int*)(0x40011000 + 0x00) = 0x00000001;//GPIOC_CRL是配置0-7引脚号
*(int*)(0x40011000 + 0x0c) = 0x00000000;//配置输出高电平GPIOC_ODR
}
}//PC0端口点亮led
void SystemInit()
{
}
这下可以点亮了
还是不懂为什么,这两句的区别。求教
*((int*)(0x40021000 + 0x18)) = 0x00000010;//打开时钟RCC_APB2ENR
*((int*)(0x40021000 + 0x18)) |=1<<4;//打开时钟RCC_APB2ENR
更新一下,以下是做出来的结果有效:
#define RCC_APB2ENR *((int *)(0x40021000 + 0x18))
void SystemInit()
{
}
void led_Init()
{
RCC_APB2ENR |= (1 << 4) ;
*(int*)(0x40011000 + 0x00) = 0x00000001;
}
void delay(unsigned int x)
{
while( x-- );
}
int main()
{
led_Init();
while(1)
{
*(int*)(0x40011000 + 0x0c) = 0x00000001;
delay(0xfffff);
*(int*)(0x40011000 + 0x0c) = 0x00000000;
delay(0xfffff);
}
}
GPIO的初始化需要放在while{ }的前面,不应该放在里面。犯了一个低级错误(真的是被弄晕了)。还哈改过来了。大概就是这样了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)