码迷,mamicode.com
首页 > 其他好文 > 详细

AVR第4课:流水灯

时间:2014-11-20 12:09:29      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:avr   单片机   流水灯   

bubuko.com,布布扣


代码:流水灯程序。

/*
*info:led flow
*author:chenlu
*date:2014.11.20
*/

//input the head file so that the program can work normally
//iom16v---know the register
//macros---know the BIT(x)
#include<iom16v.h>
#include<macros.h>
//use those can make your study very conveninet
#define uint unsigned int
#define uchar unsigned char

//display methods 
void initSystem();
void delay();

//display the variable data
uchar flag;

//the main function
void main()
{
 	//init your system
	initSystem();
	while(1)
	{
	  	//start your function,and this is core solution
		for(flag=0;flag<8;flag++)
		{
		 	PORTA = BIT(flag);
			delay();
		}	 	 
	}
}

//the method of init system
void initSystem()
{
 	//to make PA port output 
	DDRA = 0xFF;
	//to make PA port output high level
	PORTA = 0xFF;
}

//the sub method of delay
void delay()
{
 	uchar i,j;
 	for(i=0;i<200;i++)
	  for(j=0;j<200;j++);
}

在这里就不上传实验结果图片了。读者自己揣摩循环的机制。利用了for循环和BIT(x)操作。

AVR第4课:流水灯

标签:avr   单片机   流水灯   

原文地址:http://blog.csdn.net/kotei_88_luluc_66/article/details/41308797

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!