MAX6953是紧凑的行共阴显示驱动器,通过IIC的串行接口将微控制器连接到5X7LED点阵屏。MAX6953可驱动多达4位单色或2位双色的5x7点阵屏,6953包含104个ASCII字符字模、复用扫描电路、行列驱动器以及用于存储每一们字符和24个用户自定义字符字模数据的静态RAM.LED的段电流由内部逐位数字亮度控制电跑设定。
本例运行时,4块点阵屏将流动显示一组信息串,字符由MAX6953提供。
Proteus运行截图:
Atmel Studio6.20编译通过截图:
程序清单:
/*
* GccApplication31.c
*
* Created: 2014-12-9 22:46:45
* Author: Administrator
*/
#define F_CPU 4000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/twi.h>
#include <util/delay.h>
#include <string.h>
#include <stdint.h>
#define MAX6953R 0B10100001 //READ
#define MAX6953W 0B10100000 //WRITE
#define Wait() while((TWCR & _BV(TWINT))==0)
#define START() {TWCR = _BV(TWINT)|_BV(TWSTA)|_BV(TWEN);Wait();}
#define STOP() (TWCR = _BV(TWINT) | _BV(TWSTO)|_BV(TWEN))
#define WriteByte(x) {TWDR = (x);TWCR = _BV(TWINT)|_BV(TWEN);Wait();}
#define ACK() (TWCR |= _BV(TWEA))
#define NACK() (TWCR &=~_BV(TWEA))
char LED_String[] = "LEDSHOW: ddllxxrr ========0123456";
uint8_t MAX6953_Write(uint8_t addr,uint8_t dat)
{
START();
if(TW_STATUS != TW_START) return 0;
WriteByte(MAX6953W);
if(TW_STATUS != TW_MT_SLA_ACK) return 0;
WriteByte(addr);
if(TW_STATUS != TW_MT_DATA_ACK) return 0;
WriteByte(dat);
if(TW_STATUS != TW_MT_DATA_ACK)return 0;
STOP();
_delay_ms(2);
return 1;
}
void MAX6953_INIT()
{
MAX6953_Write(0x01,0xFF);
MAX6953_Write(0x02,0xFF);
MAX6953_Write(0x03,0x03);
MAX6953_Write(0x04,0x01);
MAX6953_Write(0x07,0x00);
}
int main(void)
{
uint8_t i,j;
DDRD = 0x00;PORTD = 0xFF;
MCUCR = 0x02;
GICR = 0x40;
SREG = 0x80;
MAX6953_INIT();
while(1)
{
//TODO:: Please write your application code
for(i=0;i<=strlen(LED_String) - 4;i++)
{
for(j=0;j<4;j++)
MAX6953_Write(0x20 | j,(uint8_t)LED_String[i+j]);
_delay_ms(300);
}
_delay_ms(2000);
}
}
ISR(INT0_vect)
{
static uint8_t Shut_Down_6955 = 0x01;
Shut_Down_6955 ^=0x01;
MAX6953_Write(0x04,0x00 | Shut_Down_6955);
}
|