展开全部
我这里有protues+代码:(内容是串口通信,A机测量,B机数码管显示)
代码给你吧,protues 需要再说
#include <reg51.h>
#define uint unsigned int
#define uchar unsigned char
#define PinData P0
sbit LED0 = P1^0;
sbit LED1 = P1^1;
sbit PinSTART = P1^5;
sbit PinOE = P1^6;
sbit PinEOC = P1^7;
sbit CLK = P3^4;
//短延时函数:ShortDelay()
void nNop(uchar i)
{
for(;i>0;i--) ;
}
//长延时函数:LongDelay()
void LongDelay(uint i)
{
uint j;
for(;i>0;i--)
{ for(j=1000;j>0;j--);}
}
//引脚初始化
void InitIO()
{
PinData = 0xff;
PinSTART = 1;
PinEOC = 1;
PinOE = 1;
CLK = 1;
}
//UART的初始化:模式1,8位,9600Bds
void InitSerial()
{
TMOD = 0x20 ; // Timer 1 in mode 2
TH1 = 0xF4; // 9600 Bds at 11.059MHz
TL1 = 0xF4; // 9600 Bds at 11.059MHz
TR1 = 1; // Timer 1 run
PCON = 0x00; // Timer 1 run
SCON = 0x50; // uart in mode 1 (8 bit), REN=1
}
//T0定时脉冲中断初始化
void init_uart()
{
TMOD=0x01;
TH0= (65536-4000)/256;
TL0= (65536-4000)%256;
TR0=1;
// ET0=1;
EA=1;
}
//等待A/D转换结束函数:WaitADCEnd()
void WaitADCEnd(void)
{
while(!PinEOC) ;
}
//读取A/D转换后的数据函数:ReadData()
uchar ReadData()
{
uchar tempt;
ET0=1;
PinSTART = 0;
//nNop(1);
PinSTART = 1;
PinSTART = 0;
WaitADCEnd();
PinOE =1;
nNop(2);
tempt = PinData & 0xff;
ET0=0;
return(tempt);
//PinOE =0;
}
//子机送数据给主机
void sendtomain(uchar temp)
{
SBUF = temp;
while(!TI);
TI=0;
}
void main()
{
uchar temp, tab;
InitIO();
init_uart();
InitSerial();
while(1)
{
temp = ReadData();
sendtomain(temp);
while(!RI);
tab = SBUF;
RI = 0;
if(tab == 0)
{
LED0 = 1;
LED1 = 0;
}
else if(tab == 1)
{
LED0 = 1;
LED1 = 1;
}
else
{
LED0 = 0;
LED1 = 1;
}
}
}
void clk(void) interrupt 1 using 0
{
TH0= (65536-4000)/256;
TL0= (65536-4000)%256;
CLK= ~CLK;
}
#include<reg51.h>
#define PDATA P2
#define aver 2
#define uint unsigned int
#define uchar unsigned char
sbit Ledlow = P1^3;
sbit Ledhig = P1^4;
uchar table2 []={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar table1 []={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
//短延时函数:ShortDelay()
void nNop(uchar temp)
{
uint i;
for(i=0 ;i<temp; i++) ;
}
//UART初始化:模式1,8位,9600Bds at 11.059MHz
void InitSerial()
{ // uart in mode 1 (8 bit), REN=1
TMOD = 0x20 ; // Timer 1 in mode 2
TH1 = 0xF4; // 9600 Bds at 11.059MHz
TL1 = 0xF4; // 9600 Bds at 11.059MHz
TR1 = 1;
PCON = 0x00; // Timer 1 run
SCON = 0x50;
}
//主机接受信息给从机
uchar recivefromslave()
{
uchar temp;
while(!RI);
temp=SBUF;
RI=0;
return(temp);
}
// 显示
void leddisp(uint temp )
{
uint i;
uint getdata1 = 0;
uint getdata2 = 0;
temp=temp*aver;
getdata1=temp/100;
getdata2=temp/10;
getdata2=getdata2%10;
for(i=0;i<30;i++)
{
PDATA=table1[getdata1];
Ledlow =0;
Ledhig = 1;
nNop(1000);
Ledlow =0;
Ledhig = 0;
PDATA=table2[getdata2];
Ledlow =1;
Ledhig = 0;
nNop(1000);
Ledlow =0;
Ledhig = 0;
}
}
void main()
{
uint tab;
uint tempt;
Ledlow = 0;
Ledhig = 0;
PDATA = 0x00;
InitSerial();
while(1)
{
tempt = (uint) recivefromslave(); //接收从机采集的信息
leddisp(tempt); //显示信息
if(tempt<0x60) //判断信息
{
tab = 0;
}
else if(tempt>0xc0)
{
tab = 2;
}
else
{
tab = 1;
}
SBUF = (uchar)tab; //对采集信息进行控制
while(!TI);
TI = 0;
}
}
代码给你吧,protues 需要再说
#include <reg51.h>
#define uint unsigned int
#define uchar unsigned char
#define PinData P0
sbit LED0 = P1^0;
sbit LED1 = P1^1;
sbit PinSTART = P1^5;
sbit PinOE = P1^6;
sbit PinEOC = P1^7;
sbit CLK = P3^4;
//短延时函数:ShortDelay()
void nNop(uchar i)
{
for(;i>0;i--) ;
}
//长延时函数:LongDelay()
void LongDelay(uint i)
{
uint j;
for(;i>0;i--)
{ for(j=1000;j>0;j--);}
}
//引脚初始化
void InitIO()
{
PinData = 0xff;
PinSTART = 1;
PinEOC = 1;
PinOE = 1;
CLK = 1;
}
//UART的初始化:模式1,8位,9600Bds
void InitSerial()
{
TMOD = 0x20 ; // Timer 1 in mode 2
TH1 = 0xF4; // 9600 Bds at 11.059MHz
TL1 = 0xF4; // 9600 Bds at 11.059MHz
TR1 = 1; // Timer 1 run
PCON = 0x00; // Timer 1 run
SCON = 0x50; // uart in mode 1 (8 bit), REN=1
}
//T0定时脉冲中断初始化
void init_uart()
{
TMOD=0x01;
TH0= (65536-4000)/256;
TL0= (65536-4000)%256;
TR0=1;
// ET0=1;
EA=1;
}
//等待A/D转换结束函数:WaitADCEnd()
void WaitADCEnd(void)
{
while(!PinEOC) ;
}
//读取A/D转换后的数据函数:ReadData()
uchar ReadData()
{
uchar tempt;
ET0=1;
PinSTART = 0;
//nNop(1);
PinSTART = 1;
PinSTART = 0;
WaitADCEnd();
PinOE =1;
nNop(2);
tempt = PinData & 0xff;
ET0=0;
return(tempt);
//PinOE =0;
}
//子机送数据给主机
void sendtomain(uchar temp)
{
SBUF = temp;
while(!TI);
TI=0;
}
void main()
{
uchar temp, tab;
InitIO();
init_uart();
InitSerial();
while(1)
{
temp = ReadData();
sendtomain(temp);
while(!RI);
tab = SBUF;
RI = 0;
if(tab == 0)
{
LED0 = 1;
LED1 = 0;
}
else if(tab == 1)
{
LED0 = 1;
LED1 = 1;
}
else
{
LED0 = 0;
LED1 = 1;
}
}
}
void clk(void) interrupt 1 using 0
{
TH0= (65536-4000)/256;
TL0= (65536-4000)%256;
CLK= ~CLK;
}
#include<reg51.h>
#define PDATA P2
#define aver 2
#define uint unsigned int
#define uchar unsigned char
sbit Ledlow = P1^3;
sbit Ledhig = P1^4;
uchar table2 []={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar table1 []={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
//短延时函数:ShortDelay()
void nNop(uchar temp)
{
uint i;
for(i=0 ;i<temp; i++) ;
}
//UART初始化:模式1,8位,9600Bds at 11.059MHz
void InitSerial()
{ // uart in mode 1 (8 bit), REN=1
TMOD = 0x20 ; // Timer 1 in mode 2
TH1 = 0xF4; // 9600 Bds at 11.059MHz
TL1 = 0xF4; // 9600 Bds at 11.059MHz
TR1 = 1;
PCON = 0x00; // Timer 1 run
SCON = 0x50;
}
//主机接受信息给从机
uchar recivefromslave()
{
uchar temp;
while(!RI);
temp=SBUF;
RI=0;
return(temp);
}
// 显示
void leddisp(uint temp )
{
uint i;
uint getdata1 = 0;
uint getdata2 = 0;
temp=temp*aver;
getdata1=temp/100;
getdata2=temp/10;
getdata2=getdata2%10;
for(i=0;i<30;i++)
{
PDATA=table1[getdata1];
Ledlow =0;
Ledhig = 1;
nNop(1000);
Ledlow =0;
Ledhig = 0;
PDATA=table2[getdata2];
Ledlow =1;
Ledhig = 0;
nNop(1000);
Ledlow =0;
Ledhig = 0;
}
}
void main()
{
uint tab;
uint tempt;
Ledlow = 0;
Ledhig = 0;
PDATA = 0x00;
InitSerial();
while(1)
{
tempt = (uint) recivefromslave(); //接收从机采集的信息
leddisp(tempt); //显示信息
if(tempt<0x60) //判断信息
{
tab = 0;
}
else if(tempt>0xc0)
{
tab = 2;
}
else
{
tab = 1;
}
SBUF = (uchar)tab; //对采集信息进行控制
while(!TI);
TI = 0;
}
}
追问
是自己做的吗?网上不能用。
追答
我测试过了 ,两个at89c51 , adc0808 , 共阳极数码管,变阻器(5v范围)
展开全部
数字电压表仿真实例,可以参考一下。
追问
用Proteus打开背景怎么是黑色的
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
直接用ADC芯片就可以了。去查查资料吧。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-05-08
展开全部
可以根据你的要求做出来,不过收费哦
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-05-08
展开全部
我做过现成的。有不同的AD做的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询