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

AVR第7课:动态数码管

时间:2014-11-20 15:22:41      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:单片机   avr   avr基础知识   动态数码管   共阴极数码管   


以下是动态数码管的电路图。

bubuko.com,布布扣

代码:动态数码管。

/*
*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;
uchar table[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07};

//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++)
		{
		    PORTC = ~(PORTC | BIT(0));	
		    PORTA = table[flag]; 
		    PORTB = ~BIT(flag);
		    PORTC = PORTC | BIT(0);
		    delay();
		}	
		
	}
}

//the method of init system
void initSystem()
{
 	//control PA
	DDRA = 0xFF;
	PORTA = table[0];
	//to make PB port output 
	DDRB = 0xFF;
	//to make PB port output high level
	PORTB = 0xFE;
	
	//control PC0
	DDRC = DDRC | BIT(0);
	PORTC = PORTC | BIT(0);
}

//the sub method of delay
void delay()
{
 	uint i,j;
 	for(i=0;i<10;i++)
	  for(j=0;j<5;j++);
}
不断改变delay()函数中变量的值,会出现不一样的效果。主要是熟悉AVR单片机IO口的使用。

AVR第7课:动态数码管

标签:单片机   avr   avr基础知识   动态数码管   共阴极数码管   

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

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