大学生
最后登录1970-1-1
在线时间 小时
注册时间2017-4-8
|
/*
*新建工程模板--寄存器版本去
*/
#include "stm32f4xx.h"
/*peripheral 外设*/
#define PERIPH_BASE ((unsigned int)0x40000000)
#define AHB1PERIPH_BASE (PERIPH_BASE+0x00020000)
#define GPIOH_BASE (AHB1PERIPH_BASE+0x00001c00)
#define GPIOA_BASE (AHB1PERIPH_BASE+0x00000000)
#define GPIOH_MODE *(unsigned int *)(GPIOH_BASE+0x00)
#define GPIOH_OTYPER *(unsigned int *)(GPIOH_BASE+0x04)
#define GPIOH_OSPEEDR *(unsigned int *)(GPIOH_BASE+0x08)
#define GPIOH_PUPDR *(unsigned int *)(GPIOH_BASE+0x0c)
#define GPIOH_IDR *(unsigned int *)(GPIOH_BASE+0x10)
#define GPIOH_ODR *(unsigned int *)(GPIOH_BASE+0x14)
#define GPIOH_BSRR *(unsigned int *)(GPIOH_BASE+0x18)
#define GPIOH_LCKR *(unsigned int *)(GPIOH_BASE+0x1c)
#define GPIOH_AFRL *(unsigned int *)(GPIOH_BASE+0x20)
#define GPIOH_AFRH *(unsigned int *)(GPIOH_BASE+0x24)
typedef unsigned int u32;
typedef unsigned short u16;
typedef struct
{
u32 MODE;
u32 OTYPER;
u32 OSPEEDR;
u32 PUPDR;
u32 IDR;
u32 ODR;
u16 BSRRL;
u16 BSRRH;
u32 LCKR;
u32 AFR[2];
}GPIO_TypeDef;
#define GPIOH ((GPIO_TypeDef *)GPIOH_BASE) //把GPIO强制转换成指针
#define GPIOA ((GPIO_TypeDef *)GPIOA_BASE) //把GPIO强制转换成指针
#define RCC_BASE (AHB1PERIPH_BASE+0x3800)
#define RCC_AHB1RSTR *(unsigned int *)(RCC_BASE+0x30)
#if 1
/*使用寄存器结构体指针的方式来操作GPIO*/
int main(void)
{
/*打开时钟*/
RCC_AHB1RSTR |=(1<<7);
/*PH10先清零,再设置输出*/
GPIOH->MODE &=~(3<<(2*10));
GPIOH->MODE |= (1<<(2*10));
/*设置PH10为推挽输出*/
GPIOH->OTYPER &=~(1<<10);
/*设置PH10输出速度*/
GPIOH->OSPEEDR &=~(3<<(2*10));
GPIOH->OSPEEDR |= (2<<(2*10));
/*PH10输出低电平*/
GPIOH->ODR &=~(1<<10);
while(1);
}
#else
int main()
{
/*打开时钟*/
RCC_AHB1RSTR |=1<<7;
/*PH10先清零,再设置输出*/
GPIOH_MODE &=~(3<<(2*10));
GPIOH_MODE |= (1<<(2*10));
/*设置PH10为推挽输出*/
GPIOH_OTYPER &=~(1<<10);
/*设置PH10输出速度*/
GPIOH_OSPEEDR &=~(3<<(2*10));
GPIOH_OSPEEDR |= (2<<(2*10));
/*PH10输出低电平*/
GPIOH_ODR &=~(1<<10);
while(1);
}
#endif
/*函数为空,目的是为了骗过编译器不报错*/
void SystemInit(void)
{
}
*** Using Compiler 'V5.05 update 2 (build 169)', folder: 'F:\keil5\ARM\ARMCC\Bin'
Build target 'Target 1'
compiling main.c...
main.c(56): error: #7: unrecognized token
PIOH->MODE &=~(3<<(2*10));
main.c(56): error: #29: expected an expression
PIOH->MODE &=~(3<<(2*10));
main.c(57): error: #7: unrecognized token
PIOH->MODE |= (1<<(2*10));
main.c(57): error: #29: expected an expression
PIOH->MODE |= (1<<(2*10));
main.c(60): error: #7: unrecognized token
PIOH->OTYPER &=~(1<<10);
main.c(60): error: #29: expected an expression
PIOH->OTYPER &=~(1<<10);
main.c(63): error: #7: unrecognized token
PIOH->OSPEEDR &=~(3<<(2*10));
main.c(63): error: #29: expected an expression
PIOH->OSPEEDR &=~(3<<(2*10));
main.c(64): error: #7: unrecognized token
PIOH->OSPEEDR |= (2<<(2*10));
main.c(64): error: #29: expected an expression
PIOH->OSPEEDR |= (2<<(2*10));
main.c(67): error: #7: unrecognized token
PIOH->ODR &=~(1<<10);
main.c(67): error: #29: expected an expression
PIOH->ODR &=~(1<<10);
main.c: 0 warnings, 12 errors
".\Output\LED-REG.axf" - 12 Error(s), 0 Warning(s).
Target not created.
Build Time Elapsed: 00:00:00 |
|