51单片机自动控制升旗系统(共11页).doc

上传人:飞****2 文档编号:13991579 上传时间:2022-05-02 格式:DOC 页数:11 大小:53KB
返回 下载 相关 举报
51单片机自动控制升旗系统(共11页).doc_第1页
第1页 / 共11页
51单片机自动控制升旗系统(共11页).doc_第2页
第2页 / 共11页
点击查看更多>>
资源描述

《51单片机自动控制升旗系统(共11页).doc》由会员分享,可在线阅读,更多相关《51单片机自动控制升旗系统(共11页).doc(11页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、精选优质文档-倾情为你奉上/*51单片机升旗系统*/*步进电机升旗和降旗,蜂鸣器奏国歌,*/*数码管显示系统时间和高度*/#include #define uint unsigned int#define uchar unsigned charuchar code FFW=0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09; /正转的步码uchar code REV=0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01; /反转的步码uchar th=0x0f,0x5d,0xab;/3个定时器值,高8位uchar tl=0xa0,0xc0,

2、0xe0;/3个定时器值,低8位code uchar SZ = 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f; /数码管unsigned int code FreqTab1=64216,64360,64489,64547,64654,64752,64837,64876,64948,65012,65042,65095,65144,65186,65206,65242,65274,65289,65135,65340,65361,;unsigned int code FreqTab= /简谱对应的简谱码、T值 65535,64260,64400,6

3、4524,64579,64685,64778,64860,64898,64968,65030,65057,65110,65157,65198,65217,65252,65283,65297,65323,65346,65367, ;unsigned char code yyjjxq= 8,0x08,0,0x04,5,0x04,8,0x0c,8,0x04,8,0x06,8,0x02,5,0x04,6,0x02,7,0x02,8,0x08,8,0x08,0,0x04,10,0x04,8,0x04,9,0x02,10,0x02,/10,0x04,10,0x04,8,0x04,9,0x02,10,0x0

4、2,12,0x08,12,0x08,10,0x06,10,0x02,8,0x06,10,0x02,12,0x06,10,0x02,9,0x08,/12,0x10,9,0x10,13,0x08,12,0x08,9,0x08,10,0x08,12,0x04,10,0x04,0,0x04,12,0x04,/12,0x04,10,0x04,10,0x04,12,0x04,10,0x04,9,0x02,10,0x02,8,0x08,10,0x08,0,0x08,/10,0x08,10,0x08,5,0x06,6,0x04,8,0x04,8,0x04,10,0x06,10,0x02,12,0x04,12,

5、0x04,9,0x04,9,0x02,9,0x02,6,0x08,9,0x0c,5,0x04,8,0x0c,8,0x04,10,0x0c,10,0x04,12,0x10,8,0x06,10,0x02,12,0x04,12,0x04,13,0x08,12,0x08,10,0x06,8,0x02,12,0x08,10,0x04,0,0x04,8,0x04,0,0x04,/10,0x04,10,0x04,8,0x04,8,0x04,5,0x08,8,0x08,10,0x06,8,0x02,12,0x08,10,0x04,0,0x04,8,0x04,0,0x04,/10,0x04,10,0x04,8,

6、0x04,8,0x04,5,0x08,8,0x08,5,0x08,8,0x08,5,0x08,8,0x08,8,0x08,0,0x08,/8,0x08,0xff,0xff,;uchar speed_count=2;uchar flag=0;bit timer_flag=0;bit MOTOR_FFW_FLAG=0;bit MOTOR_REV_FLAG=0;sbit K1 = P30; /正转sbit K2 = P31; /反转sbit K5 = P34; /停止sbit led1=P20;sbit led2=P21;sbit led3=P22;sbit led4=P23;sbit led5=P

7、24;sbit led6=P25;sbit beep=P37;void smg_display();void K1_stop_state();void K2_stop_state();void K5_stop_state();void music();uchar num1=0,num2=0,num3=0;uint cnt=0,Time=0,Length=0;uchar a=0;uchar tl0,th0;void delay(unsigned char t) /-延时函数-/ unsigned char t1; unsigned long t2; for(t1=0;t1t;t1+) for(t

8、2=0;t20;a-)for(b=124;b0;b-);void DTIME(int n)/延时程序uchar i;for(i=0;i2) speed_count=2; void down(void) interrupt 2/减速 speed_count-;if(speed_count500)cnt=0;if(flag!=1&flag!=2)Time=0;if(flag=1)if(K5=0) K5_stop_state(); ET1=1; TR1=1;if(num3=5)num3=0;SETP_MOTOR_FFW();if(num1=100)num1=0;Time+;if(Time=43)a=

9、Length;MOTOR_FFW_FLAG=1;MOTOR_REV_FLAG=0;K1_stop_state();if(num2=24)num2=0;Length+;if(flag=2)if(num3=5)num3=0;SETP_MOTOR_REV();if(num1=100)num1=0;Time-;if(Time=0)a=Length;a+;MOTOR_FFW_FLAG=0;MOTOR_REV_FLAG=1;K2_stop_state();if(num2=24)num2=0;Length-; void K1_stop_state() while(1) P2|=0xff;led1=0;P0=

10、SZTime/10;DTIME(2); P2|=0xff;led2=0;P0=SZTime%10;DTIME(2); /*case 2:P2|=0xff;led3=0;P0=SZTime%100%10;break; */P2|=0xff;led4=0;P0=SZa/100; DTIME(2); P2|=0xff;led5=0;P0=SZa/10%10;DTIME(2);P2|=0xff;led6=0;P0=SZa%100%10;DTIME(2); if(K2=0) flag=2;break; void K2_stop_state() while(1) P2|=0xff;led1=0;P0=SZ

11、Time/10;DTIME(2); P2|=0xff;led2=0;P0=SZTime%10;DTIME(2); /*case 2:P2|=0xff;led3=0;P0=SZTime%100%10;break; */P2|=0xff;led4=0;P0=SZa/100; DTIME(2); P2|=0xff;led5=0;P0=SZa/10%10;DTIME(2);P2|=0xff;led6=0;P0=SZa%100%10;DTIME(2); if(K1=0) flag=1;break; void K5_stop_state()P2|=0xff;led1=0;P0=SZ0;while(1);void music() unsigned char k; ET0=1; while(1) if( yyjjxqk=0xff)beep=1;TR0=0;delayms(50);else if( yyjjxqk=0x00) TR0=0;delay(yyjjxqk+1); k+=2; else th0=FreqTab yyjjxqk/256; tl0=FreqTab yyjjxqk%256; TR0=1; delay(yyjjxqk+1); k+=2; 电路原理图如下所示: 专心-专注-专业

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