extern interrupt0.c

/*********************************************************************************
*程序名称:extern interrupt0.c
*程序描述:外部中断0
*编    制:LZS
*备    注:编译器keil C51 V7.06;时间2008.2.10;版本:v1.0
**********************************************************************************/
void Delay(unsigned int delay);
#include "reg51.h"
unsigned char tmp;
int main(void)
{

 tmp=0xAA;
 EA=1;
 EX0=1;
 while(1)
 {
  P0=tmp;
 }
}

/**********************************************************************
*函数名称:void Ext_Interrupt0(void)
*函数描述:外部中断0服务函数
*入口参数:无
*出口参数:无
*备    注:无
***********************************************************************/
void Ext_Interrupt0(void) interrupt 0 using 2
{
 if(tmp==0x55)
 {
  tmp=0xAA;
 }

 
 else
 {
  tmp=0x55;
 }
 Delay(10);
}

/**********************************************************************
*函数名称:Delay()
*函数描述:延时delay个ms
*入口参数:delay
*出口参数:无
*备    注:假设晶振频率为12MHZ时延时为delay个ms
***********************************************************************/
void Delay(unsigned delay)
{
 unsigned int tmp;//一个临时变量
 for(;delay>0;delay--)
 {
  for(tmp=0;tmp<124;tmp++)
  {
   ;
  }
 }
}

 /***********************************************************************************************************************
*关于本程序有几点不明白:1.为什么直接用P0口判断不行,如:if(P0==0x55) P0=0xaa;
                                            2.如何使得刚好按下一个键触发一次外部中断(适当延时可以解决)
************************************************************************************************************************/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果您遇到了重复定义的问题,可以使用如下方法解决: 1. 将 `g_timeMilliseconds` 定义为一个全局变量,然后在两个函数中都使用它,而不是在 `SysTick_Handler` 函数中直接对它进行操作。 例如,您可以在某个头文件中定义 `g_timeMilliseconds`: ```c // 在头文件中定义全局变量 extern uint32_t g_timeMilliseconds; ``` 然后在一个 C 文件中定义这个全局变量: ```c #include "header.h" uint32_t g_timeMilliseconds = 0; ``` 然后在 `SysTick_Handler` 函数中,将其修改为: ```c void SysTick_Handler(void) { g_timeMilliseconds++; } ``` 在 `xPortSysTickHandler` 函数中,您可以通过 `g_timeMilliseconds` 全局变量来获取当前时间的值,而不需要在该函数中对其进行操作。例如: ```c void xPortSysTickHandler( void ) { /* Increment the RTOS tick. */ if( xTaskIncrementTick() != pdFALSE ) { /* A context switch is required. Context switching is performed in the PendSV interrupt. Pend the PendSV interrupt. */ portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; } } ``` 2. 如果您仍然想要在 `xPortSysTickHandler` 函数中对时间进行操作,您可以将其代码合并到 `SysTick_Handler` 函数中,而不需要在 `xPortSysTickHandler` 函数中重新定义。例如: ```c void SysTick_Handler(void) { g_timeMilliseconds++; /* Increment the RTOS tick. */ if( xTaskIncrementTick() != pdFALSE ) { /* A context switch is required. Context switching is performed in the PendSV interrupt. Pend the PendSV interrupt. */ portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; } } ``` 然后在 `xPortSysTickHandler` 函数中,您可以删除对 `g_timeMilliseconds` 的操作,只保留对 RTOS tick 的操作: ```c void xPortSysTickHandler( void ) { /* Increment the RTOS tick. */ if( xTaskIncrementTick() != pdFALSE ) { /* A context switch is required. Context switching is performed in the PendSV interrupt. Pend the PendSV interrupt. */ portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值