嵌入式系统 课后实验总结

汇编实验:

STACK_TOP EQU 0x20002000      ; SP初始值,常数
NUM EQU 20       

; Vector Table Mapped to Address 0 at Reset
	AREA    RESET, CODE, READONLY ;(段名为RESET)
 DCD     STACK_TOP        ; Top of Stack
 DCD     START             ; Reset Handler
	ENTRY		; 指示程序从这里开始执行
START   	; 主程序开始
		LDR		R0, =src					;从R0的地址(0x08000044)开始,先加载地址,在相应地址赋值,即在相应地址放入代码段里定义的值
	 	LDR		R1, =dst					;从R1的地址(0x2000000)开始,连续开辟一段空间(大小等于NUM),其值都为0
		MOV		R2, #NUM			    	;将立即数20放入R2(0x00000014)h
		MOVS   	R3, R2, LSR #3				;R3 <-(R2>>3)     R3(0x00000002)h
		BEQ		COPYWORDS		         	;关系标志位(Z=1时跳转)R3(0x00000002)h

		STMFD	   SP!, {R4-R11}            ;//R4~R11全部为((0x00000000)h)
                                            ;从sp指针的位置,以地址递减储存的方式连续储存R4-R11 ,栈顶放的是LR	

OCTCOPY
		LDMIA.W		R0!, {R4-R11}			; R4~R11  分别放入的是1~8
                                            ;从地址R0处读取多个字,并依次储存到R4-R11,每储存一个字后R0自增一次
		STMIA.W		R1!, {R4-R11}			; R4~R11的内容R1的地址(0x2000000)开始,依次放入
                                            ;从地址R1开始依次读取多个字,每次读取后R1自增一次
		SUBS	R3, R3, #1			 		 ;R3=R3-1 并更新标志位
              



		BNE		OCTCOPY					; 条件:上一次操作时(z=0时跳转) 
		                                ;第一次运行后R3(0x0000001)h;
										;回到上部	OCTCOPY处从新执行,目的将剩余的数放入R4~R11中内容是9~16
										;第二次运行后R3(0x0000000)h
										

		LDMFD.W		SP!, {R4-R11}       ;将sp指针所指的内容赋值给R4~R11 目的将R4~R11清空

COPYWORDS
		ANDS	 R2, R2, #7						; number of odd words to copy 
		BEQ		STOP							; 判断R2中的内容是否为1 此时R2(0x00000004)
WORDCOPY
		LDR		R3, [R0], #4;					; 【R0】赋值给R3; R0=R0+4;   R3(0x0000012)h	 R0(0x0800008c)  
		STR		R3, [R1], #4;0x20000040			; store a word to the destination 
		SUBS	R2, R2, #1						; decrement the counter 
		bne		WORDCOPY						; 循环完毕后从R1的地址连续储存三个数分别是 18 19 20
             
STOP	
		B	.	; 工作完成后,进入无穷循环
		
		;定义数据区 
 AREA mydata1, DATA, READONLY  
src		DCD   1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
	AREA mydata2, DATA, READWRITE    
dst		SPACE   NUM 		 	
    END	; 标记文件结束







LED闪烁:

#include "stm32f10x.h"
 // pb5 led1
 //	pD6  led2
 // pD3 led3
void 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-LED2
	V8----- PD3-LED3
	k1------ PC5
	k2-------PC2
	k3-------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-TX
	RXD2----- 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);					     //禁止发缓冲器空中断, 
  }	
}









