欢迎来到天天文库
浏览记录
ID:42657997
大小:131.50 KB
页数:16页
时间:2019-09-19
《自动避障红外电动小车C51程序》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、自动避障红外电动小车C51程序AutomaticobstacleavoidanceinfraredelectriccarC51programAutomaticobstacleavoidanceinfraredelectriccarC51program#ineludez/reg51・H〃#inelude#clefineucharunsignedchar#clefineuintunsignedint#clefineleftinfrare0#clefineright_infrare1#definedjstatel0X5F//progress#de
2、finedjstate20X4F//right#clefinedj_state30X1F//turnleftPoundsignclefinedjstate4OXOF//back#clefinedjstate5OXfF//stop#definelight_offOxOf//turnthelightA:#defineleft_light0X5F//leftturnlightsandtwoare5f#defineright_lightOXaF//rightturnsignalOXaF,andtwoareOxbfThe#defineback_lightOXcF//bra
3、kelightistherearlight#definefront_light0x3f//headlights#definelight_onOxff//openallthelights1#definetrue#definefalse0#defineLCD_DataPO#defineBusy0x80//fortheBusyidentificationintheLCDstatuswordSbitc=Pl2;//turnthelightontheenergyUcharcodetalkl[]二{〃backward〃};Ucharcodetalk2[]二{〃forward
4、〃};Ucharcodetalk3[]二{〃Turnleft〃};Ucharcodetalk4[]二{〃Turnright〃};Ucharflage二0xOO;Sbitledcs二p八2;//74H573//sbitleft_led=PO2;//leftinfraredtransmittingtube//sbitright_led=PO3;//rightinfraredtransmittertubeSbitLCD_RS二Pl"5;//LCDdefinespinsSbitLCD_RW二Pl八6;//SbitLCD_E二Pl八7;VoidDelay5Ms(void)
5、{UintTempCyc二5552;While(TempCyc--);}//400msdelayVoidDelay400Ms(void)(ucharTempCycA二5;UintTempCycB;Wh订e(TempCycA--){TempCycB二7269;While(TempCycB--);}!//LCDreadingstateUnsignedcharReadStatusLCD(void){LCD_Data二0XFF;LCD_RS二0;LCD_RW二1;LCD_E二0;LCD_E=0;LCDE=1;While(LCD_Data&Busy);//detectbu
6、sysignalsReturn(LCD_Data);}//LCDwritingdataVoidWriteDataLCD(unsignedcharWDLCD){ReadStatusLCD();//testingbusyLCD_Data二WDLCD;LCD_RS二1;LCD_RW二0;LCD_E二0;//ifthevibrationistoohigh,youcanaddasmalldelayafterthisLCD_E=0;//delay,forsafetyLCD_E二0;//delayLCD_E二1;//LCDwritinginstructionVoidWrite
7、CoimnandLCD(unsignedcharWCLCD,BuysC){thebusyIf(BuysC)ReadStatusLCD();//whentheBuysCis0,testisignoredasneededLCD_Data二WCLCD;LCD_RS二0;LCD_RW二0;LCD_E=0;//delay,forsafetyLCD_E二0;LCD_E二0;//delayLCD_E二1;}VoidLCDInit(void)//LCDinitializationDelay400Ms();LCD_Data二0;X38WriteCommandLCD(0,0);//
8、threedisplay
此文档下载收益归作者所有