|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2007-11-17 21:00:39
|
显示全部楼层
马老师:您好!
我用的是jtag ice仿真器。用到PC的I/O因此,我把程序中的C口改成了D口,运行后6个数码管显示的都是0,修改dis_buff[],中的数据,加了一条语句让它循环在显示程序上,本想因该看到数据有变化但看到的还是0。不知为何请指教,谢谢。下面是截取的图片。
![](http://cache.amobbs.com/bbs_upload782111/files_8/ourdev_181355.jpg)
![](http://cache.amobbs.com/bbs_upload782111/files_8/ourdev_181356.jpg)
/*********************************************
File name : demo_6_5.c
Chip type : ATmega16
Program type : Application
Clock frequency : 4.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*********************************************/
#include <mega16.h>
#include <delay.h>
flash unsigned char led_7[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
flash unsigned char position[6]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
unsigned char time[3]; // 时、分、秒计数
unsigned char dis_buff[6]; // 显示缓冲区,存放要显示的6个字符的段码值
unsigned char time_counter; // 1秒计数器
bit point_on; // 秒显示标志
void display(void) // 扫描显示函数,执行时间12ms
{
unsigned char i;
//for(i=0;i<=5;i++)
while(1)
{ for(i=0;i<=5;i++)
{
PORTA = led_7[dis_buff];
if (point_on && ( i==2 || i==4 )) PORTA |= 0x80; // (1)
PORTD = position;
delay_ms(2); // (2)
PORTD = 0xff;
} // (3)
}
}
void time_to_disbuffer(void) // 时间值送显示缓冲区函数
{
unsigned char i,j=0;
for (i=0;i<=2;i++)
{
dis_buff[j++] = time % 10;
dis_buff[j++] = time / 10;
}
}
void main(void)
{
PORTA=0x00; // PORTA初始化
DDRA=0xFF;
PORTD=0x3F; // PORTC初始化
DDRD=0x3F;
time[2] = 23; time[1] = 58; time[0] = 55; // 时间初值23:58:55
time_to_disbuffer(); // 时间值送显示缓冲区函数
while (1)
{
display(); // 显示扫描,执行时间12ms
if (++time_counter >= 40)
{
time_counter = 0; // (4)
point_on = ~point_on; // (5)
if (++time[0] >= 60)
{
time[0] = 0;
if (++time[1] >= 60)
{
time[1] = 0;
if (++time[2] >= 24) time[2] = 0;
}
}
time_to_disbuffer();
}
delay_ms(13); // 延时13ms,可进行其它处理(6)
}
} |
|