📄 homesec1.c
字号:
// 瘤糯捞 焊靛 七傀绢
// 哪颇老矾 : KEIL C DEMO
// 2003.12.15
// 公茄抛农愁矾瘤
#include <AT89X51.h>
// 屈 急攫
#define byte unsigned char
// 副饭捞 柯 烹脚 内靛
#define RLY0_ON 11
#define RLY1_ON 12
#define RLY2_ON 13
#define RLY3_ON 14
#define RLY4_ON 15
#define RLY5_ON 16
#define RLY6_ON 17
#define RLY7_ON 18
// 副饭捞 坷橇 烹脚 内靛
#define RLY0_OFF 21
#define RLY1_OFF 22
#define RLY2_OFF 23
#define RLY3_OFF 24
#define RLY4_OFF 25
#define RLY5_OFF 26
#define RLY6_OFF 27
#define RLY7_OFF 28
// 季辑 柯 烹脚 内靛
#define SEN0_ON 31
#define SEN1_ON 32
#define SEN2_ON 33
#define SEN3_ON 34
#define SEN4_ON 35
#define SEN5_ON 36
#define SEN6_ON 37
#define SEN7_ON 38
// 季辑 坷橇 烹脚 内靛
#define SEN0_OFF 41
#define SEN1_OFF 42
#define SEN2_OFF 43
#define SEN3_OFF 44
#define SEN4_OFF 45
#define SEN5_OFF 46
#define SEN6_OFF 47
#define SEN7_OFF 48
// 傈眉 蔼 夸没 内靛
#define SEN_RQ 51
// 器飘 巧 概俏
sbit lamp = P3^2;
sfr sensor = 0x80;//P0
sfr relay = 0xA0; //P2
// 烹脚 荐脚 滚欺
#define rsize 20
#define RTIME 1
byte rbuf[rsize];
byte rcount=0,rtime=0,pcount=0;
byte rbuf1, rbuf2;
byte oldBuf=255;
bit isTx;
// ETC
#define LAMPTIME 5000
// 老矫 措扁 窃荐
delay(byte d)
{
byte d2;
while(d--){
d2 = 0xff;
while(d2--);
}
}
// 烹脚 价脚 措扁 窃荐
wait_ti()
{
byte i = 255;
while(!TI && i--);
}
// sensor ON/OFF 内靛 价脚
send_sensor_code(byte b)
{
byte i;
byte oldB,newB;
for(i=0;i<8;i++){
wait_ti();
oldB=oldBuf & (1 << i);
newB=b & (1 << i);
if (oldB != newB) {
if (newB) SBUF=SEN0_OFF + i;
else SBUF = SEN0_ON + i;
}
}
oldBuf=b;
}
// 林 窃荐
main()
{
int lamp_count;
byte sen_buf;
// 扁夯蔼 汲沥
// SP = 0x50;
relay = 0x00;
// 烹脚 棺 烹脚 牢磐反飘 汲沥
EA = 0;
PCON = 0;//
SCON = 0x50;
TMOD = 0x21;
TH1 = 0x0fd;
TL0 = 0x00;
TH0 = 0x00;
TR1 = 1;
ES = 1;
EA = 1;
// 泪矫 措扁
delay(255);
// 皑瘤 涝仿 烹脚栏肺 免仿
sen_buf = sensor;
send_sensor_code(sen_buf);
while(1){
if(!lamp_count--){
lamp = !lamp;// 伐橇 柯 坷橇
lamp_count = LAMPTIME;
}
if((rcount>0)&&(rtime--)) continue;// 烹脚 荐脚 辆丰 眉农 (矫埃瞒)
if((rcount==0)&&(sen_buf!=sensor)){
sen_buf =sensor;
send_sensor_code(sen_buf);
}
if(rcount==0) continue;
if(pcount>=rcount){
rcount = pcount = 0;
continue;
}
rtime = 0;
rbuf2 = rbuf[pcount++];
if (rbuf2==SEN_RQ){ // 季辑 皑瘤 葛滴 夸没 窍搁
sen_buf = sensor;
send_sensor_code(sen_buf); // 季辑 惑怕 焊郴绊
} else
if (rbuf2>=RLY0_ON && rbuf2<=RLY7_ON){ // 副饭捞 柯 夸没捞搁
relay |= (1 << (rbuf2-RLY0_ON));
} else
if (rbuf2>=RLY0_OFF && rbuf2<=RLY7_OFF){ // 副饭捞 坷橇 夸没捞搁
relay &= ~(1 << (rbuf2-RLY0_OFF));
}
}
}
ser_int() interrupt SIO_VECTOR
{
if (RI){ //Recive Buffer is Fill
rbuf1 = SBUF;
RI = 0;
rtime = RTIME;
if(rcount<rsize) rbuf[rcount++]=rbuf1;
else rtime=0;
} else if (TI)
TI = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -