//*******************************************************************************************//
/*------------------------------------------------------
用ATMAGE128驱动MAX7219
2008年3月25日,原创
从左至右分别为1到8位,分为左右各4位分别使用
没有小数点功能,如果要使用小数点可将操作数和0X80求或,可另外写函数封装
译码方式初始化为"不使用BCD译码方式"
特殊字符 -:0A; E:0B; H:0C; L:0D; P:0E; 黑屏:0F
--------------------------------------------------------*/
/*----------MAX7219操作指令--------------
----------功能--------|---指令---|--------操作数--------|
1、BCD译码方式选择 | 0x09 |0x00:不使用,0xff:使用|
2、亮度调节 | 0x0a |0x00------0x0f,16级 |
3、扫描位数设定 | 0x0b |0x00------0x07,1--8位 |
4、待机开关 | 0x0c |0x00:灭,0x01:开 |
5、显示器检测 | 0x0f |0x01:检测,0x00:不检测|
6、位操作指令 |0x01--0x08|要显示的数字 |
-----------------------------------------*/
/*=======================================================
工作时
==========================================================
可选择void WriteWord(uchar add,uchar dat)子程序
可选择void WriteWord(unsigned char addr,unsigned char num)子程序
========================================================*/
//ICC-AVR application builder : 2008-3-9 17:30:16
// Target : M128
// Crystal: 7.3728Mhz
#include
#include
#include "display.h"
//#include "eeprom.h"
/* 主函数 */
void main(void)
{
uchar temp_;
port_init();
InitDisplay (); // MAX7219初始化
clear();
while(1)
{
clear();
key1_function();
count_();
}
//-------------------------------------------------------------*/
}
//*********************************************************************************************//
//delay.c
#include
#include
#include "display.h"
//================== 延时t毫秒 ===================================*/
void delay_loop_2(int i)
{
int j;
for(j=i;j<0;j--)
;
}
void delay_1ms(void)
{
delay_loop_2(34000);
}
void delay_nms(uint i)
{
uchar t=0;
for(t=i;t>0;t--)
{
delay_1ms();
}
}
//*************************************************************************************************//
//function.c
#include
#include
#include "display.h"
#include "eeprom.h"
uchar Digit【8】={1,2,3,4,5,6,7,8,}; //数码管寄存器
uchar DisBuffer【】={0,1,2,3,4,5,6,7,8,9,0x0f};
uchar dis_buf【5】;
uchar eeprom_date【】={111,30,40,50,60,70,80,90,100,99};
uchar eeprom_addr【】={10,11,12,13,14,15,16,17,18,19};
uchar pine_buff,key1=0x50,key2=0x30,key3=0x60;
void port_init(void)
{
PORTA = 0xff;
DDRA = 0xff;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0xF8;
DDRD = 0xFF;
PORTE = 0x00;
DDRE = 0x00;
PORTF = 0x00;
DDRF = 0x00;
PORTG = 0x00;
DDRG = 0x00;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
XDIV = 0x00; //xtal divider
XMCRA = 0x00; //external memory
port_init();
MCUCR = 0x00;
EICRA = 0x00; //extended ext ints
EICRB = 0x00; //extended ext ints
EIMSK = 0x00;
TIMSK = 0x00; //timer interrupt sources
ETIMSK = 0x00; //extended timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
//*==========