/*我写的51AD 转换程序,LED 灯显示,随着外部电压升高,亮的小灯数会逐渐增加*/ #include//包含单片机寄存器的头文件 #include //包含_nop_()函数定义的头文件 unsigned char result; //A/D 转换结果变量 void main(void) { unsigned long i; unsigned char status; ADC_CONTR|=0x80; //开A/D 转换电源,第一次使用时要打开内部模拟电源 for (i=0;i<10000;i++); //适当延时 P1ASF=0x04; //选择 P1.2 作为 A/D 转换通道 ADC_CONTR=0xE2; for (i=0;i<10000;i++); //适当延时 while(1) //循环进行 A/D 转换 { ADC_CONTR|=0x08; //启动 A/D 转换 status=0; while(status==0) //等待 A/D 转换结束 { status=ADC_CONTR&0x10; } ADC_CONTR&=0xE7; //将 ADC_FLAG 清 0 result=ADC_RES; //保存A/D 转换结果 if(result<32) P0=0xff; else if(result<64) P0=0xfe; else if(result<96) P0=0xfc; else if(result<128) P0=0xf8; else if(result<160) P0=0xf0; else if(result<192) P0=0xe0; else if(result<214) P0=0xc0; else if(result<236) P0=0x80; else P0=0x00; } } /*---------------------------------------------------------------------------------------------------------------------------*/ /*--************************功能【AD 转换,液晶显示】**************************--*/ /*--************************芯片:【STC12C5A60S2】******************************--*/ /*--************************液晶:【LCD1602】***********************************--*/ /*--************************ADC 管脚:【P1.0~P1.7 】***************************--*/ /*--************************检测范围:【0.00~4.99V】***************************--*/ /*---------------------------------------------------------------------------------------------------------------------------*/ #include "reg52.h" #include "intrins.h" typedef unsigned char uchar; typedef unsigned int uint; #define _Nop() _nop_() /*------------------------以下为 LCD1602 显示模块定义-----------------------*/ unsigned char data_char_table[]= {"0123456789ABCDEF"}; //LCD 数据 unsigned char...