完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
回复本帖可获得 2 分积分奖励! 每人限 5 次 |
我打算用51单片机和ad7705做一个电压采集,但是无论我读取ad7705的什么寄存器都显示255附件是原理图,下面是程序,有没有懂得人万分感谢了 还有如果将程序里main函数的int a;改成uchar a;就显示-256 #include"reg51.h" #include"intrins.h" #include "stdio.h" #include"math.h" ***it AD7705_SCLK = P2^0; ***it AD7705_DRDY = P2^3; ***it AD7705_DOUT = P2^2; ***it AD7705_DIN = P2^1; // 通讯寄存器地址定义 #define uchar unsigned char #define uint unsigned int #define WR_SETUP_REG 0x10 //选中设置寄存器,写 #define RD_SETUP_REG 0x18 //选中设置寄存器,读 #define WR_CLOCK_REG 0x20 //选中时钟寄存器,写 #define RD_DATA_REG 0x38 //选中数据寄存器,读 #define WR_OFFSET_REG 0x60 //选中offset寄存器,写 #define RD_OFFSET_REG 0x68 //选中offset寄存器,读 #define WR_FULL_REG 0x70 //选中full scale寄存器,写 #define RD_FULL_REG 0x78 //选中full scale寄存器,读 #define SYS_ZERO_CALI 0x80 //系统零校准模式 #define SYS_FULL_CALI 0xC0 //系统满量程校准模式 #define ZERO_CALIBRAtiON 0x00 //系统零校准 #define FULL_CALIBRATION 0x01 //系统满量程校准 #define CLOCK_REG_SET 0x04 //CLOCK寄存器设置,无分频,50HZ输出更新速率 #define DELAY() {_nop_();_nop_();_nop_();} void v_DelayMs_f(unsigned int nDelay); void v_Lcd_SendCmd_f(unsigned char byCmd); //发送命令 void v_Lcd_SendData_f(unsigned char byData); //发送数据 void v_Lcd_Init_f(void); //初始化 void v_Lcd_SetAddress_f(unsigned char x,y); //地址转换 void v_Lcd_PutString_f(unsigned char x,unsigned char y,unsigned char *pData); void DelayMs(unsigned int nDelay); ***it LCD_RS = P2^7; ***it LCD_RW = P2^6; ***it LCD_EN = P2^5; ***it LCD_PSB = P3^2; #define LCD_DATAPORT P0 #define SET_DATA LCD_RS = 1 #define SET_INC LCD_RS = 0 #define SET_READ LCD_RW = 1 #define SET_WRITE LCD_RW = 0 #define SET_EN LCD_EN = 1 #define CLR_EN LCD_EN = 0 void AD7705_Init(void); void AD7705_Reset(void); void AD7705_Start(void); uchar AD7705_ReadByte(void); void AD7705_WriteByte(uchar d); int AD7705_ReadVol(void); void main(void) { int a; char z[16]="01231"; AD7705_Init(); AD7705_Start(); a=AD7705_ReadVol(); sprintf(z,"%d",a); v_Lcd_Init_f(); v_Lcd_PutString_f(0,1,z); } void v_DelayMs_f(unsigned int nDelay) //延时 { unsigned int i ; for(;nDelay>0;nDelay--) { for(i=125;i>0;i--) ; } } void v_Lcd_SendCmd_f(unsigned char byCmd) //发送命令 { v_DelayMs_f(50); SET_INC;//rs 0 SET_WRITE;//rw 0 CLR_EN; //e 0 LCD_DATAPORT=byCmd; _nop_(); _nop_(); SET_EN; // e1 _nop_(); _nop_(); CLR_EN;//e 0 SET_READ; //rw 1 SET_INC; //rs 0 } void v_Lcd_SendData_f(unsigned char byData) //发送数据 { v_DelayMs_f(50); SET_DATA; //rs1 SET_WRITE; //rw0 CLR_EN; //e0 LCD_DATAPORT=byData ; _nop_(); _nop_(); SET_EN; //e1 _nop_(); _nop_(); CLR_EN; //e0 SET_READ; //rw1 SET_INC; //rs0 } void v_Lcd_Init_f(void) //初始化 { v_Lcd_SendCmd_f(0x30); //基本指令集 v_DelayMs_f(50); v_Lcd_SendCmd_f(0x01); //清屏 v_DelayMs_f(50); v_Lcd_SendCmd_f(0x06); //光标右移 v_DelayMs_f(50); v_Lcd_SendCmd_f(0x0c); //开显示 } void v_Lcd_SetAddress_f(unsigned char x,y) //地址转换 { unsigned char byAddress ; switch( y ) { case 0 : byAddress=(0x80+x); break; case 1 : byAddress=(0x90+x); break; case 2 : byAddress=(0x88+x); break; case 3 : byAddress=(0x98+x); break; default: break ; } v_Lcd_SendCmd_f(byAddress); } void v_Lcd_PutString_f(unsigned char x,unsigned char y,unsigned char *pData) { v_Lcd_SetAddress_f(x,y); while(*pData!=' |