为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

跑马灯实验代码

2019-05-09 24页 doc 42KB 71阅读

用户头像

is_769254

暂无简介

举报
跑马灯实验代码一、在PORTB口的小灯上循环显示跑马灯。 方法1:查表 #include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ const unsigned char patten[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; void delay(unsigned int countert) { unsigned int i,j;...
跑马灯实验代码
一、在PORTB口的小灯上循环显示跑马灯。 1:查表 #include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ const unsigned char patten[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; void delay(unsigned int countert) { unsigned int i,j; for(i=0;i /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ void delay(unsigned int countert) { unsigned int i,j; for(i=0;i>=1; PORTB|=0x80; if(PORTB==0xFF) PORTB=0x7F; } } ******************************************************************************* ******************************************************************************* 二、将PORTA口接8位DIP开关,在PORTB口的小灯上显示其状态。 方法1:DIP开关由A口输入,B口显示 #include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ const unsigned char patten[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};//表格应该是没用 void delay(unsigned int countert) { unsigned int i,j; for(i=0;i /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ void delay(unsigned int countert) { unsigned int i,j; for(i=0;i /* common defines and macros */ #include "derivative.h" /* derivative-specif unsigned char flag; const unsigned char patten[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; void delay(unsigned int countert) { unsigned int i,j; for(i=0;i /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ unsigned char flag; void delay(unsigned int countert) { unsigned int i,j; for(i=0;i>=1; PORTB|=0x80; if(PORTB==0xFF) PORTB=0x7F; } delay(j); } } void interrupt 6 IRQ(void) { flag=1; } ******************************************************************************* ******************************************************************************* 四、利用IRQ作为中断源,采用中断方式,利用8位DIP开关控制跑马灯的循环速度。#include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ unsigned char flag; void delay(unsigned int countert) { unsigned int i,j; for(i=0;i>=1; PORTB|=0x80; if(PORTB==0xFF) PORTB=0x7F; } } void interrupt 6 IRQ(void) { flag=1; } ******************************************************************************* ******************************************************************************* 五、利用XIRQ作为中断源,采用中断方式,利用8位DIP开关控制跑马灯的循环速度。方法同四,只是中断函数不同: Void interrupt 5 XIRQ(void) { flag=1; } ******************************************************************************* ******************************************************************************* 六、将PORTA口低4位接DIP开关,高4位接LED,将开关的状态显示在LED灯上,重复五 #include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ unsigned char flag; const unsigned char patten[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; void delay(unsigned int countert) { unsigned int i,j; for(i=0;i /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ unsigned char flag; const unsigned char patten[16]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0 x80}; void delay(unsigned int countert) { unsigned int i,j; for(i=0;i /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ unsigned char flag; void delay(unsigned int countert) { unsigned int i,j; for(i=0;i>=1; PORTB|=0x80; if(PORTB==0xFF) { PORTB=0x3F; for(;;) { delay(j); PORTB>>=1; PORTB|=0x80; if(PORTB==0xFF) { PORTB=0x1F; for(;;) { delay(j); PORTB>>=1; PORTB|=0x80; delay(j); if(PORTB==0xFF) { PORTB=0x0F; for(;;) { delay(j); PORTB>>=1; PORTB|=0x80; if(PORTB==0xFF) goto back; } } } } } } } } void interrupt 6 IRQ(void) { flag=1; }
/
本文档为【跑马灯实验代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索