文档详情

AVR单片机 mega128 例程大全.pdf

发布:2021-10-15约4.08万字共92页下载文档
文本预览下载声明
//16 超声波LED 显示 #include iom16v.h//PA0 接控制引脚PA7 接接收引脚 #include macros.h #define chao 100 longint time=0; void delay(long int z) { inti,j; for(i=0;iz;i++) for(j=0;j100;j++); } void main() { int o=0; DDRD=0xff; DDRA=0x0f; TCNT1H=0x00; TCNT1L=0x00; while(1) { PORTA=0x0f; delay(1); PORTA=0x00; while((PINA0x80)==0x00); TCCR1B=0x03; while((PINA0x80)==0x80); TCCR1B=0x00; time=TCNT1H*256+TCNT1L; TCNT1H=0x00; TCNT1L=0x00; if(timechao) { if(timechao) { o=500; while(o--) PORTD=0x04; } } if(timechao) { if(timechao) { o=500; while(o--) PORTD=0x08; } } } } //AD #includeiom128v.h #includemacros.h #define unint unsigned int #define unchar unsigned char #pragma data:code const table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; unint mega128_ad() { unintaddata; DDRF=~BIT(0); PORTF=~BIT(0); ADMUX=0; ADCSRA=0X80; ADCSRA|=BIT(ADSC); while(!(ADCSRA(BIT(ADIF)))); addata=ADCL; addata=addata+ADCH*256; returnaddata; } void show(count) { unchar temp1,temp2,temp3,temp4; temp1=count/1000; temp2=(count%1000)/100; temp3=(count%100)/10; temp4=count%10; HC_595_OUT(table[temp4]); DDRB|=(14); PORTB|=(14); delay(10); DDRB|=(14); PORTB=~(14); HC_595_OUT(table[temp3]); DDRB|=(15); PORTB|=(15); delay(10); DDRB|=(15); PORTB=~(15); HC_595_OUT(table[temp2]); DDRB|=(16); PORTB|=(16); delay(10); DDRB|=(16); PORTB=~(16); HC_595_OUT(table[temp1]); DDRB|=(17); PORTB|=(17); delay(10); DDRB|=(17);
显示全部
相似文档