STM32开发板点灯
来源:互联网 发布:java怎么做图形界面 编辑:程序博客网 时间:2024/04/28 19:39
本来计划下午是在家写个AVR的点灯程序玩的,结果。。。。。AVR jtag下载器一直一直都连不上AVR studio,上网查了好久,没有头绪。只能说明自己人品差,估计那玩意坏了。。。等过两个月后买个回来,在把AVR的补起来。。。
好了,所以玩玩stm32,Jlink是个好东西,坏了自己可以烧写固件,只要不是彻底崩溃就好。。。
同样看图
我现在只控制一个,实现最最最简单的led控制。
这里的延时程序我调用stm32的内部SysTick定时器,这个东西好。。。呵呵,比自己写延时方便多了。。。。也比较准确,STM32的固件库也是比较好玩的东西,当然网上好多人都对此抱不一样的态度,我还好,自己玩开心就行,反正是自己喜欢的。。。。
总是不喜欢排版,慢慢来改 上代码:
main.c:
#include <stdio.h>
#include "stm32f10x.h"
#include "Delay.h"
#include "Usart.h"
#include "led.h"
void RCC_Configuration(void);
void NVIC_Configuration(void);
void GPIO_Configuration(void);
void EXTI_Configuration(void);
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
NVIC_Configuration();
SysTick_Configuration();
USART_Configuration();
printf("New Lib Start!\n\r");
printf("this is test led\n\r");
while(1){
led_init();
}
}
/*------函数名:void RCC_Configuration(void)-----------*/
//功能:配置stm32端口时钟,这个端口时钟参考固件库RCC的配置。
//因为led灯要用到GPIOD所以此处就要将GPIOD的端口时钟开放。更详细的硬件说明可以看看32的数据手册
void RCC_Configuration(void){
/* Enable peripheral clocks --------------------------------------------------*/
//RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC|RCC_AHBPeriph_SRAM|RCC_AHBPeriph_FLITF, ENABLE);
//RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|
RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE|RCC_APB2Periph_USART1|
RCC_APB2Periph_AFIO,ENABLE);
}
void GPIO_Configuration(void){
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //这个是端口速度。一般IO口无特殊要求就选择50MHz
//------------- USART1 ----------------//
//============= USART1_Tx PA9 ================//
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //配置成端口复用推挽输出,这里是串口暂时不考虑
GPIO_Init(GPIOA, &GPIO_InitStructure);
//============= USART1_Rx PA10 ================//
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //配置成浮空输入,这里是串口可以不考虑
GPIO_Init(GPIOA, &GPIO_InitStructure);
//============PD3,PD6====================//
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
void NVIC_Configuration(void){
//NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
/*NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);*/
}
void EXTI_Configuration(void){
/*EXTI_InitTypeDef EXTI_InitStructure;
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource0);
EXTI_InitStructure.EXTI_Line = EXTI_Line0 ;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);*/
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
delay.c:
#include "stm32f10x.h"
#include "Delay.h"
vu32 TimingDelay;
void SysTick_Configuration(void){
SysTick_Config(72000);
}
void Delay_ms(u16 nMs){
TimingDelay = nMs;
while(TimingDelay != 0);
}
led.c:
#include "stm32f10x.h"
#include "led.h"
#include "delay.h"
void led_init(void)
{
led2_ON; //灯亮
Delay_ms(2000); //调用stm32内部systick秒延时.这里是延时2秒。。。Delay_ms(1000)就是延时1秒,修改此处调节灯的闪烁时间
led2_OFF; //灯灭
Delay_ms(2000);
}
- STM32开发板点灯
- STM32点灯
- STM32点灯
- GCC 开发 STM32 点灯 串口 程序
- STM32入门开发--按键模块实现按键点灯
- stm32串口点灯
- stm32 汇编点灯程序
- STM32的IO配置点灯
- STM32-学习经验总结 ———stm32-从点灯开始
- Android驱动开发-Ok6410点灯
- STM32学习笔记2——GPIO点灯
- STM32 JLINK 开发板
- Eclipse+JLink GDB Sever在mini2440开发板leds点灯程序调试过程
- 《STM32开发指南》ALIENTEK战舰STM32开发板资料
- STM32开发板-环境篇
- STM32开发板按键实验
- Android之在GEC210板上点灯。
- 2440裸板程序之点灯
- asp.net 维护网站
- vc中读取wav文件的时长和文件播放的几种方式
- EditPlus使用技巧
- storm常见问题解答
- root后台service
- STM32开发板点灯
- delphi实现FTP上传与下载
- SessionFactory的构建
- 牛人博客收集
- c与c++的一些区别
- 从字符串向 datetime 转换时失败
- java连接sqlserver数据库(纯java方式连接-需要加载驱动)
- 增强 Linux 桌面安全性
- h.264学习(二)