
#include<stdio.h>
#include <intrins.h>
typedef unsigned char uchar
typedef unsigned int uint
#define LCD_Data P0
#define Busy0x80 //用于检测LCD状态字中的Busy标识
sbit LCD_RS=P2^7//定义引脚
sbit LCD_RW=P2^6
sbit LCD_E=P2^5
float volts,amps
//5ms延时
void Delay5Ms(void)
{
unsigned int TempCyc = 5552
while(TempCyc--)
}
//400ms延时
void Delay400Ms(void)
{
unsigned char TempCycA = 5
unsigned int TempCycB
while(TempCycA--)
{
TempCycB=7269
while(TempCycB--)
}
}
//读状态
unsigned char ReadStatusLCD(void)
{
LCD_Data = 0xFF
LCD_RS = 0
LCD_RW = 1
LCD_E = 0
LCD_E = 0
LCD_E = 1
while (LCD_Data &Busy)//检测忙信号
return(LCD_Data)
}
//写数据
void WriteDataLCD(unsigned char WDLCD)
{
ReadStatusLCD()//检测忙
LCD_Data = WDLCD
LCD_RS = 1
LCD_RW = 0
LCD_E = 0//若晶振速度太高可以在这后加小的延时
LCD_E = 0//延时
LCD_E = 1
}
//写指令
void WriteCommandLCD(unsigned char WCLCD,BuysC) //BuysC为0时忽略忙检测
{
if (BuysC) ReadStatusLCD()//根据需要检测忙
LCD_Data = WCLCD
LCD_RS = 0
LCD_RW = 0
LCD_E = 0
LCD_E = 0
LCD_E = 1
}
//读数据
unsigned char ReadDataLCD(void)
{
LCD_RS = 1
LCD_RW = 1
LCD_E = 0
LCD_E = 0
LCD_E = 1
return(LCD_Data)
}
void LCDInit(void) //LCM初始化
{
LCD_Data = 0
WriteCommandLCD(0x38,0)//三次显示模式设置,不检测忙信号
Delay5Ms()
WriteCommandLCD(0x38,0)
Delay5Ms()
WriteCommandLCD(0x38,0)
Delay5Ms()
WriteCommandLCD(0x38,1)//显示模式设置,开始要求每次检测忙信亩段数号
WriteCommandLCD(0x08,1)//关闭显示
WriteCommandLCD(0x01,1)//显示清屏
WriteCommandLCD(0x06,1)// 显示光标移动设置
WriteCommandLCD(0x0C,1)// 显示开及光标设置
}
//按指定位置显示一个字符
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
{
Y &= 0x1
X &= 0xF//限制X不能大于15,Y不能大于燃山1
if (Y) X |= 0x40//当要显示第二行时地址码+0x40
X |= 0x80// 算出指令码
WriteCommandLCD(X, 0)//这里不检测忙信号迅首,发送地址码
WriteDataLCD(DData)
}
//按指定位置显示一串字符
void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData)
{
unsigned char ListLength
ListLength = 0
Y &= 0x1
X &= 0xF//限制X不能大于15,Y不能大于1
while (DData[ListLength]>=0x20) //若到达字串尾则退出
{
if (X <= 0xF) //X坐标应小于0xF
{
DisplayOneChar(X, Y, DData[ListLength])//显示单个字符
ListLength++
X++
}
}
}
把你的电压电流什么的放在数组里,然后用 DisplayListChar()这个命令显示出来,格式比如 DisplayListChar(0,0,dianya[])什么的,0行0列显示电压。把这一大段程序放在你的mian函数上面,在mian函数里写显示什么东西 。显示的东西放不下加个按键,按一下显示下一种数据
exter0() interrupt 0 // 外中断0用来从外设输入数据,并采用窗口宽度为8的均值滤波来滤除噪声干扰。{
unsigned int dat
uchar count,temp,temp1,j
count++ // 数据个数加1
EX0=0 胡销 // 暂时禁止中断
P2=0xff // 准备从P2口输入数据
MRD=0 // 发出读命令
HBEN=0 // 读取低8位
temp=P2 // 低8位,放temp中
delayus(1)
HBEN=1 //读取高八位
temp1=P2 // 放temp1中
temp1&=0x0f // 数据只有12位,则屏蔽掉最高4位
num=temp1*256+temp // 还原成1个数据
num1=num1+num // 求累和
if(count==8) // 是否已经有8个数了
{
count = 0 困做逗 // 是,重新从0开始
num2 = num1 /8 // 累和除以8,也就是求平均
num1 = 0 // 类和再次从0开始
j++ 汪卖 // 平均的数据又多了一个
if(j>7) j=0 // 如果有多于8个的平均值,又从0开始
}
numb[j]=num2 // 存放这个有用的均值
MRD=1 // 结束读信号
init(0x40+j)
EX0=1 // 开外中断0
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)