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

📄 xsj-client.c00

📁 基于89c2051开发的ptr8000一对多无线通信程序.
💻 C00
字号:
#include <reg51.h>
#include <absacc.h> 
#include <stdio.h>
#define SBUFFLEN 7
#define RBUFFLEN 15
unsigned char TLV=0;
unsigned char THV=0;
unsigned short SECTICKS=24; //65536/(65536-(THV*256+TLV))*18;
unsigned short HALFSECTICKS=12;
unsigned char sbuff[SBUFFLEN],rbuff[RBUFFLEN],sbuffp=0,rbuffp=0;
unsigned char count=0,triggle=0,chno=0;
unsigned char ticks=0,oldP1Stat;
sbit GLed = P1^2;
sbit RLed = P1^3;
sbit RT   = P3^2;
void delay()
{
 unsigned short i,j;
 for(i=0;i<30;i++) j=i;
}
void t0int() interrupt 1
{
 unsigned char i;
 count++;
 if((oldP1Stat^P1) & 0x10) ticks++;
 oldP1Stat=P1;
 if(count == HALFSECTICKS)
 {
  //RLed=0;
  //triggle=1;
  //RT=1;//Change to Send.
 }
 if(count == SECTICKS)
 {
  count=0; 
  sbuff[3]=P1;
  sbuff[4]=ticks;
  ticks=0;
  //triggle=1;
  //RLed=0;
  //RT=1;//Change to Send.
 }
}

void Serialint() interrupt 4
{
 if(RI)
 {
  RI=0;
  rbuff[rbuffp]=SBUF;
  if ((rbuff[rbuffp]=='S')||(rbuff[rbuffp]=='E')) 
  {
   GLed=~GLed;
   RLed=0; //RLed is on.
   RT=1; //Change to Send.
   triggle=1;
  }
  if (++rbuffp==RBUFFLEN) rbuffp=0;
 }
}

void main (void)
{
 unsigned char i;
 sbuff[0]=0xD7;
 sbuff[1]=6;
 sbuff[2]='S';
 sbuff[5]=0;
 sbuff[6]='E';
 SCON  = 0x50;		        /* SCON: mode 1, 8-bit UART, enable rcvr      */
 TMOD |= 0x21;              /* TMOD: timer 1, mode 2, 8-bit reload        */
 TH1   = 0xd8; //1200.0xfb;              // 9600 bps @ 18.432MHz,as for 11.0592 this value should be 0xfd.  */
 TR1   = 1;                 /* TR1:  timer 1 run                          */
 TR0   = 1;
 TI    = 1;
 oldP1Stat=P1;
 IE    = 0x92;              //Enable serial and T0 interrupt.
 while (1)
 {
  if (triggle)
  {
   triggle=0; 
   for(i=0;i<SBUFFLEN;i++) putchar(sbuff[i]);
   RLed=1;
   RT=0; //Change to Recieve.
  }
 }
}

⌨️ 快捷键说明

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