ourdev

时间:2024-07-21 09:15:32编辑:分享君

有什么学习单片机的论坛或者网站推荐?

matlab中文论坛;csdn;东哥单片机学习网;ourdev等等。简介:单片微型计算机简称单片机,是典型的嵌入式微控制器(Microcontroller Unit), 常用英文字母的缩写MCU表示单片机。单片机又称单片微控制器,它不是完成某一个逻辑功能的芯片,而是把一个计算机系统集成到一个芯片上。单片机由运算器,控制器,存储器,输入输出设备构成,相当于一个微型的计算机(最小系统),和计算机相比,单片机缺少了外围设备等。概括的讲:一块芯片就成了一台计算机。它的体积小、质量轻、价格便宜、为学习、应用和开发提供了便利条件。同时,学习使用单片机是了解计算机原理与结构的最佳选择。它最早是被用在工业控制领域。由于单片机在工业控制领域的广泛应用,单片机由仅有CPU的专用处理器芯片发展而来。最早的设计理念是通过将大量外围设备和CPU集成在一个芯片中,使计算机系统更小,更容易集成进复杂的而对体积要求严格的控制设备当中。

定义一个有10个元素的一维整型数组,从键盘输入给数组的每个元素赋值,并把每个元素进行输出。

#includeprintf("请输入10个整数:\n");for(i=0;i<n;i++)scanf("%d",&a[i]);printf("\n输入的10个数是:\n");printf("输出你输入的元素:\n");for(int i=0;i<10;i++){printf("arr[%d]=%d\n",i,arr[i]);}printf("数组总和为:%d\n",sum);}与结构或类中的字段数组中的所有元素都具有相同类型(这一点和结构或类中的字段不同,它们可以是不同类型)。数组中的元素存储在一个连续性的内存块中,并通过索引来访问(这一点也和结构和类中的字段不同,它们通过名称来访问)。数组元素并非只能是基元数据类型,还可以是结构、枚举或类。以上内容参考:百度百科-数组

枸椽酸阿莫昔芬片可以让胸变小?

1.仅凭一个超声说明不了问题。你好歹给个病史吧?性别,年龄,发病时间。再有查体也很重要啊。几方面结合才好给出倾向性诊断。2.他莫昔芬是乳腺癌内分泌治疗用的,对于一些癌前病变,比如不典型增生有预防癌变的作用。这个医院可能是因为这个才给你开的吧。如果是单纯的乳腺增生症,当然不用吃了。3.他莫昔芬绝经前后妇女都可以用,但绝经前妇女应定期复查妇科超声,了解有无子宫内膜改变。


怎样用PID算法对恒温箱的温度进行控制,求相关的51单片机汇编程序

本设计要求:本温度控制系统为以单片机为核心,实现了对温度实时监测和控制,实现了控制的智能化。设计恒温箱温度控制系统,配有温度传感器,采用DS18B20数字温度传感器,无需数模拟∕数字转换,可直接与单片机进行数字传输,采用了PID控制技术,可以使温度保持在要求的一个恒定范围内,配有键盘,用于输入设定温度;配有数码管LED用来显示温度。
技术参数和设计任务:
1、利用单片机AT89C2051实现对温度的控制,实现保持恒温箱在最高温度为110℃。
2、可预置恒温箱温度,烘干过程恒温控制,温度控制误差小于±2℃。
3、预置时显示设定温度,恒温时显示实时温度,采用PID控制算法显示精确到0.1℃。
4、温度超出预置温度±5℃时发出声音报警。
5、对升、降温过程没有线性要求。
6、温度检测部分采用DS18B20数字温度传感器,无需数模拟∕数字转换,可直接与单片机进行数字传输
7、人机对话部分由键盘、显示和报警三部分组成,实现对温度的显示、报警。

需要的话联系用户名扣扣


如何用PID算法编程,使单片机通过控制继电器来实现恒温功能。

