/********************************************************************************************
**单 位:中国计量学院
** 杭州量立自动化技术有限公司
** 三花测控技术工程中心
**文 件 名:MAX1452通讯
**作 者:邵建文
sloan2459@126.com
**用 途:MAX1452通讯
**创建时间:2010.5.13
**完成时间:2010.
**申 明:任何个人或团体,如若参引本程序,请得到公司或者作者的同意,尊重他人劳动成果,谢谢!
**注 明:
*********************************************************************************************/
#include "p24FJ256GB110.h"
#include "variate_def.h"
struct error_flag{
unsigned uart_rev:1; //if or not recieve data from PC (RS232)
unsigned uart_ver:1; //if or not data recieved from PC is correct
unsigned :6;
unsigned max1452_1:1; //max1452 can recieve data
unsigned max1452_2:1; //max1452 baud selfcheck is error
unsigned max1452_3:1; //max1452 ICR selfcheck is error
unsigned max1452_4:1; //max1452 EEPROM selfcheck is error
unsigned max1452_5:1; //max1452 IRSP slefcheck is error
unsigned :4;
} error;
//---------------------------------------------------------------------------
// MAX1452 SUBPROGRAMM
// input: the code of an interface register set
// output:NULL
//---------------------------------------------------------------------------
void max1452_irs_operation(unsigned char irs)
{
unsigned char i;
AD_V_C_LKd=0;
AD_V_C_LK=1; //UNLOCK pin == 1
AD_V_C_IOd=0;
AD_V_C_IO=1; //set IO =1
delay1ms(5);
AD_V_C_IO=0; //START bit
delay_9600();
for (i=0;i<1;i++){;}
for (i=0;i<8;i++) //8 bata bits
{
if (irs&0x01) AD_V_C_IO=1;
else AD_V_C_IO=0;
delay_9600();
irs=irs>>1;
}
AD_V_C_IO=1; //END bit
}
//---------------------------------------------------------------------------
// MAX1452 SUBPROGRAMM
// input:
// output:the test result:"CA"
//---------------------------------------------------------------------------
void max1452_baud_initiate(void)
{
unsigned char i, test;
unsigned int wait_time=0;
AD_V_C_LKd=0;
AD_V_C_LK=1;
delay1ms(5);
max1452_irs_operation(0xFF);
delay1ms(1);
max1452_irs_operation(0x01);
delay1ms(1);
max1452_irs_operation(0xF8);
delay1ms(1);
max1452_irs_operation(0x59);
AD_V_C_IOd=1; //AD_V_C_IO is input port
//CNPD2bits.CN16PDE=1; //内部下拉
CNPU2bits.CN16PUE=1; //内部上拉
wait_time=0;
do //wait I/O
{
error.max1452_1=0;
if(wait_time++>0x1000)error.max1452_1=1; //if no data go out ,then set error flag
}while(AD_V_C_IO && !error.max1452_1);
delay_4800();
for (i=0;i<8;i++)
{
test >>=1;
delay_9600();
if (AD_V_C_IO==1) test |= 0x80;
else test &= 0x7F;
}
if(test==0xCA) error.max1452_2=0;
else error.max1452_2=1;
AD_V_C_IOd=0;
//CNPD2bits.CN16PDE=0; //内部下拉
CNPU2bits.CN16PUE=1; //内部上拉
delay1ms(1);
}
//---------------------------------------------------------------------------
// MAX1452 SUBPROGRAMM
// input: icr -- 16bit write to the internal calibration registers
// icra -- the address of the target internal calibration register
// output:NULL
//---------------------------------------------------------------------------
void max1452_icr_write(unsigned int icr, unsigned char icra)
{
//int icr_data,wait_time;
unsigned char data0,data1,data2,data3;
data0 = icr<<4;
data1 = icr;
data2 = icr>>4;
data3 = icr>>8;
data0 &= 0xF0;
data1 &= 0xF0;
data2 &= 0xF0;
data3 &= 0xF0;
data0 |= WR_DHR_30;
data1 |= WR_DHR_74;
data2 |= WR_DHR_B8;
data3 |= WR_DHR_FC;
max1452_irs_operation(data0); //send 16bit data to DHR
delay1ms(1);
max1452_irs_operation(data1);
delay1ms(1);
max1452_irs_operation(data2);
delay1ms(1);
max1452_irs_operation(data3);
delay1ms(1);
data0 = icra; //send the address of the target internal calibration register to ICRSA
data0 |= WR_ICRA_30;
max1452_irs_operation(data0);
delay1ms(1);
data0 = CRIL_LdICR; //write the load internal calibration register(LdICR) command to CRIL
data0 |= WR_CRIL_30;
max1452_irs_operation(data0);
delay1ms(1);
}
//---------------------------------------------------------------------------
// MAX1452 SUBPROGRAMM
// input: icra -- the address of the target internal calibration register
// output: 16bit write to the internal calibration registers
//---------------------------------------------------------------------------
unsigned int max1452_icr_read(unsigned char icra)
{
unsigned int data,wait_time;
unsigned char dal=0,dah=0,addr,comm,i;
addr = icra; //send the address of the target internal calibration register to ICRSA
addr |= WR_ICRA_30;
max1452_irs_operation(addr);
delay1ms(1);
comm = CRIL_RdICR; //the read internal calibration register(LdICR) command to CRIL
comm |= WR_CRIL_30;
max1452_irs_operation(comm);
delay1ms(1);
//--- //now data is in DHR,
//first DHR[7:0] to DIO
addr = IRSP_HDR_70; //send the address of the target internal calibration register to IRSP
addr |= WR_IRSP_30;
max1452_irs_operation(addr);
delay1ms(1);
comm = CRIL_RdIRS; //send the DHR[7:0] to DIO
comm |= WR_CRIL_30;
max1452_irs_operation(comm);
//---
AD_V_C_IOd=1; //AD_V_C_IO is input port
//CNPD2bits.CN16PDE=1; //内部下拉
CNPU2bits.CN16PUE=1; //内部上拉
wait_time=0;
do //wait I/O
{
error.max1452_3=0;
if(wait_time++ >0x1000)error.max1452_3=1; //if no data go out ,then set error flag
} while(AD_V_C_IO && !error.max1452_3);
delay_4800();
for (i=0;i<8;i++)
{
dal>>=1;
delay_9600d();
if (AD_V_C_IO==1) dal |= 0x80;
else dal &= 0x7F;
}
AD_V_C_IOd=0;
//CNPD2bits.CN16PDE=0; //内部下拉
CNPU2bits.CN16PUE=1; //内部上拉
delay1ms(2);
//--- //now data is in DHR,
//second read DHR[15:8] to DIO
addr = IRSP_HDR_F8; //send the address of the target internal calibration register to IRSP
addr |= WR_IRSP_30;
max1452_irs_operation(addr);
delay1ms(1);
comm = CRIL_RdIRS; //send the DHR[15:8] to DIO
comm |= WR_CRIL_30;
max1452_irs_operation(comm);
//----
AD_V_C_IOd=1; //AD_V_C_IO is input port
//CNPD2bits.CN16PDE=1; //内部下拉
CNPU2bits.CN16PUE=1; //内部上拉
wait_time=0;
do //wait I/O
{ error.max1452_3=0;
if(wait_time++ >0x1000)error.max1452_3=1; //if no data go out ,then set error flag
} while(AD_V_C_IO && !error.max1452_3);
delay_4800();
for (i=0;i<8;i++)
{
dah>>=1;
delay_9600d();
if (AD_V_C_IO==1) dah |= 0x80;
else dah &= 0x7F;
}
AD_V_C_IOd=0;
//CNPD2bits.CN16PDE=0; //内部下拉
CNPU2bits.CN16PUE=1; //内部上拉
delay1ms(2);
data = (unsigned int)dah;
data<<=8;
data |= (unsigned int)dal;
return(data);
}
//---------------------------------------------------------------------------
// MAX1452 SUBPROGRAMM
// input: data_cp -- the data pointer of writed data
// addr -- EEPROM MEMORY Page (0-B)
// output:NULL
//---------------------------------------------------------------------------
void max1452_epprom_write(unsigned char *data_cp, unsigned char page)
{
unsigned int addr;
unsigned char addr0,addr1,addr2, comm;
unsigned char data,data0,data1,i;
data_cp += 3;
//first erase page
switch(page)
{
case 0: addr=0x000; addr2=0x00; addr1=0x00; addr
信号调理max1452
需积分: 22 5 浏览量
2017-09-14
13:47:15
上传
评论 1
收藏 3KB RAR 举报
wevsmy520
- 粉丝: 0
- 资源: 1
最新资源
- 前端开发-什么是前端开发-关于前端开发的一些相关介绍
- Sora AI-关于文生视频的使用场景说明
- suno AI文生视频的相关教程和介绍使用
- 什么是后端开发-关于后端开发的一些小介绍分享
- Jurassic Pack Vol. II Dinosaurs 侏罗纪包卷恐龙二号Unity游戏模型资源unitypackage
- Jurassic Pack Vol. III Dinosaurs 侏罗纪包卷恐龙三号Unity游戏模型资源unitypackag
- Ultimate Seating Controller 终极座椅控制器Unity游戏开发插件资源unitypackage
- 什么是人工智能-关于人工智能的相关介绍说明
- Figma Converter for Unity适用Unity的Figma转换器Unity游戏开发插件unitypackage
- Creepy Animatronic Anims 令人毛骨悚然的电子动画Unity游戏动画插件资源unitypackage
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