164驅(qū)動8位LED顯示 CVAVR程序
//164驅(qū)動數(shù)碼管顯示
//芯片 ATMEGA16L
//時鐘 4MHz 內(nèi)部
//采用CVAVR編寫,使用了系統(tǒng)自帶延時函數(shù)
//PD0 PD1 模擬164時序
#include
#include
#define hc164_da
#define hc164_clk PORTD.1
void led164_display (void); // 數(shù)碼管顯示
void hc164_send_byte (unsigned char byte);
unsigned char ledxs[8] = {1,2,3,4,5,6,7,8}; // 數(shù)碼管顯示緩沖區(qū) 1
unsigned char ledxs2[8] = {0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0,17}; // 數(shù)碼管顯示緩沖區(qū) 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);
}