|
MAX197 |
![]() |
MAX197 的PDF資料下載,131284K |
其他型號 |
MAX197的供應商: |
聯(lián)系人:詹小姐 電話:0755-83797351 |
聯(lián)系人:王先生 電話:13510086379 |
聯(lián)系人:柚子/芒果 電話:0755-83663056/0755-83209937 |
聯(lián)系人:李小姐 電話:0755-23941053 |
|
>>更多供應商 |
MAX197的帶液晶顯示源程序
include<reg52.h>
#include<intrins.h>
#include<absacc.h>
#define uint unsigned int
#define uchar unsigned char
#define max197 XBYTE[0xefff]
sbit EN=P2^0;
sbit RS=P2^1;
sbit CS=P2^2;
sbit HBEN=P2^3;
sbit duan=P2^6;
uchar templ,temph,flag;
float dianya;
uint temp,temp1[25];
unsigned long voltage;
void delay(uint i)
{
while(i--);
}
void delay1(uint z)
{
int x,y;
for(x=z;x>0;x--)
for(y=114;y>0;y--);
}
void write_com(uchar com)
{
RS=0;
P1=com;
delay1(5);
EN=1;
delay1(5);
EN=0;
}
void write_data(uchar date)
{
RS=1;
P1=date;
delay1(5);
EN=1;
delay1(5);
EN=0;
}
void initial()
{
EN=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
void printc(uchar lcd_data) //輸出一個字符到LCD
{
write_data(lcd_data);
}
void prints(uchar *lcd_string) //輸出一個字符串到LCD
{
uchar i=0;
while(lcd_string[i]!=0x00)
{
write_data(lcd_string[i]);
i++;
}
}
void setPosition(uchar x) //LCD光標定位到x處
{
write_com(0x80+x);
}
uchar TempBuffer[7];
void IntToStr(uint temp, uchar *str, uchar n)
{
uchar a[7]; char i, j; //取得整數(shù)值到數(shù)組
dianya=temp/4096.0;
voltage=dianya*100000;
a[0]=voltage/10000;
a[1]=voltage%10000/1000;
a[2]=voltage%1000/100;
a[3]=voltage%100/10;
a[4]=voltage%10;
for(i=0; i<5; i++) //轉(zhuǎn)成ASCII碼
a[i]=a[i]+'0';
for(i=0; a[i]=='0' && i<=5; i++);
for(j=5-n; j<i; j++) //填充空格
{ *str=' '; str++; }
for(; i<5; i++)
{ *str=a[i]; str++; } //加入有效的數(shù)字
*str='\0';
}
void initial_max197()
{
//uchar *AD;
// AD=&max197;
//單片機初始化
EA=1;
IT1=1;
EX1=1;
duan=0;
//初始化MAX197
//*AD=0x40;
}
void main()
{
uchar i;
initial();
initial_max197();
//CS=0;
max197=0x40;
setPosition(0x00);
prints("The voltage is :");
while(1)
{
//采集15次;
for(i=0;i<15;i++)
{
flag=0;
max197=0x40;
while(!flag);
HBEN=1;
temph=max197;
_nop_();
HBEN=0;
templ=max197;
temp=temph;
temp<<=8;
temp1[i]=temp|templ;
}
temp=0;
for(i=0;i<15;i++)
{
temp=temp+temp1[i];
}
temp=temp/15;//取平均值
IntToStr(temp,&TempBuffer[0],5);
setPosition(0x40);
printc(TempBuffer[0]);
printc(TempBuffer[1]);
printc('.');
printc(TempBuffer[2]);
printc(TempBuffer[3]);
printc(TempBuffer[4]);
prints("mv");
delay1(500);
max197=0x40;
}
}
void convert() interrupt 2 using 2
{
flag=1;
}
|
|||
|
© 2025 維庫電子市場網(wǎng)(www.udpf.com.cn) 版權所有 經(jīng)營許可證編號:浙B2-20050339 版權聲明
二十一年專注打造優(yōu)質(zhì)電子元器件采購網(wǎng)、IC交易平臺。 |