发表于:2007-04-13 17:47:00
楼主
#include <reg51.h>
//max7219 part
#define DECODE_MODE 0x09
#define INTENSITY 0x0A
#define SCAN_LIMIT 0x0B
#define SHUT_DOWN 0x0C
#define DISPLAY_TEST 0x0F
sbit LOAD = P0^1; //MAX7219 Load-Data Input: rising edge pin 12
sbit DIN = P0^0; //MAX7219 Serial-Data Input: rising edge pin 1
sbit CLK = P0^2; //MAX7219 Serial-Clock Input: maximum 10MHz pin 13
/***********************************************************
函数声明
***********************************************************/
void Write_Max7219_byte(unsigned char temp);
void Write_Max7219(unsigned char address,unsigned char dat);
void main(void)
{
Write_Max7219(SHUT_DOWN, 0x01); //Normal Operation XXXXXXX1 Shutdown Mode XXXXXXXX0
Write_Max7219(DISPLAY_TEST, 0x00); //Normal Operation XXXXXXX0 Display Test Mode XXXXXXXX1
Write_Max7219(DECODE_MODE, 0xFF); //Decode Mode Select D7~D0 1 B decode 0 No decode
Write_Max7219(SCAN_LIMIT, 0x02); //SCAN LIMIT 0~7 0xX0~0xX7
Write_Max7219(INTENSITY, 0x0F); //Set Intensity 0xX0~0xXf
while(1)
{Write_Max7219(0x01,1);}
}
/******************************************
发送一个字节的子程序:
上升沿发送数据,
MSB first
******************************************/
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;
}
}
/**********************************************************
向寄存器中写入一个数据
先写地址,后写数据
load 上升沿锁存数据
**********************************************************/
void Write_Max7219(unsigned char address,unsigned char dat)
{
LOAD = 0;
Write_Max7219_byte(address);
Write_Max7219_byte(dat);
LOAD = 1;
CLK = 1;
}
数码管随意闪烁,就是数字不固定,不能准确显示,求教一下,这是哪里的问题,谢谢各位高手了!!!