- #include <REG52.H>
- #include <stdio.h>
- sbit RS485 = P1^4;
- bit SendFlag;
- unsigned int ReData,SenData;
- void delay(unsigned char i)
- {
- unsigned char j;
- for(i; i > 0; i--)
- for(j = 200; j > 0; j--);
- }
- void main (void)
- {
- SCON = 0x50;
- TMOD|= 0x20;
- PCON|= 0x80;
- TH1 = 0xF3;
- TL1 = 0xF3;
- TR1 = 1;
- ES = 1;
- EA = 1;
-
- // IE = 0x0;
- while(1)
- {
-
- if (SendFlag==1)
- {
- RS485=1;
- SBUF=SenData;
- delay(50);
- }
- else
- {
- RS485=0;
- }
- }
- }
- void ser_int (void) interrupt 4 using 1
- {
- if(TI == 1)
- {
- TI = 0;
- SendFlag = 0;
- }
- if(RI == 1)
- {
- RI = 0;
- ReData = SBUF;
- SenData=ReData;
- SendFlag = 1;
- }
- }
复制代码
|