那位大哥知道,如何通过MAX7219来实现LED的亮度调整?最好有源代码
发布网友
发布时间:2022-05-14 16:47
我来回答
共1个回答
热心网友
时间:2023-10-14 01:50
Send7219(0x0A,0x00);
0x0a寄存器就是你所以的亮度,在max7219的表格有对应的亮度输出。
如我上面的写的就是最小的亮度
还有1-F的没写,你可以在上面的查,后面的数字越大,越亮
有什么问题,消息给我
//The Drivers for MAX7219
//made by OurWay
//#include<reg52.h>
#include<intrins.h>
//#include"max7219.h"
//定义显示数字0-9数组
code unsigned char LEDcode[]={0x7e,0x50,0x6D,0x79,0x53,0x3B,0x3F,0x70,0x7F,0x7B,0x00};
//code unsigned char LEDcode[]={0x7e,0x30,0x6D,0x79,0x33,0x5B,0x5F,0x70,0x7F,0x7B,0x00};
//sbit IO7219=P2^0;
//sbit CLK7219=P2^2;
//sbit CS7219=P2^1; //根据实际情况定义
sbit IO7219=P1^2;
sbit CLK7219=P1^1;
sbit CS7219=P1^0; //根据实际情况定义
sbit ACC0=ACC^0;
sbit ACC7=ACC^7;
//Send 8bit data
void SendByte7219(unsigned char Dat)
{
unsigned char i;
ACC=Dat;
for(i=8;i>0;i--)
{
IO7219=ACC7;
CLK7219=1;
_nop_();
_nop_();
CLK7219=0;
ACC=ACC<<1;
}
}
//Send Command & Data
void Send7219(unsigned char CMD,unsigned char Dat)
{
CLK7219=0;
CS7219=0;
IO7219=0;
SendByte7219(CMD);
SendByte7219(Dat);
CS7219=1;
}
//The initialation MAX7219
void Init7219(void)
{
Send7219(0x0c,0x01); //Shutdown(normal operation)
Send7219(0x0a,0x08); //Intensity Register Format(31/32)
Send7219(0x0b,0x07); //Scan-Limit Register Format(Display digits 0 1 2 3 4 5 6 7)
Send7219(0x09,0x00); //Decode-Mode Register Examples(No decode for digits 7–0)
Send7219(0x0f,0x00); //Display-Test Register Format(normal operation)
}
void Clear7219(void)
{
unsigned char i;
for(i=8;i>0;i--)
{
Send7219(i,0x00);
}
}
/*main()
{
Init7219();
Clear7219();
//P1|=0x80;
for(;;)
{
Send7219(0x01,LEDcode[5]);
Send7219(0x02,LEDcode[6]+0x80);
Send7219(0x03,LEDcode[7]);
Send7219(0x04,LEDcode[9]);
//Send7219(0x05,LEDcode[5]);
//Send7219(0x06,LEDcode[6]+0x80);
//Send7219(0x07,LEDcode[7]);
//Send7219(0x08,LEDcode[8]);
// Clear7219();
}
} */