






stm32f10x.h檔案
/用來存放STM32暫存器映射的代碼
//外設 perirhral
#define PERIPH_BASE ((unsigned int)0x40000000)
#define APB1PERIPH_BASE PERIPH_BASE
#define APB2PERIPH_BASE (PERIPH_BASE + 0x10000)
#define AHBPERIPH_BASE (PERIPH_BASE + 0x20000)
#define RCC_BASE (AHBPERIPH_BASE + 0x1000)
#define GPIOB_BASE (APB2PERIPH_BASE + 0x0C00)
#define RCC_APB2ENR *(unsigned int*)(RCC_BASE + 0x18)
#define GPIOB_CRL *(unsigned int*)(GPIOB_BASE + 0x00)
#define GPIOB_CRH *(unsigned int*)(GPIOB_BASE + 0x04)
#define GPIOB_IDR *(unsigned int*)(GPIOB_BASE + 0x08)
#define GPIOB_ODR *(unsigned int*)(GPIOB_BASE + 0x0C)
#define GPIOB_BSRR *(unsigned int*)(GPIOB_BASE + 0x10)
#define GPIOB_BRR *(unsigned int*)(GPIOB_BASE + 0x14)
#define GPIOB_LCKR *(unsigned int*)(GPIOB_BASE + 0x18)
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef struct
{
uint32_t CRL;
uint32_t CRH;
uint32_t IDR;
uint32_t ODR;
uint32_t BSRR;
uint32_t BRR;
uint32_t LCKR;
}GPIO_TypeDef;
typedef struct
{
uint32_t CR;
uint32_t CFGR;
uint32_t CIR;
uint32_t APB2RSTR;
uint32_t APB1RSTR;
uint32_t AHBENR;
uint32_t APB2ENR;
uint32_t APB1ENR;
uint32_t BDCR;
uint32_t CSR;
}RCC_TypeDef
#define GPIOB ((GPIO_TypeDef*)GPIOB_BASE)
#define RCC ((RCC_TypeDef*)RCC_BASE)
main.c檔案
//#if 0
//#include<reg52.h>
//sbit LED = P0^0
//void main(void)
//{
// P0 =0XFE; //總線操作 strP0 0X80
//
// LED = 0; //位操作
//}
//#endif
#include "stm32f10x.h"
int main(void)
{
#if 0
//打開GPIOB 埠的時鐘
*( unsigned int * )0x40021018 |= ( (1)<<3);
//配置IO口為輸出
*( unsigned int * )0x40010C00 |= ( (1)<<(4*0));
//控制ODR暫存器
*( unsigned int * )0x40010C0C &=~(1<<0);
#elif 0
//打開GPIOB埠的時鐘
RCC_APB2ENR |= ((1) <<3);
//配置IO口為輸出
GPIOB_CRL &= ((0x0f)<<(4*0));
GPIOB_CRL |= ( (1) << (4*0));
//控制ODR暫存器
GPIOB_ODR &=~(1<<0);
//GPIOB_ODR |=(1<<0);
#elif 1
//打開GPIOB埠的時鐘
RCC->APB2ENR |= ((1) <<3);
//配置IO口為輸出
GPIOB->CRL &= ((0x0f)<<(4*0));
GPIOB->CRL |= ((1)<<(4*0));
//控制ODR暫存器
GPIOB->ODR &=~(1<<0);
//GPIOB->ODR |= (1<<0);
#endif
}
void SystemInit(void)
{
//函式體為空,目的是為了騙過編譯器不報錯
}
結果如下
*** Using Compiler 'V5.05 update 2 (build 169)', folder: 'D:\stm32\ARM\ARMCC\Bin'
Rebuild target 'Template-REG'
assembling startup_stm32f10x_hd.s...
compiling main.c...
main.c(21): error: #65: expected a ";"
int main(void)
main.c(51): warning: #12-D: parsing restarts here after previous syntax error
CC->APB2ENR |= ((1) <<3);
main.c(54): error: #18: expected a ")"
PIOB->CRL &= ((0x0f)<<(4*0));
main.c(54): error: #79: expected a type specifier
PIOB->CRL &= ((0x0f)<<(4*0));
main.c(54): error: #101: "GPIO_TypeDef" has already been declared in the current scope
PIOB->CRL &= ((0x0f)<<(4*0));
main.c(54): error: #141-D: unnamed prototyped parameters not allowed when body is present
PIOB->CRL &= ((0x0f)<<(4*0));
main.c(54): error: #130: expected a "{"
PIOB->CRL &= ((0x0f)<<(4*0));
main.c(61): warning: #12-D: parsing restarts here after previous syntax error
}
main.c: 2 warnings, 6 errors
".\Objects\Template-REG.axf" - 6 Error(s), 2 Warning(s).
Target not created.
Build Time Elapsed: 00:00:01
有誰知道問題出在哪里?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/216420.html
標籤:C語言
下一篇:第七行的3是什么意思啊!搞不明白
