资源预览内容
第1页 / 共84页
第2页 / 共84页
第3页 / 共84页
第4页 / 共84页
第5页 / 共84页
第6页 / 共84页
第7页 / 共84页
第8页 / 共84页
第9页 / 共84页
第10页 / 共84页
亲,该文档总共84页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
微控制器系统设计与应用刘燎原江苏建筑职业技术学院实验 1.KEIL使用步骤 2.单片机开发板使用方法,烧录程序步骤 3. K1按下, 8个流水灯从上到下逐个点亮,若K1断开, 8个流水灯从 下到上逐个点亮,然后依次循环u #include /包含AT89X52.H头文件 u sbit k1=P34;unsigned char code sz1=0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f; u void Delay(unsigned int t) u u unsigned int i, j; u for(i=0;i /包含AT89X52.H头文件 u #include u sbit k1=P34; u void Delay(unsigned int t) u u unsigned int i, j; u for(i=0;i u unsigned char code sz1=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa 1,0x86,0x8e ; u void delay(unsigned int a) u uunsigned char i; uwhile(a-) u ufor(i=0;i u void delay(unsigned int a) u uunsigned char i; uwhile(a-) u ufor(i=0;i u unsigned char code sz1=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0 x88,0x83,0xc6,0xa1,0x86,0x8e; u void delay(unsigned int a) u uunsigned char i; uwhile(a-) u ufor(i=0;i u unsigned char code sz1=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88, 0x83,0xc6,0xa1,0x86,0x8e ; u void delay(unsigned int a) u uunsigned char i; uwhile(a-) u ufor(i=0;i usbit s1=P32; uunsigned char code sz1=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83, 0xc6,0xa1,0x86,0x8e ; uvoid delay(unsigned int a) u uunsigned char i; uwhile(a-) u ufor(i=0;i u #include u unsigned char code sz1=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x 83,0xc6,0xa1,0x86,0x8e; u void delay(unsigned int a) u uunsigned char i; uwhile(a-) u ufor(i=0;i uunsigned char code sz1=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0 x8e; usbit seg1=P36; usbit seg2=P37; uvoid delay(unsigned int a) u uunsigned char i; uwhile(a-) u ufor(i=0;i usbit dzh=P26;/段选信号的锁存器控制 usbit weix=P27;/位选信号的锁存器控制 uunsigned char code sz1=0x3F,0x06,0x5B,0x4F,0x66,0x6d,0X7d,0X07,0X7f,0X6f; /数码管段值数组 uunsigned char code sz2=0xfe,0xfd,0xfb; /数码管位选信号数组 uunsigned char sz3=0x00,0x00,0x00; uvoid delay(unsigned int a) u uunsigned int b; uwhile(a-) ufor(b=0;b usbit dzh=P26;/段选信号的锁存器控制 usbit weix=P27;/位选信号的锁存器控制 uunsigned char code sz1=0x3F,0x06,0x5B,0x4F,0x66,0x6d,0X7d,0X07,0X7f,0X6f; / 数码管段值数 uvoid delay(unsigned int a) u uunsigned int b; uwhile(a-) ufor(b=0;b u #include u void delay(unsigned int a) u unsigned char i; uwhile(-a!= 0) u for(i=0;i /包含AT89X52.H头文件 uunsigned char code sz1=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x 86,0x8e; uunsigned char m; usbit dua=P36; usbit wei=P37; uvoid delay(unsigned int a) u uunsigned char i; uwhile(a-) u ufor(i=0;i u unsigned char code sz1=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0 x86,0x84; u void delay(unsigned int a) u unsigned char i; uwhile(a-) u for(i=0;i u #include u unsigned char code sz1=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86, 0x84,0x8e; u unsigned char m=0; u void delay(unsigned int a) u uunsigned char i; uwhile(-a!= 0) u ufor(i=0;i /包含AT89X52.H头文件 u unsigned char code sz1=0x3F,0x06,0x5B,0x4F,0x66,0x6d,0X7d,0X07,0X7f,0X6f; u unsigned char m; u sbit dua=P26; u sbit wei=P27; u sbit s=P37;u void delay(unsigned int a) u uunsigned char i; uwhile(a-) u ufor(i=0;i120;i+); u u u void disp(unsigned char m) u u unsigned char i,j; u i=m/10; u j=m%10; u u dua=1; u P0=sz1i; u dua=0; u u wei=1; u P0=0xfe; u wei=0; u u delay(5); u u dua=1; u P0=sz1j; u dua=0; u u wei=1; u P0=0xfd; u wei=0; u u delay(5); u u void main() u u s=0; u EA=1;EX0=1;IT0=1; u while(1) u u disp(m); u u u void zd0() interrupt 0 u u m+; u if(m=100) u m=0; u 例:矩阵键盘接外部中断有键按下时,对 应的u四、外部中断的扩展对多个外部中断源,采用中断加查询相结合的方法响应中断扩展电路原理如下图所示。中断加查询? 中断:4个外部中断源(有中断请求,输出高电平)通过或非门电路后产生0与P3.2(P3.3)相连,向CPU产生中断请求。 查询:每一个外部中断源和1个并行I/O口相连,通过逐个查询的方式,来识别哪根线上有 中断请求。(类似于矩阵键盘中的行扫描) 方法:在多个外部中断源中若有一个或几个为高电平则输出为0,则P3.2(P3.3)为低电平 ,向CPU发出中断请求;CPU在执行中断服务程序时,先依次查询P1口的中断源输入状 态,然后转入到相应的中断服务程序。课后作业:课后自己完成多个中断源, 主程序、中断服务子程序的编写1u实验:记录按键的次数(2位数码管动态显示),并且设置 一个清零键。按下清零键,从0开始计按键次数。
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号