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

📄 yizhan.c01

📁 基于89c2051开发的ptr8000一对多无线通信程序.
💻 C01
字号:
#include <reg51.h>
#include <absacc.h> 
#include <stdio.h>
unsigned char TLV=0x00;
unsigned char THV=0xe7;
unsigned short SECTICKS=240; //24; //65536/(65536-(THV*256+TLV))*18;
unsigned short HALFSECTICKS=120; //12;
unsigned char sbuff[7];
unsigned char count=0,triggle=0,chno=0;
unsigned char ticks=0,oldP1_Re=0xff,P14_Re=0xff,P15_Re=0xff;
unsigned char direction_Re=0,P1_Re=0xff;
sbit RLed = P1^3;
sbit P14=P1^4;
sbit P15=P1^5;
bit direction=0;
/*void delay()
{
 unsigned short i,j;
 for(i=0;i<30;i++) j=i;
}*/
void t0int() interrupt 1
{
 //unsigned char i;
 TH0=THV; //Bcause TLV=0,no need to init TL0;
 count++;
 P14_Re<<=1,P14_Re |= P14;
 P15_Re<<=1,P15_Re |= P15;
 P1_Re=P1; //Read P1.
 switch (P14_Re & 0x03)
 {
  case 0x03: P1_Re |= 0x10;
  case 0x00: P1_Re &= 0xef;
 }
 switch (P15_Re & 0x03)
 {
  case 0x03: P1_Re |= 0x20;
  case 0x00: P1_Re &= 0xdf;
 }
 if ((oldP1_Re & 0x10)==0x10 && (P1_Re & 0x10)==0x00) //UP triggle.
 {
  direction_Re<<=1;
  if (P1_Re & 0x20) direction_Re|=0x01;
  if ((direction_Re & 0x03) == 0x03) direction=1; //filter modoul.
  if ((direction_Re & 0x03) == 0x00) direction=0;
 }
 if((oldP1_Re ^ P1_Re) & 0x10) ticks++;
 if((oldP1_Re ^ P1_Re) & 0x20) ticks++;
 oldP1_Re=P1_Re;
 if(count == HALFSECTICKS)
 {
  RLed=1;
  triggle=1;
 }
 if(count == SECTICKS)
 {
  count=0; 
  RLed=0;
  sbuff[3]=P1;
  //Notice P1 had been modified.
  sbuff[3]=(sbuff[3] | 0x20);
  if (!direction) sbuff[3]=sbuff[3]-0x20;
  sbuff[4]=ticks;
  ticks=0;
  triggle=1;
 }
}
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; //1200bps .0xfb; // 9600 bps,0xd8;        /* TH1:  reload value for 1200 baud @ 18.432MHz   */
 TR1   = 1;                  /* TR1:  timer 1 run                          */
 TR0   = 1;
 TI    = 1;
 oldP1_Re=P1;
 IE    = 0x82;
 while (1)
 {
  if (triggle)
  {
   triggle=0; 
   for(i=0;i<7;i++) putchar(sbuff[i]);
  }
 }
}

⌨️ 快捷键说明

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