mega16_C程序适合初学者学习
1.参考书P121 数码管轮流显示0~F
#include 《mega16.h》
#include 《delay.h》
flash unsigned char led_7[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07, 0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
flash unsigned char posiTIon[8]={ 0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void main(void)
{
unsigned char i=0,j=0;
PORTA=0x00; // 显示控制I/O端口初始化
DDRA=0xFF;
PORTC=0xFF;
DDRC=0xFF;
while(1)
{
for(i=0;i《=7;i++)
{
PORTC=posiTIon[i];
for(j=0;j《16;j++)
{
PORTA=led_7[j];
delay_ms(500);
}
}
};
}
用定时器实现数码管轮流显示0~F
#include 《mega16.h》
flash unsigned char led_7[17]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71,0x00};
flash unsigned char posiTIon[8]={ 0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char disbuff[8]; // 显示缓冲区,存放要显示的8个字符的段码值
unsigned char posit,TIme_counter;
bit time_500ms_ok;