/***********************************************************************
PID温度控制程序
程序说明:
系统上电后显示 “--温度”
表示需要先设定温度才开始进行温度检测
温度设定完毕后程序才开始进行PID温控
***********************************************************************/
#include
#include
#include"DS18B20.H"
#include"PID.H"
#define uchar unsigned char
#define uint unsigned int
unsigned char code tab[]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xBF
}
;
/*个位0~9的数码管段码*/
unsigned char code sao[]=
{
0x7f,0xbf,0xdf,0xef
}
;
//扫描码
uchar set=30,keyflag=1 ; //set初始化为30° keyflag为进入温度设定的标志位
//4个按键使用说明
sbit key_out=P1^0 ; //用于温度设定后的退出
sbit key_up=P1^1 ; //设定温度加
sbit key_down=P1^2 ; //设定温度减
sbit key_in=P1^3 ; //在程序的运行中如需要重新设定温度 按下此键才能进入设置模式并且此时是停在温度控制的,按下key_out键后才表示设定完毕
void Show_key();
/***********************************************************/
void delays(unsigned char k)
{
unsigned char i,j ;
for(i=0;i<k;i++)
for(j=0;j<50;j++);
}
/*********************************************************
//数码管显示函数
P0口 作为数据口
P2口的低四位作为扫描口
变量 x表示扫描
d表示是否要加小数点 为1是 为0不加
y表示传递的数值
*********************************************************/
LCD_disp_char(uchar x,bit d,uchar y)
{
P2=0XFF ;
P0=0xFF ;
if(d==0)
P0=tab[y];
else
P0=tab[y]&0x7f ; //与上0x7f表示是否要加小数点
P2=sao[x]; //打开扫描端号

}
/*********************************************************
按键扫描
*********************************************************/
void keyscan(void)
{
if(key_in==0) //按键进入函数
{
delays(10); //延时消抖 (以下同)
if(key_in==0)
{
while(key_in==0)
{
Show_key(); //如果一直按着键不放 就一直显示在当前状态 (以下同)
}
keyflag=1 ; //按键标志位
}
}
/***********************/
if(key_out==0) //按键退出
{
delays(10);
if(key_out==0)
{
while(key_out==0)
{
Show_key();
}
keyflag=0 ;
set_temper=set ;
}
}
/*************************/
if(key_up==0) //设定温度的加
{
delays(10);
if(key_up==0)
{
while(key_up==0)
{
Show_key();
}
if(keyflag==1)
{
set++;
if(set>90) //如果大于90°就不在加
set=90 ;
}
}
}
/*************************/
if(key_down==0) //温度设定的减
{
delays(10);
if(key_down==0)
{
while(key_down==0)
{
Show_key();
}
if(keyflag==1)
{
set--;
if(set<30) //温度减到30°时不在往下减
set=30 ;
}
}
}
}
/*********************************************************************
按键按下时的显示函数
***********************************************************************/
void Show_key()
{
output=1 ;
LCD_disp_char(3,0,10); //显示 -
delays(3);
LCD_disp_char(2,0,10); //显示- (表示温度设定 )
delays(3);
LCD_disp_char(1,0,set/10); //显示温度十位
delays(3);
LCD_disp_char(0,0,set%10); //显示温度个位
delays(3);
}
/*****************************************************************/
void main()
{
unsigned int tmp ;//声明温度中间变量
unsigned char counter=0 ;
PIDBEGIN(); //PID参数的初始化
output=1 ; //关闭继电器输出
while(1)
{
keyscan();
if(keyflag)
{
Show_key(); //显示温度设定
}
else
{
if(counter--==0)
{
tmp=ReadTemperature();//每隔一段时间读取温度值
counter=20 ;
}
LCD_disp_char(3,0,tmp/1000); //显示温度十位
delays(3);
LCD_disp_char(2,1,tmp/100%10); //显示温度个位
//显示小数点
delays(3);
LCD_disp_char(1,0,tmp/10%10); //显示温度小数后一位
delays(3);
LCD_disp_char(0,0,tmp%10);//显示温度小数后二位
delays(3);
P2=0XFF ;
P0=0xff ;
compare_temper(); //比较温度


}
}
}
/**********************************************************************************************************************************************/
//PID算法温控C语言2008-08-17 18:58
#ifndef _PID_H__
#define _PID_H__
#include
#include
#include
struct PID
{
unsigned int SetPoint ;
// 设定目标 Desired Value
unsigned int Proportion ;
// 比例常数 Proportional Const
unsigned int Integral ;
// 积分常数 Integral Const
unsigned int Derivative ;
// 微分常数 Derivative Const
unsigned int LastError ;
// Error[-1]
unsigned int PrevError ;
// Error[-2]
unsigned int SumError ;
// Sums of Errors
}
;
struct PID spid ;
// PID Control Structure
unsigned int rout ;
// PID Response (Output)
unsigned int rin ;
// PID Feedback (Input)

