你把#include "lcd1602.c"去掉,再把《 lcd1602.c》文件里内容全部复制到《测电压.c》文件中,即可用keil编译。文件如下:
#include "reg51.h"
//#include "lcd1602.c"
#define DBPort P0 //LCD数据端口
***it LcdRs = P2^5;
***it LcdRw = P2^6;
***it LcdEn = P2^7;
***it Lcdbf = P0^7; //LCD忙标志 Busy Flag
***it start=P2^0;
***it stop=P2^2;
***it OE=P2^1;
***it clk=P2^4;
***it key=P3^0;
void delay(unsigned int t); //延时
void LCD_Wait(void); //读忙状态
void LCD_Write(bit style, unsigned char input); //写数据1/命令0
void LCD_Initial(void); //初始化LCD
void GotoXY(unsigned char x, unsigned char y); //移动光标到指定位置
void Print(unsigned char *str); //指定坐标输出字符串
unsigned char flag;
void timerint()
{
TMOD=0x11;//设置定时器0为工作方式1(为十六位计数)
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
EA=1;//开总中断
ET0=1;//开定时器0中断
TR0=1;//启动定时器0
}
void main()
{
int temp,a,b,temp1;
int sum = 0;
LCD_Initial();
timerint();
GotoXY(5,0);
Print(" The Vol Is:");
while(1)
{
int k;
OE=0;
start=0;
start=1;
start=0;//下降沿,开始转换
while(stop==0)//查询是否转换结束
{
k++;
if(k>200)
break;
}
OE=1;
if(flag==0)
{
temp=P1;
a = temp*(1000/51)*1.028;//1.032是修正系数
temp=0;
GotoXY(1,1);
Print("DC");
GotoXY(4,1);
LCD_Write(1,a/1000+0x30);
Print(".");
LCD_Write(1,a%1000/100+'0');
LCD_Write(1,a%100/10+'0');
LCD_Write(1,a%10+'0');
Print("V");
}
if(flag==1)
{
temp1=P1;
b = temp1*(1000/51);
if(b>1.5) b=b*1.491;
if(b>1.0&&b<1.5) b=b*2;
GotoXY(1,1);
Print("AC");
GotoXY(4,1);
LCD_Write(1,b/1000+0x30);
Print(".");
LCD_Write(1,b%1000/100+'0');
LCD_Write(1,b%100/10+'0');
LCD_Write(1,b%10+'0');
Print("V");
}
OE=0;
delay(1000);
}
}
void time0() interrupt 1
{
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
clk=~clk;
if(key==0)
{
flag++;
while(key==0);
if(flag==2) flag=0;
}
}
/*******************************************************************/
//端口定义
//#define DBPort P0 //LCD数据端口
//***it LcdRs = P2^5;
//***it LcdRw = P2^6;
//***it LcdEn = P2^7;
//***it Lcdbf = P0^7; //LCD忙标志 Busy Flag
void delay(unsigned int t) //延时
{
while(t--);
}
void LCD_Wait(void) //读忙状态
{
LcdRs=0;
LcdRw=1;
LcdEn=1;delay(10);LcdEn=0; //下降沿
while(Lcdbf)
{
LcdEn=0;LcdEn=1; //仿真才需要此语句,实际硬件中不需要
}
}
void LCD_Write(bit style, unsigned char input) //写数据1/命令0
{
LcdRs=style;
LcdRw=0;
DBPort=input;
LcdEn=1;delay(10);LcdEn=0;
LCD_Wait();
}
void LCD_Initial(void) //初始化LCD
{
LCD_Write(0,0x38); //8位数据端口,2行显示,5*7点阵
delay(300);
LCD_Write(0,0x0c); //显示模式
LCD_Write(0,0x01); //清屏
LCD_Write(0,0x06); //输入模式
}
void GotoXY(unsigned char x, unsigned char y) //移动光标到指定位置
{
if(y==0) LCD_Write(0,0x80|x);
if(y==1) LCD_Write(0,0xc0|x);
}
void Print(unsigned char *str) //指定坐标输出字符串
{
while(*str) LCD_Write(1,*str++);
}
你把#include "lcd1602.c"去掉,再把《 lcd1602.c》文件里内容全部复制到《测电压.c》文件中,即可用keil编译。文件如下:
#include "reg51.h"
//#include "lcd1602.c"
#define DBPort P0 //LCD数据端口
***it LcdRs = P2^5;
***it LcdRw = P2^6;
***it LcdEn = P2^7;
***it Lcdbf = P0^7; //LCD忙标志 Busy Flag
***it start=P2^0;
***it stop=P2^2;
***it OE=P2^1;
***it clk=P2^4;
***it key=P3^0;
void delay(unsigned int t); //延时
void LCD_Wait(void); //读忙状态
void LCD_Write(bit style, unsigned char input); //写数据1/命令0
void LCD_Initial(void); //初始化LCD
void GotoXY(unsigned char x, unsigned char y); //移动光标到指定位置
void Print(unsigned char *str); //指定坐标输出字符串
unsigned char flag;
void timerint()
{
TMOD=0x11;//设置定时器0为工作方式1(为十六位计数)
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
EA=1;//开总中断
ET0=1;//开定时器0中断
TR0=1;//启动定时器0
}
void main()
{
int temp,a,b,temp1;
int sum = 0;
LCD_Initial();
timerint();
GotoXY(5,0);
Print(" The Vol Is:");
while(1)
{
int k;
OE=0;
start=0;
start=1;
start=0;//下降沿,开始转换
while(stop==0)//查询是否转换结束
{
k++;
if(k>200)
break;
}
OE=1;
if(flag==0)
{
temp=P1;
a = temp*(1000/51)*1.028;//1.032是修正系数
temp=0;
GotoXY(1,1);
Print("DC");
GotoXY(4,1);
LCD_Write(1,a/1000+0x30);
Print(".");
LCD_Write(1,a%1000/100+'0');
LCD_Write(1,a%100/10+'0');
LCD_Write(1,a%10+'0');
Print("V");
}
if(flag==1)
{
temp1=P1;
b = temp1*(1000/51);
if(b>1.5) b=b*1.491;
if(b>1.0&&b<1.5) b=b*2;
GotoXY(1,1);
Print("AC");
GotoXY(4,1);
LCD_Write(1,b/1000+0x30);
Print(".");
LCD_Write(1,b%1000/100+'0');
LCD_Write(1,b%100/10+'0');
LCD_Write(1,b%10+'0');
Print("V");
}
OE=0;
delay(1000);
}
}
void time0() interrupt 1
{
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
clk=~clk;
if(key==0)
{
flag++;
while(key==0);
if(flag==2) flag=0;
}
}
/*******************************************************************/
//端口定义
//#define DBPort P0 //LCD数据端口
//***it LcdRs = P2^5;
//***it LcdRw = P2^6;
//***it LcdEn = P2^7;
//***it Lcdbf = P0^7; //LCD忙标志 Busy Flag
void delay(unsigned int t) //延时
{
while(t--);
}
void LCD_Wait(void) //读忙状态
{
LcdRs=0;
LcdRw=1;
LcdEn=1;delay(10);LcdEn=0; //下降沿
while(Lcdbf)
{
LcdEn=0;LcdEn=1; //仿真才需要此语句,实际硬件中不需要
}
}
void LCD_Write(bit style, unsigned char input) //写数据1/命令0
{
LcdRs=style;
LcdRw=0;
DBPort=input;
LcdEn=1;delay(10);LcdEn=0;
LCD_Wait();
}
void LCD_Initial(void) //初始化LCD
{
LCD_Write(0,0x38); //8位数据端口,2行显示,5*7点阵
delay(300);
LCD_Write(0,0x0c); //显示模式
LCD_Write(0,0x01); //清屏
LCD_Write(0,0x06); //输入模式
}
void GotoXY(unsigned char x, unsigned char y) //移动光标到指定位置
{
if(y==0) LCD_Write(0,0x80|x);
if(y==1) LCD_Write(0,0xc0|x);
}
void Print(unsigned char *str) //指定坐标输出字符串
{
while(*str) LCD_Write(1,*str++);
}
举报