您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 电子星系工程pic程序
#includep18f452.h#includedelays.h#defineRSPINPORTBbits.RB5//DataorInstrumentSelect#defineRWPINPORTBbits.RB4//WriteorRead#defineEPINPORTBbits.RB3//6800modeEnablesingle#defineINPUTPORTBbits.RB2#definecoldPORTBbits.RB6#definewarmPORTBbits.RB7#defineSTSPORTAbits.RA0#defineCSPORTAbits.RA1#defineA0PORTAbits.RA2#defineCEPORTAbits.RA3#defineRCPORTAbits.RA4voidInterruptHandlerHigh(void);#defineucharunsignedchar//宏定义#defineuintunsignedint#defineK_UP0X20//定义键值#defineK_DOWN0X21#defineK_CLEAR0X24#defineK_OK0X25#defineK_ONE0X30#defineK_FOUR0X31#defineK_SEVEN0X32#defineK_POINT0X33#defineK_TWO0X34#defineK_FIVE0X43#defineK_EIGHT0X36#defineK_ZERO0X37#defineK_THREE0X38#defineK_SIX0X40#defineK_NINE0X41#defineK_SET0X42#includekey.h////////////////////全局变量/////////////////////////////unsignedintTimeout;floatTEMP_NOW=0.0;floatTEMP_SET=21.0;uintT_Count=0;uintS_Count=0;uintP_Count=0;uintN_Count=0;uintM_Count=1;ucharCurrent_Temp_Display_Buffer[]={NOW:-23.5};ucharset_Temp_Display_Buffer[]={SET:21.0};intsel=0;voidComparison();//////////////////////定时///////////////////////////////voidtimer0_init(void){Timeout=0;INTCON=0x20;//disableglobalandenableTMR0interruptINTCON2=0x84;//TMR0highpriorityRCONbits.IPEN=1;//enableprioritylevelsTMR0H=0;//cleartimerTMR0L=0;//cleartimerT0CON=0x82;//setuptimer0-prescaler1:8INTCONbits.GIEH=1;//enableinterruptsTRISD=0;/*configurePORTDforoutput*/PORTD=0X00;if(Timeout==1){//timeout?Timeout=0;//cleartimeoutindicorRead_Temperature();Display_Temperature();N_Count=1;}}//Highpriorityinterruptvector//PIC中断标准服务程序#pragmacodeInterruptVectorHigh=0x08//中断向量voidInterruptVectorHigh(void){_asmgotoInterruptHandlerHigh//jumptointerruptroutine_endasm}//----------------------------------------------------------------------------//Highpriorityinterruptroutine//中断服务程序#pragmacode#pragmainterruptInterruptHandlerHighvoidInterruptHandlerHigh(){if(INTCONbits.TMR0IF){//checkforTMR0overflowINTCONbits.TMR0IF=0;//clearinterruptflagTimeout=1;//indicatetimeout}}voidComparison(){if(N_Count&&M_Count){if(TEMP_NOWTEMP_SET){warm=1;cold=0;}if(TEMP_NOWTEMP_SET){cold=1;warm=0;}if(TEMP_NOW==TEMP_SET){cold=0;warm=0;}}}ucharint_LM20();voidRead_Temperature();voidDisplay_Temperature();voidad_convertor(){floattemp;OpenADC(ADC_FOSC_32&ADC_RIGHT_JUST&ADC_8ANA_0REF,ADC_RA0&ADC_INT_OFF);//A/D时钟源,晶振32分频率//A/D转换结果右对齐//A/D参考电压源,电源工作电压//通道选择//中断关闭,查询模式Delay10TCYx(5);//Delayfor50TCYConvertADC();//Startconversionwhile(BusyADC());//Waitforcompletiontemp=ReadADC();//ReadresultCloseADC();//DisableA/DconverterNop();Temp_Value[0]=temp/256;Temp_Value[1]=temp%256;}voidDisplay_Temperature(){uchart=150,ng=0;if((Temp_Value[1]&0xf8)==0xf8){Temp_Value[1]=~Temp_Value[1];Temp_Value[0]=~Temp_Value[0]+1;if(Temp_Value[0]==0x00)Temp_Value[1]++;ng=1;}Display_Digit[0]=df_Table[Temp_Value[0]&0x0f];CurrentT=((Temp_Value[0]&0xf0)4)|((Temp_Value[1]&0x07)4);Display_Digit[3]=CurrentT/100;Display_Digit[2]=CurrentT%100/10;Display_Digit[1]=CurrentT%10;Current_Temp_Display_Buffer[11]=Display_Digit[0]+'0';Current_Temp_Display_Buffer[10]='.';Current_Temp_Display_Buffer[9]=Display_Digit[1]+'0';Current_Temp_Display_Buffer[8]=Display_Digit[2]+'0';Current_Temp_Display_Buffer[7]=Display_Digit[3]+'0';TEMP_NOW=Display_Digit[2]*10+Display_Digit[1]+Display_Digit[0]*0.1;if(Display_Digit[3]==0)Current_Temp_Display_Buffer[7]='';if(Display_Digit[2]==0&&Display_Digit[3]==0)Current_Temp_Display_Buffer[8]='';if(ng){TEMP_NOW=-(Display_Digit[2]*10+Display_Digit[1]+Display_Digit[0]*0.1);if(Current_Temp_Display_Buffer[8]=='')Current_Temp_Display_Buffer[8]='-';elseif(Current_Temp_Display_Buffer[7]=='')Current_Temp_Display_Buffer[7]='-';elseCurrent_Temp_Display_Buffer[6]='-';}}unsignedcharKeys_Scan();voidset_num();voidset();voidDelay_key();ucharKeys_Scan();ucharcodeKeyCodeTable[]={0xEE,0xED,0xEB,0xE7,0xDE,0xDD,0xDB,0xD7,0xBE,0xBD,0xBB,0xB7,0x7E,0x7D,0x7B,0x77};voidDelay_key(){uchari;for(i=0;i200;i++);}ucharKeys_Scan(){uchark,kCode;TRISD=0B11110000;PORTD=11111110;kCode=PORTD;if(kCode==KeyCodeTable[0])returnK_ONE;elseif(kCode==KeyCodeTable[1])returnK_TWO;elseif(kCode==KeyCodeTable[2])returnK_THREE;elseif(kCode==KeyCodeTable[3])returnK_FOUR;elseif(kCode==KeyCodeTable[4])returnK_FIVE;elseif(kCode==KeyCodeTable[5])returnK_SIX;elseif(kCode==KeyCodeTable[6])returnK_SEVEN;elseif(kCode==KeyCodeTable[7])returnK_EIGHT;elseif(kCode==KeyCodeTable[8])returnK_NINE;elseif(kCode==KeyCodeTable[9])returnK_UP;elseif(kCode==KeyCodeTable[10])returnK_DOWN;elseif(kCode==KeyCodeTable[11])returnK_CLEAR;elseif(kCode==KeyCodeTable[12])returnK_OK;elseif(kCode==KeyCodeTable[13])returnK_ZERO;elseif(kCode==KeyCodeTable[14])returnK_POINT;elseif(kCode==KeyCodeTable[15])returnK_SET;PORTD=11111101;kCode=PORTD;if(kCode==KeyCodeTable[0])returnK_ONE;elseif(kCode==KeyCodeTable[1])returnK_TWO;elseif(kCode==KeyCodeTable[2])returnK_THREE;elseif(kCode==KeyCodeTable[3])returnK_FOUR;elseif(kCode==KeyCodeTable[4])returnK_FIVE;elseif(kCode==KeyCodeTable[5])returnK_SIX;elseif(kCode==KeyCodeTable[6])returnK_SEVEN;elseif(kCode==KeyCodeTable[7])returnK_EIG
本文标题:电子星系工程pic程序
链接地址:https://www.777doc.com/doc-75662 .html