sbit output=P1^4;
unsigned char high_time,low_time,count=0 ;
//占空比调节参数
unsigned char set_temper ;
void PIDInit(struct PID*pp)
{
memset(pp,0,sizeof(struct PID)); //PID参数初始化全部设置为0
}
unsigned int PIDCalc(struct PID*pp,unsigned int NextPoint)
{
unsigned int dError,Error ;
Error=pp->SetPoint-NextPoint ;
// 偏差
pp->SumError+=Error ;
// 积分
dError=pp->LastError-pp->PrevError ;
// 当前微分
pp->PrevError=pp->LastError ;
pp->LastError=Error ;
//比例
//积分项
return(pp->Proportion*Error+pp->Integral*pp->SumError+pp->Derivative*dError);
// 微分项
}
/***********************************************************
温度比较处理子程序
***********************************************************/
void compare_temper()
{
unsigned char i ;
//EA=0;
if(set_temper>temper)
{
if(set_temper-temper>1)
{
high_time=100 ; //大于1°不进行PID运算
low_time=0 ;
}
else
{ //在1°范围内进行PID运算
for(i=0;i<10;i++)
{
//get_temper();
rin=s;
// Read Input
rout=PIDCalc(&spid,rin); //执行PID运算
// Perform PID Interation
}
if(high_time<=100) //限制最大值
high_time=(unsigned char)(rout/800);
else
high_time=100;
low_time=(100-high_time);
}
}
/****************************************/
else if(set_temper<=temper) //当实际温度大于设置温度时
{
if(temper-set_temper>0)//如果实际温度大于设定温度
{
high_time=0 ;
low_time=100 ;
}
else
{
for(i=0;i<10;i++)
{
//get_temper();
rin=s ;
// Read Input
rout=PIDCalc(&spid,rin);
// Perform PID Interation
}
if(high_time<100) //此变量是无符号字符型
high_time=(unsigned char)(rout/10000);
else
high_time=0 ;//限制不输出负值
low_time=(100-high_time);
//EA=1;
}
}
}

/*****************************************************
T0中断服务子程序,用于控制电平的翻转 ,40us*100=4ms周期
******************************************************/
void serve_T0()interrupt 1 using 1
{
if(++count<=(high_time))
output=0 ;
else if(count<=100)
{
output=1 ;
}
else
count=0 ;
TH0=0x2f ;
TL0=0xe0 ;
}
void PIDBEGIN()
{

TMOD=0x01 ;
TH0=0x2f ;
TL0=0x40 ;

EA=1 ;
ET0=1 ;
TR0=1 ;

high_time=50 ;
low_time=50 ;
PIDInit(&spid);
// Initialize Structure
spid.Proportion=10 ;
// Set PID Coefficients
spid.Integral=8 ;
spid.Derivative=6 ;
spid.SetPoint=100 ;
// Set PID Setpoint

}
#endif

转自他人程序。


上一篇:分析数据的方法

下一篇:华为p6参数