Module Led 7 + MAX7219
Mô tả:
- Kích thước: 119x21MM
- Điện áp: 5V
- Sử dụng MAX7219
- Thứ tự chân: Vcc - GND - CLK - DIN - CS
Code Support
#include <AT89X52.H>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit DIN = P1^0; //MAX7219
sbit CLK = P1^1; //MAX7219
sbit LOAD = P1^2; //MAX7219
#define NoOp 0x00
#define Digit0 0x01
#define Digit1 0x02
#define Digit2 0x03
#define Digit3 0x04
#define Digit4 0x05
#define Digit5 0x06
#define Digit6 0x07
#define Digit7 0x08
#define DecodeMode 0x09
#define Intensity 0x0a
#define ScanLimit 0x0b
#define ShutDown 0x0c
#define DisplayTest 0x0f
#define ShutdownMode 0x00
#define NormalOperation 0x01
#define ScanDigit 0x07
#define DecodeDigit 0xff
#define IntensityGrade 0x0a
#define TestMode 0x01
#define TextEnd 0x00
uchar DisBuffer[8]={0,0,0,0,0,0,0,0};
//************************************
void delay(uint t);
void SendChar(uchar ch);
void WriteWord(uchar addr,uchar num);
void InitDisplay(void);//MAX7219
void main(void)
{
InitDisplay (); // MAX7219
WriteWord(DisplayTest,TestMode);
delay(1500);
WriteWord (DisplayTest,TextEnd);
WriteWord (Digit0,0x00);
WriteWord (Digit1,0x80);
WriteWord (Digit2,0x01);
WriteWord (Digit3,0x81);
WriteWord (Digit4,0x02);
WriteWord (Digit5,0x82);
WriteWord (Digit6,0x03);
WriteWord (Digit7,0x83);
while(1);
}
//*********************** MAX7219 ******************
void InitDisplay (void)
{
WriteWord (ScanLimit,ScanDigit);
WriteWord (DecodeMode,DecodeDigit);
WriteWord (Intensity,IntensityGrade);
WriteWord (ShutDown,NormalOperation);
}
void WriteWord (uchar addr,uchar num)
{
LOAD=0;
_nop_();
SendChar(addr);
_nop_();
SendChar(num);
_nop_();
LOAD=1;
}
//*********************************
void SendChar (uchar ch)
{
uchar i,temp;
_nop_();
for (i=0;i<8;i++)
{
temp=ch&0x80;
ch=ch<<1;
if(temp)
{
DIN=1;
CLK=0;
CLK=1;
}
else
{
DIN=0;
CLK=0;
CLK=1;
}
}
}
//********************************************************
void delay(uint t)
{
uint i;
while(t--)
{
for (i=0;i<125;i++)
{}
}
}