赞
踩
链接:https://pan.baidu.com/s/1clANAhH7iIB7-ITJlyyFSg
提取码:o2uh
仿真图:
#include <reg52.h> #include <intrins.h> #include "timer.h" #include "key.h" #include "lcd.h" #include "global.h" #include "adcdac.h" #define delay4us() {_nop_();_nop_();_nop_();_nop_();} #define vout 1 #define vset 0 #define vmode #define MODE_B 1 #define MODE_A 0 bit workmode; //sbit KEY1 = P3^6; //sbit KEY2 = P3^7; /* typedef struct { union {uint I; uchar C[2];}tempval1; union {uint I; uchar C[2];}tempval2; }sData; sData D; */ void Delayms(uint ms) { uchar i; while(ms--) { for(i=0;i<120;i++); } } void main() { uchar B; uchar temp; uint d,v; Initialize_LCD(); InitTimer(); Delayms(10); v = 0x0100; StartTimer(0); B = 0; workmode = MODE_A; while(1) { KEYPORT = 0xf0; if(KEYPORT != 0xf0) { temp = Keys_Scan(); keyhandle(temp); } if(workmode==MODE_A) { d = Get_AD_Result(vset); d &=0x00FF; Set_DAC(d*4); d = d*1000.0/255; strcpy(Display_Buffer1 , "SetVoltage:"); if(d/1000) { Display_Buffer1[11]=d/1000+'0'; Display_Buffer1[12]=d/100%10+'0'; Display_Buffer1[13]='.'; Display_Buffer1[14]=d/10%10+'0'; Display_Buffer1[15]=d%10+'0'; } else { Display_Buffer1[11]=d/100%10+'0'; Display_Buffer1[12]='.'; Display_Buffer1[13]=d/10%10+'0'; Display_Buffer1[14]=d%10+'0'; Display_Buffer1[15]=' '; } d = Get_AD_Result(vout); d &=0x00FF; d = d*1000.0/255; strcpy(Display_Buffer0 , "OutVoltage:"); if(d/1000) { Display_Buffer0[11]=d/1000+'0'; Display_Buffer0[12]=d/100%10+'0'; Display_Buffer0[13]='.'; Display_Buffer0[14]=d/10%10+'0'; Display_Buffer0[15]=d%10+'0'; } else { Display_Buffer0[11]=d/100%10+'0'; Display_Buffer0[12]='.'; Display_Buffer0[13]=d/10%10+'0'; Display_Buffer0[14]=d%10+'0'; Display_Buffer0[15]=' '; } DisplayUpdate(); } else { if((updateflag)&&(!setenable)) { d = Get_AD_Result(vout); d &=0x00FF; d = d*1000.0/255; if(d/1000) { Display_Buffer0[11]=d/1000+'0'; Display_Buffer0[12]=d/100%10+'0'; Display_Buffer0[13]='.'; Display_Buffer0[14]=d/10%10+'0'; Display_Buffer0[15]=d%10+'0'; } else { Display_Buffer0[11]=d/100%10+'0'; Display_Buffer0[12]='.'; Display_Buffer0[13]=d/10%10+'0'; Display_Buffer0[14]=d%10+'0'; Display_Buffer0[15]=' '; } DisplayUpdate(); } } } }
.
文件仅供参考:
.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。