这里就以Telink B91开发板来驱动一个8*8点阵的显示模块,当然在级联的情况下它就可显示更多的内容。
点阵模块与开发板的具体连接关系为:
CS ---PB5
为输出高低电平,所作的定义为:
#defineCLK_high gpio_set_level(GPIO_PB4, 1)
#defineCLK_low gpio_set_level(GPIO_PB4, 0)
#defineDIN_high gpio_set_level(GPIO_PB5, 1)
#defineDIN_low gpio_set_level(GPIO_PB5, 0)
#defineCS_high gpio_set_level(GPIO_PB6, 1)
#defineCS_low gpio_set_level(GPIO_PB6, 0)
以GPIO口方式串行字节数据的函数为:
- voidWrite_Max7219_byte(unsignedchar DATA)
- {
- unsignedchar i;
- CS_low;
- for(i=8;i>=1;i--)
- {
- CLK_low;
- if(DATA&0x80)
- DIN_high;
- else
- DIN_low;
- DATA=DATA<<1;
- CLK_high;
- }
- }
Max7219向指定地址发送控制字的函数为:
- void Write_Max7219(unsignedchar address,unsignedchar dat)
- {
- CS_low;
- Write_Max7219_byte(address);
- Write_Max7219_byte(dat);
- CS_high;
- }
对Max7219进行初始化的函数为:
- voidInit_MAX7219(void)
- {
- Write_Max7219(0x09, 0x00);
- Write_Max7219(0x0a, 0x03);
- Write_Max7219(0x0b, 0x07);
- Write_Max7219(0x0c, 0x01);
- Write_Max7219(0x0f, 0x00);
- }
为了进行显示,所配置的字库结构为:
- unsignedchar disp1[38][8]=
- {
- {0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//0
- {0x10,0x30,0x50,0x10,0x10,0x10,0x10,0x10},//1
- {0x7E,0x2,0x2,0x7E,0x40,0x40,0x40,0x7E},//2
- ...
- {0x8,0x14,0x22,0x3E,0x22,0x22,0x22,0x22},//A
- {0x3C,0x22,0x22,0x3E,0x22,0x22,0x3C,0x0},//B
- {0x3C,0x40,0x40,0x40,0x40,0x40,0x3C,0x0},//C
- ...
- {0x8,0x7F,0x49,0x49,0x7F,0x8,0x8,0x8},//中
- {0xFE,0xBA,0x92,0xBA,0x92,0x9A,0xBA,0xFE},//国
- };
实现点阵模块显示测试的主程序为:
- intmain (void)
- {
- unsignedchar i,j;
- sys_init(LDO_1P4_LDO_1P8, VBAT_MAX_VALUE_GREATER_THAN_3V6);
- user_read_flash_value_calib();
- CCLK_24M_HCLK_24M_PCLK_24M;
- user_init();
- Init_MAX7219();
- while(1)
- {
- for(j=0;j<38;j++)
- {
- for(i=1;i<9;i++)
- Write_Max7219(i,disp1[j][i-1]);
- delay_ms(1000);
- }
- }
- return 0;
- }
经程序的编译与下载,其显示效果如图1至图3所示。
图1显示数字
图2 显示字符
图3显示汉字