单片机程序源代码[共43页]

上传人:1528****253 文档编号:154880616 上传时间:2022-09-21 格式:DOC 页数:43 大小:295.54KB
收藏 版权申诉 举报 下载
单片机程序源代码[共43页]_第1页
第1页 / 共43页
单片机程序源代码[共43页]_第2页
第2页 / 共43页
单片机程序源代码[共43页]_第3页
第3页 / 共43页
资源描述:

《单片机程序源代码[共43页]》由会员分享,可在线阅读,更多相关《单片机程序源代码[共43页](43页珍藏版)》请在装配图网上搜索。

1、 LED (D0 和 D1 ),编写程序,实现两个#define uint unsigned int#define uchar unsigned char#define uchar unsigned char D0 和 D7 灭,其次是 D1 和 D6 灭,再是 D2#define uchar unsigned char uint i,j,xx2=0xaa,0xff,yy2=0xf0,0x0f,zz2=0xb6,0xff; LED 数码管,编写程序,使数码管循环显示从#define uchar unsigned char #define uint unsigned int#define uch

2、ar unsigned chardelay(ms) #define uchar unsigned charcase 0xfe:case 0xfd:case 0xfb:case 0xf7:case 0xef:case 0xdf:case 0xbf:case 0x7f:#define uchar unsigned char uchar i,j;P2=0xf0;temp=P2;temp&=0xf0;switch(temp)case 0xe0:num=1;break;case 0xd0:num=2;break;case 0xb0:num=3;break;case 0x70:num=4;switch(t

3、emp)case 0xe0:num=5;break;case 0xd0:num=6;break;case 0xb0:num=7;break;case 0x70:num=8;case 0xe0:num=9;break; if(num=0)P0=0xbf;#define uchar unsigned char#define uint unsigned intsbit LED1=P20;sbit LED2=P21; uchar code LED_code=uchar i,j;uchar temp;P1=0xfe;/key1-key4 第一行按下temp=P1;switch(temp) switch(

4、temp) switch(temp)temp=P1;switch(temp) 时,8 位数码管均显示 “-”,每按下一个号码后,原位。8 位 LED 数码管显示的内容向左移动#define uint unsigned int#define uchar unsigned charuchar keycount=0,num;uchar code LED1_code= uchar LED2_wei8= 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01;uchar i,j;switch(temp)case 0xee:keycount+;num=0;break;case 0x

5、de:keycount+;num=1;break;case 0xbe:keycount+;num=2;break;case 0x7e:keycount+;num=3;break; temp=P3;switch(temp)case 0xed:keycount+;num=4;break;case 0xdd:keycount+;num=5;break;case 0xbd:keycount+;num=6;break;case 0x7d:keycount+;num=7;break; switch(temp)case 0xeb:keycount+;num=8;break;temp=P3;switch(te

6、mp) for(i=0;i7;i+)LED2_duani=LED2_duani+1;后,8 只 LED 暂停默认显示,而进行闪烁显示,当显示达到5 次后,继续按默认规律显示。#define uint unsigned int#define uchar unsigned charvoid LED_shan() interrupt 0 P0 端口作为输出口,外接条形2 次按下按键 K 后,LED /将 led 值映射到 LED 灯delayms(500); /延时 500msvoid delayms(unsigned int ms)EX0 = 1; / 打开外部中断 0EA = 1; /打开总中断

7、t = 0; #include/ 头文件#define uchar unsigned char#define uint unsigned intuchar temp,key_count;uchar code tab= case 0:loop_leftmove();break;case 1:loop_rightmove();break;case 2:open_close();break;default:break;void key_interrupt() interrupt 0/ 外部中断 INT0 中断服务程序key_count+;key_count%=3;/*if(key_count=3)k

8、ey_count=0;*/P0 端口作为输出口,外接#define uchar unsigned char#define uint unsigned intsbit key1=P32;sbit key2=P33;sbit beep=P10; EX0=1;/ 打开外部中断 INT0EX1=1;/ 打开外部中断 INT1 switch(key_count%2)case 1:left_right_move();break;/奇数次按键左移右移显示case 0:break;/偶数次按键拉幕式显示 P0 端口作为输出口,外接#define uchar unsigned char #define ucha

9、r unsigned charuchar key1=0,key2=0,m,n,k;uchar table=0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f; 使用单片机 P0、P2 端口作为输出口,外接一个#include/ 头文件shi=count/10;/ 分离十位ge=count%10;/ 分离个位P2=tablege;/ 显示个位P0=tableshi;/ 显示十位 #include/ 头文件void delay(uint ms)/ 延时子函数 使用单片机 P0、P2 端口作为输出口,外接一个K2 时,暂停加 1 计数,按键 K13 次按下按键 K2 时,

10、LED 数码管显示为 0;第 4 TMOD=0x05;/ 设置工作方式为 1 选择计数效用TH0=0xff; #define uchar unsigned char #define uchar unsigned char任务三:用 T2 实现流水灯控制#include/ 头文件 ET2=1;/ 打开定时器 2 中断TR2=1;/ 启动定时器 2init();/ 调用初始化函数while(1);void Timer2() interrupt 5 /T2 定时器的中断服务子程序TF2=0; /溢出标志位软件清零#include#define uchar unsigned char#define u

11、int unsigned intuchar code table= ET0=1;/ 打开定时器 0 中断TR0=1; / 启动定时器 0while(1) /循环display(); / 扫描数码管 任务五: LED 滚动闪烁控制#define uchar unsigned charuchar table15=0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe;uint count,i,num;void int_int()EX0=1;/ 允许外部中断EX1=1;void key1_1() inter

12、rupt 0num=num-2000;if(num=2000)num=2000;void key2_2() interrupt 2void timer_0() interrupt 1 #include#define uchar unsigned char#define uint unsigned int#define a2#define e2#define T 1000sbit key=P37;/ 880.000Hz a2/ 659.255Hz e2/定义音符结构/发声频率(对应的定时器初值)/发声时值uchar ReloadH;uchar ReloadL;TMOD=0x01;ET0=1; v

13、oid sound(CNote *note) SPEAKER=1;void inter() interrupt 1#include/ 头文件#define uint unsigned intTMOD=0x05;/ 设置计数器 0 工作方式 1ET0=1; / 打开计数器 0 中断TR0=1;/ 启动定时器 0void beep_interrupt() interrupt 1 / 计数器 0 中断服务子程序 #include#define uint unsigned int#define uchar unsigned charuchar table15=0xfe,0xfd,0xfb,0xf7,0

14、xef,0xdf,0xbf,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe;uint count,i,num;void int_int()EX0=1;/ 允许外部中断EX1=1;void key1_1() interrupt 0void key2_2() interrupt 2 void timer_0() interrupt 1 12MHz , 单片机 P0,P2 端口作为输出口,外接#define uchar unsigned char TMOD=0X01; 单片机甲机的 P3.2 外接按键 K1,P3.3 外接按键;单片机乙机P0、P2 端口作为输出口,外始/暂停”控制按键,甲机的按键PC 发送过来的 09 的数字,并将接受的科教兴国43

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


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