嵌入式原理及应用考试复习
简答题
1:LED静态显示和动态显示的区别?
静态显示:
指几个LED灯同时显示,编程较为简单,但占用的I/O资源较多,硬件成本较高
动态显示:
指几个LED灯分时(扫描)显示,节省硬件资源,但编程较为复杂,占用较多CPU时间
2:Cortex-M3有哪些特点?
高性能:允许单片机高频运行
低功耗:逻辑门数少,具有休眠模式
支持较多外部中断输入
支持串行调试
最佳的代码密度,只使用Thumb-2指令集
3:同步、异步通信的区别
同步通信:
要求接收端时钟频率和发送端时钟频率一致,发送端发送连续的比特流;效率高;较复杂,双方时钟的允许误差较小;可用于点对多点;数据格式:2位同步字符+n位数据+1~2位校验位
异步通信:
不要求接收端时钟和发送端时钟同步,适用于数据的随机发送/接收;效率较低;简单,双方时钟可允许一定误差;异步通信只适用于点对点。数据格式:1位起始位+5~8位数据位+1位校验位+1位停止位;
4:RCC时钟与RTC时钟的区别
RCC时钟:
是STM32的时钟控制器,高速时钟源,可开启或关闭各总线的时钟,控制着绝大部分外设功能的使用;本身无中断、事件、标志。
RTC时钟:
是STM32内部一个简单的低速时钟(计数器),可以看作为一个本身具有中断、事件、标志的外设器件;最重要的功能是断电不复位,为单片机提供精确的实时时间。
5:GPIO的模式
- 输入浮空
- 模拟输入
- 输入上拉
- 输入下拉
- 推挽式输出
- 推挽式复用输出
- 开漏输出
- 开漏复用输出
程序题
1:LED1(PE5)和LED2(PB5)同时闪烁显示,要求GPIO时钟频率为10MHZ
#include "stm32f10x.h"
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE|RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_Init(GPIOE,&GPIO_InitStructure);
}
int main()
{
int i=100000;
LED_Init();
while(1)
{
GPIO_SetBits(GPIOE,GPIO_Pin_5);
GPIO_SetBits(GPIOB,GPIO_Pin_5);
for(i=100000;i>0;i--);
GPIO_ResetBits(GPIOE,GPIO_Pin_5);
GPIO_ResetBits(GPIOB,GPIO_Pin_5);
for(i=100000;i>0;i--);
}
}
2:绘制LED1,LED2,LED3,LED4的电路图,并编写一个流水灯
电路图:
代码:
#include "stm32f10x.h"
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(GPIOE,&GPIO_InitStructure);
}
int main()
{
int i=100000;
LED_Init();
while(1)
{
GPIO_Write(GPIOE,0xfffe);
for(i=100000;i>0;i--);
GPIO_Write(GPIOE,0xfffd);
for(i=100000;i>0;i--);
GPIO_Write(GPIOE,0xfffb);
for(i=100000;i>0;i--);
GPIO_Write(GPIOE,0xfff7);
for(i=100000;i>0;i--);
}
}
3: 按键(PC1)输入控制蜂鸣器(PE5)的开关
#include "stm32f10x.h"
void Buzzer_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(GPIOE,&GPIO_InitStructure);
}
void KEY_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置成上拉输入
GPIO_Init(GPIOC,&GPIO_InitStructure);
}
int main()
{
int i=100000;
Buzzer_Init();
KEY_Init();
while(1)
{
if(GPIO_ReadInputDateBit(GPIOC,GPIO_Pin_1)==0)
{
for(i=100000;i>0;i--);
if(GPIO_ReadInputDateBit(GPIOC,GPIO_Pin_1)==0)
{
GPIO_WriteBit(GPIOE,GPIO_Pin_5,!GPIO_ReadOutputDataBit(GPIOE,GPIO_Pin_5));
}
while(GPIO_ReadInputDateBit(GPIOC,GPIO_Pin_1)==0);
}
}
}