查看文章 STM32 keil mdk启动代码发分析_转201001月29日 星期五 13:50 ;// Stack Configuration ;// Stack Size (in Bytes) ;// Stack_Size EQU 0x00000200 ;//定义堆栈大小 AREA STACK, NOINIT, READWRITE, ALIGN=3 ;//定义一个数据段 按8字节对齐 ;AREA 伪指令用于定义一个代码段或数据段 NOINIT:指定此数据段仅仅保留了内存单元,而没有将各初始值写入内存单元,或者将各个内存单元值初始化为0 Stack_Mem SPACE Stack_Size ;//保留Stack_Size大小的堆栈空间 分 配连续 Stack_Size 字节的存储单元并初始化为 0 __initial_sp ;//标号,代表堆栈顶部地址,后面有用 ;// Heap Configuration ;// Heap Size (in Bytes) ;// Heap_Size EQU 0x00000020 ;//定义堆空间大小 AREA HEAP, NOINIT, READWRITE, ALIGN=3 ;//定义一个数据段,8字节对齐 __heap_base Heap_Mem SPACE Heap_Size ;//保留Heap_Size的堆空间 __heap_limit ;//标号,代表堆末尾地址,后面有用 PRESERVE8 ;//指示编译器8字节对齐 THUMB ;//指示编译器为THUMB指令 ; Vector Table Mapped to Address 0 at Reset AREA RESET, DATA, READONLY ;//定义只读数据段,其实放在CODE区,位于0地址 EXTERN NMIException EXTERN HardFaultException EXTERN MemManageException EXTERN BusFaultException EXTERN UsageFaultException EXTERN SVCHandler EXTERN DebugMonitor EXTERN PendSVC EXTERN SysTickHandler ;//声明这些符号在外部定义,同C ;//在××it.c中实现这些函数 ,中断就能自动调用了 EXPORT __Vectors EXPORT __initial_sp ;EXPORT:在程序中声明一个全局的标号__Vectors,该标号可在其他的文件中引用;IMPORT:伪指令用于通知编译器要使用的标号在其他的源文件中定义, ;但要在当前源文件中引用,而且无论当前源文件是否引用该标号,该标号均会被加入到当前源文件的符号表中 __Vectors DCD __initial_sp ; Top of Stack //Cotex-M 要求此处为堆栈顶部地址 DCD Reset_Handler ; Reset Handler DCD NMIException ; NMI Handler DCD HardFaultException ; Hard Fault Handler DCD MemManageException ; MPU Fault Handler DCD BusFaultException ; Bus Fault Handler DCD UsageFaultException ; Usage Fault Handler DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD SVCHandler ; SVCall Handler DCD DebugMonitor ; Debug Monitor Handler DCD 0 ; Reserved DCD PendSVC ; PendSV Handler DCD SysTickHandler ; SysTick Handler //一大堆的异常处理函数地址 ; External Interrupts EXTERN WWDG_IRQHandler EXTERN PVD_IRQHandler EXTERN TAMPER_IRQHandler EXTERN RTC_IRQHandler EXTERN FLASH_IRQHandler EXTERN RCC_IRQHandler EXTERN EXTI0_IRQHandler EXTERN EXTI1_IRQHandler EXTERN EXTI2_IRQHandler EXTERN EXTI3_IRQHandler EXTERN EXTI4_IRQHandler EXTERN DMAChannel1_IRQHandler EXTERN DMAChannel2_IRQHandler EXTERN DMAChannel3_IRQHandler EXTERN DMAChannel4_IRQHandler EXTERN DMAChannel5_IRQHandler EXTERN DMAChannel6_IRQHandler EXTERN DMAChannel7_IRQHandler EXTERN ADC_IRQHandler EXTERN USB_HP_CAN_TX_IRQHandler EXTERN USB_LP_CAN_RX0_IRQHandler EXTERN CAN_RX1_IRQHandler EXTERN CAN_SCE_IRQHandler EXTERN EXTI9_5_IRQHandler EXTERN TIM1_BRK_IRQHandler EXTERN TIM1_UP_IRQHandler EXTERN TIM1_TRG_COM_IRQHandler EXTERN TIM1_CC_IRQHandler EXTERN TIM2_IRQHandler EXTERN TIM3_IRQHandler EXTERN TIM4_IRQHandler EXTERN I2C1_EV_IRQHandler EXTERN I2C1_ER_IRQHandler EXTERN I2C2_EV_IRQHandler EXTERN I2C2_ER_IRQHandler EXTERN SPI1_IRQHandler EXTERN SPI2_IRQHandler EXTERN USART1_IRQHandler EXTERN USART2_IRQHandler EXTERN USART3_IRQHandler EXTERN EXTI15_10_IRQHandler EXTERN RTCAlarm_IRQHandler EXTERN USBWakeUp_IRQHandler ;//同上, DCD WWDG_IRQHandler ; Window Watchdog DCD PVD_IRQHandler ; PVD through EXTI Line detect DCD TAMPER_IRQHandler ; Tamper DCD RTC_IRQHandler ; RTC DCD FLASH_IRQHandler ; Flash DCD RCC_IRQHandler ; RCC DCD EXTI0_IRQHandler ; EXTI Line 0 DCD EXTI1_IRQHandler ; EXTI Line 1 DCD EXTI2_IRQHandler ; EXTI Line 2 DCD EXTI3_IRQHandler ; EXTI Line 3 DCD EXTI4_IRQHandler ; EXTI Line 4 DCD DMAChannel1_IRQHandler ; DMA Channel 1 DCD DMAChannel2_IRQHandler ; DMA Channel 2 DCD DMAChannel3_IRQHandler ; DMA Channel 3 DCD DMAChannel4_IRQHandler ; DMA Channel 4 DCD DMAChannel5_IRQHandler ; DMA Channel 5 DCD DMAChannel6_IRQHandler ; DMA Channel 6 DCD DMAChannel7_IRQHandler ; DMA Channel 7 DCD ADC_IRQHandler ; ADC DCD USB_HP_CAN_TX_IRQHandler ; USB High Priority or CAN TX DCD USB_LP_CAN_RX0_IRQHandler ; USB Low Priority or CAN RX0 DCD CAN_RX1_IRQHandler ; CAN RX1 DCD CAN_SCE_IRQHandler ; CAN SCE DCD EXTI9_5_IRQHandler ; EXTI Line 9..5 DCD TIM1_BRK_IRQHandler ; TIM1 Break DCD TIM1_UP_IRQHandler ; TIM1 Update DCD TIM1_TRG_COM_IRQHandler ; TIM1 Trigger and Commutation DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare DCD TIM2_IRQHandler ; TIM2 DCD TIM3_IRQHandler ; TIM3 DCD TIM4_IRQHandler ; TIM4 DCD I2C1_EV_IRQHandler ; I2C1 Event DCD I2C1_ER_IRQHandler ; I2C1 Error DCD I2C2_EV_IRQHandler ; I2C2 Event DCD I2C2_ER_IRQHandler ; I2C2 Error DCD SPI1_IRQHandler ; SPI1 DCD SPI2_IRQHandler ; SPI2 DCD USART1_IRQHandler ; USART1 DCD USART2_IRQHandler ; USART2 DCD USART3_IRQHandler ; USART3 DCD EXTI15_10_IRQHandler ; EXTI Line 15..10 DCD RTCAlarm_IRQHandler ; RTC Alarm through EXTI Line DCD USBWakeUp_IRQHandler ; USB Wakeup from suspend ;//同上 AREA |.text|, CODE, READONLY ;//定义代码段 ; Reset Handler Reset_Handler PROC ;过程的开始 ;//Rset_Handler的实现 利用PROC、ENDP这一对伪指令把程序段分为若干个过程,使程序的结构加清晰 EXPORT Reset_Handler [WEAK] ;//在外部没有定义该符号时导出该符号,见HELP中[WEAK] IMPORT __main ;//导入符号,__main为 运行时库提供的函数;完成堆栈,堆的初始话 LDR R0, =__main ;//等工作,会调用下面定义的__user_initial_stackheap; BX R0 ;//跳到__main,进入C的世界 ENDP ;过程的结束 ALIGN ; User Initial Stack & Heap IF :DEF:__MICROLIB ;//如果使用micro lib,micro lib 描述见armlib.chm EXPORT __heap_base EXPORT __heap_limit ;//只导出几个定义 ELSE ;//如果使用默认C运行时库 IMPORT __use_two_region_memory EXPORT __user_initial_stackheap __user_initial_stackheap ;//则进行堆栈和堆的赋值,在__main函数执行过程中调用。 LDR R0, = Heap_Mem LDR R1, =(Stack_Mem + Stack_Size) LDR R2, = (Heap_Mem + Heap_Size) LDR R3, = Stack_Mem BX LR ALIGN ENDIF END ;//OK ,完了 http://blog.csdn.net/chehlcy/archive/2010/01/09/5164472.aspx http://files.ourdev.cn/bbs_upload134190/files_11/ourdev_495775.txt ====================================================================== Reset_Handler PROC EXPORT Reset_Handler [WEAK] IMPORT __main LDR R0, =__main BX R0 ENDP 这段代码什么意思。 有2个地方不理解 一:PROC ENDP 二: [WEAK] 什么意思 ------------------------------------------------------------------------------- 一:PROC为子程序开始,ENDP为子程序结束 二:[weak]的意思就是弱。 怎么弱呢?如果你在其他地方写一个同名函数,比如Reset_handler, 你写的这个函数就可以取代它这个函数了。 语法格式: EXPORT 标号 {[WEAK]} EXPORT 伪指令用于在程序中声明一个全局的标号,该标号可在其他的文件中引用。 EXPORT可用 GLOBAL 代替。标号在程序中区分大小写, [WEAK] 选项声明其他的同名标号优先于该标号被引用。 使用示例: AREA Init , CODE , READONLY EXPORT Stest ;声明一个可全局引用的标号Stest…… END
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值