跑马灯实验代码
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
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<countert;i++)
DDRB=0xFF;
PORTB=0x7F;
DDRA=0xF0;
PORTA=PORTA|0x80;
flag=0;
asm ANDCC #$BF
EnableInterrupts;
i=0;
j=10;
m=2;
n=4;;
for(;;)
{
if(flag==1)
{
flag=0;
settime=PORTA&0x7f;
j=10;
for(;;)
{
if(flag==1)
{
flag=0;
settime=PORTA;
j=settime*10;
}
delay(j);
PORTA=PORTA<<4;
}
}
void interrupt 5 XIRQ(void)
{
flag=1;
}
*******************************************************************************
一、在PORTB口的小灯上循环显示跑马灯。
方法1:查表
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
const unsigned char patten[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
三、利用IRQ作为中断源,采用中断方式,按动IRQ键后显示跑马灯。
#include <hidef.h> /* 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};
二、将PORTA口接8位DIP开关,在PORTB口的小灯上显示其状态。
方法1:DIP开关由A口输入,B口显示
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
for(j=0;j<10000;) j++;
}
void main(void)
{
unsigned int j;
DDRB=0xFF;
PORTB=0x00;
DDRA=0xF0;
flag=0;
asm ANDCC #$BF
EnableInterrupts;
j=10;
for(;;)
{
if(flag==1)
{
//flag=0;//这里有些不理解,如果flag=0,岂不是每按一次灯只能循环显示一次就变为初态了吗???
void delay(unsigned int countert)
{
unsigned int i,j;
for(i=0;i<countert;i++)
for(j=0;j<10000;) j++;
}
void main(void)
{
unsigned char i;
unsigned int j;
DDRB=0xFF;
for(;;)
{
delay(j);
PORTB>>=1;
PORTB|=0x80;
if(PORTB==0xFF)
PORTB=0x7F;
}
}
**************************************************************************************************************************************************************
PORTB|=0x80;
if(PORTB==0xFF)
PORTB=0x7F;
}
}
void interrupt 6 IRQ(void)
{
flag=1;
}
**************************************************************************************************************************************************************
for(j=0;j<10000;) j++;
}
void main(void)
{
unsigned char i,settime;
unsigned int j;
DDRB=0xFF;
PORTB=0x7F;
DDRA=0xF0;
flag=0;
asm ANDCC #$BF
EnableInterrupts;
i=0;
五、利用XIRQ作为中断源,采用中断方式,利用8位DIP开关控制跑马灯的循环速度。
方法同四,只是中断函数不同:
Void interrupt 5 XIRQ(void)
{
flag=1;
}
**************************************************************************************************************************************************************
void delay(unsigned int countert)
{
unsigned int i,j;
for(i=0;i<countert;i++)
for(j=0;j<2;) j++;
}
void main(void)
{
unsigned char i,settime;
unsigned int j,m,n;
PORTB=0x7F;
i=0;
j=10;
for(;;)
{
delay(j);
i++;
PORTB = ~patten[i%8];
}
}
方法2:移位
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include "derivative.h" /* derivative-specific definitions */
unsigned char flag;
void delay(unsigned int countert)
{
unsigned int i,j;
for(i=0;i<countert;i++)
PORTB=PORTA;
}
}
方法2:DIP开关低四位由A口低四位输入,经A口高四位送LED灯低四位输出
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
unsigned int j;
DDRB=0xFF;
PORTB=0x7F;
DDRA=0xF0;
flag=0;
asm ANDCC #$BF
EnableInterrupts;
for(;;)
{
if(flag==1)
{
flag=0;
settime=PORTA;
j=settime*10;
}
delay(j);
PORTB>>=1;
void delay(unsigned int countert)
{
unsigned int i,j;
for(i=0;i<countert;i++)
for(j=0;j<10000;) j++;
}
void main(void)
{
unsigned int j;
DDRB=0xFF;
PORTB=0x7F;
j=2;
j=settime*10;
PORTA=PORTA&0x7f;
}
delay(j);
i++;
PORTB = ~patten[i%8];
void interrupt 6 IRQ(void)
{
flag=1;
}
个人理解的程序。实现功能为:在不按IRQ的时候显示的为所有灯都亮。每按动一下IRQ跑马灯就跑一次。
#include <hidef.h> /* common defines and macros */
unsigned char flag;
void delay(unsigned int countert)
{
unsi来自百度文库ned int i,j;
for(i=0;i<countert;i++)
for(j=0;j<10000;) j++;
}
void main(void)
{
unsigned char settime;
*******************************************************************************七、自己设计一种小灯的显示方式。(小灯的显示方式、开关与LED灯的对应关系、中断源的控制方式)
PORTB>>=1;
PORTB|=0x80;
if(PORTB==0xFF)PORTB=0x7F;
}
delay(j);
}
}
void interrupt 6 IRQ(void)
{
flag=1;
}
**************************************************************************************************************************************************************
j=10;
for(;;)
{
delay(j);
PORTA=PORTA<<4;
}
}
**************************************************************************************************************************************************************
for(j=0;j<10000;) j++;
}
void main(void)
{
unsigned char i;
unsigned int j;
DDRB=0xFF;//注意一下这里的赋值
PORTB=0x7F;
DDRA=0xFF;
i=0;
j=10;
for(;;)
{
delay(j);
i++;//应去掉
PORTA = ~patten[i%8];//此行应该去掉,实验时将DIP开关的状态赋给PORTA
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<countert;i++)
void delay(unsigned int countert)
{
unsigned int i,j;
for(i=0;i<countert;i++)
for(j=0;j<10000;) j++;
}
void main(void)
{
unsigned int j;
DDRB=0xFF;
PORTB=0xFF;
DDRA=0xF0;
四、利用IRQ作为中断源,采用中断方式,利用8位DIP开关控制跑马灯的循环速度。
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
六、将PORTA口低4位接DIP开关,高4位接LED,将开关的状态显示在LED灯上,重复五
#include <hidef.h> /* 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<countert;i++)
DDRB=0xFF;
PORTB=0x7F;
DDRA=0xF0;
PORTA=PORTA|0x80;
flag=0;
asm ANDCC #$BF
EnableInterrupts;
i=0;
j=10;
m=2;
n=4;;
for(;;)
{
if(flag==1)
{
flag=0;
settime=PORTA&0x7f;
j=10;
for(;;)
{
if(flag==1)
{
flag=0;
settime=PORTA;
j=settime*10;
}
delay(j);
PORTA=PORTA<<4;
}
}
void interrupt 5 XIRQ(void)
{
flag=1;
}
*******************************************************************************
一、在PORTB口的小灯上循环显示跑马灯。
方法1:查表
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
const unsigned char patten[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
三、利用IRQ作为中断源,采用中断方式,按动IRQ键后显示跑马灯。
#include <hidef.h> /* 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};
二、将PORTA口接8位DIP开关,在PORTB口的小灯上显示其状态。
方法1:DIP开关由A口输入,B口显示
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
for(j=0;j<10000;) j++;
}
void main(void)
{
unsigned int j;
DDRB=0xFF;
PORTB=0x00;
DDRA=0xF0;
flag=0;
asm ANDCC #$BF
EnableInterrupts;
j=10;
for(;;)
{
if(flag==1)
{
//flag=0;//这里有些不理解,如果flag=0,岂不是每按一次灯只能循环显示一次就变为初态了吗???
void delay(unsigned int countert)
{
unsigned int i,j;
for(i=0;i<countert;i++)
for(j=0;j<10000;) j++;
}
void main(void)
{
unsigned char i;
unsigned int j;
DDRB=0xFF;
for(;;)
{
delay(j);
PORTB>>=1;
PORTB|=0x80;
if(PORTB==0xFF)
PORTB=0x7F;
}
}
**************************************************************************************************************************************************************
PORTB|=0x80;
if(PORTB==0xFF)
PORTB=0x7F;
}
}
void interrupt 6 IRQ(void)
{
flag=1;
}
**************************************************************************************************************************************************************
for(j=0;j<10000;) j++;
}
void main(void)
{
unsigned char i,settime;
unsigned int j;
DDRB=0xFF;
PORTB=0x7F;
DDRA=0xF0;
flag=0;
asm ANDCC #$BF
EnableInterrupts;
i=0;
五、利用XIRQ作为中断源,采用中断方式,利用8位DIP开关控制跑马灯的循环速度。
方法同四,只是中断函数不同:
Void interrupt 5 XIRQ(void)
{
flag=1;
}
**************************************************************************************************************************************************************
void delay(unsigned int countert)
{
unsigned int i,j;
for(i=0;i<countert;i++)
for(j=0;j<2;) j++;
}
void main(void)
{
unsigned char i,settime;
unsigned int j,m,n;
PORTB=0x7F;
i=0;
j=10;
for(;;)
{
delay(j);
i++;
PORTB = ~patten[i%8];
}
}
方法2:移位
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include "derivative.h" /* derivative-specific definitions */
unsigned char flag;
void delay(unsigned int countert)
{
unsigned int i,j;
for(i=0;i<countert;i++)
PORTB=PORTA;
}
}
方法2:DIP开关低四位由A口低四位输入,经A口高四位送LED灯低四位输出
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
unsigned int j;
DDRB=0xFF;
PORTB=0x7F;
DDRA=0xF0;
flag=0;
asm ANDCC #$BF
EnableInterrupts;
for(;;)
{
if(flag==1)
{
flag=0;
settime=PORTA;
j=settime*10;
}
delay(j);
PORTB>>=1;
void delay(unsigned int countert)
{
unsigned int i,j;
for(i=0;i<countert;i++)
for(j=0;j<10000;) j++;
}
void main(void)
{
unsigned int j;
DDRB=0xFF;
PORTB=0x7F;
j=2;
j=settime*10;
PORTA=PORTA&0x7f;
}
delay(j);
i++;
PORTB = ~patten[i%8];
void interrupt 6 IRQ(void)
{
flag=1;
}
个人理解的程序。实现功能为:在不按IRQ的时候显示的为所有灯都亮。每按动一下IRQ跑马灯就跑一次。
#include <hidef.h> /* common defines and macros */
unsigned char flag;
void delay(unsigned int countert)
{
unsi来自百度文库ned int i,j;
for(i=0;i<countert;i++)
for(j=0;j<10000;) j++;
}
void main(void)
{
unsigned char settime;
*******************************************************************************七、自己设计一种小灯的显示方式。(小灯的显示方式、开关与LED灯的对应关系、中断源的控制方式)
PORTB>>=1;
PORTB|=0x80;
if(PORTB==0xFF)PORTB=0x7F;
}
delay(j);
}
}
void interrupt 6 IRQ(void)
{
flag=1;
}
**************************************************************************************************************************************************************
j=10;
for(;;)
{
delay(j);
PORTA=PORTA<<4;
}
}
**************************************************************************************************************************************************************
for(j=0;j<10000;) j++;
}
void main(void)
{
unsigned char i;
unsigned int j;
DDRB=0xFF;//注意一下这里的赋值
PORTB=0x7F;
DDRA=0xFF;
i=0;
j=10;
for(;;)
{
delay(j);
i++;//应去掉
PORTA = ~patten[i%8];//此行应该去掉,实验时将DIP开关的状态赋给PORTA
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<countert;i++)
void delay(unsigned int countert)
{
unsigned int i,j;
for(i=0;i<countert;i++)
for(j=0;j<10000;) j++;
}
void main(void)
{
unsigned int j;
DDRB=0xFF;
PORTB=0xFF;
DDRA=0xF0;
四、利用IRQ作为中断源,采用中断方式,利用8位DIP开关控制跑马灯的循环速度。
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
六、将PORTA口低4位接DIP开关,高4位接LED,将开关的状态显示在LED灯上,重复五
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */