控制74HC164数据转换程序
扫描二维码
随时随地手机看文章
/*
//======164数据转换程序=======
voidchuanshu164(uchardata_buf)
{
uchari;
ACC=data_buf;//数据送累加器
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;//设置timer1中断
SEI();//中断使能
}
//
voidmain(void)
{
unsignedcharx;
init_devices();
//insertyourfunctionalcodehere...
for(;;){
x++;
}
}
*/