新手入门
- 积分
- 26
- 金钱
- 26
- 注册时间
- 2013-5-16
- 在线时间
- 0 小时
|
初学stm32,试着写1602的程序,一直没成功,然后自己弄了8个二极管,显示二进制1到8,用GPIOA的时候完全正常,而用GPIOB却显示出些奇怪的东西,请高手赐教!太疑惑了。。。
这是我的程序,
#include "stm32f10x.h"
#include "delay.h"
int main(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
SysTick_Init();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB,&GPIO_InitStruct);
while(1)
{
GPIOB->ODR = (GPIOB->ODR & 0xff00 )| 0x01;Delay_ms(1000);
GPIOB->ODR = (GPIOB->ODR & 0xff00 )| 0x02;Delay_ms(1000);
GPIOB->ODR = (GPIOB->ODR & 0xff00 )| 0x03;Delay_ms(1000);
GPIOB->ODR = (GPIOB->ODR & 0xff00 )| 0x04;Delay_ms(1000);
GPIOB->ODR = (GPIOB->ODR & 0xff00 )| 0x05;Delay_ms(1000);
GPIOB->ODR = (GPIOB->ODR & 0xff00 )| 0x06;Delay_ms(1000);
GPIOB->ODR = (GPIOB->ODR & 0xff00 )| 0x07;Delay_ms(1000);
GPIOB->ODR = (GPIOB->ODR & 0xff00 )| 0x08;Delay_ms(1000);
}
}//GPIOA完全正常,而GPIOB就不行,为什么?
这是延时用的源文件
#include "delay.h"
u32 nTime;
void SysTick_Init(void)
{
SysTick_Config(72);//1us
}
void Delay_us(u32 us)
{
nTime=us;
while(nTime);
}
void Delay_ms(u32 us)//ms
{
nTime=us*1000;
while(nTime);
}
void SysTick_Handler(void)
{
nTime--;
}
帮帮忙,不胜感激!
还有,其实我是想测试像51给IO口那样给gpio送数据(像这样P0=0x03),就不明白为什么这样不行。。
|
|