《关于MPLAB的问题.docx》由会员分享,可在线阅读,更多相关《关于MPLAB的问题.docx(8页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、关于MPLAB的问题关于MPLAB的问题JayWong19882021-12-08各位大神好,我是一个加拿大的电子系的留学生,我有一个实验需要写一个MPLAB的单机片,我硬件已连接显示屏,keypad,LM60温度感应器,我用的IC是p24HJ128GP502,我的C语言编程不是太好,所以请各位大神帮帮我吧!它的要求如下:我怎样在whileloop里添加一下的功能呢?1.上电自检。红色LED闪烁三次。好的消息。2.显示选项:1)读取,2)保存,3)召回和4)去除。3.要求选择按1,读取传感器读数并在LCD上显示读数。4.眨了一次。按2保存传感器读数,并确认保存在LCD上。5.眨了两次。按3来回
2、忆一个保存的浏览。询问浏览数字。6.按4去除不保存的读数。7.眨了一次。完成任何选择后,返回到显示选项屏幕。这是我的代码,我尝试了把它的要求写进去,但都失败。#includepic24_all.h#includestdio.h#defineRS_HIGH()(_LATB9=1)#defineRS_LOW()(_LATB9=0)#defineCONFIG_RS()CONFIG_RB9_AS_DIG_OUTPUT()#defineRW_HIGH()(_LATB13=1)#defineRW_LOW()(_LATB13=0)#defineCONFIG_RW()CONFIG_RB13_AS_DIG_OU
3、TPUT()#defineE_HIGH()(_LATB14=1)#defineE_LOW()(_LATB14=0)#defineCONFIG_E()CONFIG_RB14_AS_DIG_OUTPUT()#defineLED(_LATB14)#defineLCD4O(_LATB5)#defineLCD5O(_LATB6)#defineLCD6O(_LATB7)#defineLCD7O(_LATB8)#defineLCD7I(_RB8)#defineCONFIG_LCD4_AS_INPUT()CONFIG_RB5_AS_DIG_INPUT()#defineCONFIG_LCD5_AS_INPUT(
4、)CONFIG_RB6_AS_DIG_INPUT()#defineCONFIG_LCD6_AS_INPUT()CONFIG_RB7_AS_DIG_INPUT()#defineCONFIG_LCD7_AS_INPUT()CONFIG_RB8_AS_DIG_INPUT()#defineCONFIG_LCD4_AS_OUTPUT()CONFIG_RB5_AS_DIG_OUTPUT()#defineCONFIG_LCD5_AS_OUTPUT()CONFIG_RB6_AS_DIG_OUTPUT()#defineCONFIG_LCD6_AS_OUTPUT()CONFIG_RB7_AS_DIG_OUTPUT
5、()#defineCONFIG_LCD7_AS_OUTPUT()CONFIG_RB8_AS_DIG_OUTPUT()#defineGET_BUSY_FLAG()(LCD7I)/PulsetheEclock,1usdelayaroundedgesfor/setup/holdtimesvoidpulseE(void)DELAY_US(1);E_HIGH();DELAY_US(1);E_LOW();DELAY_US(1);uint8_tu8_wdtState;if(u8_CheckBusy)RS_LOW();/RS=0tocheckbusy/checkbusyconfigBusAsInLCD();/
6、setdatapinsallinputu8_wdtState=_SWDTEN;/saveWDTenablestateCLRWDT();/cleartheWDTtimer_SWDTEN=1;/enableWDTtoescapeinfinitewaitdoE_HIGH();DELAY_US(1);/readupper4bitu8_BusyFlag=GET_BUSY_FLAG();E_LOW();DELAY_US(1);pulseE();/pulseagainforlower4-bitwhile(u8_BusyFlag);_SWDTEN=u8_wdtState;/restoreWDTenablest
7、ateelseDELAY_MS(10);/dontusebusy,justdelayconfigBusAsOutLCD();if(u8_DataFlag)RS_HIGH();/RS=1,databyteelseRS_LOW();/RS=0,commandbyteoutputToBusLCD(u8_Cmd4);/sendupper4bitpulseE();if(u8_Send8Bits)outputToBusLCD(u8_Cmd);/sendlower4bitpulseE();/InitializetheLCD,modifytosuityourapplicationandLCDvoidinitL
8、CD()DELAY_MS(50);/waitfordevicetosettlewriteLCD(0x20,0,0,0);/4bitinterfacewriteLCD(0x28,0,0,1);/2linedisplay,5x7fontwriteLCD(0x28,0,0,1);/repeatwriteLCD(0x06,0,0,1);/enabledisplaywriteLCD(0x0C,0,0,1);/turndisplayon;cursor,blinkisoffwriteLCD(0x01,0,0,1);/cleardisplay,movecursortohomeDELAY_MS(3);/Outp
9、utastringtotheLCDvoidoutStringLCD(char*psz_s)while(*psz_s)writeLCD(*psz_s,1,1,1);psz_s+;#defineC0_RB12#defineC1_RB2#defineC2_RB3#defineC3_RA2staticinlinevoidCONFIG_COLUMN()CONFIG_RB12_AS_DIG_INPUT();ENABLE_RB12_PULLUP();CONFIG_RB2_AS_DIG_INPUT();ENABLE_RB2_PULLUP();CONFIG_RB3_AS_DIG_INPUT();ENABLE_R
10、B3_PULLUP();CONFIG_RA2_AS_DIG_INPUT();ENABLE_RA2_PULLUP();#defineR0_RA3#defineR1_RB4#defineR2_RA4#defineCONFIG_R0_DIG_OUTPUT()CONFIG_RA3_AS_DIG_OUTPUT()#defineCONFIG_R1_DIG_OUTPUT()CONFIG_RB4_AS_DIG_OUTPUT()#defineCONFIG_R2_DIG_OUTPUT()CONFIG_RA4_AS_DIG_OUTPUT()voidCONFIG_ROW()#defineNUM_ROWS3#defin
11、eNUM_COLS4constuint8_tau8_keyTableNUM_ROWSNUM_COLS=1,4,7,*,2,5,8,0,3,6,9,#;#defineKEY_PRESSED()(!C0|!C1|!C2|!C3)/anylow#defineKEY_RELEASED()(C0C1C2C3)/allhigh/#definetemp_c#defineVREF3.3intmain(void)configBasic(HELLO_MSG);/*PIOconfig*/configKeypad();/*ConfiguretheTimer*/configTimer3();configControlL
12、CD();/configuretheLCDcontrollineinitLCD();/initializetheLCDuint16_tu16_adcVal;floatf_adcVal;charbuff50;CONFIG_RA0_AS_ANALOG();configADC1_ManualCH0(RA0_AN,31,0);while(1)/u16_adcVal=convertADC1();/getADCvalue/f_adcVal=u16_adcVal;/f_adcVal=f_adcVal/1024.0*VREF;/converttofloatinrange0.0toVREF/printf(ADCinput:%4.2fV(0x%04x),T=%7,4fcn,(double)f_adcVal,u16_adcVal);/sprintf(buff,ADCinput:%4.2fV(0x%04x),T=%7,4fcn,(double)f_adcVal,u16_adcVal);/writeLCD(0x01,0,1,1);/outStringLCD(buff);/endwhile(1)