跑马灯实验代码
- 格式:doc
- 大小:68.00 KB
- 文档页数:11
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
PORTB=PORTA;
}
}
方法2:DIP开关低四位由A口低四位输入,经A口高四位送LED灯低四位输出
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
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;
PORTB|=0x80;
if(PORTB==0xFF)
PORTB=0x7F;
}
}
void interrupt 6 IRQ(void)
{
flag=1;
}
**************************************************************************************************************************************************************
#include "derivative.h" /* derivative-specific definitions */
unsigned char flag;
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;
二、将PORTA口接8位DIP开关,在PORTB口的小灯上显示其状态。
方法1:DIP开关由A口输入,B口显示
#include <hidef.h> /* 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<countert;i++)
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 */
三、利用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,0xቤተ መጻሕፍቲ ባይዱ1};
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 */
*******************************************************************************七、自己设计一种小灯的显示方式。(小灯的显示方式、开关与LED灯的对应关系、中断源的控制方式)
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++)
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;
}
*******************************************************************************
五、利用XIRQ作为中断源,采用中断方式,利用8位DIP开关控制跑马灯的循环速度。
方法同四,只是中断函数不同:
Void interrupt 5 XIRQ(void)
{
flag=1;
}
**************************************************************************************************************************************************************
六、将PORTA口低4位接DIP开关,高4位接LED,将开关的状态显示在LED灯上,重复五
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
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;
PORTB>>=1;
PORTB|=0x80;
if(PORTB==0xFF)PORTB=0x7F;
}
delay(j);
}
}
void interrupt 6 IRQ(void)
{
flag=1;
}
**************************************************************************************************************************************************************
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;
for(j=0;j<10000;) j++;
}
void main(void)
{
unsigned char i;
unsigned int j;