⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 light.c00

📁 基于89c2051开发的ptr8000一对多无线通信程序.
💻 C00
字号:
#include <reg51.h>
#include <stdio.h>
bit startframe=0,com2rb=1;
unsigned char TLV=0xc0;      //0xc0; //for 18432000,4 times baudrate,
unsigned char THV=0xfe;      //0xfe; if 8times baudrate it's 0x60 and 0xff respectively.
unsigned char com2sbufp=0,com2buffs[2],com2buffr[20],com2buffrp=0;
unsigned short SECTICKS=4800; //65536/(65536-(THV*256+TLV))*18;
unsigned short HALFSECTICKS=2400;
unsigned char rbuff[20],sbuff[11];
unsigned char rbuffp=0;
unsigned char triggle=0,chno=0,ensend=0,rest;
unsigned char ticks1=0,ticks2=0,ticksl2=0,ticksh2=0,ticks3;
unsigned char temptl0,tempth0;
unsigned short filterB=0xffff,count=0,com2sbuf;
sbit P32 = P3^2;
sbit COM2R=P3^0;
sbit COM2S=P3^1;
void delay()
{
 unsigned short i,j;
 for(i=0;i<30;i++) j=i;
}
void e0int() interrupt 0
{
 P1=P1 ^ 0x80; // Feed watchdog.
 ticks3++;
}
void e1int() interrupt 2
{
 ticks1++;
}
void t0int() interrupt 1
{
 // unsigned char i;
 temptl0=TL0;
 tempth0=TH0;
 TH0=THV+tempth0;
 TL0=TLV+temptl0;
 filterB<<=1;
 filterB&=0xfffe;
 filterB|=COM2R;
 switch (filterB&0x7)
 {
  case 0x7: 
           com2rb=1;
		   break;
  case 0x0:
            com2rb=0;
            if(!startframe)
		    {
			 startframe=1;
			 com2sbufp=0;
			 rest=count&0x3;
			}
			break;
  default:
            break;
 }
 if(startframe && ((count&0x3) == rest))
 {
  com2sbuf>>=1;
  com2sbuf&=0xfeff;
  if(com2rb) com2sbuf|=0x0100;
  com2sbufp++;
  if(com2sbufp==10)
  {
   startframe=0;
   if(com2sbuf&0x100)
   {
    com2buffr[com2buffrp]=com2sbuf;
    TI=0;
    SBUF=com2sbuf;
    if(++com2buffrp==20) com2buffrp=0;
   }
  }
 }
 count++;
 if(count == SECTICKS)
 {
  count=0;
  triggle=1;
 }
}
void comint() interrupt 4
{
 if(RI)
 {
  RI=0;
  rbuff[rbuffp]=SBUF;
  if((rbuff[rbuffp] == 'E') && (rbuff[(rbuffp+11)%20] == 'S') && (rbuff[(rbuffp+12)%20] == '0'))
  {
   switch (rbuff[(rbuffp+13)%20])
   {
    case 'A': ensend=1;
	break;
    case 'D':
	break;
	default:break;
   }
  }
  rbuffp++;
  if(rbuffp == 20) rbuffp=0;
 }
}
void main (void)
{
 unsigned char i;
 sbuff[0]=0xff;	
 sbuff[1]='S';
 sbuff[2]='0';
 sbuff[9]=0;
 sbuff[10]='E';
 SCON  = 0x50;		        /* SCON: mode 1, 8-bit UART, enable rcvr      */
 TMOD |= 0x21;               /* TMOD: timer 1, mode 2, 8-bit reload        */
 TH1   = 0xd8;                /* TH1:  reload value for 1200 baud @ 184320000MHz   */
 TR1   = 1;                  /* TR1:  timer 1 run                          */
 IT1   = 1;
 IT0   = 1;
 TI    = 1;                  /* TI:   set TI to send first char of UART    */
 TR0   = 1;
 IE    = 0x87;
 while (1)
 {
  if (triggle==1)
  {
   P32=0;
   //for(i=0;i<11;i++) putchar(sbuff[i]);
   //putchar(temptl0);
   triggle=0;
   P32=1;
  }
  delay();
 }
}

⌨️ 快捷键说明

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