MAX6955也是一种紧凑型的显示驱动器,IIC接口,可驱动多达16位7段、8位14段、8位16段或128个分立的LED.本程使MAX6955工作于全解码模式,因此只需要向MAX6955输出待显示字符ASCII码即可,不需要编写并发送各字符的段码。
Proteus仿真结果:
Studio6.2编译通过的截图:
程序清单:
/*
* GccApplication32.c
*
* Created: 2014-12-11 22:11:01
* Author: Administrator
*/
#define F_CPU 4000000UL
#include <avr/io.h>
#include <util/twi.h>
#include <util/delay.h>
#include <string.h>
#include <stdint.h>
#define MAX6955R 0b11000001
#define MAX6955W 0B11000000
#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 SEG_LED_String[] = "01234567890";
uint8_t MAX6955_Write(uint8_t addr,uint8_t dat)
{
START();
if(TW_STATUS != TW_START) return 0;
WriteByte(MAX6955W);
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(20);
return 1;
}
void MAX6955_INIT()
{
MAX6955_Write(0x01,0xFF);
MAX6955_Write(0x02,0x03);
MAX6955_Write(0x03,0x07);
MAX6955_Write(0x04,0x01);
MAX6955_Write(0x06,0x00);
MAX6955_Write(0x0c,0x00);
MAX6955_Write(0x07,0x01);
_delay_ms(1000);
MAX6955_Write(0x07,0x00);
}
int main(void)
{
uint8_t i,j,Len = strlen(SEG_LED_String);
DDRD = 0xFF; PORTD = 0x00;
MAX6955_INIT();
while(1)
{
//TODO:: Please write your application code
for(i = 0;i<Len;i+=8)
{
for(j = 0; j< 8;j++)
MAX6955_Write(0x20 | j,(uint8_t)SEG_LED_String[i+j]);
for(;j<8;j++)
MAX6955_Write(0x20 | j,(uint8_t)(' '));
_delay_ms(2000);
}
}
}
|