电子产品制作教案(8)

更新时间:2023-03-11 19:52:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

浙江工业职业技术学院实习教案

课题名称 授课班级 项目3 浆泵液位控制器设计(2) 12电子信息工程技术(1) 课题号 授课日期 No.8 5.7 目的与要求: 1. 理解浆泵液位控制器的软件要求 2. 掌握逻辑控制信号输入输出的配合方法 3. 掌握根据要求在图书馆,互联网上查询资料的能力 课时安排: 5.7 1-2节 浆泵液位控制器软件设计要求讲解 5.7 3-5.8 6 查询相关资料,完成浆泵液位控制器软件的设计工作。 检测手段: 1. 课堂提问 2. 设计成果检查 安全与注意事项: 1. 正确操作电脑 2. 注意数据的及时保存 3. 注意机房的卫生 课后分析: 项目3 浆泵液位控制器设计(2) 一、知识点: 1、理解浆泵液位控制器的软件要求 2、掌握逻辑控制信号输入输出的配合方法 3、掌握根据要求在图书馆,互联网上查询资料的能力 二、软件设计要求 基本要求: ① 控制信号包括自动挡、手动挡、运行信号、液位信号、正转、反转等 ② 自动挡信号需要与运行信号、液位信号配合 a)接入自动挡后,需要判断是否有运行信号 b)如果有运行信号,则逐路判断是否有液位信号 i. 如果没有液位信号,对应路的正转工作 ii. 如果有液位信号,对应路的正转停止工作 c)在自动挡里面,正反转信号无效,反转继电器也不工作,仅控制 正传继电器。 ③ 手动挡信号需要与正转、反转信号配合,以及其它条件 a)接入手动挡后,无论是否有正反转信号预先接入,正反转继电器都不工作 只有在手动挡后,确定没有正反转信号接入(已接入的需要离开)后,新接入的正转(或者反转)信号才会有效,而且任何时刻仅只有一种信号有效。 b)在手动挡后,运行信号无效、液位信号无效 三、参考程序 #include #include \ #define uchar unsigned char; #define uint unsigned int; #define HAND_STATE 1 #define AUTO_STATE 0 #define RUNNING_STATE 1 #define ARRIVE_STATE 1 #define NO_ARRIVE_STATE 1 #define TIMEOVER_STATE 1 #define NO_TIMEOVER_STATE 0 #define MOTOR_ZHUAN 1 #define MOTOR_STOP 0 #define YEWEI_1 1 #define YEWEI_0 0 #define hand_is_zheng 1 #define hand_is_fan 2 #define hand_is_no 0 struct PortType { }; struct CoreType { }; struct PortType PortData[4]; unsigned char signal_running; unsigned char delay;//1->0.5s,2->1s,3->1.5s.............. unsigned char input_YeWei; unsigned char flag_yewei; unsigned char input_Zheng; unsigned char flag_zheng; unsigned char input_Fan; unsigned char flag_fan; unsigned char input_hand_auto; unsigned char flag_hand_auto; unsigned char output_Zheng; unsigned char output_Fan; unsigned char time;// unsigned char flag_timeover;// unsigned char hand_zheng_fan; unsigned char hand_auto_switch_f; /* CoreData used to store input signal CoreData_save used to store real input signal read input signal each 100ms and store them in CoreData, compare with CoreData_save and if different, need read input signal next 100ms and confirm again ----to avoid mistake signal------------------- */ struct CoreType CoreData,CoreData_save; /* ----1----- ----2----- -----3------ ---4------ input: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 foot: 10 11 12 13 14 15 16 17 32 33 34 35 36 37 00 01 Pport: P1------P1 P1-------P1 P3-------P3 P3-------P0 ---boma--- -run-- input:1 2 3 68 foot: 02 03 04 05 Pport:P0------------P0 */ //--yewei----hand_auto--zheng------fan----- //--boma1----boma2------boma3------run----- //struct Signal //{ // char K1_Signal;char K2_Signal;char K3_Signal;char K4_Signal; // char K5_Signal;char K6_Signal;char K7_Signal;char K8_Signal; // char K9_Signal;char K10_Signal;char K11_Signal;char K12_Signal; // char K13_Signal;char K14_Signal;char K15_Signal;char K16_Signal; // char DIPSwitch1;char DIPSwitch2;char DIPSwitch3;char Work_Signal; //}input_port; /* output channel coder ---1- --2-- --3-- --4-- output: 1 2 3 4 5 6 7 8 foot: 20 21 22 23 24 25 26 27 Pport: P2--------------------------P2 */ //---zheng-------fan----- //struct Action //{ // char OUT1;char OUT2; // char OUT3;char OUT4; // char OUT5;char OUT6; // char OUT7;char OUT8; //}output_port; /* modify-date 2013.6.26 first create */ void read_input() { char a=0,b=0,c=0; a = (char)DIPSwitch1&0x01; b = (char)DIPSwitch2&0x01; c = (char)DIPSwitch3&0x01;// ′??è°¥?è?a1?ó3

} /* */ CoreData.delay = a*4+b*2+c;//max 7,min 0 CoreData.delay = CoreData.delay *2;//?a1?1?μ???200ms?μD? CoreData.signal_running = Work_Signal;// ′??è?èííí?·? CoreData.PortData[0].input_YeWei = K1_Signal; CoreData.PortData[0].input_hand_auto = K2_Signal; CoreData.PortData[0].input_Zheng = K3_Signal; CoreData.PortData[0].input_Fan = K4_Signal; CoreData.PortData[1].input_YeWei = K5_Signal; CoreData.PortData[1].input_hand_auto = K6_Signal; CoreData.PortData[1].input_Zheng = K7_Signal; CoreData.PortData[1].input_Fan = K8_Signal; CoreData.PortData[2].input_YeWei = K9_Signal; CoreData.PortData[2].input_hand_auto = K10_Signal; CoreData.PortData[2].input_Zheng = K11_Signal; CoreData.PortData[2].input_Fan = K12_Signal; CoreData.PortData[3].input_YeWei = K13_Signal; CoreData.PortData[3].input_hand_auto = K14_Signal; CoreData.PortData[3].input_Zheng = K15_Signal; CoreData.PortData[3].input_Fan = K16_Signal; modify date 2013.6.26 first create , refer to CoreData & CoreData_save note 2013.7.13 how to deal with running signal....... void inputsignal_deal() { char channel=0; CoreData_save.delay =CoreData.delay ;//max 7,min 0 CoreData_save.signal_running =CoreData.signal_running ; for(channel=0; channel<4; channel++) { if(CoreData.PortData[channel].input_YeWei { } else { } //4 channels' hand-auto if(CoreData.PortData[channel].input_hand_auto!= { if(CoreData.PortData[channel].flag_hand_auto==1) { CoreData_save.PortData[channel].input_hand_auto = //if(CoreData.PortData[channel].flag_yewei==1)//?????¢ìó//{ CoreData.PortData[channel].flag_yewei =0; //} if(CoreData.PortData[channel].flag_yewei==1) { } else{ } CoreData.PortData[channel].flag_yewei =1; CoreData_save.PortData[channel].input_YeWei= CoreData.PortData[channel].flag_yewei =0;//???òa±ó? != CoreData_save.PortData[channel].input_YeWei) CoreData.PortData[channel].input_YeWei; a?2????èó3Dè??2?ó3??ó?£??′??±ùa±ó? CoreData_save.PortData[channel].input_hand_auto) CoreData.PortData[channel].input_hand_auto; } } CoreData.PortData[channel].flag_hand_auto =0; else { } CoreData.PortData[channel].flag_hand_auto =1; else { } //4 channels' zheng if(CoreData.PortData[channel].input_Zheng!= { if(CoreData.PortData[channel].flag_zheng==1) { } CoreData_save.PortData[channel].input_Zheng CoreData.PortData[channel].flag_zheng =0; //2013.7.30 if(CoreData_save.PortData[channel].input_Zheng CoreData.PortData[channel].hand_zheng_fan == = = //if(CoreData.PortData[channel].flag_hand_auto==1) //{ CoreData.PortData[channel].flag_hand_auto =0; //} CoreData_save.PortData[channel].input_Zheng) CoreData.PortData[channel].input_Zheng; MOTOR_STOP) hand_is_no; else if(CoreData_save.PortData[channel].input_Zheng == CoreData.PortData[channel].hand_zheng_fan = MOTOR_ZHUAN) hand_is_zheng; } else { CoreData.PortData[channel].flag_zheng =1; //2013.7.30 NEW ADD if(CoreData_save.PortData[channel].input_hand_auto==HAND_STATE } && //&& CoreData.PortData[channel].hand_zheng_fan == hand_is_fan) CoreData_save.PortData[channel].input_Zheng==MOTOR_STOP CoreData.PortData[channel].flag_zheng =0; else { } //4 channels' fan if(CoreData.PortData[channel].input_Fan!= { if(CoreData.PortData[channel].flag_fan==1) { CoreData_save.PortData[channel].input_Fan CoreData.PortData[channel].flag_fan =0; //2013.7.30 if(CoreData_save.PortData[channel].input_Fan== CoreData.PortData[channel].hand_zheng_fan = = //if(CoreData.PortData[channel].flag_zheng==1) //{ CoreData.PortData[channel].flag_zheng =0; //} CoreData_save.PortData[channel].input_Fan) CoreData.PortData[channel].input_Fan; MOTOR_STOP) hand_is_no; } /* } } } else if(CoreData_save.PortData[channel].input_Fan== = MOTOR_ZHUAN) CoreData.PortData[channel].hand_zheng_fan hand_is_fan; else { CoreData.PortData[channel].flag_fan =1; //2013.7.30 NEW ADD if(CoreData_save.PortData[channel].input_hand_auto==HAND_STATE } && //&& CoreData.PortData[channel].hand_zheng_fan == hand_is_zheng) CoreData_save.PortData[channel].input_Fan==MOTOR_STOP) CoreData.PortData[channel].flag_fan =0; else { } //if(CoreData.PortData[channel].flag_fan==1) //{ CoreData.PortData[channel].flag_fan =0; //} date:2013-7-1 this function is used to deal with 16 channels signal and to modify <> data

