#include "reg52.h"
#include "my_type.h"
#define Addr_No_Op 0x00 //不工作寄存器地址
#define Addr_Digit0 0x01
#define Addr_Digit1 0x02
#define Addr_Digit2 0x03
#define Addr_Digit3 0x04
#define Addr_Digit4 0x05
#define Addr_Digit5 0x06
#define Addr_Digit6 0x07
#define Addr_Digit7 0x08
#define Addr_Decode_Mode 0x09 //译码模式寄存器地址
#define Addr_Intensity 0x0a //亮度控制寄存器地址(max7221)
#define Addr_Scan_Limit 0x0b //扫描控制寄存器地址
#define Addr_Shutdowm 0x0c //掉电模式寄存器地址
#define Addr_Display_Test 0x0f //显示检测寄存器地址
sbit Max7219_Din=P1^5;
sbit Max7219_Load=P1^6;
sbit Max7219_Clk=P1^7;
uchar code max7219_7led_code[18]={0x7e,0x30,0x6d,0x79, //0-1-2-3
0x33,0x5b,0x5f,0x70, //4-5-6-7
0x7f,0x7b,0x01,0x4e, //8-9-"-"-E
0x37,0x0e,0x67,0x00}; //H-L-P-空白
void wr_max7219(uchar addr,uchar dat)
{
uchar i;
Max7219_Load=0;
Max7219_Clk=0;
for(i=0;i<8;i++)
{
Max7219_Din = (bit)(addr&0x80);
addr=addr<<1;
Max7219_Clk=1;
Max7219_Clk=0;
}
for(i=0;i<8;i++)
{
Max7219_Din=(bit)(dat&0x80);
dat=dat<<1;
Max7219_Clk=1;
Max7219_Clk=0;
}
Max7219_Load=1;
Max7219_Load=0;
}
main()
{
uchar j;
for(j=200;j>0;j--);
wr_max7219(Addr_Shutdowm,0x01);
wr_max7219(Addr_Scan_Limit,0x07);
wr_max7219(Addr_Intensity,0x0f);
wr_max7219(Addr_Decode_Mode,0x00);
wr_max7219(Addr_Digit0,max7219_7led_code[1]);
wr_max7219(Addr_Digit1,max7219_7led_code[2]);
wr_max7219(Addr_Digit2,max7219_7led_code[3]);
wr_max7219(Addr_Digit3,max7219_7led_code[4]);
wr_max7219(Addr_Digit4,max7219_7led_code[5]);
wr_max7219(Addr_Digit5,max7219_7led_code[6]);
wr_max7219(Addr_Digit6,max7219_7led_code[7]);
wr_max7219(Addr_Digit7,max7219_7led_code[8]);
P0=0x00;
// wr_max7219(Addr_Display_Test,0x01); //测试
while(1);
}
用户217759 2009-8-6 21:31
用户217759 2009-8-6 21:31