完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
void initialize(void);
void reset_converter(void); void toggle_sdo(void); char receive_byte(void); void transfer_byte(char); void write_to_register(char command,char low,char mid, char high); void read_register(char command); void acquire_conversion(char command); /*** Byte Memory Map Equates ***/ sfr P1=0x90; /*Port One*/ sfr ACC=0xE0; /*Accumulator Register Equate*/ ***it CS=0x90; /* Chip Select, only used in four-wire mode*/ ***it SDI=0x91; /* Serial Data In*/ ***it SDO=0x92; /*Serial Data Out*/ ***it SCLK=0x93; /*Serial Clock*/ /*** Global Variable ***/ char command, /*Memory Storage Variable for Command Byte */ high_byte, /*Memory Storage Variable for Most Significant Byte*/ mid_byte, /* Memory Storage Variable for Most Significant Byte*/ low_byte, /* Memory Storage Variable for Most Significant Byte*/ temp, /*General Purpose Temporary Variable*/ mode; /*Variable Stores Mode of Operation 0 = three wire, 1 = 4 wire*/ main() { mode = 1; /*Make Communication be Four-Wire Mode*/ initialize(); /*Call Routine to Initialize 80C51 and CS5525/6/9*/ while(1){ command = 0x82; /*Prepare to Write to Gain Register*/ high_byte= 0x80; /*Make High_byte 80 (HEX)*/ mid_byte= 0x00; /*Make Mid_byte all Zero’s*/ low_byte= 0x00; /*Make low_byte all Zero’s*/ write_to_register(command,low_byte,mid_byte,high_byte);/*Write to gain Register*/ read_register(0x92); /*Read Contents of Gain Register*/ while(1) { acquire_conversion(0xC0); /*Acquire a Single Conversion*/ }/*End inner while loop*/ }/*End While Loop*/ }/*end main*/ void initialize() /*** Local Variables ***/ data int counter; /*** Body of Subroutine ***/ /*** Initialize 80C51’s Port 1 ***/ P1 = 0xF4; /*SCLK - Output */ for(counter=0;counter<2047;counter++){ SCLK = 0x01; /*Assert SCLK*/ SCLK = 0x00; /*Deassert*/ } /*Reset Serial Port on CS5525/6/9*/ SDI = 0x01; /*Assert SDI*/ for(counter=0;counter<255;counter++) { SCLK = 0x01; /*Assert SCLK*/ SCLK = 0x00; /*Deassert SCLK*/ } SDI = 0x00; /*Deassert SDI PIN*/ SCLK = 0x01; /*Assert SCLK*/ SCLK = 0x00; /* Deassert SCLK*/ } void calibrate() { write_to_register(0x84,0x01,0x00,0x00); /*Assert RS bit*/ /*Read Configuration Register Until DF Bit is Asserted*/ do { read_register(0x94); /*Read Configuration Register*/ temp = low_byte&0x08; /*Mask DF bit to 1*/ } while (temp != 0x08); read_register(0x92); /*Deasserts DF Bit*/ }/*End calibrate */ void write_to_register(char command,char low,char mid,char high){ if(mode == 1) P1 = 0xF4; /*Assert if necessary*/ CS transfer_byte(command); /*Transfer Command Byte to CS5525/6/9*/ transfer_byte(high); /*Transfer High Byte to CS5525/6/9*/ transfer_byte(mid); /*Transfer Middle Byte to CS5525/6/9*/ transfer_byte(low); /*Transfer Low Byte to CS5525/6/9*/ if(mode == 1) P1 = 0xF5; /*Deassert if necessary*/ CS } void read_register(char command){ if(mode == 1) P1 = 0xF4; /*Assert if necessary */ CS transfer_byte(command); /*Transfer Command Byte to CS5525/6/9*/ high_byte = receive_byte(); /*Receive Command Byte from CS5525/6/9*/ mid_byte = receive_byte(); /*Receive Command Byte from CS5525/6/9*/ low_byte = receive_byte(); /*Receive Command Byte from CS5525/6/9*/ if(mode == 1)P1 = 0xF5; /*Deassert if necessary */ CS } void acquire_conversion(char command){ /*** Read Configuration Register to Prevent Previously Set Bits from being Altered ***/ read_register(0x94); /*Read Configuration Register*/ low_byte = low_byte|0x20; /*Assert Port Flag Bit*/ write_to_register(0x84,low_byte, mid_byte, high_byte);/*Actually Send Commands*/ /*Acquire a Conversion*/ if(mode == 1)P1 = 0xF4; transfer_byte(0xC0); /*Transfer Command to CS5525/6/9*/ toggle_sdo(); /*Clear SDO*/ high_byte = receive_byte(); /*Receive Command Byte from CS5525/6/9*/ mid_byte = receive_byte(); /*Receive Command Byte from CS5525/6/9*/ low_byte = receive_byte(); /*Receive Command Byte from CS5525/6/9*/ if(mode == 1) P1 = 0xF5; /*Deassert if necessary*/ } |
|
相关推荐
3个回答
|
|
这个是CS5525的设置例程,51的,上面是我截取的部分
|
|
|
|
|
|
很好,谢谢分享
|
|
|
|
只有小组成员才能发言,加入小组>>
3035个成员聚集在这个小组
加入小组2930 浏览 1 评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
3606 浏览 2 评论
请问怎么把下面51单片机的代码改成msp430 g2 pocket的代码,还有改下时间变成30秒
2343 浏览 1 评论
4807 浏览 1 评论
2573 浏览 1 评论
1330浏览 3评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
3607浏览 2评论
2930浏览 1评论
1517浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-1 13:47 , Processed in 1.429666 second(s), Total 90, Slave 69 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号