单片机 串口通信 长字符串

#include <reg52.h>
/*数据定义区*/
#define uchar	unsigned char
#define uint	unsigned int
uchar		flag, a, i;
uchar code	table[]		= "I get ";
unsigned char	receive[20]	= { 0 }; /* 接收缓存 长度20 */

/*程序定义区*/
void init()
{
	TMOD	= 0x20;
	TH1	= 0xfd;
	TL1	= 0xfd;
	TR1	= 1;
	SCON	= 0x50;
	EA	= 1;
	ES	= 1;
}


void main( void )
{
	init();
	while ( 1 )
	{
		if ( flag == 1 )
		{
			ES = 0;
			for ( i = 0; i < 6; i++ ) /* 注意:若把i<6改成i<7,现象出错; */
			{
				SBUF = table[i];
				while ( !TI )
					;
				TI = 0;
			}
			i = 0;
			do /* 注意:若把i<6改成i<7,现象出错; */
			{
				SBUF = receive[i];
				while ( !TI )
					;
				TI = 0;
				i++;
			}
			while ( receive[i] != 0 );
			ES	= 1;
			flag	= 0;
			for ( i = 0; i < 19; i++ )//清空接受缓存
			{
				receive[i] = 0x00;
			}
		}
	}
}


void ser() interrupt 4
{
	static unsigned char count;
	RI = 0;
	if ( SBUF == 0x2e )//判断数据头
	{
		count = 1;
	}else if ( SBUF == 0x2d )//判断数据尾
	{
		count	= 0;
		flag	= 1;
		ES	= 0;
	}else  {
		receive[count - 1] = SBUF;//接收数据到数组receive
		count++;
	}
}


Proteus串口仿真7.0

Matlab 线性规划 linprog

x = linprog( c , A , b , Aeq , beq , lb , ub , x0 )是求解线性规划问题的命令。
c是目标函数的系数向量,A是不等式约束AX<=b的系数矩阵,b是不等式约束AX<=b的常数项
Aeq是等式约束AeqX=beq的系数矩阵,beq是等式约束AeqX=beq的常数项,lb是X的下限,ub是X的上限,X是向量[x1,x2,…xn]即决策变量。
指定迭代的初始值x0;
如果模型中不包含不等式约束条件,可用[]代替A和b表示缺省;如果没有等式约束条件,可用[]代替Aeq和beq表示缺省;如果某个xi无下界或上界,可以设定lb(i)=-inf或ub(i)=inf;
用[x , Fval]代替上述各命令行中左边的x,则可得到在最优解x处的函数值Fval;


继续阅读

matlab 5月17日

定积分:
syms x;
f=((x+2)^0.5-3^0.5)/(x-1);
limit(f,x,1,’left’)
syms x;
f=((2*x-1)/(2*x+1))^(x+1);
limit(f,x,0,’right’)

syms x;
f=exp(1/x);
limit(f,x,0,’left’)

求导:
syms x;
f=sin(x)+x^2;
diff(f);
pretty(ans);
syms x;
f=x*exp(x^2);
diff(f);
pretty(ans);
y=ln x / x^2 求导
syms x;
f=log(x)/(x^2);
diff(f);
pretty(ans);

syms x;
f=sin(2*x)*cos(3*x);
diff(f);
pretty(ans);
x=pi;
2*cos(2*x)*cos(3*x)-3*sin(2*x)*sin(3*x)

不定积分:
int(f);表示f的 不定积分
int(f,a,b);表示f在ab区间中的定积分

syms x;
f=3*x*sin(2*x);
int(f);
pretty(ans);

syms x;
f=exp(x)*sin(x)^2;
int(f);
pretty(ans);

syms x;
f=(1+sin(x)/1+cos(x))*exp(x);
int(f);
pretty(ans);

syms x;
f=(3*x-5)*acos(x);
int(f,0,1);
pretty(ans);

syms x;
f=(1-sin(2*x))^0.5;
int(f,0,pi/2);
pretty(ans);

syms x;
f=(1/((2*pi)^0.5));
fs=exp((-x^2)/2)
int(fs,-inf,+inf);
pretty(ans*f);
ans*f