#include<reg52.h>
#include<absacc.h>
#define uchar unsigned char
#define uint unsigned int
#define LCDCOM XBYTE[0x8ffc] //LCD写命令寄存器地址
#define LCDDATA XBYTE[0x8ffd] //LCD写数据寄存器地址
#define LCDSTATUS XBYTE[0x8ffe] //LCD读状态寄存器地址
#define IN2 XBYTE[0x7ffa] //IN2通道地址
sbit ad_busy=P3^2
sbit bflag=ACC^7
//函数的声明部分
void delay1(uint x)
void lcd_busy()
void lcd_cmd(uchar lcd_cmd)
void lcd_data(uchar lcd_data)
void lcd_moveto(uchar position)
void init(void)
void ad0809(void)
uchar string[10]={"dianya is:"}
uchar temp[6]={0x00,0x0a,0x00,0x00,0x00,0x0b}
uchar code dis_buf[13]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x2e,0x56,0x20}//为0到9的ASCLL码
void delay1(uint x) //延时1ms程序
{
uchar j
while(x--)
{
for(j=0j<125j++)
{}
}
}
void lcd_busy()//检测lcd忙程序
{
do
{
ACC=LCDSTATUS
}
while(bflag==1) //当他忙的时候就不停的检测,直到空闲为止
}
void lcd_cmd(uchar lcd_cmd) //写命令函数
{
LCDCOM=lcd_cmd
lcd_busy()
}
void lcd_data(uchar lcd_data)//写数据函数
{
LCDDATA=lcd_data
lcd_busy()
}
void lcd_moveto(uchar position)//确定卖碰显示位置
{
uchar temp //为显示位置对应的地址
if (position<16)
temp=(position+0x80-1)//为在第一行
else
temp=((position-16)+0xc0) //为第二行
lcd_cmd(temp)
}
void init(void) //lcd初始化
{
lcd_cmd(0x30) //置功能:1行,5*7字符
lcd_busy()
lcd_cmd(0x30) //置功能:1行,5*7字符
lcd_busy()
lcd_cmd(0x30)//置功能:1行,5*7字符
lcd_busy()
lcd_cmd(0x38)//置功能:2行,5*7字符
lcd_busy()
lcd_cmd(0x06)//置输入模式:地址增量,显示屏不移动
lcd_busy()
lcd_cmd(0x0c)//置显示开,不春漏显示光标,光标不闪烁
lcd_busy()
lcd_cmd(0x01)//清显示
lcd_busy()
}
void ad0809(void)
{
uchar i
uint a=0
IN2=0
i=i
i=i
while(ad_busy==0)
a=IN2
a=a*200/255
a=a*25
temp[0]=a/1000
temp[2]=a%1000/100
temp[3]=a%100/10
temp[4]=a%10
}
void main(void)
{
uchar i,j
P2=0xff
P1=0xff
P0=0xff
delay1(20)
init()
while(1)
{
ad0809()
lcd_moveto(1)
for(j=0j<10j++)
{
lcd_data(string[j])
}
lcd_moveto(16)
for(i=0i<6i++)
{
lcd_data(dis_buf[temp[i]])
}
}
}
void writedata(unsigned char *pt,unsigned int n) //pt为输入字节的头地址,银斗n为输锋野磨入字脊碰节的个数{
unsigned int i=8
unsigned char temp
while(n--)
{
while(i--)
{
temp=*pt
SCLK=0
if((temp&=0x80))
SDIN=1
else
SDIN=0
SCLK=1
temp<<=1
}
pt++
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)