zoukankan      html  css  js  c++  java
  • 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使用口。



    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    HDU2059(龟兔赛跑)
    pat 1012 The Best Rank
    pat 1010 Radix
    pat 1007 Maximum Subsequence Sum
    pat 1005 Sign In and Sign Out
    pat 1005 Spell It Right
    pat 1004 Counting Leaves
    1003 Emergency
    第7章 输入/输出系统
    第六章 总线
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4834878.html
Copyright © 2011-2022 走看看