完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
出现的错误为下面这些compiling newone.C...newone.C(1): warning C318: can't open file 'iom8v.h'newone.C(2): warning C318: can't open file 'macros.h'NEWONE.C(3): warning C245: unknown #pragma, line ignoredNEWONE.C(4): warning C245: unknown #pragma, line ignoredNEWONE.C(5): warning C245: unknown #pragma, line ignoredNEWONE.C(10): warning C245: unknown #pragma, line ignoredNEWONE.C(17): error C202: 'TCNT0': undefined identifierNEWONE.C(22): error C202: 'ICR1': undefined identifierNEWONE.C(24): error C202: 'SREG': undefined identifierNEWONE.C(26): error C202: 'ICR1': undefined identifierNEWONE.C(27): error C202: 'TCNT1': undefined identifierNEWONE.C(28): error C202: 'TCCR1B': undefined identifiernewone.C - 6 Error(s), 6 Warning(s).
下面为运行的程序;; #include #include #pragma interrupt_handler intt0:10 //T0溢出中断 #pragma interrupt_handler icp_timer1:6 //T1捕捉中断 #pragma data:code //设定数据区为程序存储器 const unsigned char tab1[]={0X28,0XEE,0X32,0XA2,0XE4, 0XA1,0X21,0XEA,0X20,0XA0};//七段译码字型表(lm,cm) const unsigned char tab2[]={0X08,0XCE,0X12,0X82,0XC4, 0X81,0X01,0XCA,0X00,0X80};//七段译码字型表(m) #pragma data:data //设定数据区回到数据存储器 unsigned char ledbuff[]={0X08,0X28,0X28};//显示缓冲区 unsigned char count; unsigned char newcount; unsigned char oldcount; void intt0(void)//T0中断定时程序,定时58US,即测距1CM. { TCNT0=0XC6; count++; } void icp_timer1(void)//ICP1捕捉中断,捕捉频率38.5~41.6 { if (96<=ICR1<=104) { SREG&=0X7f; newcount=count-13; ICR1=0; TCNT1=0; TCCR1B=0X81; } } void delay_1us(void)//1us { asm("nop"); } void delay_us(unsigned int t)//tus { unsigned int i=0; for(i=0;i } void delay_1ms(void)//1ms { unsigned int i; for(i=1;i<1142;i++); } void delay_ms(unsigned char t) { unsigned char i=0; for(i=0;i delay_1ms(); } } #define k1 P3_4 #define c***out P3_5 //超声波发送 #define c***int P3_7 //超声波接收 #define c***c=0.034 #define bg P3_3 unsigned char c***ds,opto,digit,buffer[3],xm1,xm2,xm0,key,jpjs;//显示标识 unsigned char convert[10]= {0x3F,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//0~9段码 unsigned int s,t,i, xx,j,sj1,sj2,sj3,mqs,sx1; bit cl; void c***cj(); void delay(j); //延时函数 void scanLED(); //显示函数 void timeToBuffer(); //显示转换函数 void keyscan(); void k1cl(); void k2cl(); void k3cl(); void k4cl(); void offmsd(); void send40kHz(void) //发射40KHz超声波 { count=0; TIMSK&=0XDF;//禁止ICP1使能 OCR2=0X64; TCCR2=0X19; } void close40kHz(void) //停止发射超声波 { TCCR2=0X00; } void hextobcd(unsigned char m)//将count十六进制数据转换为LED七段码 { unsigned char temp; temp=m%10; ledbuff[0]=tab1[temp];//mm位 m=m/10; temp=m%10; ledbuff[1]=tab1[temp];//lm位 temp=m/10; ledbuff[2]=tab2[temp];//m位 } void main() //主函数 { EA=1; //开中断 TMOD=0x11; //设定时器0为计数,设定时器1定时 ET0=1; //定时器0中断允许 ET1=1; //定时器1中断允许 TH0=0x00; TL0=0x00; TH1=0x9E; TL1=0x57; c***ds=0; c***int=1; c***out=1; cl=0; opto=0xff; jpjs=0; sj1=45; sj2=200; sj3=400; k4cl(); TR1=1; while(1) { keyscan(); if(jpjs<1) { c***cj(); if(s>sj3) { buffer[2]=0x76; buffer[1]=0x76; buffer[0]=0x76; } else if(s buffer[2]=0x40; buffer[1]=0x40; buffer[0]=0x40; } else timeToBuffer(); } else timeToBuffer(); //将值转换成LED段码 offmsd(); scanLED(); //显示函数 if(s bg=1; } } void display3led(void) //数码管显示 { unsigned char i; for(i=0;i<3;i++) { PORTD=ledbuff; PORTC=~(1< delay_1ms(); PORTC=(1< } } void display8led(void) //8LED显示 { if(newcount<10) PORTD=0XFE; else if (newcount<20) PORTD=0XFD; else if (newcount<30) PORTD=0XFB; else if (newcount<40) PORTD=0XF7; else if (newcount<50) PORTD=0XEF; else if (newcount<100) PORTD=0XDF; else if (newcount<180) PORTD=0XBF; else PORTD=0X7F; } void mcu_init(void)//MCU初始化 { DDRD=0XFF; PORTD=0XFF; DDRC=0XDF; //PC5为输入 PORTC=0XFF; DDRB=0XFE; PORTB=0XF7; TCNT2=0X00; TCNT0=0XC6; //T0定时58US TCCR0=0X02; //T0定时器1/8分频 TCNT1=0X00; TCCR1A=0X00; TCCR1B=0X81; //输入捕获噪音抑制允许,ICP1下降沿触发,系统时钟 TIMSK=0X01; //使能T0定时溢出 } void main(void) { unsigned char i; mcu_init(); for(;;) { send40kHz(); SREG|=0X80; delay_us(50); close40kHz(); delay_us(20); TIMSK=0X21; if(!(PINC&0X20)) //如果插上JD1短路块,则数码管显示距离 { if (newcount!=oldcount) oldcount=newcount; hextobcd(oldcount); for(i=0;i<20;i++) display3led(); } else { PORTC=0XFF; display8led(); delay_ms(100); } } } |
|
相关推荐
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1483 浏览 0 评论
1925 浏览 0 评论
Protues中自己封装的芯片元件无Program File、Clock Frequency选项怎么解决,求求大神了!
3703 浏览 1 评论
基于51单片机的车辆倒车雷达报警系统,HC-SR04超声波测距,全套资料
1006 浏览 0 评论
【原创】收藏!单片机输出4种波形的函数信号发生器毕设(Proteus仿真+原理图+源码和论文)
4541 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-23 12:16 , Processed in 0.527345 second(s), Total 73, Slave 56 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191