• max7219 八位数码管


    #include <stdio.h>
    #include <stdint.h>
    
    typedef enum {
    	DIGIT_1 = 1, DIGIT_2 = 2, DIGIT_3 = 3, DIGIT_4 = 4,
    	DIGIT_5 = 5, DIGIT_6 = 6, DIGIT_7 = 7, DIGIT_8 = 8
    } MAX7219_Digits;
    
    static uint32_t lcdPow10(uint8_t n)
    {
    	uint32_t retval = 1u;
    
    	while (n > 0u)
    	{
    		retval *= 10u;
    		n--;
    	}
    
    	return retval;
    }
    
    MAX7219_Digits max7219_PrintNtos(MAX7219_Digits position, uint32_t value, uint8_t n)
    {
    	if (n > 0u)
    	{
    		uint32_t i = lcdPow10(n - 1u);
    
    		while (i > 0u)	/* Display at least one symbol */
    		{
    			if(position > 0u)
    			{
    				printf("i : [%d]\n",(value / i) % 10u);
    				position--;
    			}
    
    			i /= 10u;
    		}
    	}
    	return position;
    }
    
    int main(int argc, char **argv)
    {
    	max7219_PrintNtos(DIGIT_8,12345678,8);
    return 0;
    
    }
    i : [1]
    i : [2]
    i : [3]
    i : [4]
    i : [5]
    i : [6]
    i : [7]
    i : [8]
    
    

    https://www.21ic.com/embed/hardware/drivers/201801/50256.html
    http://news.eeworld.com.cn/LED/article_2018012012418.html

    #define DECODE_MODE  0x09   //译码控制寄存器
    #define INTENSITY    0x0A   //亮度控制寄存器
    #define SCAN_LIMIT   0x0B   //扫描界限寄存器
    #define SHUT_DOWN    0x0C   //关断模式寄存器
    #define DISPLAY_TEST 0x0F   //测试控制寄存器        
        Write7219(SHUT_DOWN,0x01);         //开启正常工作模式(0xX1)
        Write7219(DISPLAY_TEST,0x00);      //选择工作模式(0xX0)
        Write7219(DECODE_MODE,0xff);       //选用全译码模式
        Write7219(SCAN_LIMIT,0x07);        //8只LED全用
        Write7219(INTENSITY,0x04);          //设置初始亮度     
    
    (1)        译码控制寄存器(X9H)
    如图4所示,MAX7219有两种译码方式:B译码方式和不译码方式。当选择不译码时,8个数据为分别一一对应7个段和小数点位;B译码方式是BCD译码,直接送数据就可以显示。实际应用中可以按位设置选择B译码或是不译码方式。
    	w_max7219(0x09, 0x00); //译码方式,0x00为不译码,0xff为译码[!--empirenews.page--]
    
    (2)        扫描界限寄存器(XBH)
    如图5所示,此寄存器用于设置显示的LED的个数(1~8),比如当设置为0xX4时,LED 0~5显示。
    	w_max7219(0x0b, 0x07); //8位扫描显示,取值范围0x01~0x07
    (3)        亮度控制寄存器(XAH)
    共有16级可选择,用于设置LED的显示亮度,从0xX0~0xXF
    	w_max7219(0x0a, 0x01); //显示亮度,取值范围0~f
    (4)        关断模式寄存器(XCH)
    共有两种模式选择,一是关断状态,(最低位 D0=0)一是正常工作状态(D0=1)。
    	w_max7219(0x0c, 0x01); //操作方式,0x00为低功耗模式,0x01为正常操作模式
    (5)        显示测试寄存器(XFH)
    用于设置LED是测试状态还是正常工作状态,当测试状态时(最低位 D0=1)各位显示全亮,正常工作状态(D0=0)。
    各寄存器具体操作见驱动程序详解。
    	w_max7219(0x0f, 0x00); //显示状态,0x00为正常显示,0x01为显示测试
    

    bit顺序

    /*
     *   AAAAAA\      
     *  FF  __BB\     
     *  FF /  BB |    
     *   GGGGGG  |    
     *  EE  __CC<     
     *  EE /  CC |    
     *  \DDDDDD  |  DP\ 
     *   \______/   \__|
     *  
     *    数码管
     */
    disp_table[i]| (1 << 7) 打开dp方法
    unsigned char disp_table[] = {
    //0x7e, 0x30, 0x6d, 0x79, 0x33, 0x5b, 0x5f, 0x70, 0x7f, 0x7b, 0x77, 0x1f, 0x4e, 0x3d, 0x01, 0x00
    //dp,a,b,c,d,e,f,g 位
    0b01111110,//0
    0b00110000,//1
    0b01101101,
    0b01111001,
    0b00110011,
    0b01011011,
    0b01011111,
    0b01110000,
    0b01111111,
    0b01111011,
    0b01110111,
    0b00011111,
    0b01001110,
    0b00111101,
    0b00000001,
    0b00000000
    };
    static const uint8_t to_ascii_tab[][2] = {
        'A', 0x77,  '=',0x09,
        'B', 0x1F,  '-',0x01,
        'C', 0x4E,  '+',0x31,
        'D', 0x3D,  '(',0x4E,
        'E', 0x4f,  ')',0x78,
        'F', 0x47,  0,  0,
        'G', 0x5e,
        'H', 0x37,
        'I', 0x78,
        'J', 0x38,
        'K', 0x57,
        'L', 0x0e,
        'M', 0x76,
        'N', 0x15,
        'O', 0x1d,
        'P', 0x67,
        'Q', 0x73,
        'R', 0x46,
        'S', 0x49,
        'T', 0x0f,
        'U', 0x3e,
        'V', 0x1c,
        'W', 0x3f,
        'X', 0x13,
        'Y', 0x3b,
        'Z', 0x2d,
    };
    
    /*
    *********************************************************************************************************
    * LED Segments:         a
    *                     ----
    *                   f|    |b
    *                    |  g |
    *                     ----
    *                   e|    |c
    *                    |    |
    *                     ----  o dp
    *                       d
    *   Register bits:
    *      bit:  7  6  5  4  3  2  1  0
    *           dp  a  b  c  d  e  f  g
    *********************************************************************************************************
    * Example : The letter 'I' is represented by illuminating LED's 'b' and 'c' (refer above diagram)
    *           Therfore the binary representation of 'I' is as follows
    *
    *           abcdefg
    *           0110000
    * 
    *           The table below contains all the binary values for the desired font. New font characters
    *           can be added or altered as required. 
    *           
    *           The DP bit is used to switch on the decimal place LED. DP is not included in the below table
    *           but is added in the register within the libary depending on the content being displayed.  
    *********************************************************************************************************
    
    */
    

    点阵屏

    https://blog.csdn.net/qq_36955622/article/details/114090207
    
    

    arduion

    https://zhuanlan.zhihu.com/p/353321881
    
  • 相关阅读:
    javascript 如何获取return回来的对象值
    遮罩层背景设置
    Javascript跨域请求的几种解决方法
    手机端viewport的设置规范
    javascript定义类和类的实现
    javascript 中对this关键字的一些理解
    实例化对象的时候。其实就是调用构造函数
    Javascript定义类(class)的三种方法
    javascript面向对象基础讲解(工厂模式、构造函数模式、原型模式、混合模式、动态原型模式)
    JavaScript判断横屏/竖屏
  • 原文地址:https://www.cnblogs.com/marklove/p/15717505.html
Copyright © 2020-2023  润新知