int01.c

来自「MCS51的实现无线接收发送(315M或433M)源程序代码。」· C语言 代码 · 共 153 行

C
153
字号
/**********************************************************
*                  Int01.c                                *
**********************************************************/
#define INT01_GLOBALS 
//=========================================================
#include "Sm5964.h"
#include "Struct.h"
#include "Tools.h"
#include "Uart.h"
#include "Error.h"
#include "Os.h"
#include "TskMan.h"
#include "TmrTsk.h"
#include "Int01.h"
#include "Tmr2.h"
#include "..\Config.h"
#include "..\RfServer.h"
//=========================================================
#define DEBUG_INT01 0
//=========================================================
static INT8U Int0RecvByte;
//=========================================================
void RfSendByte(INT8U Data)
{
   INT8U i;
   
   EA=0;
   EX0=0;

   RFSEND=1;
   Delay2X(40);
   RFSEND=0;
   Delay2X(40);
   RFSEND=1;
   Delay2X(36);
   
   for(i=0;i<8;i++)
     {
      if(Data&0x01) RFSEND=1;
      else RFSEND=0;
      Delay2X(33);
      Data=Data>>1;
     }
   RFSEND=0;
   Delay10X(40);
   
   //TF0=0;
   IE0=0;
   EX0=1;
   EA=1;
}
//=========================================================
void RfSend(INT8U *Data,INT8U Len)
{
   for(;Len>0;Len--) RfSendByte(*Data++);
}
//=========================================================
static void InitInt0(void)
{
   #if DEBUG_INT01
   //MDebugStrLF((INT8UC *)"InitInt0()");
   #endif
   
   IT0=1;
   PX0=1;
   EX0=1;
}
//=========================================================
static void Int0RdTmrProc(void)
{
   #if DEBUG_INT01
   //MDebugStrLF((INT8UC *)"Int0RdTmrProc");
   #endif
	  if(Int0RdIndex!=Int0WrIndex) SendTskMsg(INT01TSKID,MSG_INT0RECV,0);
}
//=========================================================
void InitInt01Tsk(void)
{
   #if DEBUG_INT01
   MDebugStrLF((INT8UC *)"InitInt01Tsk()");
   #endif
   InitInt0();
   
   RFSEND=0;

   Int0RdIndex=0;
   Int0WrIndex=0;
   InitExMemBuf(Int0RecvBuf,0X00,sizeof(Int0RecvBuf));
   
   InstallTmr(INT01TMRID,Int0RdTmrProc);
}
//=========================================================
void HdlInt0Recv(void)
{
   #if DEBUG_INT01
   //MDebugStrLF((INT8UC *)"HdlInt0Recv");
   //MDebugExMemHex(Int0RecvBuf,Int0WrIndex);
   #endif
   HdlRfData();
}
//=========================================================
void Int01TskEntry(void)
{
   #if DEBUG_INT01
   //MDebugStrLF((INT8UC *)"Int01TskEntry()");
   #endif
	  if(TskMsg.MsgId==MSG_INT0RECV) HdlInt0Recv();
}
//=========================================================
//=========================================================
void ExInt0 (void) interrupt INT0_VECTOR using 3{
   EA=0;
   PSW=0x18;
   
   #pragma asm  
   MOV       R1,       #55
Int0_Interrupt_L1:
   DJNZ      R1,       Int0_Interrupt_L1
   
   JNB       RFRECV,   Int0_Interrupt_L6

   MOV       R0,       #0X08               ;2        
Int0_Interrupt_L3:
   MOV       R1,       #43                 ;2         
Int0_Interrupt_L4:
   DJNZ      R1,       Int0_Interrupt_L4   ;2

   MOV       C,        RFRECV
   RRC       A
   DJNZ      R0,       Int0_Interrupt_L3
   
   MOV       Int0RecvByte,       A
   
   MOV       R1,       #25
Int0_Interrupt_L5:
   DJNZ      R1,       Int0_Interrupt_L5
   #pragma endasm
   
   Int0RecvBuf[Int0WrIndex++]=Int0RecvByte;
   if(Int0WrIndex>=INT0RECVBUFSIZE) Int0WrIndex=0;
   if(OsInitEndFlag==true) DelayTime[INT01TMRID]=5;

   #pragma asm  
Int0_Interrupt_L6:
   #pragma endasm
   
   //TF0=0;
   IE0=0;
   EA=1;
}
//=========================================================

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?