控制74HC164數(shù)據(jù)轉(zhuǎn)換程序
/*
//======164數(shù)據(jù)轉(zhuǎn)換程序=======
voidchuanshu164(uchardata_buf)
{
uchari;
ACC=data_buf;//數(shù)據(jù)送累加器
for(i=8;i>0;i--)
{
clk=0;
data1=a0;
clk=1;
ACC=ACC>>1;
}
clk=0;
}
//ICC-AVRapplicationbuilder:2005-2-2423:07:53
//Target:M8
//Crystal:8.0000MHz
#include
#include
unsignedcharn;
//TIMER1initialISAtion-prescale:256
//actualvalue:1.000Hz(0.0%)
voidtimer1_init(void)
{
TCCR1B=0x00;//stop
TCNT1H=0x85;//setup
TCNT1L=0xEE;
OCR1AH=0x7A;
OCR1AL=0x12;
OCR1BH=0x7A;
OCR1BL=0x12;
ICR1H=0x7A;
ICR1L=0x12;
TCCR1A=0x00;
TCCR1B=0x04;//startTimer
}
//timer1中斷,1秒
#pragmainterrupt_handlertimer1_ovf_isr:9
voidtimer1_ovf_isr(void)
{
unsignedcharch,i;
TCNT1H=0x85;//reloadcounterhighvalue
TCNT1L=0xEE;//reloadcounterlowvalue
if(++n==10)n=0;
ch=n|0x70;
PORTB&=~0x01;//消隱
PORTD&=~0x40;//CLK
for(i=0;i<8;i++){
if(ch&0x80)
PORTD|=0x80;
else
PORTD&=~0x80;
ch<<=1;
PORTD|=0x40;
asm("nop");
PORTD&=~0x40;
}
PORTB|=0x01;//顯示
}
//初始化
voidinit_devices(void)
{
CLI();//禁止中斷
DDRB=0x01;//初始化操作74LS164的管腳
DDRD=0xC0;//初始化操作74LS164的管腳
timer1_init();
MCUCR=0x00;
GICR=0x00;
TIMSK=0x04;//設(shè)置timer1中斷
SEI();//中斷使能
}
//
voidmain(void)
{
unsignedcharx;
init_devices();
//insertyourfunctionalcodehere...
for(;;){
x++;
}
}
*/