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

📄 text.c

📁 我设计的数字电源的源代码 还有原理图
💻 C
字号:

#include <reg51.h>
#include <intrins.h>

typedef unsigned char BYTE;
typedef unsigned int WORD;
typedef bit BOOL ; 
BYTE dispbuf[8]={10,10,10,10,0,0,0,0};

BYTE getdata;
unsigned long temp;
BYTE code dis1[] = {"Digital Power *"};
BYTE code dis2[]={'0','1','2','3','4','5','6','7','8','9','V','.'} ;
BYTE code dis3[]={"                 "};
BYTE code dis4[]={"Welcome Nudt_RY"};
BYTE code dis5[]={"value:"};
BYTE i;
BYTE *app=dis2;
BYTE num[10];
BYTE ast;
unsigned int at;
sbit rs	= P2^0;		//
sbit rw = P2^1;
sbit ep = P2^2;
sbit ST=P2^3;
sbit OE=P2^4;
sbit EOC=P2^5;
sbit protect=P3^7;
sbit light=P2^7;

delay(BYTE ms)
{							// 延时子程序
	BYTE i;
	while(ms--)
	{
		for(i = 0; i< 250; i++)
		{
			_nop_();
			_nop_();
			_nop_();
			_nop_();
		}
	}
}

BOOL lcd_bz()
{							// 测试LCD忙碌状态
	BOOL result;
	rs = 0;
	rw = 1;
	ep = 1;
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	result = (BOOL)(P0 & 0x80);
	ep = 0;
	return result;	
}

lcd_wcmd(BYTE cmd)
{							// 写入指令数据到LCD
	while(lcd_bz());
	rs = 0;
	rw = 0;
	ep = 0;
	_nop_();
	_nop_();	
	P0 = cmd;
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	ep = 1;
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	ep = 0;		
}

lcd_pos(BYTE pos)
{							//设定显示位置
	lcd_wcmd(pos | 0x80);
}

lcd_wdat(BYTE dat)	
{							//写入字符显示数据到LCD
	while(lcd_bz());
	rs = 1;
	rw = 0;
	ep = 0;
	P0 = dat;
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	ep = 1;
	_nop_();
	_nop_();
	_nop_();
	_nop_();
	ep = 0;	
}

lcd_init()
{							//LCD初始化设定
	lcd_wcmd(0x38);			//
	delay(1);
	lcd_wcmd(0x0c);			//
	delay(1);
	lcd_wcmd(0x06);			//
	delay(1);
	lcd_wcmd(0x01);			//清除LCD的显示内容
	delay(1);
}


void Display(void)//演示一行连续字符串dis4,配合上位程序演示移动字串
                  
{

 
 for (i=15;i>0;i--) 
 {
lcd_pos(i);

ast=0;
while((dis4[ast] != '\0')&&ast<=(16-i))
	{						// 显示字符
		lcd_wdat(dis4[ast]);
		ast++;
    	}
delay(99);
 lcd_init();
 }
}

main()
{
   
   BYTE i;

   
	lcd_init();				// 初始化LCD			
	delay(10);
   Display(); 
	
   
	lcd_pos(0x00);				// 设置显示位置为第一行的第5个字符
	i = 0;
 
	while(dis1[i] != '\0')
	{						// 显示字符
		lcd_wdat(dis1[i]);
		i++;
	}
    ST=0;
   OE=0;

   ST=1;
_nop_();

   ST=0;
delay(10);
_nop_();
light=0;
while(1) //检测
{
  if(EOC==1)
   {
   OE=1;
	if(P1>0xdf||P1<0x03)  //保护
	{
	protect=1;
	light=1;
	}
	

   getdata=P1;
   OE=0;
  if (getdata<=0x06)  //xiaozheng校正
{at=5000-909*(getdata-0x03);}
else if (0x19>=getdata&&getdata>0x06)
    {at=2273-(1236*(getdata-0x06))/(0x19-0x06);}
else if (0x2d>=getdata&&getdata>0x19)
    {at=1037-((getdata-0x019)*(1037-846))/(0x2d-0x19);}
else if (0x40>=getdata&&getdata>0x2d)
    {at=846-((getdata-0x02d)*(846-800))/(0x40-0x2d);}
else if (0x40<getdata&&getdata<=0x52)
    {at=800-((800-781)*(getdata-0x40))/(0x52-0x40);}

else if (0x065>=getdata&&getdata>0x52)
    {at=781-((781-751)*(getdata-0x52))/(0x65-0x52);}
else if (0x7d>=getdata&&getdata>0x065)
    {at=751-((751-712)*(getdata-0x65))/(0x7d-0x65);}
else if (0x94>=getdata&&getdata>0x7d)
    {at=712-((712-692)*(getdata-0x7d))/(0x94-0x7d);}

else if (0xa6>=getdata&&getdata>0x94)
    {at=692-((692-694)*(getdata-0x94))/(0xa6-0x94);}
else if (0xb9>=getdata&&getdata>0xa6)
    {at=694-((694-692)*(getdata-0xa6))/(0xb9-0xa6);}
else if (0xdf>=getdata&&getdata>0xb9)
    {at=692-((692-679)*(getdata-0xb9))/(0xdf-0xb9);}





   temp=getdata*25;
	
temp=temp*at;

   temp=temp/1280;
	i=0;
    while(i<8)
	 {
	 num[i]=0x00;
	 i++;
	 }


   i=3;
   

   while(i<=4)
     {
  num[i]=temp%10;

  temp=temp/10;


  i++;
      }

num[i++]=11;
while(temp/10)
{
   num[i]=temp%10;
i++;
 temp=temp/10;
 } 
  num[i]=temp;  
 num[2]=10; 
 
  ST=1;
_nop_();
  ST=0;
_nop_();
   }

delay(10); //在显示屏上输出实际电压值
   i = 0;
lcd_pos(0x41);
	while(dis3[i] != '\0')
	{						// 显示字符
		lcd_wdat(dis3[i]);
		i++;
	}
i=0;
	lcd_pos(0x41);
	// 设置显示位置为第二行第二个字符
while(dis5[i] != '\0')
	{						// 显示字符
		lcd_wdat(dis5[i]);
		i++;
	}
lcd_pos(0x48);
	i = 7;

while(i>1)

	{
	ast=num[i];				          // 显示字符电压 *
		lcd_wdat(*(app+ast));
		i=i-1;
		}
delay(10);
}
}

⌨️ 快捷键说明

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