AVR学习日志(四)---- 花样流水灯

呵呵,那天貌似写流水灯写上瘾了,再来一个了……
/******************************************************************
//文件名称:led_tri
//功    能:实现Led灯花样闪烁
//作    者:懒猫爱飞
//日    期:2010.05.23
*******************************************************************/
#include<iom8515v.h>
#include<macros.h>
#define uchar unsigned char
#define uint  unsigned int
#define Bit(n) (1<<n)
__flash uchar Pattern_PORTB[]=
{
  0xfc,0xf9,0xf3,0xe7,0xcf,0x9f
};
__flash uchar  Pattern_PORTD[]=
{
  0xf5,0xf6,0xfe,0x54,0x56,0x76,0xd7,0x49,0xa9,0xe4,0xc6
};
/****************************************************************
//函数名称: delay(void)
//功    能:延时
//入口参数:无
//出口参数:无
*****************************************************************/
void delay(void)
{
uint i;
for(i=1;i<100;i++)
    ;
}
/****************************************************************
//函数名称:delay_1ms(void)
//功    能:延时1ms
//入口参数:无
//出口参数:无
*****************************************************************/
void delay_1ms(void)//1ms
{
uint i;
for(i=1;i<(uint)(8*143-2);i++)
    ;
}
/****************************************************************
//函数名称:delay_ms(uint time)
//功    能:延时time ms
//入口参数:time
//出口参数:无
*****************************************************************/
void delay_ms(uint time)//time*1ms
{
   uint i="0";
   while(i<time)
   {
   delay_1ms();
    i++;
   }
}
/****************************************************************
//函数名称:Port_init(void)
//功    能:端口初始化
//入口参数:无
//出口参数:无
*****************************************************************/
void Port_init(void)
{
DDRA  = 0x00;   //A口设为输入,呈高阻状态  
PORTA = 0x00;

DDRB  = 0xff;         //B口为输出,控制灯闪烁
PORTB = 0xff;

DDRC  = 0x00;   //C口
PORTC = 0x00;

DDRD  = 0xff;   //D口输出,控制灯闪烁
PORTD = 0xff;
}
/****************************************************************
//函数名称:main(void)
//功    能:主程序
//入口参数:无
//出口参数:无
*****************************************************************/
void main(void)
{
uchar i;
Port_init();
while(1)
{
  for(i=0;i<8;i++)//up to down
  {
   PORTB=~(1<<i);
   delay_ms(150);
  }
  for(i=7;i>0;i--)//down to up
  {
   PORTD=~(1<<i);
   delay_ms(150);
  }
  for(i=136;i>0;i--)
  {
   PORTB="Pattern"_PORTB[i];
   PORTD="Pattern"_PORTD[i];
   delay_ms(150);
  }
}
}
 
 
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值