想实现电脑发送数据,单片机处理,返回电脑一个数据。用keil编译的时候,memory model 设置成small,可以通信,但是改成large就不显示数据,是什么原因?
单片机源程序:
- #include "reg52.h"
- #include "string.h"
- #include "stdlib.h"
- #include "stdio.h"
- #define uchar unsigned char
- #define uint unsigned int
-
- unsigned char flag,c;
- uchar receivedata[12];
- double number1,number2,p;
- uint number4,number5,number6,number3;
- uchar number[2][4];
- uint length,count,i,point,j,k;
- uchar senddata[10];
- void UsartInit()
- {
- SCON=0x50;
- TMOD=0X20;
- PCON=0X80;
- TH1=0XF3;
- TL0=0XF3;
- ES=1;
- EA=1;
- TR1=1;
- }
- void Usart() interrupt 4
- {
- if(RI==1)
- {
- receivedata[count]=SBUF;
- if(receivedata[count]=='=')
- {
- flag=1;
- length=count;
- }
- count++;
- RI=0;
- }
- }
- void main()
- {
- UsartInit();
- while(1)
- {
- if(flag==1)
- {
- ES=0;
- while(receivedata[i])
- {
- if(receivedata[i]=='=')
- break;
- if((receivedata[i]>=48 && receivedata[i]<=57) || receivedata[i]=='.')
- {
- if(receivedata[i]=='.')
- point=1;
- number[j][i-k]=receivedata[i];
- i++;
- }
- else
- {
- i++;
- k=i;
- j++;
- }
- }
- if(point==1)
- {
- number1=atof(number[0]);
- number2=atof(number[1]);
- number3=atoi(number[2]);
- if(number3>=20 && number3<38) //number2>=5 充电时长大于等于5小时
- {
- p=number1*0.0365-number2*0.003+0.891;
- }
- if(number3>=38 && number3<=52) //number2>=4 充电时长大于等于4小时
- {
- p=number1*0.032-number2*0.07+1.226;
- }
- sprintf(senddata,"%.3f",p);
- }
- else
- {
- number4=atoi(number[0]);
- number5=atoi(number[1]);
- number6=atoi(number[2]);
- if(number6>=20 && number6<38) //number2>=5 充电时长大于等于5小时
- {
- p=number4*0.0365-number5*0.003+0.891;
- }
- if(number6>=38 && number6<=52) //number2>=4 电时长大于等于4小时
- {
- p=number4*0.032-number5*0.07+1.226;
- }
- sprintf(senddata,"%.3f",p);
- }
- for(c=0;c<10;c++)
- {
- SBUF=senddata[c];
- while(!TI);
- TI=0;
- }
- ES=1;
- flag=0;
- }
- if(p)
- break;
- }
- }
复制代码
|