




已阅读5页,还剩11页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
*数码管动态显示*#include#define uint unsigned int#define uchar unsigned charsbit dula=P37;uchar code table1=0,1,2,3,4,5,6,7;uchar code table=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71;void delay(uint z);void main()uchar i=0;uchar num=0;while(1)P0=tablenum;P2=table1i;delay(2);num+;i+;if(i=8)num=0;i=0 ;void delay(uint z)uint x,y;for(x=100;x0;x-)for(y=z;y0;y-);*数码管静态显示*#include#define uint unsigned int#define uchar unsigned charsbit dula=P37;sbit wela=P2;void delay(uint z);void main()wela=1;P2=0xf8;wela=0;dula=1;P0=0x71;dula=0;while(1);void delay(uint z)uint x,y;for(x=100;x0;x-)for(y=z;y0;y-);*流水灯*#include#include #define uint unsigned int#define uchar unsigned charuchar a;uint i,j;void delay(uint);void main() a=0xfe;P0=a;while(1)a=_crol_(a,1);delay(600);P0=a;delay(600); void delay(uint z)uint x,y;for(x=10;x0;x-)for(y=z;y0;y-);*跑马灯* #include#define LED P0void delay()unsigned int i;for(i=0;i10000;i+);void main()unsigned char i,k;for(;)k=0xfe;for(i=0;i8;i+)LED=k;delay();k=k1;*#include#define uint unsigned int#define uchar unsigned char#define wela P2sbit dula=P37;sbit led=P00;uchar code table1=0,1,2,3,4,5,6,7;uchar code table=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71;void main()wela=1;P2=0xff;wela=1;dula=1;P0=0x71;dula=0;while(1);/*uchar i,num;while(1)wela=table1i;for(i=0;i8;i+)dula=1;P0=tablenum;dula=0;num+;i+; */*中断*#include#define uint unsigned int#define uchar unsigned char#define wela P2sbit dula=P37;sbit led=P12;uchar i,num;uchar code table1=0xff,0xfe,0xfd,0xfc,0xfb,0xfa,0xf9,0xf8;uchar code table=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71;void delay(uint);void main()EA=1;EX0=1;IT0=1; while(1)wela=table1i;dula=1;P0=tablenum;delay(6000);dula=0;num+;i+;if(i=8)i=0;if(num=16)num=0; void delay(uint z)uint x,y;for(x=10;x0;x-)for(y=z;y0;y-);void exter0() interrupt 0led=0;*定时器*#include#define uint unsigned int#define uchar unsigned char#define wela P2sbit dula=P37;sbit led=P12;uchar i,num,tt;uchar code table1=0xff,0xfe,0xfd,0xfc,0xfb,0xfa,0xf9,0xf8;uchar code table=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71;void delay(uint);void main()tt=0;TMOD=0x01;/设置定时器0为工作方式1TH0=(65536-50000)/256;TL0=(65536-50000)%256;EA=1;ET0=1;/开定时器0中断TR0=1; while(1) if(tt=4) tt=0;wela=table1i;dula=1;P0=tablenum;dula=0;num+;i+;if(i=8)i=0;if(num=16)num=0; void delay(uint z)uint x,y;for(x=10;x0;x-)for(y=z;y0;y-);void exter0() interrupt 1TH0=(65536-50000)/256;TL0=(65536-50000)%256;tt+;*矩阵键盘*#include#define uint unsigned int#define uchar unsigned charsbit dula=P37;uchar code table=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0;uchar num,temp,num1;uchar keyscan();void delay(uint z)uint x,y;for(x=100;x0;x-)for(y=z;y0;y-);void main()num=17; P2=0xff;dula=1;P0=0;dula=0;P0=0xff;while(1)num1=keyscan();dula=1;P0=tablenum1-1;dula=0; uchar keyscan()P1=0xfe;temp=P1;temp=temp&0xf0;while(temp!=0xf0)delay(5);temp=P1;temp=temp&0xf0;while(temp!=0xf0) switch(temp)case 0xe0:num=1;break;case 0xd0:num=2;break;case 0xb0:num=3;break;case 0x70:num=4;break;while(temp!=0xf0)temp=P1;temp=temp&0xf0; P1=0xfd;temp=P1;temp=temp&0xf0;while(temp!=0xf0)delay(5);temp=P1;temp=temp&0xf0;while(temp!=0xf0) switch(temp)case 0xe0:num=5;break;case 0xd0:num=6;break;case 0xb0:num=7;break;case 0x70:num=8;break;while(temp!=0xf0)temp=P1;temp=temp&0xf0;P1=0xfb;temp=P1;temp=temp&0xf0;while(temp!=0xf0)delay(5);temp=P1;temp=temp&0xf0;while(temp!=0xf0) switch(temp)case 0xe0:num=9;break;case 0xd0:num=10;break;case 0xb0:num=11;break;case 0x70:num=12;break;while(temp!=0xf0)temp=P1;temp=temp&0xf0;P1=0xf7;temp=P1;temp=temp&0xf0;while(temp!=0xf0)delay(5);temp=P1;temp=temp&0xf0;while(temp!=0xf0) switch(temp)case 0xe0:num=13;break;case 0xd0:num=14;break;case 0xb0:num=15;break;case 0x70:num=16;break;while(temp!=0xf0)temp=P1;temp=temp&0xf0;return num;*串行通信*#includeunsigned char flag,a;void main()TMOD=0x20;/设置定时器1为工作方式2TH1=0xfd;TL1=0xfd;TR1=1;REN=1;SM0=0;SM1=1;EA=1;ES=1;while(1)/*if(RI=1)RI=0;P0=SBUF; */if(flag=1)ES=0;flag=0;SBUF=a;while(!TI);TI=0;ES=1;void ser() interrupt 4RI=0;P0=SBUF;a=SBUF;flag=1;*E2p*#include#define uchar unsigned charsbit sda=P36;sbit scl=P15;uchar a;void delay();void delay1(uchar x)uchar a,b;for(a=x;a0;a-)for(b=100;b0;b-);void start()/开始信号sda=1;delay();scl=1;delay();sda=0;delay();void stop() /停止信号sda=0;delay();scl=1;delay();sda=1;delay();void respons() /应答信号char i;scl=1;delay();while(sda=1)&(i250)i+;scl=0;delay();void init()sda=1;scl=1;void write_byte(uchar date)uchar i,temp;temp=date ;scl=0;delay();for(i=0;i8;i+) temp=temp1;sda=CY;delay();scl=1;delay();scl=0;delay();sda=1;delay();uchar read_byte()uchar i,j,k;scl=0;delay();sda=1;delay();for(i=0;i8;i+)scl=1;delay();j=sda;k=(k1)|j;scl=0;delay();return k;void write_add(uchar address,uchar date)start();write_byte(0xa0);respons();write_byte(address);respons();write_byte(date);respons();stop();uchar read_add(uchar address)uchar date;start();write_byte(0xa0);respons();write_byte(address);respons();start();write_byte(0xa1);respons();date=read_byte();stop();return date;void main()init();write_add(23,0xaa);delay1(100);P0=read_add(23); while(1);*计数*#include#define uint unsigned int#define uchar unsigned char#define wela P2sbit dula=P37;uchar ge,shi,bai,num,temp,aa,numdu;uchar code table1=0xff,0xfe,0xfd,0xfc,0xfb,0xfa,0xf9,0xf8;uchar code table=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 乐器制造行业绿色制造模式-洞察及研究
- 微电子废弃物资源化途径探讨-洞察及研究
- 教育质量评估体系的构建与优化-洞察及研究
- 大数据赋能供应链响应能力提升-洞察及研究
- 基于行为分析的入侵检测算法优化-洞察及研究
- 脑梗塞的护理试题及答案
- 幼儿园亲子活动策划方案及实施总结
- 小学英语口语表达能力训练册
- 医学遗传学重点复习选择题集
- 企业数字化转型管理实践案例汇编
- 义务教育阶段中小学学生转学申请表
- 高速公路工程电子招标标准施工招标文件(2022年试行版)
- 云南省临沧县富康河铜矿勘探项目环评报告
- 公司档案分类方案
- 茶学概论-第一章-茶的起源与传播(2学时)课件
- 网络空间安全导论-西北工业大学中国大学mooc课后章节答案期末考试题库2023年
- 宋小宝小品《碰瓷》完整台词
- 破产管理人考试题库及答案
- 中国建筑史PPT(东南大学)完整全套教学课件
- 重庆.住宅物业单位服务等级标准
- 9第九章-心境障碍PPT
评论
0/150
提交评论