📄 max7219.c
字号:
#include <max7219.h>
#include <INTRINS.H>
extern unsigned char code ascii[];
void WriteToMax7219 (unsigned char Cmd ,unsigned char Data)
{
unsigned char tLoop = 0;
unsigned int tMask = 0x0001;
unsigned int tWord = 0;
tWord = Cmd;
tWord = (tWord << 8) + Data;
CLK0 = 0;
CS0 = 0;
for(tLoop=0,tMask=0x8000; tLoop<16 ;tLoop++)
{
DIN0=tWord&tMask;
_nop_();
_nop_(); //rising edge
CLK0=1;
if(tLoop==15) //Take CS high (while CLK is still high after clocking in
CS0=1;
CLK0=0;
DIN0=0;
tMask=tMask>>1;
}
CS0=1;
}
void InitialMax7219(void)
{
unsigned char i;
CS0=1;
CLK0=0;
//Enter display test mode
//WriteToMax7219(0x0F,0x01);
//Exit display test mode
WriteToMax7219(0x0F,0x00);
// Exit shutdown mode -->normal mode
WriteToMax7219(0x0C,0x01);
//Set globalk intensity to full-scale
WriteToMax7219(0x0A ,0x06);
// WriteToMax7219(0x02 ,0x08);
//Decode mode enabled 0-7 BCD decode
WriteToMax7219(0x09,0xFF) ;
//Display Digit 0-7 only
WriteToMax7219(0x0B,0x07) ;
//reset all 8 leds to blank
for(i=2;i<9;i++)
{
WriteToMax7219(i,ascii[8]);
}
WriteToMax7219(0x01,0x0E);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -