补齐这段C51代码,完成ADC0808的数字电压表虚拟仿真,在LCD1602上显示电压(格式:v=X.XXV,其中“X”对应具体值): #include "reg52.h" #include "intrins.h" typedef unsigned int uint; typedef unsigned char uchar; sbit P3^2=CLOCK; sbit P3^3=EOC; sbit P3^4=START; sbit P3^5=OE; sbit P1^0=OUT8; sbit P1^1=OU
时间: 2024-04-02 15:34:01 浏览: 136
T7; void delay(uint i) { while(i--); } void write_com(uchar com) { P1 = com; P3^2 = 0; _nop_(); P3^2 = 1; delay(10); } void write_data(uchar dat) { P1 = dat; P3^2 = 1; _nop_(); P3^2 = 0; delay(10); } void init_lcd() { write_com(0x38); delay(5); write_com(0x0c); delay(5); write_com(0x06); delay(5); write_com(0x01); delay(5); } void init_adc() { P3^4 = 1; P3^5 = 1; } uint read_adc() { uint value; P3^4 = 0; P3^5 = 0; P3^4 = 1; while(P3^3); for(int i=0;i<8;i++) { P3^2 = 0; P3^2 = 1; value = value << 1; value |= OUT8; } P3^5 = 1; return value; } void main() { init_lcd(); init_adc(); while(1) { uint adc_value = read_adc(); float voltage = adc_value * 5.0 / 255.0; write_com(0x80); write_data('v'); write_data('='); write_data((int)voltage+'0'); write_data('.'); write_data((int)(voltage*10)%10+'0'); write_data((int)(voltage*100)%10+'0'); write_data('V'); } }
阅读全文