嵌入式系统 课后实验总结
来源:互联网 发布:php没人要了 编辑:程序博客网 时间:2024/06/05 12:41
汇编实验:
STACK_TOP EQU 0x20002000 ; SP初始值,常数NUM EQU 20 ; Vector Table Mapped to Address 0 at ResetAREA RESET, CODE, READONLY ;(段名为RESET) DCD STACK_TOP ; Top of Stack DCD START ; Reset HandlerENTRY; 指示程序从这里开始执行START ; 主程序开始LDRR0, =src;从R0的地址(0x08000044)开始,先加载地址,在相应地址赋值,即在相应地址放入代码段里定义的值 LDRR1, =dst;从R1的地址(0x2000000)开始,连续开辟一段空间(大小等于NUM),其值都为0MOVR2, #NUM ;将立即数20放入R2(0x00000014)hMOVS R3, R2, LSR #3;R3 <-(R2>>3) R3(0x00000002)hBEQCOPYWORDS ;关系标志位(Z=1时跳转)R3(0x00000002)hSTMFD SP!, {R4-R11} ;//R4~R11全部为((0x00000000)h) ;从sp指针的位置,以地址递减储存的方式连续储存R4-R11 ,栈顶放的是LROCTCOPYLDMIA.WR0!, {R4-R11}; R4~R11 分别放入的是1~8 ;从地址R0处读取多个字,并依次储存到R4-R11,每储存一个字后R0自增一次STMIA.WR1!, {R4-R11}; R4~R11的内容R1的地址(0x2000000)开始,依次放入 ;从地址R1开始依次读取多个字,每次读取后R1自增一次SUBSR3, R3, #1 ;R3=R3-1 并更新标志位 BNEOCTCOPY; 条件:上一次操作时(z=0时跳转) ;第一次运行后R3(0x0000001)h;;回到上部OCTCOPY处从新执行,目的将剩余的数放入R4~R11中内容是9~16;第二次运行后R3(0x0000000)hLDMFD.WSP!, {R4-R11} ;将sp指针所指的内容赋值给R4~R11 目的将R4~R11清空COPYWORDSANDS R2, R2, #7; number of odd words to copy BEQSTOP; 判断R2中的内容是否为1 此时R2(0x00000004)WORDCOPYLDRR3, [R0], #4;; 【R0】赋值给R3; R0=R0+4; R3(0x0000012)h R0(0x0800008c) STRR3, [R1], #4;0x20000040; store a word to the destination SUBSR2, R2, #1; decrement the counter bneWORDCOPY; 循环完毕后从R1的地址连续储存三个数分别是 18 19 20 STOPB.; 工作完成后,进入无穷循环;定义数据区 AREA mydata1, DATA, READONLY srcDCD 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20AREA mydata2, DATA, READWRITE dstSPACE NUM END; 标记文件结束
LED闪烁:
#include "stm32f10x.h" // pb5 led1 //pD6 led2 // pD3 led3void rcc_configration(){ SystemInit(); // 初始化系统硬件信息等}void led_configration(){ GPIO_InitTypeDef GPIO_InitStructure; // 结构体声明 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOD,ENABLE); // 使能 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; GPIO_Init(GPIOB,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_3; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; GPIO_Init(GPIOD,&GPIO_InitStructure); }int main(){ rcc_configration() ; led_configration(); while(1) { GPIO_SetBits(GPIOB,GPIO_Pin_5); GPIO_SetBits(GPIOD,GPIO_Pin_6); GPIO_SetBits(GPIOD,GPIO_Pin_3); GPIO_ResetBits(GPIOD,GPIO_Pin_3); // 清除端口为位 while(1); } }
系统滴答定时器:(注意定时器设置)
#include "stm32f10x.h"void LED_Config(void){ GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //LED1 V6 配置为通用推挽输出 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //口线翻转速度为50MHz GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; //LCD背光控制 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_ResetBits(GPIOD, GPIO_Pin_13); //LCD背光关闭}void RCC_Configuration(void){ SystemInit(); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD| RCC_APB2Periph_GPIOE , ENABLE);}void Delay_us(uint32_t n);uint8_t a;int main(){ RCC_Configuration(); LED_Config(); //SysTick_Config(72000000); a=0; while(1) { Delay_us(50000); GPIO_SetBits(GPIOB, GPIO_Pin_5); //LED1 亮 Delay_us(50000); GPIO_ResetBits(GPIOB, GPIO_Pin_5); //LED1 灭 } while(1); }// /****************************************************************************************************\Function Delay_us*\Description 系统滴答时间*\Parameter n*\Return void*\Note *\Log 2014年6月16日15:53:09 Ver 1.0 孙晓磊* 系统延时函数***************************************************************************************************/void Delay_us(uint32_t n) ////////延时多少微秒,n就输入多少!{ SysTick->LOAD=72*n; //装载计数值,因为时钟72M,72次在1μs SysTick->CTRL=0x00000005;//时钟来源设为为HCLK(72M),打开定时器 while(!(SysTick->CTRL&0x00010000));//等待计数到0 SysTick->CTRL=0x00000004;//关闭定时器}键盘处理中断 ledl亮灭:
/* LED1-LED3 ---V6——V8 V6----- PB5-LED1 V7----- PD6-LED2V8----- PD3-LED3k1------ PC5k2-------PC2k3-------PC3 */#include "stm32f10x.h"#include "stm32f10x_exti.h"#include "stm32f10x_rcc.h"#include "misc.h"/****************************************************************************************************\Function Rcc_configration*\Description RCC配置*\Parameter void*\Return void*\Note *\Log 2014.05.28 Ver 1.0 孙晓磊* 创建函数。***************************************************************************************************/void Rcc_configration(){ SystemInit(); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); }/****************************************************************************************************\Function GPIO_configration*\Description GPIO配置*\Parameter void*\Return void*\Note *\Log 2014.05.28 Ver 1.0 孙晓磊* 配置函数。***************************************************************************************************/void GPIO_configration(){ GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOC,ENABLE); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; GPIO_Init(GPIOB,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; GPIO_Init(GPIOD,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; GPIO_Init(GPIOD,&GPIO_InitStructure); //////////////////////////////////////////////////////// GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU; GPIO_Init(GPIOC,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU; GPIO_Init(GPIOC,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU; GPIO_Init(GPIOC,&GPIO_InitStructure);}/****************************************************************************************************\Function NVIC_Configration*\Description NVIC配置*\Parameter void*\Return void*\Note *\Log 2014.05.28 Ver 1.0 孙晓磊* 配置函数。***************************************************************************************************/void NVIC_Configration(){NVIC_InitTypeDef NVIC_Structure;EXTI_InitTypeDef EXTI_InitStructure;NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //选定优先级分组NVIC_Structure.NVIC_IRQChannel=EXTI9_5_IRQn;// 对各个通道进行优先级设定NVIC_Structure.NVIC_IRQChannelSubPriority=0;NVIC_Structure.NVIC_IRQChannelPreemptionPriority=0;NVIC_Init(&NVIC_Structure);NVIC_Structure.NVIC_IRQChannel=EXTI2_IRQn;NVIC_Structure.NVIC_IRQChannelSubPriority=0;NVIC_Structure.NVIC_IRQChannelPreemptionPriority=0;NVIC_Init(&NVIC_Structure);NVIC_Structure.NVIC_IRQChannel=EXTI3_IRQn;NVIC_Structure.NVIC_IRQChannelSubPriority=0;NVIC_Structure.NVIC_IRQChannelPreemptionPriority=0;NVIC_Init(&NVIC_Structure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource5); // 选择通道 GPIO_PinSource0~15 GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource2); GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource3); EXTI_InitStructure.EXTI_Line=EXTI_Line5; //对应相应的中断通道 ,开启相应的中断 EXTI_Line0~15 EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd=ENABLE; EXTI_Init(&EXTI_InitStructure); EXTI_InitStructure.EXTI_Line=EXTI_Line2; EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd=ENABLE; EXTI_Init(&EXTI_InitStructure); EXTI_InitStructure.EXTI_Line=EXTI_Line3; EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd=ENABLE; EXTI_Init(&EXTI_InitStructure);}unsigned char _it0=0,num=0;/****************************************************************************************************\Function Delay*\Description 延时函数*\Parameter void*\Return void*\Note *\Log 2014.05.28 Ver 1.0 孙晓磊* 配置函数***************************************************************************************************/void Delay(__IO uint32_t nCount){ for(; nCount != 0; nCount--);}/****************************************************************************************************\Function find_key*\Description 检测键盘函数*\Parameter void*\Return void*\Note *\Log 2014.05.28 Ver 1.0 孙晓磊* 配置函数***************************************************************************************************/void find_key(){ if(_it0==1) { if(!GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5)) { Delay(0x3ffff); if(!GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5)) { GPIO_SetBits(GPIOB,GPIO_Pin_5); } } GPIO_ResetBits(GPIOD,GPIO_Pin_6); GPIO_ResetBits(GPIOD,GPIO_Pin_3); } else if(_it0==3) { if(!GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_3)) { Delay(0x3ffff); if(!GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_3)) { GPIO_SetBits(GPIOD,GPIO_Pin_3); } } GPIO_ResetBits(GPIOB,GPIO_Pin_5); GPIO_ResetBits(GPIOD,GPIO_Pin_6); } else if(_it0==2) { if(!GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_6)) { Delay(0x3ffff); if(!GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_6)) { GPIO_SetBits(GPIOD,GPIO_Pin_6); } } GPIO_ResetBits(GPIOB,GPIO_Pin_5); GPIO_ResetBits(GPIOD,GPIO_Pin_3); }}int main(){Rcc_configration(); GPIO_configration(); NVIC_Configration(); _it0=0; while(1) { find_key(); // 循环检测,当对应通道为低电平时,触发外部中断! } } // stm32f10x_it.c /****************************************************************************************************\Function EXTI9_5_IRQHandler*\Description 中断处理函数*\Parameter void*\Return void*\Note *\Log 2014.05.28 Ver 1.0 孙晓磊* 中断函数***************************************************************************************************/void EXTI9_5_IRQHandler(void){ if(EXTI_GetITStatus(EXTI_Line5) != RESET) //判别是否有键按下 {_it0=1; //按键中断标志 EXTI_ClearITPendingBit(EXTI_Line5); //清除中断请求标志 }}/* /****************************************************************************************************\Function EXTI2_IRQHandler*\Description 中断处理函数*\Parameter void*\Return void*\Note *\Log 2014.05.28 Ver 1.0 孙晓磊* 中断函数***************************************************************************************************/void EXTI2_IRQHandler(void){ if(EXTI_GetITStatus(EXTI_Line2) != RESET) //判别是否有键按下 {_it0=2; //按键中断标志 EXTI_ClearITPendingBit(EXTI_Line2); //清除中断请求标志 }} /****************************************************************************************************\Function EXTI3_IRQHandler*\Description 中断处理函数*\Parameter void*\Return void*\Note *\Log 2014.05.28 Ver 1.0 孙晓磊* 中断函数***************************************************************************************************/void EXTI3_IRQHandler(void){ if(EXTI_GetITStatus(EXTI_Line3) != RESET) //判别是否有键按下 {_it0=3; //按键中断标志 EXTI_ClearITPendingBit(EXTI_Line3); //清除中断请求标志 }} */usart中断发送字符:
#include "stm32f10x.h" #include "platform_config.h" #include "stm32f10x_usart.h" #include "misc.h" #include "stdarg.h" /* TXD2----- PA2-US2-TXRXD2----- PA3-US2-RX速率:9600,n,8,1 */ /****************************************************************************************************\Function RCC_configration*\Description RCC配置*\Parameter void*\Return void*\Note *\Log 2014.05.28 Ver 1.0 孙晓磊* 创建函数。***************************************************************************************************/ void RCC_configration() { SystemInit(); RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO,ENABLE); // RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART2,ENABLE); } /****************************************************************************************************\Function RCC_configration*\Description RCC配置*\Parameter void*\Return void*\Note *\Log 2014.05.28 Ver 1.0 孙晓磊* 创建函数。***************************************************************************************************/ void GPIO_configration() { GPIO_InitTypeDef GPIO_Structure; GPIO_Structure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Structure.GPIO_Pin=GPIO_Pin_9; GPIO_Structure.GPIO_Mode=GPIO_Mode_AF_PP; GPIO_Init(GPIOA,&GPIO_Structure); GPIO_Structure.GPIO_Pin=GPIO_Pin_10; GPIO_Structure.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA,&GPIO_Structure); } /****************************************************************************************************\Function Usart_configration*\Description Usart配置*\Parameter void*\Return void*\Note *\Log 2014.05.28 Ver 1.0 孙晓磊* 创建函数。***************************************************************************************************/ void Usart_configration() { USART_InitTypeDef USART_InitStructure; USART_InitStructure.USART_BaudRate = 9600; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl =USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; USART_Init(USART1, &USART_InitStructure); USART_ITConfig(USART1, USART_IT_TXE, ENABLE); USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); USART_Cmd(USART1, ENABLE); } /****************************************************************************************************\Function NVIC_configration*\Description NVIC配置*\Parameter void*\Return void*\Note *\Log 2014.05.28 Ver 1.0 孙晓磊* 创建函数。***************************************************************************************************/ void NVIC_configration() { NVIC_InitTypeDef NVICInitStructure;NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); NVICInitStructure.NVIC_IRQChannel = USART1_IRQn; NVICInitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVICInitStructure.NVIC_IRQChannelSubPriority = 0;NVICInitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVICInitStructure); } int main() { RCC_configration();GPIO_configration();Usart_configration();NVIC_configration();//复位时先发送ABC////////////////////////////////////////////////////// USART_SendData(USART1,'A'); while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET); USART_SendData(USART1,'B'); while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET); USART_SendData(USART1,'C');while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);////////////////////////////////////////////////////while(1); }/////stm32f10x_it.c///////////////////////////////////////////////////////****************************************************************************************************\Function USART1_IRQHandler*\Description Usart1中断函数*\Parameter void*\Return void*\Note *\Log 2014.05.28 Ver 1.0 孙晓磊* Usart1中断函数***************************************************************************************************/void USART1_IRQHandler(void) //串口2 中断服务程序{ uint8_t c; if(USART_GetFlagStatus(USART1,USART_IT_RXNE)!=RESET) { c=USART_ReceiveData(USART1); USART_SendData(USART1,c); while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET); } if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET) //这段是为了避免STM32 USART 第一个字节发不出去的BUG // 发送中断还没有清零 { USART_ITConfig(USART1, USART_IT_TXE, DISABLE); //禁止发缓冲器空中断, }}
0 0
- 嵌入式系统 课后实验总结
- 嵌入式系统总结
- 嵌入式系统总结
- 嵌入式系统总结1
- WinCE实验教程之一嵌入式系统简介
- WinCE实验教程之一嵌入式系统
- 嵌入式系统的基础总结
- 嵌入式系统接口技术总结
- 嵌入式系统知识大总结
- 课后总结
- 课后总结
- TI8168嵌入式系统教学实验平台 & TI8168实验箱 & TI8168教学实验箱 & TI8168DSP实验箱
- 实验二课后作业
- 实验三课后作业
- 实验四课后作业
- 实验五课后作业
- 实验六课后作业
- 实验七课后作业
- DirectoryEntry.Children 属性
- 5. 面对对象(基础) Part 5 --- 学习笔记
- java maven quartz exampe 实战攻略
- Android面试题目整理与讲解(二)
- Windows Server 2008远程桌面端口更改方法
- 嵌入式系统 课后实验总结
- 我们都是好孩子
- 导入android项目总数出现:Unable to resolve target 'android-9'
- 分享个很不错的LookAndFeel
- 王岳伦亲口否认李湘怀孕 称为生二宝时刻准备着
- sql函数RIGHT的简单用法
- 引用绑定好的lua
- Hashtable和HashMap的区别
- 著名中国黑客网站目录