继电器图1.系统组成框图第三届全国电子专业人才设计与技能大赛单片机设计与开发模拟试题“模拟智能传送装置”设计任务书功能简述“传送装置”可实现货物重量检测,改变装置的传输方向,超重记录及超重报警功能。“传送装置”的硬件电路主要由单片机控制电路、数码管显示电路、模数转换电路、已已?尺0乂存储电路、按键控制电路、蜂鸣器及继电器电路组成,系统框图如图1所示。竞赛时间:5小时题号总分酉己分得分设计任务及要求一.电路原理图设计二.电路板焊接与装配要求焊点大小适中,无漏、假、虚、连焊,焊点光滑、圆润、干净,无毛刺;引脚加工尺寸及成形符合工艺要求;导线长度、剥头长度符合工艺要求,芯线完好,捻头镀锡。要求印制板插件位置正确,元器件极性正确,元器件、导线安装及字标方向均应符合工艺要求;接插件、板间连接、紧固件安装可靠牢固,印制板安装对位;无烫伤和划伤处,整板清洁无污物。三.程序编写及流程图绘制四.硬件调试参考程序#includepcf8591.h#defineucharunsignedchar#defineuintunsignedintsbitHC138A=P2^5;sbitHC138B=P2^6;sbitHC138C=P2^7;sbits7=P3^0;sbits6=P3^1;sbits5=P3^2;sbits4=P3^3;sbitrelay=P0^4;ucharVtable[]={0,0,0,0};externucharrecev_table[1];ucharcodesmg_du[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};ucharcodesmg_we[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};ucharnum,num1,num2,a,tt,b;//num1,num2控制正转、反转//a灯第几个亮//b上电读取上次超重的值voiddelayms(uintx){uchart;while(x--)for(t=0;t120;t++);}voiddisplay(ucharwe,uchardu){HC138C=1;HC138B=1;HC138A=1;P0=smg_du[du];HC138C=1;HC138B=1;HC138A=0;P0=smg_we[we];}voidkeyscan(){if(s4==0){delayms(5);if(s4==0){HC138C=1;HC138B=0;HC138A=1;P0=0x1f;//开继电器num=1;//开始工作标准HC138C=1;HC138B=0;HC138A=0;P0=0xff;while(!s4);}}if(s5==0){delayms(5);if(s5==0&&num==1){while(!s5);a=0;num1=1;//正向}}if(s6==0){delayms(5);if(s6==0&&num==1){while(!s6);a=0;num1=2;//反向}}if(s7==0){delayms(5);if(s7==0){while(!s7);num=0;num1=0;TR0=0;HC138C=1;HC138B=0;HC138A=1;P0=0;HC138C=1;HC138B=0;HC138A=0;P0=0xff;}}}voidpros(ucharval)//处理数据{uinttemp;temp=val*200/51;Vtable[0]=(temp)/1000;Vtable[1]=(temp)/100%10;Vtable[2]=(temp)/10%10;Vtable[3]=(temp)%10;}/////////////////////////////////////////////////////////////////////////////////////voidwrite_24c02_add(ucharadd,ucharbyte){start();iic_writebyte(0xa0);iic_writebyte(add);iic_writebyte(byte);stop();}ucharread_24c02_add(ucharadd){uchark;start();iic_writebyte(0xa0);iic_writebyte(add);start();iic_writebyte(0xa1);k=iic_readbyte();stop();returnk;}voidinit(){TMOD=0x01;TH0=(65536-50000)/256;TL0=(65536-50000)%256;EA=1;ET0=1;IT0=1;EX0=1;}voidmain(){uchari;HC138C=1;HC138B=0;HC138A=1;P0=0xaf;//关蜂鸣器HC138C=1;HC138B=0;HC138A=0;P0=0xff;//关流水灯init();/*b=read_24c02_add(0);//读24c02上次超重结果if(b191){pros(b);write_24c02_add(0,0);while(1){display(0,Vtable[0]);delayms(1);//显示超重结果display(1,Vtable[1]);delayms(1);display(2,Vtable[2]);delayms(1);display(3,Vtable[3]);delayms(1);}}*/while(1){keyscan();if(num1==1){//判断启动定时器流水灯工作TR0=1;num2=1;}if(num1==2){TR0=1;num2=2;}/*ad_pcf8591(0x07);ad_pcf8591(0x07);pros(recev_table[0]);display(0,Vtable[0]);delayms(1);display(1,Vtable[1]);delayms(1);display(2,Vtable[2]);delayms(1);display(3,Vtable[3]);delayms(1);if(recev_table[0]191){s5=0;EX0=1;}if(recev_table[0]191){s5=1;EX0=0;}*/}}voidint0()interrupt0{TR0=0;HC138C=1;HC138B=0;HC138A=0;P0=0xff;HC138C=1;HC138B=0;HC138A=1;P0=0x40;while(1){ad_pcf8591(0x07);ad_pcf8591(0x07);pros(recev_table[0]);display(0,Vtable[0]);delayms(1);display(1,Vtable[1]);delayms(1);display(2,Vtable[2]);delayms(1);display(3,Vtable[3]);delayms(1);write_24c02_add(0,recev_table[0]);if(recev_table[0]191){s5=1;EX0=0;HC138C=1;HC138B=0;HC138A=1;P0=0x10;//关蜂鸣器开继电器break;//退出外部中断}}}voidT0_time()interrupt1{TH0=(65536-50000)/256;TL0=(65536-50000)%256;tt++;if(tt==4){tt=0;a++;if(a==9){a=1;if(num==1){HC138C=1;HC138B=0;HC138A=1;P0=0x10;//开继电器以防自动跳掉HC138C=1;HC138B=0;HC138A=0;P0=0xff;}}if(num2==1){if(a==1){HC138C=1;HC138B=0;HC138A=0;P0=0xfe;}if(a==2){HC138C=1;HC138B=0;HC138A=0;P0=0xfd;}if(a==3){HC138C=1;HC138B=0;HC138A=0;P0=0xfb;}if(a==4){HC138C=1;HC138B=0;HC138A=0;P0=0xf7;}if(a==5){HC138C=1;HC138B=0;HC138A=0;P0=0xef;}if(a==6){HC138C=1;HC138B=0;HC138A=0;P0=0xdf;}if(a==7){HC138C=1;HC138B=0;HC138A=0;P0=0xbf;}if(a==8){HC138C=1;HC138B=0;HC138A=0;P0=0x7f;}}if(num2==2){if(a==8){HC138C=1;HC138B=0;HC138A=0;P0=0xfe;}if(a==7){HC138C=1;HC138B=0;HC138A=0;P0=0xfd;}if(a==6){HC138C=1;HC138B=0;HC138A=0;P0=0xfb;}if(a==5){HC138C=1;HC138B=0;HC138A=0;P0=0xf7;}if(a==4){HC138C=1;HC138B=0;HC138A=0;P0=0xef;}if(a==3){HC138C=1;HC138B=0;HC138A=0;P0=0xdf;}if(a==2){HC138C=1;HC138B=0;HC138A=0;P0=0xbf;}if(a==1){HC138C=1;HC138B=0;HC138A=0;P0=0x7f;}}}}