本帖最后由 werasd 于 2022-5-25 15:16 编辑
串行数码管显示模块的外观如图1所示,它具有输入端和输出端可多个模块级联起来使用,以显示更多位的数码值。
图1 串行数码管模块
串行数码管显示模块的电路原理图见图2所示,该模块采用5V电压来工作。
图2 原理图
该显示模块与开发板的连接关系为: SCL---PA2 SDA---PA3 CS ---PA4 图3 显示效果
Max7219字节数据发送函数为: void Write_Max7219_byte(unsigned char DATA)
{
unsigned char i;
GPIO_ClearOutBits(HT_GPIOA, GPIO_PIN_4);
__Delay(10);
for(i=8;i>=1;i--)
{
GPIO_ClearOutBits(HT_GPIOA, GPIO_PIN_2);
if(DATA&0x80) GPIO_SetOutBits(HT_GPIOA, GPIO_PIN_3);
else GPIO_ClearOutBits(HT_GPIOA, GPIO_PIN_3);
__Delay(10);
DATA=DATA<<1;
GPIO_SetOutBits(HT_GPIOA, GPIO_PIN_2);
__Delay(10);
}
}
Max7219写寄存器函数为: void Write_Max7219(char address,char dat)
{
GPIO_ClearOutBits(HT_GPIOA, GPIO_PIN_4);
Write_Max7219_byte(address);
Write_Max7219_byte(dat);
GPIO_SetOutBits(HT_GPIOA, GPIO_PIN_4);
}
Max7219初始化函数为: void Init_MAX7219(void)
{
Write_Max7219(0x09, 0xff);
Write_Max7219(0x0a, 0x03);
Write_Max7219(0x0b, 0x07);
Write_Max7219(0x0c, 0x01);
Write_Max7219(0x0f, 0x01);
}
主程序为: int main(void)
{
NVIC_Configuration();
CKCU_Configuration();
GPIO_Configuration();
RETARGET_Configuration();
T1_GPIO_Configuration();
Init_MAX7219();
__Delay(1000000);
Write_Max7219(0x0f, 0x00);
Write_Max7219(1,8);
Write_Max7219(2,7);
Write_Max7219(3,6);
Write_Max7219(4,5);
Write_Max7219(5,4);
Write_Max7219(6,3);
Write_Max7219(7,2);
Write_Max7219(8,1);
while (1)
{
;
}
}
|