at89c51 lcd显示 键盘输入c语言程序 仿真电路图,求下面这个仿真图的程序,TLC1543与ACS712与at89c51单片机,lcd1602的输入和显示程......

#include

#include

#define uint unsigned int

#define uchar unsigned char

#define ulong unsigned long

#define CLOCK P1_0

#define D_IN  P1_1

#define D_OUT P1_2

#define _CS   P1_3

sbit g1=P2^7;

sbit g2=P2^1;

sbit g3=P2^3;

sbit g4=P2^5;

ulong AD_ad1,AD_ad2;

float JiZhun_AD=2.5;

float AD_Data=0.0;

ulong AD_ad=0;

char chi;

unsigned char code table[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

void delay02s(void)

{

unsigned char i,j,k;

for(i=1;i>0;i--)

for(j=10;j>0;j--)

for(k=200;k>0;k--);

}

uint read1543(uchar port)

{

uint ad;

uint i;

uchar al=0,ah=0;

CLOCK=0;

_CS=0;

port<<=4;

for (i=0;i<4;i++) //将四位通道地址送1543

{

D_IN=(bit)(port&0x80);CLOCK=1;CLOCK=0;

port<<=1;

}

for (i=0;i<6;i++) //填6个CLOCK信号

{

CLOCK=1;CLOCK=0;

}

_CS=1;

_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

_nop_();_nop_();_nop_();

_CS=0; //等待AD转换结束

_nop_();_nop_();_nop_();

for (i=0;i<2;i++) //D9,D8

{

D_OUT=1;CLOCK=1;ah<<=1;

if (D_OUT) ah +=0x01;

CLOCK=0;

}

for (i=0;i<8;i++) //取出D7--D0

{

D_OUT=1;CLOCK=1;al <<= 1;

if (D_OUT)

al +=0x01;

CLOCK=0;

}

_CS=1;

ad = (uint)ah;

ad <<= 8;

ad +=(uint)al; //

return(ad);

}

void main()

{

TMOD=0x01;

TH0=(65535-20000)/255;

TL0=(65535-20000)%255;

EA=1;ET0=1;TR0=1;

while(1)

{

P0=table[(AD_ad%10)];

g1=1;

delay02s();

g1=0;

P0=table[(AD_ad/10)%10];

g2=1;

delay02s();

g2=0;

P0=table[(AD_ad/100)%10];

g3=1;

delay02s();

g3=0;

P0=table[(AD_ad/1000)]|0X80;

g4=1;

delay02s();

g4=0;

}

}

zhongduan()interrupt 1

{

TH0=(65535-20000)/255;

TL0=(65535-20000)%255;

chi++;

if(chi==50)

{

chi=0;

AD_ad1 = read1543(0);   //          (通道0电压正端)

AD_Data = ((float)AD_ad1)*JiZhun_AD*2/1024+0.15005;//0.15经过实测需要加0.15减少误差

AD_ad =((AD_Data-2.68)/0.185)*1000;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值