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使用口。



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

  • 相关阅读:
    iOS NSProgress的使用
    GIT的 .gitignore 配置
    MagicalRecord入门教程
    CoreData的数据存储
    NSLog打印信息的从新设置
    大石头得博客
    exc_bad_access(code=1, address=0x789870)野指针错误
    oc 获取当前设备系统的版本号
    免证书真机调试脚本iphoneentitlements
    支持非arc
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4834878.html
Copyright © 2011-2022 走看看