|
/*
*********************************************************************************************************
* MAX7219驱动程序头文件
*
* All Rights Reserved
*
* V1.00
*
* File Name : max7219.h
* Developed By : Lv Gao Pan
* Email : lvgaopan@gmail.com
* Target MCU : ATMEGA16L
* Complier : gccavr 3.4.3 + gccavrlibc 1.2.3
* Develope Date : 2005.11.18
* Latest Change : 2005.12.05
* Note : 用于综合显示仪的双芯片串连驱动
*********************************************************************************************************
*/
#ifndef __MAX7219_H__
#define __MAX7219_H__
#include <avr/io.h>
// 寄存器地址定义
#define NO_OP 0x00
#define DECODE_MODE 0x09
#define INTENSITY 0x0a
#define SCAN_LIMIT 0x0b
#define SHUTDOWN 0x0c
#define DISP_TEST 0x0f
// 管脚定义
#define MAX7219_DIN PA7
#define MAX7219_CLK PD1
#define MAX7219_LOAD PD0
#define MAX7219_DIN_PORT PORTA
#define MAX7219_CLK_PORT PORTD
#define MAX7219_LOAD_PORT PORTD
// 端口操作宏定义
#define MAX7219_DIN_SET (MAX7219_DIN_PORT |= (1<<MAX7219_DIN))
#define MAX7219_DIN_CLR (MAX7219_DIN_PORT &= ~(1<<MAX7219_DIN))
#define MAX7219_CLK_SET (MAX7219_CLK_PORT |= (1<<MAX7219_CLK))
#define MAX7219_CLK_CLR (MAX7219_CLK_PORT &= ~(1<<MAX7219_CLK))
#define MAX7219_LOAD_SET (MAX7219_LOAD_PORT |= (1<<MAX7219_LOAD))
#define MAX7219_LOAD_CLR (MAX7219_LOAD_PORT &= ~(1<<MAX7219_LOAD))
// 函数原型
void max_init( void );
void display(unsigned char addr1,unsigned char data1,unsigned char addr2,unsigned char data2);
#endif
/*
*********************************************************************************************************
* MAX7219驱动程序
*
* All Rights Reserved
*
* V1.00
*
* File Name : max7219.c
* Developed By : Lv Gao Pan
* Email : lvgaopan@gmail.com
* Target MCU : ATMEGA16L
* Complier : gccavr 3.4.3 + gccavrlibc 1.2.3
* Develope Date : 2005.11.18
* Latest Change : 2005.12.05
* Note : 用于综合显示仪的双芯片串连驱动
*********************************************************************************************************
*/
#include "max7219.h"
void max_init(void)
{
unsigned char MAX7219_Loop;
display( INTENSITY, 0x03, INTENSITY, 0x03);
display( SCAN_LIMIT, 0x07, SCAN_LIMIT, 0x07 );
display( DECODE_MODE, 0xff, DECODE_MODE, 0xff );
display( SHUTDOWN, 0x01, SHUTDOWN, 0x01 );
for( MAX7219_Loop = 0; MAX7219_Loop < 8; MAX7219_Loop++ )
{
display(( MAX7219_Loop + 1 ), 0x0a, ( MAX7219_Loop + 1 ), 0x0a );
}
}
//IDDIS.PCB数码管分布示意
/*
addr2=4,addr2=3,addr2=2,addr2=1
addr2=8,addr2=7,addr2=6,addr2=5
addr1=8,addr1=7,addr1=6,addr1=5
addr1=4,addr1=3,addr1=2,addr1=1
*/
void display(unsigned char addr1,unsigned char data1,unsigned char addr2,unsigned char data2)
{
unsigned long Send_Data;
unsigned char Dis_Loop;
Send_Data = addr1;
Send_Data <<= 8;
Send_Data += data1;
Send_Data <<= 8;
Send_Data += addr2;
Send_Data <<= 8;
Send_Data += data2;
MAX7219_CLK_CLR;
MAX7219_LOAD_CLR;
for( Dis_Loop = 0; Dis_Loop < 32; Dis_Loop++ )
{
MAX7219_CLK_CLR;
if( Send_Data & 0x80000000 )
MAX7219_DIN_SET;
else
MAX7219_DIN_CLR;
Send_Data <<= 1;
MAX7219_CLK_SET;
}
MAX7219_LOAD_SET;
}
|
|