*/ void state_deal() { char channel=0; for(channel=0;channel<4;channel++) { CoreData_save.PortData[channel].flag_timeover=NO_TIMEOVER_STATE;/ } else//??′ˉá£?o { //??′ˉá£?oì?£??2?a°??¤??£?ó??1??òù?a??ó? CoreData_save.PortData[channel].output_Fan CoreData_save.PortData[channel].output_Zheng ==//input-->output CoreData_save.PortData[channel].output_Fan CoreData_save.PortData[channel].output_Zheng ==if(CoreData_save.PortData[channel].input_hand_auto { //need clear time CoreData_save.PortData[channel].time=0;//???? == HAND_STATE)//?ó′ˉá£?o /???? CoreData_save.PortData[channel].input_Fan; CoreData_save.PortData[channel].input_Zheng; MOTOR_STOP;//?T????·?£?o÷?è??′ˉá£?o·μì?????ì? MOTOR_STOP; if(CoreData_save.signal_running==RUNNING_STATE)//????2{ ¥Dú?èíí?2é? if(CoreData_save.PortData[channel].input_YeWei==ARRIVE_STATE )//? { ????·????3o if(CoreData_save.PortData[channel].flag_timeover != { } else//?D?a?a1?3o?è { if(CoreData_save.PortData[channel].time { < TIMEOVER_STATE)//?????D?a?a1?à?3o CoreData_save.delay )// CoreData_save.PortData[channel].time++;//100ms=1 CoreData_save.PortData[channel].output_Zheng=MOTOR_ZHUAN; CoreData_save.PortData[channel].flag_timeover=TIMEOVER_STATE; CoreData_save.PortData[channel].time=CoreData_save.delay;//avoid } else//?????a1????-3o?è { } delay to be changed when time add CoreData_save.PortData[channel].output_Zheng=MOTOR_STOP; CoreData_save.PortData[channel].output_Zheng=MOTOR_STOP;//Dí3?′-D } -£?à???ì3 } { CoreData_save.PortData[channel].time=0; else//?????·??à?Dí3o£?á??ì??òù?a,?a1??a0 CoreData_save.PortData[channel].flag_timeover=NO_TIMEOVER_STATE;/ /???? } /* è3à?: 2013.8.15 ??±ù--?¤′′--?¥áü 1′?ˉ?ˉ1?è1?? */ void inputsignal_deal2()// inputsignal_deal2ó??a??ìè??3? \\?¥áü { char channel=0; CoreData_save.delay =CoreData.delay ;//max 7,min 0 CoreData_save.signal_running =CoreData.signal_running ; for(channel=0; channel<4; channel++) } else//????°?2¥Dú?èíí?2é?£??′??aò·ü′-?2é? { } CoreData_save.PortData[channel].output_Zheng=MOTOR_ZHUAN; CoreData_save.PortData[channel].flag_timeover=NO_TIMEOVER_STATE;/ CoreData_save.PortData[channel].time=0; /???? CoreData_save.PortData[channel].output_Fan=MOTOR_STOP;//??±??a?? } } } CoreData_save.PortData[channel].output_Zheng aò£?°?áü?è?a =MOTOR_STOP;//??±??a??aò£?°?áü?è?a { CoreData_save.PortData[channel].input_hand_auto CoreData_save.PortData[channel].input_Zheng CoreData_save.PortData[channel].input_Fan = = = CoreData_save.PortData[channel].input_YeWei //íˉ?a12°a??ì???????2D??′ˉa?±??ó′ˉ£???????£??′íˉ?a?ˉóà??μ?//3a??′ˉa??ó′ˉ·μ£?°??????è???°à2£???±?′1à?Dí?£ //è3à?:3a?ì3?·μ£?á??ì????′ˉ?2é?£?è·????±?ìó??μ?ìóìμ: // 12?????ì3????ê?????ú?ó′ˉ?2é?£??ì3?·μ?°a??ì?a??2D??′ˉ?//ó?Dí3a???è2Dê£ó?a?±??èíí£???±?°???Díí§μ?è?a??ˉ?£ //a?ó??ê????′ˉa??ó′ˉ·μ£???±?′1ê£ó?£??T?????è???°à2if(CoreData.PortData[channel].input_hand_auto==HAND_STATE && CoreData_save.PortData[channel].hand_auto_switch_f = 2; = CoreData.PortData[channel].input_YeWei; a±ó? 2é??í??3o?ó′ˉ?2é??è?£8??21?ò £?ó?Dí???èó?í?2Dê£ó?a??a?èíí?2é?£???±?°??a?1Díí§?£ CoreData_save.PortData[channel].input_hand_auto==AUTO_STATE) CoreData.PortData[channel].input_hand_auto; CoreData.PortData[channel].input_Zheng; CoreData.PortData[channel].input_Fan; //??3á′¨????:?????ú??′ˉá£?oì?£?à?Día??a?ˉóàòaμ?ó3£???±//?????ú?ó′ˉá£?oì?£?Dí?èòaμ?ó3£?ó?Dí3aòù?2?a′12′?a?è£???′¨//???è?a?1Díí§?è?£ ù3?£? ?a??±ù£?a3à? if( CoreData_save.PortData[channel].input_hand_auto==AUTO_STATE) CoreData_save.PortData[channel].hand_auto_switch_f = 0; if(CoreData_save.PortData[channel].input_hand_auto==HAND_STATE) { } /* } if(CoreData_save.PortData[channel].input_Fan== MOTOR_STOP CoreData_save.PortData[channel].hand_auto_switch_f = 0; && CoreData_save.PortData[channel].input_Zheng==MOTOR_STOP) } 2013.8.15 o33ê?ˉ1?á?′? */ void state_deal2() { char channel=0; for(channel=0;channel<4;channel++) { CoreData_save.PortData[channel].flag_timeover=NO_TIMEOVER_STATE;/if(CoreData_save.PortData[channel].input_hand_auto { //1μóó±??1o÷?è?2é? // 1, óaoDo÷?è?ó′ˉ£?òù?2?a?2é??a:0 0; 1 0; 0 1; // 2£?óaoDo÷?è?ó′ˉ£?òù?2?a?2é??a:1 1£??′??Dà?èá??ì?2é?:??// 3£?2D??′ˉ?a???ù?2£?òù?2?a?2é??§í§ // // //need clear time CoreData_save.PortData[channel].time=0;//???? == HAND_STATE)//?ó′ˉá£?o ?óa???3á0ó3 /????

if(CoreData_save.PortData[channel].hand_auto_switch_f==2) { } //input-->output // ?????ú?ó′ˉá£?oì?£?Díòù?a·ê?2?aê??a???è£????èa?????//3???±??a£??a?í′ì2è?°?? //??±óó???°???ê??a???è3á?2é?£?a??? //òù1 ?20 //òù0 ?21 //òù0 ?20 //òù1 ?21---->2è?a°????¢??òù?2?a′1?èíí3á??±?£??′?if(!(CoreData_save.PortData[channel].input_Fan && CoreData_save.PortData[channel].output_Fan CoreData_save.PortData[channel].output_Zheng continue; ==MOTOR_STOP; MOTOR_STOP; ??a£2?£? a?¢ìóòù1?21?a£???±???±ó?ú?ì??μ??2é? ==MOTOR_ZHUAN CoreData_save.PortData[channel].input_Zheng==MOTOR_ZHUAN)) } else//??′ˉá£?o { //??′ˉá£?oì?£??2?a°??¤??£?ó??1??òù?a??ó? CoreData_save.PortData[channel].output_Fan CoreData_save.PortData[channel].output_Zheng =={ } CoreData_save.PortData[channel].output_Fan CoreData_save.PortData[channel].output_Zheng ==CoreData_save.PortData[channel].input_Fan; CoreData_save.PortData[channel].input_Zheng; MOTOR_STOP;//?T????·?£?o÷?è??′ˉá£?o·μì?????ì? MOTOR_STOP; if(CoreData_save.signal_running==RUNNING_STATE)//????2{ ¥Dú?èíí?2é? if(CoreData_save.PortData[channel].input_YeWei==ARRIVE_STATE )//? { if(CoreData_save.PortData[channel].flag_timeover != { } else//?D?a?a1?3o?è { if(CoreData_save.PortData[channel].time { < ????·????3o TIMEOVER_STATE)//?????D?a?a1?à?3o CoreData_save.delay )// CoreData_save.PortData[channel].time++;//100ms=1 CoreData_save.PortData[channel].output_Zheng=MOTOR_ZHUAN; CoreData_save.PortData[channel].flag_timeover=TIMEOVER_STATE; CoreData_save.PortData[channel].time=CoreData_save.delay;//avoid } else//?????a1????-3o?è { } delay to be changed when time add CoreData_save.PortData[channel].output_Zheng=MOTOR_STOP; CoreData_save.PortData[channel].output_Zheng=MOTOR_STOP;//Dí3?′-D -£?à???ì3 } /* */ void output_control() date :2013-7-1 this function control output signal according to the } } { CoreData_save.PortData[channel].time=0; else//?????·??à?Dí3o£?á??ì??òù?a,?a1??a0 CoreData_save.PortData[channel].flag_timeover=NO_TIMEOVER_STATE;/ } else//????°?2¥Dú?èíí?2é?£??′??aò·ü′-?2é? { } /???? CoreData_save.PortData[channel].output_Zheng=MOTOR_ZHUAN; CoreData_save.PortData[channel].flag_timeover=NO_TIMEOVER_STATE;/ CoreData_save.PortData[channel].time=0; /???? CoreData_save.PortData[channel].output_Fan=MOTOR_STOP;//??±??a?? } } } CoreData_save.PortData[channel].output_Zheng aò£?°?áü?è?a =MOTOR_STOP;//??±??a??aò£?°?áü?è?a <<>> {//channel_1 if(CoreData_save.PortData[0].output_Fan==MOTOR_ZHUAN) OUT2 = 1; OUT2 = 0; OUT1 = 1; OUT1 = 0; else if(CoreData_save.PortData[0].output_Zheng==MOTOR_ZHUAN) else //channel_2 if(CoreData_save.PortData[1].output_Fan==MOTOR_ZHUAN) OUT4 = 1; OUT4 = 0; OUT3 = 1; OUT3 = 0; else if(CoreData_save.PortData[1].output_Zheng==MOTOR_ZHUAN) else //channel_3 if(CoreData_save.PortData[2].output_Fan==MOTOR_ZHUAN) OUT6 = 1; OUT6 = 0; OUT5 = 1; OUT5 = 0; else if(CoreData_save.PortData[2].output_Zheng==MOTOR_ZHUAN) else //channel_4 if(CoreData_save.PortData[3].output_Fan==MOTOR_ZHUAN) OUT8 = 1; OUT8 = 0; OUT7 = 1; else if(CoreData_save.PortData[3].output_Zheng==MOTOR_ZHUAN) } else OUT7 = 0; /******************************************************************************* ì3ê±ó?·ˉ?ù 1£?±??1?ˉ 2£?ì-??°a??2??è *******************************************************************************/ void IO_Output_Init() { } /******************************************************************************* * Function Name : Delay100ms * Description : ?31ú?D?a100mS * Input : None * Output : None * Return : None *******************************************************************************/ void Delay100ms() { i = 5; j = 52; unsigned char i, j, k; //@11.0592MHz P0 = 0xff; P1 = 0xff; P2 = 0x00; P3 = 0xff;

} k = 195; do { do { while (--k); } while (--j); } while (--i); void dog_init() { } void feed_dog() { } void main() { IO_Output_Init(); Delay100ms(); Delay100ms(); dog_init(); while(1) { } Delay100ms(); Delay100ms(); feed_dog(); read_input(); state_deal2(); output_control(); WDT_CONTR = 0x3c; WDT_CONTR = 0x3c;//?a?2à???£?′¨?a1.1377S inputsignal_deal2(); } 四、小结 本次课主要进行浆泵控制器软件的设计,工作量相对比较大,需要同学们认真对待。

本文来源:https://www.bwwdw.com/article/34bw.html

Top