兴趣!发完贴,怎么感觉自己没有想自己做的项目里不是老用到数码管的显示吗?其实是一个道理,我就写了下面的代码。工作中我会用缓冲,但这里完全没有必要。
/*
** 可以自定义显示1个字符,
*/
const unsigned char MapTab[28][8]={
0x01,0x00,0x00,0x18,0x18,0x00,0x00,0x00,
0x00,0x01,0x00,0x18,0x18,0x00,0x00,0x00,
0x00,0x00,0x01,0x18,0x18,0x00,0x00,0x00,
0x00,0x00,0x00,0x18|0x01,0x18,0x00,0x00,0x00,
0x00,0x00,0x00,0x18,0x18|0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x18,0x18,0x01,0x00,0x00,
0x00,0x00,0x00,0x18,0x18,0x00,0x01,0x00,
0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x01,
0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x02,
0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x04,
0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x08,
0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x10,
0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x20,
0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x40,
0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x80,
0x00,0x00,0x00,0x18,0x18,0x00,0x80,0x00,
0x00,0x00,0x00,0x18,0x18,0x80,0x00,0x00,
0x00,0x00,0x00,0x18,0x18|0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x18|0x80,0x18,0x00,0x00,0x00,
0x00,0x00,0x80,0x18,0x18,0x00,0x00,0x00,
0x00,0x80,0x00,0x18,0x18,0x00,0x00,0x00,
0x80,0x00,0x00,0x18,0x18,0x00,0x00,0x00,
0x40,0x00,0x00,0x18,0x18,0x00,0x00,0x00,
0x20,0x00,0x00,0x18,0x18,0x00,0x00,0x00,
0x10,0x00,0x00,0x18,0x18,0x00,0x00,0x00,
0x08,0x00,0x00,0x18,0x18,0x00,0x00,0x00,
0x04,0x00,0x00,0x18,0x18,0x00,0x00,0x00,
0x02,0x00,0x00,0x18,0x18,0x00,0x00,0x00,
};
unsigned char Map;
unsigned char Row;
unsigned char DTime200ms;
const unsigned char *pBuf=MapTab[0];
#define POWER PORTB
#define GND PORTC
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
PORTE = 0x00;
DDRE = 0x00;
PORTF = 0x00;
DDRF = 0x00;
PORTG = 0x00;
DDRG = 0x00;
}
//TIMER0 initialize - prescale:64
// WGM: Normal
// desired value: 1mSec
// actual value: 0.992mSec (0.8%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop
ASSR = 0x00; //set async mode
TCNT0 = 0xC2; //set count
OCR0 = 0x3E;
TCCR0 = 0x04; //start timer
}
#pragma interrupt_handler timer0_ovf_isr:17
void timer0_ovf_isr(void)
{
TCNT0 = 0xC2; //reload counter value
/*
** 根据马老师的提示要消隐.
*/
POWER = 0x00;
GND = 0x00;
/*
** 将电源提供循环给出,数据同步得到给出.
** 将数据取反,给低电平灯会亮!
** 只要Map没有变,则一直显示当前画面!
*/
pBuf = MapTab[Map]+Row;
POWER = 0x01<<Row;
GND = ~*pBuf;
/*
** 地址选择循环
*/
Row++;
Row &= 0x07;
/*
** 0.2s切换1个画面
*/
DTime200ms++;
if (DTime200ms == 200)
{
DTime200ms = 0;
Map++;
if (Map == 28)
Map = 0;
}
} |