sanzhan.c

来自「基于89c2051开发的ptr8000一对多无线通信程序.」· C语言 代码 · 共 65 行

C
65
字号
#include <reg51.h>
#include <absacc.h> 
#include <stdio.h>
unsigned char TLV=0;
unsigned char THV=0;
unsigned short SECTICKS=18; //48; //24; //65536/(65536-(THV*256+TLV))*18;
unsigned short HALFSECTICKS=9; //24; //12;
unsigned char sbuff[7];
unsigned char count=0,triggle=0,chno=0;
unsigned char ticks=0,oldP1Stat;
sbit RLed = P1^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=1;
  triggle=1;
 }
 if(count == SECTICKS)
 {
  count=0; 
  triggle=1;
  RLed=0;
  sbuff[3]=P1;
  sbuff[4]=ticks;
  ticks=0;
  triggle=1;
 }
}
void main (void)
{
 unsigned char i;
 sbuff[0]=0xD7;
 sbuff[1]=6;
 sbuff[2]='S';
 sbuff[5]=0x0d;
 sbuff[6]='E';
 SCON  = 0x50;		        /* SCON: mode 1, 8-bit UART, enable rcvr      */
 TMOD |= 0x21;               /* TMOD: timer 1, mode 2, 8-bit reload        */
 TH1   = 0xfd; //0xfb; // 9600 bps,0xd8;        /* TH1:  reload value for 1200 baud @ 18.432MHz   */
 TR1   = 1;                  /* TR1:  timer 1 run                          */
 TR0   = 1;
 TI    = 1;
 oldP1Stat=P1;
 IE    = 0x82;
 while (1)
 {
  if (triggle)
  {
   triggle=0; 
   for(i=0;i<7;i++) putchar(sbuff[i]);
  }
 }
}

⌨️ 快捷键说明

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