51单片机程序 MAX7219
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#define MSB 0x80
#define LSB 0x01
//max7219 part
#define DECODE_MODE 0x09
#define INTENSITY 0x0A
#define SCAN_LIMIT 0x0B
#define SHUT_DOWN 0x0C
#define DISPLAY_TEST 0x0F
{
LOAD = LOW;
Write_Max7219_byte(address);
Write_Max7219_byte(dat);
LOAD = HIGH;
}
void Init_Max7219(void) //初始化max7219子函数设置工作寄存器需要查看芯片手册
{
Write_Max7219(SHUT_DOWN,0x01); //Normal Operation XXXXXXX1 Shutdown Mode XXXXXXXX0
Write_Max7219(SCAN_LIMIT,0x07); //SCAN LIMIT 0~7 0xX0~0xX7
Write_Max7219(INTENSITY,0x0f); //Set Intensity 0xX0~0xXf强度调节
}
void main(void)//显示1~8数字
{
unsigned char i;
void delayms(uint z)//延时函数
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y-Fra bibliotek);}
void Write_Max7219_byte(unsigned char temp)//发送一个字节的子程序,上升沿发送数据
{
unsigned char i;
sbit LOAD = P3^5; //MAX7219 Load-Data Input:rising edgepin 12
sbit DIN = P3^6;//MAX7219 Serial-Data Input:rising edgepin 1
sbit CLK = P3^7;//MAX7219 Serial-Clock Input:maximum 10MHzpin 13
i=0;
Init_Max7219();
while(TRUE)
{
Write_Max7219(1,0x83+i);delayms(500);
i++;
}
}
for (i=0; i<8; i++)
{
CLK = LOW;
DIN = (bit)(temp&MSB);
temp <<=1;
CLK = HIGH;
}
}
void Write_Max7219(unsigned char address,unsigned char dat)//向寄存器中写入一个数据先写地址,后写数据load上升沿锁存数据
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在非BCD译码态输入,高四位为8,9,A,B,C,D,E,F等数显示“.”低四位为正常数码管字型码。
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
//common part
#define HIGH 1
#define LOW 0
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define LSB 0x01
//max7219 part
#define DECODE_MODE 0x09
#define INTENSITY 0x0A
#define SCAN_LIMIT 0x0B
#define SHUT_DOWN 0x0C
#define DISPLAY_TEST 0x0F
{
LOAD = LOW;
Write_Max7219_byte(address);
Write_Max7219_byte(dat);
LOAD = HIGH;
}
void Init_Max7219(void) //初始化max7219子函数设置工作寄存器需要查看芯片手册
{
Write_Max7219(SHUT_DOWN,0x01); //Normal Operation XXXXXXX1 Shutdown Mode XXXXXXXX0
Write_Max7219(SCAN_LIMIT,0x07); //SCAN LIMIT 0~7 0xX0~0xX7
Write_Max7219(INTENSITY,0x0f); //Set Intensity 0xX0~0xXf强度调节
}
void main(void)//显示1~8数字
{
unsigned char i;
void delayms(uint z)//延时函数
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y-Fra bibliotek);}
void Write_Max7219_byte(unsigned char temp)//发送一个字节的子程序,上升沿发送数据
{
unsigned char i;
sbit LOAD = P3^5; //MAX7219 Load-Data Input:rising edgepin 12
sbit DIN = P3^6;//MAX7219 Serial-Data Input:rising edgepin 1
sbit CLK = P3^7;//MAX7219 Serial-Clock Input:maximum 10MHzpin 13
i=0;
Init_Max7219();
while(TRUE)
{
Write_Max7219(1,0x83+i);delayms(500);
i++;
}
}
for (i=0; i<8; i++)
{
CLK = LOW;
DIN = (bit)(temp&MSB);
temp <<=1;
CLK = HIGH;
}
}
void Write_Max7219(unsigned char address,unsigned char dat)//向寄存器中写入一个数据先写地址,后写数据load上升沿锁存数据
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在非BCD译码态输入,高四位为8,9,A,B,C,D,E,F等数显示“.”低四位为正常数码管字型码。
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
//common part
#define HIGH 1
#define LOW 0
#define TRUE 1
#define FALSE 0
#define ZERO 0