164驱动8位LED显示 CVAVR程序
扫描二维码
随时随地手机看文章
//164驱动数码管显示
//芯片 ATMEGA16L
//时钟 4MHz 内部
//采用CVAVR编写,使用了系统自带延时函数
//PD0 PD1 模拟164时序
#include
#include
#define hc164_da
#define hc164_clk PORTD.1
void led164_display (void); // 数码管显示
void hc164_send_byte (unsigned char byte);
unsigned char ledxs[8] = {1,2,3,4,5,6,7,8}; // 数码管显示缓冲区 1
unsigned char ledxs2[8] = {0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0,17}; // 数码管显示缓冲区 2
flash unsigned char tab[] = {0xb7,0x12,0x67,0x76,0xd2,0xf4,0xf5,0x16,0xf7,0xf6,0xd7,0xf1,0xa5,0x73,0xe5,0xc5,0,0xff};
//共阴极代码 0-F, 全灭,全亮
void main(void)
{
delay_ms(200);
PORTD = 0xFF;
DDRD = 0xFF; //PD输出
while(1)
{
led164_display ();
}
}
void hc164_send_byte (unsigned char byte)
{
unsigned char i;
for(i=0;i<8;i++)
{
hc164_da
hc164_clk = 1;
hc164_clk = 0;
}
}
void led164_display (void)
{
unsigned char i;
for(i=0;i<8;i++)
{
hc164_send_byte ( tab[ ledxs[i] ]);
delay_ms(1);
}
delay_ms(2000);
for(i=0;i<8;i++)
{
hc164_send_byte ( tab[ ledxs2[i] ]);
delay_ms(1);
}
delay_ms(2000);
}