|
xuexi.c
//#include "reg51.h"
//#include "stdio.h"
//#include "math.h"
//#include "intrins.h"
//#include "absacc.h"
/*===========================================*/
/*A/D*/
#define ADCOM XBYTE[0x0800]
#define ADHI XBYTE[0x0802]
#define ADLO XBYTE[0x0803]
#define uint unsigned int
sbit adbusy = P1^7;
unsigned int xdata AD_report[2];
#define AD_switch XBYTE[0x1800]
#define K_OUT XBYTE[0x2000]
/*===================================*/
/*8250 regist*/
#define INS8250_DATA XBYTE[0x5800]
#define INS8250_BAUDL XBYTE[0x5800]
#define INS8250_IER XBYTE[0x5801]
#define INS8250_BAUDH XBYTE[0x5801]
#define INS8250_IIR XBYTE[0x5802]
#define INS8250_LCR XBYTE[0x5803]
#define INS8250_MCR XBYTE[0x5804]
#define INS8250_LSR XBYTE[0x5805]
#define INS8250_MSR XBYTE[0x5806]
/*===================================*/
/*============================================*/
#define DS128870 XBYTE[0x1000]
#define DS128871 XBYTE[0x1001]
#define DS128872 XBYTE[0x1002]
#define DS128873 XBYTE[0x1003]
#define DS128874 XBYTE[0x1004]
#define DS128875 XBYTE[0x1005]
#define DS128876 XBYTE[0x1006]
#define DS128877 XBYTE[0x1007]
#define DS128878 XBYTE[0x1008]
#define DS128879 XBYTE[0x1009]
#define DS12887a XBYTE[0x100a]
#define DS12887b XBYTE[0x100b]
#define DS12887c XBYTE[0x100c]
#define DS12887d XBYTE[0x100d]
#define DS12887e XBYTE[0x100e]
#define DS12887f XBYTE[0x100f]
unsigned char xdata sample_time[6];
unsigned char xdata current_time[6];
unsigned char xdata send_report[19];
unsigned char xdata sample_data[24576];
unsigned char xdata time_table[144];
unsigned char xdata verify_time[6];
/*============================================*/
#define telephone4 XBYTE[0x2800]/*4800*/
#define telephone3 XBYTE[0x3000]/*4000*/
#define telephone2 XBYTE[0x3800]/*3800*/
#define telephone1 XBYTE[0x4000]/*3000*/
#define station_name XBYTE[0x4800]/*2800*/
#define KR_input XBYTE[0x5000]
unsigned char xdata telephone[4];
#define K_out XBYTE[0x2000]
/*=====================================*/
#define CS_5731 XBYTE[0x1800]
/*=====================================*/
/* write ds1820 command extern function declare */
WDS1820_0(unsigned char x);
WDS1820_1(unsigned char x,unsigned char y,unsigned char z);
/* read ds1820 command extern function declare */
RDS1820_0();
RDS1820_1();
RDS1820_2();
RDS1820_3();
RDS1820_4();
RDS1820_5();
/* reset ds1820 command extern function declare */
第 1 页
xuexi.c
/*=============*/
RTDS1820_0();
RTDS1820_1();
RTDS1820_2();
RTDS1820_3();
RTDS1820_4();
RTDS1820_5();
/*=============*/
/* delay 15us extern function declare */
Delay15(unsigned char x);
WDS1820_CODE();
RDS1820_code();
DS12887_ini();
INS8250_ini();
AD1674(void);
void serial(void);
send_byte(unsigned char ucI);
void read12887(unsigned char *p);
rst_watchdog();
timer_ini();
com_ini();
ini();
smec(unsigned int x);
sbit P10=P1^0;
sbit P11=P1^1;
sbit P14=P1^4;
sbit P15=P1^5;
sbit P16=P1^6;
sbit rst=P3^2;
sbit RUN=P3^4;
sbit P35=P3^5;
/*sbit temp0=temp^0;
sbit temp1=temp^1;
sbit temp2=temp^2;
sbit temp3=temp^3;
sbit temp4=temp^4;
sbit temp5=temp^5;
sbit temp6=temp^6;
sbit temp7=temp^7;
sbit temp8=temp^8;
sbit temp9=temp^9;
sbit temp10=temp^10;*/
unsigned char *pt,*t,*sam_pt;
unsigned int R_code;
/*unsigned char tempf;*/
unsigned char family_code[8];
unsigned char xdata time[6];
/*================================================================================*/
/*DS1820的编码号,第一位为28H*/
unsigned char code DS18201_code[9]={0x28,0x48,0xF2,0x0C,0x00,0x00,0x00,0xFD,0xFF};
unsigned char code DS18202_code[9]={0x28,0x4D,0xE2,0x0D,0x00,0x00,0x00,0xE5,0xFF};
unsigned char code DS18203_code[9]={0x28,0x83,0xC5,0x0C,0x00,0x00,0x00,0x4F,0xFF};
unsigned char code DS18204_code[9]={0x28,0x6E,0xDB,0x0D,0x00,0x00,0x00,0x7D,0xFF};
unsigned char code DS18205_code[9]={0x28,0xDC,0xCE,0x0C,0x00,0x00,0x00,0x35,0xFF};
unsigned char code DS18206_code[9]={0x28,0xFB,0x0F,0x0D,0x00,0x00,0x00,0x66,0xFF};
/*================================================================================*/
unsigned int xdata tempf_data[6];
unsigned char xdata tempf[6];
unsigned char xdata telephone_code[12];
/*================================================================================*/
unsigned char XOR_BYTE,right_flog,call_ring,verify_flog,sam_first;
unsigned int count;
void main(void)
{
unsigned int j,i;
unsigned char a,m;
rst_watchdog();
adbusy=1;
sample_flog = 1;
ini();
/*===============================================*/
while(1)
{
read12887(&current_time);
for(i=0;i<6;i++)
第 2 页
xuexi.c
{
if(current_time<i>=sample_time<i>)
{
m++;
if(m == 6)
{
call_ring = 1;
m=0;
}
}
else
{
i = 6;
}
}
if(verify_flog == 1)
{
rst_watchdog();
m = DS12887d;
DS12887a=0x20; DS12887b=0x82;
DS128870=0x00; DS128871=0xff;
DS128872=0x00; DS128873=0xff;
DS128874=0x00; DS128875=0xff;
DS128876=0x03; DS128877=0x1c;
DS128878=0x07; DS128879=0x01;
DS12887b=0x02; DS12887a=0x20;
m = DS12887c;
m = 0;
verify_flog = 0;
}
if(call_ring==1)
{
sam_first = 0;
telephone_code[0] = 0x41;
telephone_code[1] = 0x54;
telephone_code[2] = 0x44;
telephone_code[3] = 0x54;
telephone_code[4] = telephone4&0x0F+0x30;
telephone_code[5] = telephone3&0xF0+0x30;
telephone_code[6] = telephone3&0x0F+0x30;
telephone_code[7] = telephone2&0xF0+0x30;
telephone_code[8] = telephone2&0x0F+0x30;
telephone_code[9] = telephone1&0xF0+0x30;
telephone_code[10]= telephone1&0x0F+0x30;
telephone_code[11]= 0x0D;
A8250_MCR=A8250_MCR|0x03;
pt=&telephone_code;
for(i=0;i<12;i++)
{
send_byte(*pt++);
}
i=0;
}
}
}
/*=======================================*/
while(1)
{
AD_switch=0x20;
adbusy=1;
rst_watchdog();
read12887(&time);
telephone[0]=telephone4;
telephone[1]=telephone3;
telephone[2]=telephone2;
telephone[3]=telephone1;
AD_report[1]=AD1674();
K_OUT=0x00;
/*send_byte(0x41);
send_byte(0x54);
send_byte(0x5A);*/
AD_switch=AD_switch|0x02;
while(P10!=0)
{
第 3 页
xuexi.c
rst_watchdog();
}
send_byte(0x41);
send_byte(0x54);
send_byte(0x5A);
AD_switch=AD_switch|0x01;
while(P11==0)
{
rst_watchdog();
}
t=&phone;
while(*t!=0xff)
{
send_byte(*t++);
}
i=station_name;
i=0;
}
}
/*=====================================================*/
ini()
{
timer_ini();
DS12887_ini();
INS8250_ini();
}
timer_ini()
{
TR0 = 0;
ET0 = 0;*/
/*TMOD=0X01;*/
/*TH0 = 0x3C; */
/*TL0 = 0xB0;
TR0 = 1;
ET0 = 1;
EA=0;*/
}
com_ini()
{
PCON &= 0x7F;
SCON = 0xd0;
TMOD = 0x21;
TH1 = 0xFD;
TR1 = 1;
ET1 = 0;
TI = 0;
RI = 0;
ES = 1;
EA = 1;
EX1 = 1;
IT1 = 1;
}
DS12887_ini()
{
unsigned char i;
rst_watchdog();
i=DS12887d;
DS12887a=0x20; DS12887b=0x82;
DS128870=0x00; DS128871=0xff;
DS128872=0x00; DS128873=0xff;
DS128874=0x00; DS128875=0xff;
DS128876=0x03; DS128877=0x1c;
DS128878=0x07; DS128879=0x01;
DS12887b=0x02; DS12887a=0x20;
i=DS12887c;
}
INS8250_ini()
{
A8250_LCR=0x80;
A8250_BAUDL=0x60;
第 4 页
xuexi.c
A8250_BAUDH=0x00;
A8250_LCR=0x03;
A8250_IER=0x0F;
A8250_MCR=0x0F;
A8250_IER=0x01;
IT1=1;
EX1=1;
EA=1;
}
/*=======================================================*/
RTDS1820_0()
{
unsigned char x,i,j,exist;
rst_watchdog();
P15=0;
Delay15(468);
P15=1;
Delay15(500);
for(i=0;i<8;i++)
{
if(P14==1)
{
i=8;
exist=1;
}
}
if(exist==0)
{
return(0);
}
for(i=0;i<80;i++)
{
if(P14==0)
{
return(1);
}
}
}
/*=====================================================*/
RTDS1820_1()
{
unsigned char a,i,j,exist;
rst_watchdog();
CS_5731=CS_5731&0xFB;
Delay15(468);
CS_5731=CS_5731|0x04;
Delay15(500);
for(i=0;i<8;i++)
{
if(P16==1)
{
i=8;
exist=1;
}
}
if(exist==0)
{
return(0);
}
for(i=0;i<80;i++)
{
if(P16==0)
{
return(1);
}
}
}
/*=====================================================*/
RTDS1820_2()
{
unsigned char a,i,j,exist;
rst_watchdog();
CS_5731=CS_5731&0xF7;
Delay15(468);
第 5 页
xuexi.c
CS_5731=CS_5731|0x08;
Delay15(500);
for(i=0;i<8;i++)
{
if((KR_input&0x10)==0x10)
{
i=8;
exist=1;
}
}
if(exist==0)
{
return(0);
}
for(i=0;i<40;i++)
{
if((KR_input&0x10)==0)
{
return(1);
}
}
i=0;
}
/*=====================================================*/
RTDS1820_3()
{
unsigned char a,i,j,exist;
rst_watchdog();
CS_5731=CS_5731&0xEF;
Delay15(468);
CS_5731=CS_5731|0x10;
Delay15(500);
for(i=0;i<8;i++)
{
if((KR_input&0x20)==0x20)
{
i=8;
exist=1;
}
}
if(exist==0)
{
return(0);
}
for(i=0;i<80;i++)
{
if((KR_input&0x20)==0)
{
return(1);
}
}
}
/*=====================================================*/
RTDS1820_4()
{
unsigned char a,i,j,exist;
rst_watchdog();
CS_5731=CS_5731&0xDF;
Delay15(468);
CS_5731=CS_5731|0x20;
Delay15(500);
for(i=0;i<8;i++)
{
if((KR_input&0x40)==0x40)
{
i=8;
exist=1;
}
}
if(exist==0)
{
return(0);
}
for(i=0;i<80;i++)
{
第 6 页
xuexi.c
if((KR_input&0x40)==0)
{
return(1);
}
}
}
/*=====================================================*/
|
|