欢迎来到天天文库
浏览记录
ID:59390323
大小:750.50 KB
页数:50页
时间:2020-05-30
《飞思卡尔C语言.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include#defineHIGHSPEED8000#defineLOWSPEED11000/*速度变量,0-24000数值越大,速度越慢*/voidPWMout(int,int);/*24000-20000*/voidIOtest(void){staticunsignedchari=0,j=0x01,k;DDRB=DDRA=0xFF;PORTB=0xf0;for(;;){k=(~j)&0x7f;PORTA=PORTB=k;while(TCNT!=0x0000);while
2、(TCNT==0x0000){if(i>9){j=j<<1;i=0;}i++;}if(j>=0x80)j=0x01;}}voidPWMtest(void){intcounter=-4500;DDRB=0xff;PORTB=0xff;TSCR1=0x80;/*enabletimerTCNT*/TSCR2=0x00;/*TCNTprescalersetup*/for(;;){while(TCNT!=0x0000);while(TCNT==0x0000);counter=counter+30;if(counter>=3000){counter=0
3、;PWMout(4500,LOWSPEED);}if(counter==1500){PWMout(-4500,LOWSPEED);}PORTB=(char)(counter/100);}}voidSignalTest(void){unsignedcharsignal;intDirection,Velocity;Direction=0;Velocity=LOWSPEED;DDRA=0x00;DDRB=0xff;signal=PORTA;PORTB=~signal;switch(signal){case0x08:/*00011000*/case
4、0x10:Direction=800;Velocity=HIGHSPEED;break;case0x04:/*00100100*/case0x20:Direction=1500;Velocity=HIGHSPEED;break;case0x02:/*01000010*/case0x40:Direction=2800;Velocity=HIGHSPEED;break;case0x01:/*10000001*/case0x80:Direction=4000;Velocity=LOWSPEED;break;case0x3c:/*00111100o
5、verstartline*/case0xff:/*11111111overcrossingline*/case0x00:/*00000000gostraightnotneedchangedstate*/default:break;}if(signal>0x0f)Direction=-Direction;PWMout(Direction,LOWSPEED);}/*************************************************************************************LCD1620
6、.c*ICC-AVRapplicationbuilder:2006-1-821:43:48*Target:M8*Crystal:4.0000Mhz**Note:Don'tchangethisfileifpossible.**********************************************************************************/#defineCMD_CLEAR0x01#defineCMD_RESET0x02#include#include#defi
7、neLCD_DATA0xff#defineLCD_EN0x01//PORTC0#defineLCD_RS0x02//PORTC1#defineLCD_RW0x04//PORTC2#defineLCD_DATAPORTPORTB#defineLCD_ENPORTPORTA#defineLCD_RSPORTPORTA#defineLCD_RWPORTPORTAvoidlcd_init(void);voidlcd_write_cmd(unsignedcmd,unsigneddata);voidlcd_setxy(unsignedcharx,uns
8、ignedchary);voidlcd_write_string(unsignedcharX,unsignedcharY,unsignedchar*str);voiddelay_
此文档下载收益归作者所有