首页 > 代码库 > AVR第7课:动态数码管
AVR第7课:动态数码管
以下是动态数码管的电路图。
代码:动态数码管。
/* *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课:动态数码管
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。