lcd1602不能将所有的测量数据显示出来
时间:10-02
整理:3721RD
点击:
求大神指教啊,多谢了
感觉程序有点乱;主要在于
uchar LCD_Line_1[] = {"L1: ,R1: kp"};
uchar LCD_Line_2[] = {"L2: ,R2: kp"};
void main()
{
uint i;
uint d1;
uint d2;
uint d3;
uint d4;
LCD_Initialise();
DelayMS(10);
while(1)
{
d1=Get_AD_Result1()*200/255;
d2=Get_AD_Result2()*200/255;
d3=Get_AD_Result3()*200/255;
d4=Get_AD_Result4()*200/255;
LCD_Line_1[3]=(d1/100+'0');
LCD_Line_1[4]=(d1/10%10+'0');
LCD_Line_1[5]=d1%10+'0';
LCD_Line_1[10]=(d2/100+'0');
LCD_Line_1[11]=(d2/10%10+'0');
LCD_Line_1[12]=d2%10+'0';
LCD_Line_2[3]=(d3/100+'0');
LCD_Line_2[4]=(d3/10%10+'0');
LCD_Line_2[5]=d3%10+'0';
LCD_Line_2[10]=(d4/100+'0');
LCD_Line_2[11]=(d4/10%10+'0');
LCD_Line_2[12]=d4%10+'0';
Set_Disp_Pos(0x00);
i=0;
while(LCD_Line_1!='\0')
LCD_Write_Data(LCD_Line_1[i++]);
Set_Disp_Pos(0x40);
i=0;
while(LCD_Line_2!='\0')
LCD_Write_Data(LCD_Line_2[i++]);
}
}
Get_AD_Result1()之类的为传感器返回值,
就是不知道为什么lcd1602上第二列的数据都是0
所有的程序
//ADC0832?£êy×a??ó???ê?
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define delay4us() {_nop_(); _nop_(); _nop_(); _nop_();}
uchar Display_Buffer1[];
uchar Display_Buffer2[];
uchar Display_Buffer3[];
uchar Display_Buffer4[];
//ADC0832òy???¨ò?
sbit CS1 =P1^0;
sbit CLK1=P1^1;
sbit DIO1=P1^2;
sbit CS2 =P1^0;
sbit CLK2=P1^1;
sbit DIO2=P1^3;
sbit CS3 =P1^0;
sbit CLK3=P1^1;
sbit DIO3=P1^4;
sbit CS4 =P1^0;
sbit CLK4=P1^1;
sbit DIO4=P1^5;
//LCD1602???ú?¨ò?
sbit RS=P2^0;
sbit RW=P2^1;
sbit E =P2^2;
//ò?????êy£?á???D?êyμ?êy×?μ??1??ê??o3?
//uchar Display_Buffer[] = "000KP";
//LCDμúò?DD??ê?μ?D??¢
uchar LCD_Line_1[] = {"L1: ,R1: kp"};
uchar LCD_Line_2[] = {"L2: ,R2: kp"};
//------------------------------------------
//?óê±×ó3ìDò
//------------------------------------------
void DelayMS(uint ms)
{
uchar t;
while(ms--) for(t=0;t<120;t++);
}
//-------------------------------------------
//LCD?|×′ì??ì2a
//-------------------------------------------
bit LCD_Busy_Check()
{
bit result;
RS=0; RW=1; E=1; delay4us();result=(bit)(P0&0x80);E=0;
return result;
}
//-------------------------------------------
//LCDD′?üá?
//-------------------------------------------
void LCD_Write_Command(uchar cmd)
{
while(LCD_Busy_Check());//?D??LCDê?·??|?μ
RS = 0; RW=0; E=0; _nop_(); _nop_();P0=cmd;delay4us();
E=1;delay4us();E=0;
}
//-------------------------------------------
//éè??LCD??ê?????
//--------------------------------------------
void Set_Disp_Pos(uchar pos)
{
LCD_Write_Command(pos|0x80);
}
//---------------------------------------------
//D′LCDêy?Y
//----------------------------------------------
void LCD_Write_Data(uchar dat)
{
while(LCD_Busy_Check());//?D??LCDê?·??|
RS=1; RW=0; E=0;
P0=dat; delay4us();
E=1; delay4us(); E=0;
}
//------------------------------------------------
//LCD3?ê??ˉ
//------------------------------------------------
void LCD_Initialise()
{
LCD_Write_Command(0x38);DelayMS(1);
LCD_Write_Command(0x0c);DelayMS(1);
LCD_Write_Command(0x06);DelayMS(1);
LCD_Write_Command(0x01);DelayMS(1);
}
//------------------------------------------------
//LCDéè????ê?????
//------------------------------------------------
void LCD_Set_Position(uchar pos)
{
LCD_Write_Command(pos|0x80);
}
//-----------------------------------------
//??ê?ò?DD
//------------------------------------------
void LCD_Display_A_Line(uchar Line_Addr,uchar s[])
{
uchar i;
LCD_Set_Position(Line_Addr);
for (i=0;i<16;i++) LCD_Write_Data(s);
}
//??è?AD×a???á1?£¨1o?′??D?÷£?
//------------------------------------------------
uchar Get_AD_Result1()
{
uchar i, dat11=0, dat21=0;
//?eê???????
CS1 =0;
CLK1=0;
DIO1=1; _nop_();_nop_();
CLK1=1; _nop_();_nop_();
//μúò??????μ?????°£?éèDI=1/0
//????μ¥??/2?·?£¨SGL/DIF£??£ê??Dμ?μ¥??ê?è??£ê?
CLK1=0; DIO1=1; _nop_();_nop_();
CLK1=1; _nop_();_nop_();
//μú?t?????μ?????°£?éèDI=0/1,????CH0/CH1
CLK1=0; DIO1=0; _nop_();_nop_();
CLK1=1; DIO1=1; _nop_();_nop_();
//μúèy?????μ?????°£?éèDI=1
CLK1=0; DIO1=1; _nop_();_nop_();
//μú4μ?11£?128?????μ???áêy?Y£¨MSB->LSB£?
for(i=0;i<8;i++)
{
CLK1=1;_nop_();_nop_();
CLK1=0;_nop_();_nop_();
dat11=dat11<<1|DIO1;
}
//μú11~18£?128?????μ???áêy?Y£¨LSB->MSB£?
for(i=0;i<8;i++)
{
dat21=dat21|((uchar)(DIO1)<<i);
CLK1=1; _nop_();_nop_();
CLK1=0; _nop_();_nop_();
}
CS1=1;
//è?1?MSB->LSBoíLSB->MSB?áè?μ??á1??àí?£?·μ???áè?μ??á1?£?·??ò·μ??0
return(dat11==dat21)?dat11:0;
}
//------------------------------------------------
//??è?AD×a???á1?£¨2o?′??D?÷£?
//------------------------------------------------
uchar Get_AD_Result2()
{
uchar i, dat12=0, dat22=0;
//?eê???????
CS2 =0;
CLK2=0;
DIO2=1; _nop_();_nop_();
CLK2=1; _nop_();_nop_();
//μúò??????μ?????°£?éèDI=1/0
//????μ¥??/2?·?£¨SGL/DIF£??£ê??Dμ?μ¥??ê?è??£ê?
CLK2=0; DIO2=1; _nop_();_nop_();
CLK2=1; _nop_();_nop_();
//μú?t?????μ?????°£?éèDI=0/1,????CH0/CH1
CLK2=0; DIO2=0; _nop_();_nop_();
CLK2=1; DIO2=1; _nop_();_nop_();
//μúèy?????μ?????°£?éèDI=1
CLK2=0; DIO2=1; _nop_();_nop_();
//μú4μ?11£?128?????μ???áêy?Y£¨MSB->LSB£?
for(i=0;i<8;i++)
{
CLK2=1;_nop_();_nop_();
CLK2=0;_nop_();_nop_();
dat12=dat12<<1|DIO1;
}
//μú11~18£?128?????μ???áêy?Y£¨LSB->MSB£?
for(i=0;i<8;i++)
{
dat22=dat22|((uchar)(DIO2)<<i);
CLK2=1; _nop_();_nop_();
CLK2=0; _nop_();_nop_();
}
CS2=1;
//è?1?MSB->LSBoíLSB->MSB?áè?μ??á1??àí?£?·μ???áè?μ??á1?£?·??ò·μ??0
return(dat12==dat22)?dat12:0;
}
//------------------------------------------------
//??è?AD×a???á1?£¨3o?′??D?÷£?
//------------------------------------------------
uchar Get_AD_Result3()
{
uchar i, dat13=0, dat23=0;
//?eê???????
CS3 =0;
CLK3=0;
DIO3=1; _nop_();_nop_();
CLK3=1; _nop_();_nop_();
//μúò??????μ?????°£?éèDI=1/0
//????μ¥??/2?·?£¨SGL/DIF£??£ê??Dμ?μ¥??ê?è??£ê?
CLK3=0; DIO3=1; _nop_();_nop_();
CLK3=1; _nop_();_nop_();
//μú?t?????μ?????°£?éèDI=0/1,????CH0/CH1
CLK3=0; DIO3=0; _nop_();_nop_();
CLK3=1; DIO3=1; _nop_();_nop_();
//μúèy?????μ?????°£?éèDI=1
CLK3=0; DIO3=1; _nop_();_nop_();
//μú4μ?11£?128?????μ???áêy?Y£¨MSB->LSB£?
for(i=0;i<8;i++)
{
CLK3=1;_nop_();_nop_();
CLK3=0;_nop_();_nop_();
dat13=dat13<<1|DIO3;
}
//μú11~18£?128?????μ???áêy?Y£¨LSB->MSB£?
for(i=0;i<8;i++)
{
dat23=dat23|((uchar)(DIO3)<<i);
CLK3=1; _nop_();_nop_();
CLK3=0; _nop_();_nop_();
}
CS1=3;
//è?1?MSB->LSBoíLSB->MSB?áè?μ??á1??àí?£?·μ???áè?μ??á1?£?·??ò·μ??0
return(dat13==dat23)?dat13:0;
}
//------------------------------------------------
//??è?AD×a???á1?£¨4o?′??D?÷£?
//------------------------------------------------
uchar Get_AD_Result4()
{
uchar i, dat14=0, dat24=0;
//?eê???????
CS4 =0;
CLK4=0;
DIO4=1; _nop_();_nop_();
CLK4=1; _nop_();_nop_();
//μúò??????μ?????°£?éèDI=1/0
//????μ¥??/2?·?£¨SGL/DIF£??£ê??Dμ?μ¥??ê?è??£ê?
CLK4=0; DIO4=1; _nop_();_nop_();
CLK4=1; _nop_();_nop_();
//μú?t?????μ?????°£?éèDI=0/1,????CH0/CH1
CLK4=0; DIO1=0; _nop_();_nop_();
CLK4=1; DIO1=1; _nop_();_nop_();
//μúèy?????μ?????°£?éèDI=1
CLK4=0; DIO4=1; _nop_();_nop_();
//μú4μ?11£?128?????μ???áêy?Y£¨MSB->LSB£?
for(i=0;i<8;i++)
{
CLK4=1;_nop_();_nop_();
CLK4=0;_nop_();_nop_();
dat14=dat14<<1|DIO4;
}
//μú11~18£?128?????μ???áêy?Y£¨LSB->MSB£?
for(i=0;i<8;i++)
{
dat24=dat24|((uchar)(DIO4)<<i);
CLK4=1; _nop_();_nop_();
CLK4=0; _nop_();_nop_();
}
CS4=1;
//è?1?MSB->LSBoíLSB->MSB?áè?μ??á1??àí?£?·μ???áè?μ??á1?£?·??ò·μ??0
return(dat14==dat24)?dat14:0;
}
//---------------------------------------------
//?÷3ìDò
//---------------------------------------------
void main()
{
uint i;
uint d1;
uint d2;
uint d3;
uint d4;
LCD_Initialise();
DelayMS(10);
while(1)
{
//??è?AD×a???μ£?×?′ó?μ255??ó|×???μ??15.00V
//±?ày?Déè???a??ê?èy??êy??£?1êê1ó?500
d1=Get_AD_Result1()*200/255;
d2=Get_AD_Result2()*200/255;
d3=Get_AD_Result3()*200/255;
d4=Get_AD_Result4()*200/255;
LCD_Line_1[3]=(d1/100+'0');
LCD_Line_1[4]=(d1/10%10+'0');
LCD_Line_1[5]=d1%10+'0';
LCD_Line_1[10]=(d2/100+'0');
LCD_Line_1[11]=(d2/10%10+'0');
LCD_Line_1[12]=d2%10+'0';
LCD_Line_2[3]=(d3/100+'0');
LCD_Line_2[4]=(d3/10%10+'0');
LCD_Line_2[5]=d3%10+'0';
LCD_Line_2[10]=(d4/100+'0');
LCD_Line_2[11]=(d4/10%10+'0');
LCD_Line_2[12]=d4%10+'0';
Set_Disp_Pos(0x00);
i=0;
while(LCD_Line_1!='\0')
LCD_Write_Data(LCD_Line_1[i++]);
//Set_Disp_Pos(0x0a);
//i=11;
//while(LCD_Line_1!='\0')
//LCD_Write_Data(LCD_Line_1[i++]);
Set_Disp_Pos(0x40);
i=0;
while(LCD_Line_2!='\0')
LCD_Write_Data(LCD_Line_2[i++]);
}
}
感觉程序有点乱;主要在于
uchar LCD_Line_1[] = {"L1: ,R1: kp"};
uchar LCD_Line_2[] = {"L2: ,R2: kp"};
void main()
{
uint i;
uint d1;
uint d2;
uint d3;
uint d4;
LCD_Initialise();
DelayMS(10);
while(1)
{
d1=Get_AD_Result1()*200/255;
d2=Get_AD_Result2()*200/255;
d3=Get_AD_Result3()*200/255;
d4=Get_AD_Result4()*200/255;
LCD_Line_1[3]=(d1/100+'0');
LCD_Line_1[4]=(d1/10%10+'0');
LCD_Line_1[5]=d1%10+'0';
LCD_Line_1[10]=(d2/100+'0');
LCD_Line_1[11]=(d2/10%10+'0');
LCD_Line_1[12]=d2%10+'0';
LCD_Line_2[3]=(d3/100+'0');
LCD_Line_2[4]=(d3/10%10+'0');
LCD_Line_2[5]=d3%10+'0';
LCD_Line_2[10]=(d4/100+'0');
LCD_Line_2[11]=(d4/10%10+'0');
LCD_Line_2[12]=d4%10+'0';
Set_Disp_Pos(0x00);
i=0;
while(LCD_Line_1!='\0')
LCD_Write_Data(LCD_Line_1[i++]);
Set_Disp_Pos(0x40);
i=0;
while(LCD_Line_2!='\0')
LCD_Write_Data(LCD_Line_2[i++]);
}
}
Get_AD_Result1()之类的为传感器返回值,
就是不知道为什么lcd1602上第二列的数据都是0
所有的程序
//ADC0832?£êy×a??ó???ê?
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define delay4us() {_nop_(); _nop_(); _nop_(); _nop_();}
uchar Display_Buffer1[];
uchar Display_Buffer2[];
uchar Display_Buffer3[];
uchar Display_Buffer4[];
//ADC0832òy???¨ò?
sbit CS1 =P1^0;
sbit CLK1=P1^1;
sbit DIO1=P1^2;
sbit CS2 =P1^0;
sbit CLK2=P1^1;
sbit DIO2=P1^3;
sbit CS3 =P1^0;
sbit CLK3=P1^1;
sbit DIO3=P1^4;
sbit CS4 =P1^0;
sbit CLK4=P1^1;
sbit DIO4=P1^5;
//LCD1602???ú?¨ò?
sbit RS=P2^0;
sbit RW=P2^1;
sbit E =P2^2;
//ò?????êy£?á???D?êyμ?êy×?μ??1??ê??o3?
//uchar Display_Buffer[] = "000KP";
//LCDμúò?DD??ê?μ?D??¢
uchar LCD_Line_1[] = {"L1: ,R1: kp"};
uchar LCD_Line_2[] = {"L2: ,R2: kp"};
//------------------------------------------
//?óê±×ó3ìDò
//------------------------------------------
void DelayMS(uint ms)
{
uchar t;
while(ms--) for(t=0;t<120;t++);
}
//-------------------------------------------
//LCD?|×′ì??ì2a
//-------------------------------------------
bit LCD_Busy_Check()
{
bit result;
RS=0; RW=1; E=1; delay4us();result=(bit)(P0&0x80);E=0;
return result;
}
//-------------------------------------------
//LCDD′?üá?
//-------------------------------------------
void LCD_Write_Command(uchar cmd)
{
while(LCD_Busy_Check());//?D??LCDê?·??|?μ
RS = 0; RW=0; E=0; _nop_(); _nop_();P0=cmd;delay4us();
E=1;delay4us();E=0;
}
//-------------------------------------------
//éè??LCD??ê?????
//--------------------------------------------
void Set_Disp_Pos(uchar pos)
{
LCD_Write_Command(pos|0x80);
}
//---------------------------------------------
//D′LCDêy?Y
//----------------------------------------------
void LCD_Write_Data(uchar dat)
{
while(LCD_Busy_Check());//?D??LCDê?·??|
RS=1; RW=0; E=0;
P0=dat; delay4us();
E=1; delay4us(); E=0;
}
//------------------------------------------------
//LCD3?ê??ˉ
//------------------------------------------------
void LCD_Initialise()
{
LCD_Write_Command(0x38);DelayMS(1);
LCD_Write_Command(0x0c);DelayMS(1);
LCD_Write_Command(0x06);DelayMS(1);
LCD_Write_Command(0x01);DelayMS(1);
}
//------------------------------------------------
//LCDéè????ê?????
//------------------------------------------------
void LCD_Set_Position(uchar pos)
{
LCD_Write_Command(pos|0x80);
}
//-----------------------------------------
//??ê?ò?DD
//------------------------------------------
void LCD_Display_A_Line(uchar Line_Addr,uchar s[])
{
uchar i;
LCD_Set_Position(Line_Addr);
for (i=0;i<16;i++) LCD_Write_Data(s);
}
//??è?AD×a???á1?£¨1o?′??D?÷£?
//------------------------------------------------
uchar Get_AD_Result1()
{
uchar i, dat11=0, dat21=0;
//?eê???????
CS1 =0;
CLK1=0;
DIO1=1; _nop_();_nop_();
CLK1=1; _nop_();_nop_();
//μúò??????μ?????°£?éèDI=1/0
//????μ¥??/2?·?£¨SGL/DIF£??£ê??Dμ?μ¥??ê?è??£ê?
CLK1=0; DIO1=1; _nop_();_nop_();
CLK1=1; _nop_();_nop_();
//μú?t?????μ?????°£?éèDI=0/1,????CH0/CH1
CLK1=0; DIO1=0; _nop_();_nop_();
CLK1=1; DIO1=1; _nop_();_nop_();
//μúèy?????μ?????°£?éèDI=1
CLK1=0; DIO1=1; _nop_();_nop_();
//μú4μ?11£?128?????μ???áêy?Y£¨MSB->LSB£?
for(i=0;i<8;i++)
{
CLK1=1;_nop_();_nop_();
CLK1=0;_nop_();_nop_();
dat11=dat11<<1|DIO1;
}
//μú11~18£?128?????μ???áêy?Y£¨LSB->MSB£?
for(i=0;i<8;i++)
{
dat21=dat21|((uchar)(DIO1)<<i);
CLK1=1; _nop_();_nop_();
CLK1=0; _nop_();_nop_();
}
CS1=1;
//è?1?MSB->LSBoíLSB->MSB?áè?μ??á1??àí?£?·μ???áè?μ??á1?£?·??ò·μ??0
return(dat11==dat21)?dat11:0;
}
//------------------------------------------------
//??è?AD×a???á1?£¨2o?′??D?÷£?
//------------------------------------------------
uchar Get_AD_Result2()
{
uchar i, dat12=0, dat22=0;
//?eê???????
CS2 =0;
CLK2=0;
DIO2=1; _nop_();_nop_();
CLK2=1; _nop_();_nop_();
//μúò??????μ?????°£?éèDI=1/0
//????μ¥??/2?·?£¨SGL/DIF£??£ê??Dμ?μ¥??ê?è??£ê?
CLK2=0; DIO2=1; _nop_();_nop_();
CLK2=1; _nop_();_nop_();
//μú?t?????μ?????°£?éèDI=0/1,????CH0/CH1
CLK2=0; DIO2=0; _nop_();_nop_();
CLK2=1; DIO2=1; _nop_();_nop_();
//μúèy?????μ?????°£?éèDI=1
CLK2=0; DIO2=1; _nop_();_nop_();
//μú4μ?11£?128?????μ???áêy?Y£¨MSB->LSB£?
for(i=0;i<8;i++)
{
CLK2=1;_nop_();_nop_();
CLK2=0;_nop_();_nop_();
dat12=dat12<<1|DIO1;
}
//μú11~18£?128?????μ???áêy?Y£¨LSB->MSB£?
for(i=0;i<8;i++)
{
dat22=dat22|((uchar)(DIO2)<<i);
CLK2=1; _nop_();_nop_();
CLK2=0; _nop_();_nop_();
}
CS2=1;
//è?1?MSB->LSBoíLSB->MSB?áè?μ??á1??àí?£?·μ???áè?μ??á1?£?·??ò·μ??0
return(dat12==dat22)?dat12:0;
}
//------------------------------------------------
//??è?AD×a???á1?£¨3o?′??D?÷£?
//------------------------------------------------
uchar Get_AD_Result3()
{
uchar i, dat13=0, dat23=0;
//?eê???????
CS3 =0;
CLK3=0;
DIO3=1; _nop_();_nop_();
CLK3=1; _nop_();_nop_();
//μúò??????μ?????°£?éèDI=1/0
//????μ¥??/2?·?£¨SGL/DIF£??£ê??Dμ?μ¥??ê?è??£ê?
CLK3=0; DIO3=1; _nop_();_nop_();
CLK3=1; _nop_();_nop_();
//μú?t?????μ?????°£?éèDI=0/1,????CH0/CH1
CLK3=0; DIO3=0; _nop_();_nop_();
CLK3=1; DIO3=1; _nop_();_nop_();
//μúèy?????μ?????°£?éèDI=1
CLK3=0; DIO3=1; _nop_();_nop_();
//μú4μ?11£?128?????μ???áêy?Y£¨MSB->LSB£?
for(i=0;i<8;i++)
{
CLK3=1;_nop_();_nop_();
CLK3=0;_nop_();_nop_();
dat13=dat13<<1|DIO3;
}
//μú11~18£?128?????μ???áêy?Y£¨LSB->MSB£?
for(i=0;i<8;i++)
{
dat23=dat23|((uchar)(DIO3)<<i);
CLK3=1; _nop_();_nop_();
CLK3=0; _nop_();_nop_();
}
CS1=3;
//è?1?MSB->LSBoíLSB->MSB?áè?μ??á1??àí?£?·μ???áè?μ??á1?£?·??ò·μ??0
return(dat13==dat23)?dat13:0;
}
//------------------------------------------------
//??è?AD×a???á1?£¨4o?′??D?÷£?
//------------------------------------------------
uchar Get_AD_Result4()
{
uchar i, dat14=0, dat24=0;
//?eê???????
CS4 =0;
CLK4=0;
DIO4=1; _nop_();_nop_();
CLK4=1; _nop_();_nop_();
//μúò??????μ?????°£?éèDI=1/0
//????μ¥??/2?·?£¨SGL/DIF£??£ê??Dμ?μ¥??ê?è??£ê?
CLK4=0; DIO4=1; _nop_();_nop_();
CLK4=1; _nop_();_nop_();
//μú?t?????μ?????°£?éèDI=0/1,????CH0/CH1
CLK4=0; DIO1=0; _nop_();_nop_();
CLK4=1; DIO1=1; _nop_();_nop_();
//μúèy?????μ?????°£?éèDI=1
CLK4=0; DIO4=1; _nop_();_nop_();
//μú4μ?11£?128?????μ???áêy?Y£¨MSB->LSB£?
for(i=0;i<8;i++)
{
CLK4=1;_nop_();_nop_();
CLK4=0;_nop_();_nop_();
dat14=dat14<<1|DIO4;
}
//μú11~18£?128?????μ???áêy?Y£¨LSB->MSB£?
for(i=0;i<8;i++)
{
dat24=dat24|((uchar)(DIO4)<<i);
CLK4=1; _nop_();_nop_();
CLK4=0; _nop_();_nop_();
}
CS4=1;
//è?1?MSB->LSBoíLSB->MSB?áè?μ??á1??àí?£?·μ???áè?μ??á1?£?·??ò·μ??0
return(dat14==dat24)?dat14:0;
}
//---------------------------------------------
//?÷3ìDò
//---------------------------------------------
void main()
{
uint i;
uint d1;
uint d2;
uint d3;
uint d4;
LCD_Initialise();
DelayMS(10);
while(1)
{
//??è?AD×a???μ£?×?′ó?μ255??ó|×???μ??15.00V
//±?ày?Déè???a??ê?èy??êy??£?1êê1ó?500
d1=Get_AD_Result1()*200/255;
d2=Get_AD_Result2()*200/255;
d3=Get_AD_Result3()*200/255;
d4=Get_AD_Result4()*200/255;
LCD_Line_1[3]=(d1/100+'0');
LCD_Line_1[4]=(d1/10%10+'0');
LCD_Line_1[5]=d1%10+'0';
LCD_Line_1[10]=(d2/100+'0');
LCD_Line_1[11]=(d2/10%10+'0');
LCD_Line_1[12]=d2%10+'0';
LCD_Line_2[3]=(d3/100+'0');
LCD_Line_2[4]=(d3/10%10+'0');
LCD_Line_2[5]=d3%10+'0';
LCD_Line_2[10]=(d4/100+'0');
LCD_Line_2[11]=(d4/10%10+'0');
LCD_Line_2[12]=d4%10+'0';
Set_Disp_Pos(0x00);
i=0;
while(LCD_Line_1!='\0')
LCD_Write_Data(LCD_Line_1[i++]);
//Set_Disp_Pos(0x0a);
//i=11;
//while(LCD_Line_1!='\0')
//LCD_Write_Data(LCD_Line_1[i++]);
Set_Disp_Pos(0x40);
i=0;
while(LCD_Line_2!='\0')
LCD_Write_Data(LCD_Line_2[i++]);
}
}
这部分
sbit CS1 =P1^0;
sbit CLK1=P1^1;
sbit DIO1=P1^2;
sbit CS2 =P1^0;
sbit CLK2=P1^1;
sbit DIO2=P1^3;
sbit CS3 =P1^0;
sbit CLK3=P1^1;
sbit DIO3=P1^4;
sbit CS4 =P1^0;
sbit CLK4=P1^1;
sbit DIO4=P1^5;
IO口重复了啊!
把其改为不同IO口,再连一连电路就OK啦!
我是把那四个mpx传感器都接同样的时钟信号和使能信号的,所以有些接口是一样的,但是输出口是不同的,而且那个能够显示两路数据出来也证明应该不是这个的问题,感觉还是显示器的设置不对。
把下面3处改了应该就可以了吧!
dat12=dat12<<1|DIO1; 改为dat12=dat12<<1|DIO2;
CLK4=0; DIO1=0; _nop_();_nop_(); 改为CLK4=0; DIO4=0; _nop_();_nop_();
CLK4=1; DIO1=1; _nop_();_nop_(); 改为CLK4=1; DIO4=1; _nop_();_nop_();
真是太谢谢你了,就是你说的这样的,这几天做毕设头一次学这个,好多不懂,这个问题都困扰了我好久了,你真是帮了我的大忙了。