毕业设计-单片机的主从控制系统

while(*str!='\\0') { Lcd_Write(Lcd_Write_Data,*str); str++; } }

void Print_Char(uchar a) {

Lcd_Write(Lcd_Write_Data,a); }

/**************************************************************** **功能:LCD清屏函数 ** **参数:无 ** ****************************************************************/ void ClrScreen(void) {

GotoXY(0,0);

Print_Str(\ \ GotoXY(0,1);

Print_Str(\ \ }

附录5 主机中断程序

int Count=0; //外中断0计数 P3.2脚 int Count2=0; //外中断1计数 P3.3脚

bit Intval1=0; //中断值 bit Int_pro1=0; //中断号 bit SendTo1=0; //发送位 bit ReceiveFrom1=0; //接收位

bit Int_pro2=0; bit Intval2=0; bit SendTo2=0;

bit ReceiveFrom2=0;

void Interrupt0(void) interrupt 0 using 1 //外中断0处理 {

Count++; if(Count==1) {

36

Intval1=1; Int_pro1=1; SendTo1=0; ReceiveFrom1=1; Intval2=0; Int_pro2=0; } if(Count==2) { Count=0; Intval1=0; Int_pro1=0; Intval2=1; Int_pro2=1; SendTo2=0; ReceiveFrom2=1; } /* if(Count==3) { Count=0; Intval1=0; Int_pro1=0; Intval2=0; Int_pro2=0; } */ }

void Interrupt2(void) interrupt 2 using 3 { Count2++; if(Count2==1) { SendTo1=1; ReceiveFrom1=0; Intval1=1; Int_pro1=1; Intval2=0;

//外中断1处理37

Int_pro2=0; } if(Count2==2) { Count2=0; Intval1=0; Int_pro1=0; SendTo2=1; ReceiveFrom2=0; Intval2=1; Int_pro2=1; } /*if(Count2==3) { Count2=0;

Intval1=0; Int_pro1=0; Intval2=0; Int_pro2=0; } */ }

//*********串口中断函数

void Interrupt4(void) interrupt 4 using 2 { EA=0; if(TI) { TI=0; } if(RI) { RI=0; switch(SBUF) { case Address_Respond1 : Serial1=1; break; //如果接收到从机1发送的地址响应码

case Command_Respond1 : Serial1=2; break; //如果接收到从机命令的响应码

case Data_Command_Respond1 : Serial1=3; break; //如果接收到从机结果送主机

38

的命令响应

case Data_Receive_Respone1 : Serial1=4; break; case Address_Respond2 : Serial2=1; break; case Command_Respond2 : Serial2=2; break; case Data_Command_Respond2 : Serial2=3; break; case Data_Receive_Respone2 : Serial2=4; break; case Address_Respond3 : Serial3=1; break; case Command_Respond3 : Serial3=2; break; case Data_Command_Respond3 : Serial3=3; break; case Data_Receive_Respone3 : Serial3=4; break; default : break; } } EA=1; }

附录6 从机温度程序

#define uchar unsigned char #define uint unsigned int

char volatile xiaoshu_temp[5],zhen_temp[4]; bit dot_dis=1; bit flag;

char TTemp=0; char TTemp1=0;

char volatile DS18B20_Data[4];

void process(unsigned char,unsigned char);

void Serial_Set(void) //串口设置 { SCON=0x50; TMOD=TMOD&0x0f; TMOD=TMOD|0x20; TH1 = 0xfD; // 11.0952MHZ 波特率9600 TL1 = 0xfD; TR1=1;

39

联系客服:779662525#qq.com(#替换为@)