麻烦大家帮我看段程序
下面这段程序的功能是每组数据从左向右滚动进入显示屏,保持刷新一段时间后显示下一组。我用了两个定时器,T0用作滚动进入计时,T2用作刷新计时。可是实际T2的刷新计时比设定的长好多,不知道哪里出问题了,还有每组最后一位滚出显示屏会出现乱码的现象,这是为什么呢?
我也希望大家能不吝赐教,写出更好的代码实现该功能。
附件有源程序和仿真图。
#define F_CPU 4000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
typedef unsigned char uint8;
typedef unsigned int uint16;
const PROGMEM uint8 SEG_CODE[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92,
0x82, 0xf8, 0x80, 0x90, 0xbf, 0xff};
const PROGMEM uint8 SCAN_BITs[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
const PROGMEM uint8 Table_OF_Digits[]= {
{11, 11, 11, 11, 11, 11, 11, 11, 5, 2, 10, 2, 1, 10, 9, 0},
{11, 11, 11, 11, 11, 11, 11, 11, 9, 3, 10, 7, 5, 10, 1, 2},
{11, 11, 11, 11, 11, 11, 11, 11, 7, 7 ,10, 7, 7, 10, 7, 7}
};
uint8 row, col;
int main(void)
{
// uint8 i, j;
DDRC = 0xff; PORTC = 0x00;
DDRD = 0xff; PORTD = 0x00;
TCCR0 = 0x03; //预设分频:64
TCCR2 = 0x00; //预设分频:64
TCNT0 = 256 - F_CPU / 64.0 * 0.004;
TCNT2 = 256 - F_CPU / 64.0 * 0.004;
TIMSK = _BV(TOIE2) | _BV(TOIE0);
sei();
while(1);
}
ISR(TIMER0_OVF_vect)
{
static uint8 j = 0;
static uint8 Keep_T1 = 0;
TCNT0 = 256 - F_CPU / 64.0 * 0.004;
// PORTD = 0x00;
PORTC = 0xff;
PORTC = pgm_read_byte(&SEG_CODE[(col + j) % 16])]);
PORTD = pgm_read_byte(&SCAN_BITs);
j = (j + 1) % 8;
if (col == 8)
{
TCCR0 = 0x00;
TCCR2 = 0x04;
}
if (col == 15)
row = (row + 1) % 3;
if (++Keep_T1 == 15)
col = (col + 1) % 16;
}
ISR(TIMER2_OVF_vect)
{
static uint8 n = 0;
static uint16 Keep_T2 = 0;
TCNT2 = 256 - F_CPU / 64.0 * 0.004;
// PORTD = 0x00;
PORTC = 0xff;
PORTC = pgm_read_byte(&SEG_CODE)]);
PORTD = pgm_read_byte(&SCAN_BITs);
n = (n + 1) % 8;
if (++Keep_T2 != 10)
return;
Keep_T2 = 0;
TCCR0 = 0x03;
TCCR2 = 0x00;
} 没人指导一下么? 自己顶一下 原理图拿什么画的 我用99打不开啊
szghzhao 发表于 2013-5-26 19:47 static/image/common/back.gif
原理图拿什么画的 我用99打不开啊
是proteus仿真图 proteus仿真不一定和实际情况相同的哦 newbier 发表于 2013-5-27 20:21 static/image/common/back.gif
proteus仿真不一定和实际情况相同的哦
您下载附近验证了么?我觉得好像是代码哪里写得不对造成的。
页:
[1]