#define uchar unsigned char
#define uint unsigned int
本文引用地址:http://m.butianyuan.cn/article/201611/321049.htm//定義74LS164時鐘和數(shù)據(jù)引腳狀態(tài)
#define CLK_H() PORTA|=BIT(1)
#define CLK_L() PORTA&=~BIT(1)
#define Dat_H() PORTA|=BIT(0)
#define Dat_L() PORTA&=~BIT(0)
void delay(void)
{
uint i;
for(i=1;i<100;i++)
;
}
void delay_1ms(void)//1ms
{
uint i;
for(i=1;i<(uint)(8*143-2);i++)
;
}
void delay_ms(uint time)//time*1ms
{
uint i="0";
while(i {
delay_1ms();
i++;
}
}
void Port_init(void)
{
DDRA = 0xff;//A口設(shè)為輸出
PORTA = 0x00;
DDRB = 0xff; //B口為輸出,
PORTB = 0xff;
DDRC = 0x00;//C口
PORTC = 0x00;
DDRD = 0x00;//D口
PORTD = 0x00;
}
void Led_flowing(void)
{
uchar i;
for(i=0;i<8;i++)
{
PORTB=~(1< delay_ms(150);
}
}
void Send_byte(uchar Dat)
{
uchar i;
for(i=0;i<8;i++)
{
CLK_L();
if(Dat&0x80)
Dat_H();
else Dat_L();
CLK_H();
Dat<<=1;
}
}
void main(void)
{
Port_init();
while(1)
{
Send_byte(0x01);
delay_ms(200);
Send_byte(0x02);
delay_ms(200);
Send_byte(0x80);
delay_ms(200);
}
}
評論