MAX7219显示C代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include
#define uint unsigned int
#define uchar unsigned char
#define DECODE_MODE 0x09
#define INTENSITY 0x0A
#define SCAN_LIMIT 0x0B
#define SHUT_DOWN 0x0C
#define DISPLAY_TEST 0x0F
sbit LOAD=P1^7;
sbit DIN=P1^5;
sbit CLK=P1^6;
unsigned char code dis_code[18]={0x7E,0x30,0x6D,0x79, // 0, 1, 2, 3
0x33,0x5B,0x5F,0x70,0x7F,0x7B,0x77,0x1f,0x4e,0x3d,0x4f,0x47,0x01,0x00};// 4, 5, 6, 7, 8, 9,a,b,c,d,e,f,-, ,
void LED(uchar position ,uchar Value);
void Init_Max7219(void);/*MAX7219初始化*/
unsigned char ii;
void main()
{
Init_Max7219();
for(ii=1;ii<9;ii++)
{
LED(ii,ii);
}
while(1)
{};
}
void Write_Max7219_byte(unsigned char temp)
{
unsigned char i;
for (i=0;i<8;i++)
{
CLK=0;
DIN=(bit)(temp&0x80);
temp<<=1;
CLK=1;
}
}
//***********************************************************************/
void Write_Max7219(unsigned char address,unsigned char dat)
{
LOAD=0;
Write_Max7219_byte(address);
Write_Max7219_byte(dat);
LOAD=1;
}
//***********************************************************************/
void clear(void)
{
Write_Max7219(1,0x00);
Write_Max7219(2,0x00);
Write_Max7219(3,0x00);
Write_Max7219(4,0x00);
Write_Max7219(5,0x00);
Write_Max7219(6,0x00);
Write_Max7219(7,0x00);
Write_Max7219(8,0x00);
}
void Init_Max7219(void)
{
Write_Max7219(SHUT_DOWN, 0x00); //Normal Operation XXXXXXX1 Shutdown Mode XXXXXXXX0
Write_Max7219(DECODE_MODE, 0x00); //Decode Mode Select D7~D0 1 B decode 0 No decode
Write_Max7219(SCAN_LIMIT, 0x07); //SCAN LIMIT 0~7 0xX0~0xX7
Write_Max7219(INTENSITY, 0x0A); //Set Intensity 0xX0~0xXf
Write_Max7219(DISPLAY_TEST, 0x00); //Normal Operation XXXXXXX0 Display Test Mode
Write_Max7219(SHUT_DOWN, 0x01); //Normal Operation XXXXXXX1 Shutdown Mode XXXXXXXX0
clear();
}
void TestLED(void)
{
Write_Max7219(1,dis_code[0]);
Write_Max7219(2,dis_code[1]);
Write_Max7219(3,dis_code[2]);
Write_Max7219(4,dis_code[3]);
Write_Max7219(5,dis_code[4]);
Write_Max7219(6,dis_code[5]);
Write_Max7219(7,dis_code[6]);
Write_Max7219(8,dis_code[7]);
}
void LED(uchar position ,uchar Value)
{
Write_Max7219(position,dis_code[V alue]); }