📄 text1.c
字号:
/*------------------------------------------------------------------------------
本程序用来对一个数组求1次拟和系数
------------------------------------------------------------------------------*/
#include <REG52.H> /* special function register declarations */
/* for the intended 8051 derivative */
#include <stdio.h> /* prototype declarations for I/O functions */
#include <stdlib.h>
#ifdef MONITOR51 /* Debugging with Monitor-51 needs */
char code reserve [3] _at_ 0x23; /* space for serial interrupt if */
#endif /* Stop Exection with Serial Intr. */
/* is enabled */
// xdata float XBuffer[40];
// xdata float YBuffer[40];
xdata float Y[40]={
53.1,55.1,57.0,58.9,60.3,
62.5,64.1,65.8,67.6,69.2,
70.5,72.1,73.5,74.7,75.7,
76.4,76.7,76.7,76.8,77.0,
77.5,78.0,78.5,78.9,79.2,
79.4,79.4,79.4,79.3,79.4,
79.5,79.7,79.9,80.0,80.0,
80.0
};
// xdata float X[20];
xdata float XSquareSum=0,XSumSquare=0,XSum=0,YSum=0,XYSum=0,Delta=0;
float a1,a0;
float f1;
/*------------------------------------------------
The main C function. Program execution starts
here after stack initialization.
------------------------------------------------*/
void main (void) {
int n,i;
/*------------------------------------------------
Setup the serial port for 1200 baud at 16MHz.
------------------------------------------------*/
#ifndef MONITOR51
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 221; /* TH1: reload value for 1200 baud @ 16MHz */
TR1 = 1; /* TR1: timer 1 run */
TI = 1; /* TI: set TI to send first char of UART */
#endif
n=40;
for(i=0;i<40;i++)
{
XSum += i;
YSum += Y[i];
XSquareSum += i*i;
XYSum += i*Y[i];
}
Delta = n*XSquareSum - XSum * XSum;
a1 = ( n* XYSum - XSum* YSum)/Delta;
a0 = ( XSquareSum*YSum-XSum*XYSum)/ Delta;
printf("a0= %f , a1= %f \n",a0,a1);
for(i=0;i<n;i++)
{
f1 = Y[i]-(a0+a1*i);
printf("i= %d ,difference=%f\n",i,f1);
}
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -