|
求助,这个程序是将ad7705的输入电压显示到lcd上,用的单片机是stc89c52,可是我lcd上一直显示2.4999mV,没有变化,不知道哪里出问题了
单片机源程序如下:
- #include <intrins.h>
- #include<reg51.h>
- #define true 1
- #define false 0
- #define uchar unsigned char
- #define uint unsigned int
-
- #define lcddata 1
- #define instruction 0
- #define read 1
- #define write 0
- sbit AD_SCLK=P1^3;
- sbit AD_DIN=P1^2;
- sbit AD_OUT=P1^4;
- sbit AD_DRDY=P1^5;
- sbit CS=P1^0;
- sbit RST=P1^1;
- sbit L_DI=P2^6;
- sbit L_RW=P2^5;
- sbit L_EN=P2^7;
- void init_time(void);
- //void init_ad_7705(void);
- unsigned int read_ad7705(uchar channel);
- void ad_reset();
- void ad_write(unsigned char command_byte);
- unsigned int ad_read(unsigned char num);
- void Delayms(unsigned int no);
-
- unsigned long Temparature2,Temparature1;
- uchar CycleCheck=0;
- void Send_Data( bit DI,
- bit RW,
- unsigned char LData);
- void init_LCD() ;
- void Send_NumberV( unsigned char Row,
- unsigned char Column,
- unsigned long number,
- unsigned char no,
- unsigned char point
- );
- void Send_TextV(unsigned char Row,
- unsigned char Column,
- unsigned char code *po,
- unsigned char no
- );
- void init_ad_7705(uchar channel);
- void ad_Calculator(uchar channel);
- void main(void)
- {
- RED10 = 0;
-
- init_time();
- CS=0;
- RST=1;
-
- init_LCD() ;
-
-
- Send_TextV(0,0,"CH0: mV",12);
- Send_TextV(1,0,"CH1: mV",12);
-
- init_ad_7705(0);
- Delayms(100);
- init_ad_7705(1);
-
-
- while(1)
- { if(CycleCheck>=20)
- { CycleCheck=0;
-
- ad_Calculator(0);
- Temparature1=read_ad7705(0);
- Delayms(100);
-
- ad_Calculator(1);
- Temparature2=read_ad7705(1);
-
-
- Temparature1=Temparature1*25000/65536;
- Temparature2=Temparature2*25000/65536;
-
-
-
-
- Send_NumberV(0,4,Temparature1,5,1);
- Send_NumberV(1,4,Temparature2,5,1);
- }
- }
- }
- void ad_Calculator(uchar channel)
- {
- AD_SCLK=1;
- AD_DIN=1;
-
- if(channel==0)
- { ad_write(0x10);
- _nop_();_nop_();_nop_();
- ad_write(0x44);
-
- }
-
-
- if(channel==1)
- {
-
- ad_write(0x11);
- _nop_();_nop_();_nop_();
- ad_write(0x44);
- }
-
- AD_SCLK=1;
- AD_DIN=1;
- }
- void init_ad_7705(uchar channel)
- {
- EA=0;
- AD_SCLK=1;
- AD_DIN=1;
- ad_reset();
-
- if(channel==0)
- {
- ad_write(0x20);
- _nop_();_nop_();_nop_();
- ad_write(0x06);
-
-
-
-
- _nop_();_nop_();_nop_();
- ad_write(0x10);
- _nop_();_nop_();_nop_();
- ad_write(0x44);
-
- }
-
-
- if(channel==1)
- {
- ad_write(0x21);
- _nop_();_nop_();_nop_();
- ad_write(0x06);
-
-
-
- _nop_();_nop_();_nop_();
- ad_write(0x11);
- _nop_();_nop_();_nop_();
- ad_write(0x44);
- }
-
- AD_SCLK=1;
- AD_DIN=1;
- EA=1;
-
- }
- void Send_Data( bit DI,
- bit RW,
- unsigned char LData)
- {
-
-
- _nop_();
-
- Delayms(3);
-
-
- _nop_();_nop_();_nop_();_nop_();
- L_DI=DI;
- L_RW=RW;
- _nop_();
- P0=0xff;
- _nop_();_nop_();_nop_();_nop_();
- L_EN=0;
- P0=LData;
- _nop_();_nop_();_nop_();_nop_();
- _nop_();_nop_();_nop_();_nop_();
- L_EN=1;
- _nop_();_nop_();_nop_();_nop_();
- _nop_();_nop_();_nop_();_nop_();
- L_EN=0;
- _nop_();_nop_();_nop_();_nop_();
- P0=0xff;
- _nop_();
- L_DI=1;
- L_RW=1;
- P0=0xff;
- _nop_();
- return;
- }
- void clear_LCD(void)
- {
- _nop_();
- Send_Data(instruction,write,0x01);
- Delayms(3);
- }
- void init_LCD(void)
- { _nop_();
- Send_Data(instruction,write,0x01);
- Delayms(15);
- _nop_();
- Send_Data(instruction,write,0x3c);
- Delayms(15);
- _nop_();
- Send_Data(instruction,write,0x0c);
- _nop_();
- _nop_();
- clear_LCD();
- return;
- }
- void Send_NumberV( unsigned char Row,
- unsigned char Column,
- unsigned long number,
- unsigned char no,
- unsigned char point
- )
- {
- unsigned char address,temp,Digital,i,Clear;
- unsigned long MoveBit;
- Clear=true;
- if(Column<16 && Row<4)
- { _nop_();
- switch(Row)
- {
- case 0:
- address=0x80+Column;
- break;
- case 1:
- address=0xc0+Column;
- break;
- case 2:
- address=0x90+Column;
- break;
- case 3:
- address=0xd0+Column;
- break;
- default:
- _nop_();
- break;
- }
- _nop_();
- Send_Data(instruction,write,address);
- _nop_();
- for(i=0,MoveBit=0x0001;i<(no-1);i++)
- { MoveBit=MoveBit*10;
- }
- for(i=0;i<no;i++)
- { Digital=(number/MoveBit)%10;
- if(Digital!=0)
- { Clear=false;
- }
- if(Clear==true && (i==(no-point-1)))
- { Clear=false;
- }
- MoveBit=MoveBit/10;
- temp=0x30+Digital;
- if(Clear==true)
- { Send_Data(lcddata,write,0x20);
- }else
- { Send_Data(lcddata,write,temp);
- }
- if((i==no-point-1) & point!=0)
- { Send_Data(lcddata,write,0x2E);
- }
- }
- _nop_();
- }
- _nop_();
- return;
- }
- void Send_TextV(unsigned char Row,
- unsigned char Column,
- unsigned char code *po,
- unsigned char no
- )
- {
- unsigned char address,i;
- if(Column<16 && Row<4)
- { _nop_();
- switch(Row)
- {
- case 0:
- address=0x80+Column;
- break;
- case 1:
- address=0xc0+Column;
- break;
- case 2:
- address=0x90+Column;
- break;
- case 3:
- address=0xd0+Column;
- break;
- default:
- _nop_();
- break;
- }
- _nop_();
- Send_Data(instruction,write,address);
- _nop_();
- for(i=0;i<no;i++)
- {
- _nop_();
- Send_Data(lcddata,write,*po);
- _nop_();
- po++;
- _nop_();
- }
- _nop_();
- }
- _nop_();
- return;
- }
- void Delayms(unsigned int no)
- { unsigned char i;
- for(;no>0;)
- { for(i=120;i>0;)
- {
- _nop_();
- i--;
- _nop_();
- }
- _nop_();
-
- no--;
- _nop_();
- }
- _nop_();
- return;
- }
- void ad_reset()
- {
- uchar i;
- for(i=0;i<40;i++)
- { AD_SCLK=0;
- AD_DIN=1;
- AD_SCLK=1;
- }
- }
- void ad_write(unsigned char command_byte)
- {
- unsigned char i;
- // AD_CS=0;
- AD_SCLK=1;
- AD_DIN=1;
- for (i=0;i<32;i++)
- {
- AD_SCLK=0;
- _nop_();_nop_();_nop_();
- if (command_byte&0x80)
- {
- AD_DIN=1;
- }
- else
- {
- AD_DIN=0;
- }
- _nop_();_nop_();_nop_();
- _nop_();_nop_();_nop_();
- AD_SCLK=1;
- command_byte=command_byte*2;
- _nop_();_nop_();_nop_();
- _nop_();_nop_();_nop_();
- }
- AD_SCLK=1;
- AD_DIN=1;
- }
- unsigned int ad_read(unsigned char num)
- {
- unsigned char i;
- unsigned int ad_data;
- ad_data=0;
-
- AD_SCLK=1;
- AD_DIN=1;
- for (i=0;i<num;i++)
- { _nop_();_nop_();_nop_();
- AD_SCLK=0;
- ad_data*=2;
- _nop_();_nop_();_nop_();
- AD_SCLK=1;
- _nop_();_nop_();_nop_();
- if (AD_OUT==1)
- {
- ad_data=ad_data|0x0001;
- }
- }
- // AD_CS=
- AD_SCLK=1;
- AD_DIN=1;
- return ad_data;
- }
-
- unsigned int read_ad7705(uchar channel)
- { uint AD1;
- if(channel==0)
- { ad_write(0x39);
- } else
- { ad_write(0x38);
- }
- AD1=ad_read(16);
- return AD1;
- }
- void init_time(void)
- {
- TMOD=0x01;
- ET0=true;
- TH0=0x4c;
- TL0=0x00;
- TR0=true;
- EA=1;
- _nop_();
- return;
- }
- void time0isr(void) interrupt 1 using 1
- { EA=false;
- TH0=0x4c;
- TL0=0x00;
- EA=true;
- CycleCheck++;
- _nop_();
- return;
- }
复制代码
|
|