|
//不知道是什么原因不能仿真,请求各位帮忙看看给给建议
#include<reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit en=P2^2;
sbit rs=P2^0;
sbit rwa=P2^1;
sbit rd=P3^6; //IO口定义
sbit wr=P3^5;
sbit cs=P3^7;
uchar code lcd[]="123456789";
uchar code lcd1[]="123456789";
uchar xpos;
uchar ypos;
uchar ov;
uint num;
uchar a;
void busy_f(void)
{
P1=0xff;
rs=0;
rwa=1;
_nop_();
en=1;
_nop_();
_nop_();
while(P1 & 0x80);
en=0;
}
void wr_cmd(uchar ir)
{
busy_f();
rs=0;
rwa=0;
_nop_();
P1=ir;
_nop_();
en=1;
_nop_();
_nop_();
en=0;
}
void lcd_wr_dat(char c)
{
busy_f();
rs=0;
rwa=0;
_nop_();
P1=c;
_nop_();
en=1;
_nop_();
_nop_();
en=0;
}
void lcd_compos(uchar xpos,uchar ypos)
{
uchar tmp;
xpos &= 0x0f;
ypos &= 0x01;
tmp=xpos;
if(ypos==1)
tmp|=0xc0;
tmp|=0x80;
wr_cmd(tmp);
}
void lcd_init (void)
{
wr_cmd(0x01);
wr_cmd(0x38);
wr_cmd(0x0e);
wr_cmd(0x06);
}
void writechar(uchar xpos,uchar ypos,char c)
{
lcd_compos(xpos,ypos);
lcd_wr_dat(c);
}
void read_adc0804()//控制并读取adc0804转换好的数据
{
uchar a; //写入控制命令,启动转换
cs=1;
wr=1;
cs=0;
wr=0;
_nop_();
wr=1;
P1=0xff; //读取已转换好的数据
rd=1;
rd=0;
_nop_();
a=P1;
rd=1;
cs=1;
while(1);
}
void T0_ISR(void) interrupt 1
{
TH0=0x3c;
TL0=0xb0;
ov--;
if(ov==0)
{
num++;
ov=20;
}
}
void main()
{
uchar a,A1,A2,A3;
uint num1,num2;
TMOD=0x01;
TH0=0x3c;
TL0=0xb0;
ov=20;
ET0=1;
EA=1;
TR0=1;
while(1);
for(num=0;num<24;num++)
{
num1=num/10;
num2=num%10;
}
lcd_init();
while(1)
{
read_adc0804();
A1=a/100; //分出百,十,和个位
A2=a%100/10;
A3=a%10;
writechar(3,0,lcd[A1]);
writechar(4,0,lcd[A2]);
writechar(5,0,lcd[A3]);
writechar(6,1,lcd1[num1]);
writechar(7,1,lcd1[num2]);
}
}
|
|