本帖最后由 pengwu1207 于 2018-6-4 09:10 编辑
STC8+AD7606并口16BIT显示正负电压 不知道怎么上传视频,下面是我的微博,里面有视频,源程序附上
https://weibo.com/2419242361/profile?topnav=1&wvr=6&is_all=1
AD7606.C内容:
- #include "AD7606.h"
- U16 ADC7606[8];
- void AD7607Init(){
- AD7606_IOVCC=1;
- AD7606_RST=0;
- AD7606_RST=1;
- Delay1ms(200);
- AD7606_RST=0;
- P6M1=0XFF;P6M0=0X00; //P6输入
- P1M1=0XFF;P1M0=0X00; //P1输入
- P0M1=0X80;P0M1=0X07;//P0.7输入,其余输出
- P4M1=0X00;P0M1=0Xff;
- AD7606_OS2=AD7606_OS1=1;AD7606_OS0=0;
- AD7606_RAGE =1;// 量程范围选择。0表示正负5V, 1表示正负10V.
- AD7606_CVA=AD7606_CVB=1;
- AD7606_CS=AD7606_RD=1;
- }
- void ReadAD7606_X() //16进制码
- {
- U8 k=0x2c;//校准参数
- U8 i,j;
- U8 DatH,DatL;
- U32 ADC[8];
- AD7606_CVA=AD7606_CVB=0;
- Delay1ms(1);
- AD7606_CVA=AD7606_CVB=1;
- while(AD7606_BUSY==0);
- AD7606_CS=AD7606_RD=0;
- Delay1ms(1);
- AD7606_CS=AD7606_RD=1;
- for(i=0;i<8;i++) ADC=0;
- for(j=0;j<5;j++)
- {
- for(i=0;i<8;i++)
- {
- AD7606_CS=AD7606_RD=0;
- Delay1ms(1);
- AD7606_CS=AD7606_RD=1;
- DatH = P6;
- DatL = P1;
- ADC7606 = (U16)DatH<<8|DatL;
- ADC+=ADC7606;
- }
- }
- for(i=0;i<8;i++) ADC7606=ADC/5+k;
- }
- void ReadAD7606_mV()//转换电压
- {
- U32 V;
- U8 i;
- for(i=0;i<8;i++)
- {
- if(ADC7606>>15)
- {
- Display_ASCII("-",FONT_H*i+1,1+FONT_W*8,GREEN,BLACK); //显示负符号
- V=~ADC7606;
- }else{
- Display_ASCII(" ",FONT_H*i+1,1+FONT_W*8,GREEN,BLACK); //显示空格表示正
- V=ADC7606;
- }
- V=V*1000*10/32768; //mV输出
- ADC7606=V;
- }
- }
- AD7606.H内容:
- #ifndef __AD7606__H__
- #define __AD7606__H__
- #include <STC/STC8.h>
- #include<absacc.h>
- #include<intrins.h>
- #include<string.h>
- #include "def.h"
- #include "TFT.h"
- sbit AD7606_OS0 =P0^4;//
- sbit AD7606_OS1 =P0^5;//
- sbit AD7606_OS2 =P0^6;//
- sbit AD7606_BUSY =P0^7;
- sbit AD7606_RAGE =P4^0;// 量程范围选择。0表示正负5V, 1表示正负10V.
- sbit AD7606_CVB =P4^1;//CVA,CVB : 启动AD转换的控制信号。CVA决定1-4通道,CVB决定5-8通道。
- sbit AD7606_CVA =P4^2;
- sbit AD7606_RD =P4^3;
- sbit AD7606_RST =P4^4;
- sbit AD7606_CS =P4^5;
- sbit AD7606_FRST =P4^6; //NC
- sbit AD7606_IOVCC =P4^7;
- void AD7607Init();
- void ReadAD7606_X();
- void ReadAD7606_mV();
- #Endif#
- void main()
- {
- //U32 i;
- U8 j;
- lcd_initial();
- dsp_single_colour(BLACK);//黑色
- AD7607Init();
-
- while(1)
- {
- ReadAD7606_X();
- for(j=0;j<8;j++)
- {
- disDecX_4(ADC7606[j],1,FONT_H*j+1,RED,BLACK);
- }
- ReadAD7606_mV();
- for(j=0;j<8;j++)
- {
- disDec_5(ADC7606[j],FONT_W*9+1,FONT_H*j+1,GREEN,BLACK);
- Display_ASCII("mV",FONT_H*j+1,1+FONT_W*13,BLUE,BLACK);
- }
-
- }
- }
复制代码
|