懒猫爱飞

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

0
阅读(1539)

呵呵,那天貌似写流水灯写上瘾了,再来一个了……
 /******************************************************************
//文件名称: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);
  }
 }
}
 
  每天进步一点点,开心多一点^_^