⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ad转换.c

📁 基于8位并行AD和12位串行AD的数字直流电压表
💻 C
字号:
#include "reg51.h"
#include "intrins.h"
#include "absacc.h"
#define ADC_ch XBYTE[0x7ff8]
#define uchar unsigned char
#define uint unsigned int

sbit ADC_busy= P3^2;
idata unsigned char Rec_data=0xde;
code unsigned char display[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char count[4]={0,0,0,0};
char  str1[]="  Voltage meter";
uchar  str2[16]="Vol:       D:";
sbit RS=P3^0;
sbit RW=P3^1;
sbit EN=P3^3;

void delayl();//LCD驱动函数
void delays();  
void writecota(uchar c);
void shotchar(uchar pos,uchar c);
void showstring(uchar line,char *ptr);
void initlcd();

/*void REC(void)interrupt 0
{
		Rec_data= ADC_ch;	 //存放结果
}  */
void START(void)
{
		ADC_ch = 0; 		     /*启动A/D转换*/
		_nop_();			     /*插入空操作等待EOC信号变低*/
		_nop_();
       	 _nop_();
		 _nop_();
       	 _nop_();
		 _nop_();
       	 _nop_();
		 _nop_();
       	 _nop_();
	 while(ADC_busy ==1); /*查询转换状态*/
	 Rec_data= ADC_ch;
}
void Process(void)
{
	float temp;
	unsigned int Data_temp;
	temp=(Rec_data*5.0/255.0);
	temp*=1000;
	Data_temp=(int)temp;
	count[0]=Data_temp/1000;
	count[1]=Data_temp%1000/100;
	count[2]=Data_temp%1000%100/10;
	count[3]=Data_temp%10;

	str2[4]=count[0]|0x30;
	str2[5]='.';
	str2[6]=count[1]|0x30;
	str2[7]=count[2]|0x30;
	str2[8]=count[3]|0x30;
	str2[9]='V';
	str2[15]='H';
	if((Rec_data/16)<=9&&(Rec_data/16)>=0)str2[13]=(Rec_data/16)|0x30;
	else str2[13]=(Rec_data/16)+0x37;
	if((Rec_data%16)<=9&&(Rec_data%16)>=0)str2[14]=(Rec_data%16)|0x30;
	else str2[14]=(Rec_data%16)+0x37;
}
void delay(uchar x)
{
	while(x--)
	{
	   delays();
	}
}
void delays()
{
	uchar i;
	for(i=0;i<250;i++)
	{;}
}
void writecom(uchar c)
{ 
  delayl();
  EN=0;
  RS=0;
  RW=0;
  _nop_();
  _nop_();
  P1=c;
  EN=1;
  _nop_();
  EN=0;
}
//*************************
void writedata(uchar c)
{ 
  delayl();
  EN=0;
  RS=1;
  RW=0;
  _nop_();
  _nop_();
  P1=c;
  EN=1;
  _nop_();
  EN=0;
  RS=1;
}
//*****************
void showchar(uchar pos,uchar c)
{ uchar p;
  if(pos>=0x10)
     p=pos+0xb0;
  else
     p=pos+0x80;
  writecom(p);
  writedata(c);
 }
//****************************
void showstring(uchar line,char *ptr)
{ uchar l,i;
  l=line<<4;
  for(i=0;i<16;i++)
      {showchar(l++,*(ptr+i));}
}
//***************************
void initlcd()
{ 
  delayl();
  writecom(0x38);
  writecom(0x38);
  writecom(0x06);
  writecom(0x0c);
  writecom(0x01);
  writecom(0x80);
}
void delayl()
{ uchar j;
  for(j=0;j<100;j++)
  {;}
}
//**************************
void main(void)
{ 	uchar i;
	i='A';
	EX0=1;
	IT0=1;
	EA=1;
  	initlcd();
  	delays();
  	showstring(0,str1);
	showstring(1,str2);
   	while(1)
	{
		START();
		Process();
		showstring(1,str2);
		delay(3);
	}
  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -