1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > java微波炉程序代码_基于单片机的微波炉课程设计 原理图 仿真和源程序都有

java微波炉程序代码_基于单片机的微波炉课程设计 原理图 仿真和源程序都有

时间:2023-12-11 05:32:21

相关推荐

java微波炉程序代码_基于单片机的微波炉课程设计 原理图 仿真和源程序都有

#include

#defineuint unsigned int

#defineuchar unsigned char

uint dis[]={0x00,0x00,0x00,0x00};

uint pv=1,pv_j=6,pv_l=24; //定义 档位、加热时间、冷却时间(每个周期)

uint count_s=0; //记录定时时间

uint cyc0=20,cyc1=20; // 为了计时一秒,定时器一次中断为50ms,20*50ms=1s

uchar codevalue[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0xff};//七段数码管显示码,显示0~9和全亮

uchar codecho[]={0xfe,0xfd,0xfb,0xf7};//位选码

sbit P10=P1^0;//引脚定义

sbit P11=P1^1;

sbit P12=P1^2;

sbit P13=P1^3;

sbit P14=P1^4;

sbit P15=P1^5;

sbit P16=P1^6;

sbit P17=P1^7;

sbit duan=P2^0;

sbit wei=P2^1;

sbit P22=P2^2;

sbit P23=P2^3;

sbit P24=P2^4;

/*--------------------

延时函数,大致延时一毫秒

-------------------*/

void delay_ms(uint t)

{uchar i;

while(t--)

{

i=250;

while(--i);

}

}

/*------------------------

定时器初始化

--------------------------*/

void t_clr()

{

EA=1; //CPU开中断

ET0=1;

ET1=1; //定时器 中断允许

TMOD=0X11; //定时器T1、T0 定时 方式一

TH0=0X3c;

TL0=0Xaf;

//12M 晶振,65536-15536=50000,50000us*20=1000000us=1s

TH1=0X3c;

TL1=0X0af;

}

/*------------------------

键盘扫描函数

--------------------------*/

void key_scan()

{

if(!P10)

{

delay_ms(70);

if(!P10)

count_s+=30; //时间 +30秒

if (count_s>6000)

count_s=0;

}

if(!P11)

{

delay_ms(70);

if(!P11)

count_s+=60; //时间 +1 分

if (count_s>6000)

count_s=0;

}

if(!P12)

{

delay_ms(70);

if(!P12)

count_s+=300; //时间+5分

if (count_s>6000)

count_s=0;

}

if(!P13)

{

delay_ms(70);

if(!P13)

count_s=0; //时间清零

}

if(!P14)

{

delay_ms(70);

if(!P14)

{if (pv<3)

pv++;//档位+1

pv_j=pv*6+6; //加热时间

pv_l=30-pv_j; //冷却时间

}

}

if(!P15)

{

delay_ms(70);

if(!P15)

{if (pv>0)

pv--;//档位-1

pv_j=pv*6+6;

pv_l=30-pv_j;

}

}

if(!P16)

{

delay_ms(70);

if(!P16)

{

P22=1;

if(count_s==0) //如果没有设定时间,不加热,定时器不工作

{TR0=0;

TR1=0;}

else//如果已经设定时间,则开始计时,开始加热

{

pv_j=6*pv+6;

pv_l=30-pv_j;

t_clr();

TR0=1;

TR1=1;

P22=0;}

}

}

if(!P17)//停止加热,终止定时器

{

delay_ms(70);

if(!P17)

{P22=1;

P23=0;

TR0=0;

TR1=0;

}

}

}

/*------------------------

时间变换为每个显示位

--------------------------*/

void time_converter()

{

dis[0]=count_s/600;//取分的十位

dis[1]=(count_s/60)%10; //取分的个位

dis[2]=(count_s%60)/10; //取秒的十位

dis[3]=(count_s%60)%10;//取秒的个位

}

/*------------------------

显示函数

--------------------------*/

void display()

{

uchar t;

uchar k;

for(k=0;k<4;k++)//LED显示

{

wei=1;

P0=codecho[k];

wei=0;

P0=0xff;

delay_ms(1);

duan=1;

P0=codevalue[dis[k]];

duan=0;

P0=0xff;

delay_ms(1);

}

P3=codevalue[pv];//显示档位 */

while(!P24) //按键测试

{

for(t=0;t<4;t++)

{

wei=1;

P0=codecho[t];

wei=0;

P0=0xff;

delay_ms(1);

duan=1;

P0=codevalue[10];

duan=0;

P0=0xff;

delay_ms(1);

P3=codevalue[10];

}

}

}

/*------------------------

主函数

--------------------------*/

void main()

{

uchar n=200;

P23=0;

t_clr(); //初始化

while(1)

{

key_scan(); //键盘扫描

time_converter();//数值转换

display(); //显示

}

}

/*------------------------

定时器T0中断

--------------------------*/

void t0() interrupt 1

{

TR0=0;

TH0=0X3c;

TL0=0Xaf;

cyc0--;

if (cyc0==0)

{cyc0=20;

count_s--;//时间-1S

if (count_s==0)//如果定时已到

{

P22=1; //停止加热,定时器终止

TR0=0;

TR1=0;

P23=1;

}

else

TR0=1; //继续定时

}

else

TR0=1;

}

/*------------------------

定时器T1中断

--------------------------*/

void t1() interrupt 3

{

TR1=0;

TH1=0X3c;

TL1=0X0af;

TR1=1;

if (pv_j!=0) //需要加热

{cyc1--;

if (cyc1==0)

{cyc1=20;

pv_j--;

if (pv_j==0) //加热时间到

{

P22=1; //否则,停止加热,进入冷却阶段

}

}

}

else if (pv_l!=0) //是否需要冷却

{cyc1--;

if (cyc1==0)

{cyc1=20;

pv_l--;

if (pv_l==0) //冷却时间到

{

P22=0; //进行加热

pv_j=pv*6+6;} //再次设定加热时间

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。