📄 带spi接口的16位ad7705驱动程序 avr与虚拟仪器论坛 avrvi_com.htm
字号:
href="http://bbs.avrvi.com/read-htm-tid-6472.html">带SPI接口的16位AD7705驱动程序</A></B></TD>
<TD align=right>
<TABLE
style="BORDER-RIGHT: #8c8e7b 1px solid; BORDER-TOP: #8c8e7b 1px solid; BACKGROUND: #ffffff; BORDER-LEFT: #8c8e7b 1px solid; BORDER-BOTTOM: #8c8e7b 1px solid; FONT-FAMILY: Tahoma, Verdana"
cellSpacing=1 cellPadding=1>
<TBODY>
<TR>
<TD
style="FONT-SIZE: 7pt; BACKGROUND: #ff6500; COLOR: #ffffff"> XML </TD>
<TD style="FONT-SIZE: 7pt; BACKGROUND: #8c8e7b"> <A
title=订阅本版面最新帖子 href="http://bbs.avrvi.com/rss.php?fid=30"
target=_blank><FONT color=#ffffff>RSS 2.0</FONT></A> </TD>
<TD style="FONT-SIZE: 7pt; BACKGROUND: #8c8e7b"> <A
title=通过手机访问论坛 href="http://bbs.avrvi.com/faq-htm-faqjob-2.html#5"
target=_blank><FONT
color=#ffffff>WAP</FONT></A> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><!--ads begin-->
<TABLE cellSpacing=1 cellPadding=6 width="98%" align=center bgColor=#cccccc>
<TBODY>
<TR align=middle>
<TD class=f_one width="25%"><A style="FONT-SIZE: 12px; COLOR: #0000ff"
href="http://shop34452654.taobao.com/" target=_blank>AVRVI的淘宝店</A></TD>
<TD class=f_one width="25%"><A style="COLOR: #6600cc"
href="http://shop.avrvi.com/category-41-b0.html"
target=_blank>AVR单片机学习套餐</A></TD>
<TD class=f_one width="25%"><A style="FONT-SIZE: 18px; COLOR: blue"
href="http://shop.avrvi.com/goods-160.html" target=_blank>EasyAVR M128开发板
SK</A></TD>
<TD class=f_one width="25%"><A style="FONT-SIZE: 14px; COLOR: green"
href="http://shop.avrvi.com/"
target=_blank>国内最专业AVR开发工具商城</A></TD></TR></TBODY></TABLE><BR><!--ads end-->
<TABLE cellSpacing=0 cellPadding=1 width="98%" align=center>
<TBODY>
<TR>
<TD align=left></TD>
<TD align=right><A href="http://bbs.avrvi.com/post-htm-fid-30.html"><IMG
src="带SPI接口的16位AD7705驱动程序 AVR与虚拟仪器论坛 AVRVi_com.files/post.gif"></A> <A
href="http://bbs.avrvi.com/post-htm-action-vote-fid-30.html"><IMG
src="带SPI接口的16位AD7705驱动程序 AVR与虚拟仪器论坛 AVRVi_com.files/vote.gif"></A> <A
href="http://bbs.avrvi.com/post-htm-action-reply-fid-30-tid-6472.html"><IMG
src="带SPI接口的16位AD7705驱动程序 AVR与虚拟仪器论坛 AVRVi_com.files/reply.gif"></A>
</TD></TR></TBODY></TABLE>
<FORM name=delatc action=masingle.php?action=delatc method=post><INPUT
type=hidden value=30 name=fid> <INPUT type=hidden value=6472 name=tid>
<TABLE
style="BORDER-RIGHT: #cccccc 1px solid; BORDER-TOP: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid"
cellSpacing=0 cellPadding=1 width="98%" align=center>
<TBODY>
<TR>
<TD class=head align=left>--> <B>本页主题:</B> 带SPI接口的16位AD7705驱动程序</TD>
<TD class=head align=right><A
onclick="Addtoie('http://bbs.avrvi.com/read.php?fid=30&tid=6472','AVR与虚拟仪器论坛 AVRVi.com--带SPI接口的16位AD7705驱动程序')"
href="http://bbs.avrvi.com/#">加为IE收藏</A> | <A
href="http://bbs.avrvi.com/profile-htm-action-favor-job-add-tid-6472.html">收藏主题</A>
| <A
href="http://bbs.avrvi.com/job-htm-rd_previous-1-fid-30-tid-6472-fpage-0-goto-previous.html">上一主题</A>
| <A
href="http://bbs.avrvi.com/job-htm-rd_previous-1-fid-30-tid-6472-fpage-0-goto-next.html">下一主题</A>
</TD></TR></TBODY></TABLE><A name=tpc>
<TABLE style="TABLE-LAYOUT: fixed; WORD-WRAP: break-word" cellSpacing=1
cellPadding=0 width="98%" align=center bgColor=#cccccc>
<TBODY>
<TR>
<TD
style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px"
vAlign=top width="20%" bgColor=#ffffff height="100%"><FONT face=Gulim
color=#000066><B>铜河</B></FONT><BR>
<TABLE cellSpacing=0 cellPadding=0 width="98%">
<TBODY>
<TR>
<TD align=middle><BR><BR></TD></TR></TBODY></TABLE><BR><IMG alt=技术群用户
src="带SPI接口的16位AD7705驱动程序 AVR与虚拟仪器论坛 AVRVi_com.files/qq.jpg"> <IMG
alt=优秀斑竹奖 src="带SPI接口的16位AD7705驱动程序 AVR与虚拟仪器论坛 AVRVi_com.files/2.gif">
<BR><IMG src="带SPI接口的16位AD7705驱动程序 AVR与虚拟仪器论坛 AVRVi_com.files/5.gif">
<BR>级别: <FONT color=#555555>论坛版主</FONT><BR>精华: <A
href="http://bbs.avrvi.com/search-htm-authorid-2408-digest-1.html"
target=_blank><FONT color=green><B>7</B></FONT></A> <BR>发帖: <FONT
color=green><B>511</B></FONT><BR>威望: <FONT color=#984b98><B>746
点</B></FONT><BR>金钱: <FONT color=#984b98><B>5971 VI</B></FONT><BR>贡献值:
<FONT color=red><B>253 点</B></FONT><BR>技术积分: <FONT color=#0033ff><B>31
点</B></FONT><BR>在线时间:125(小时)<BR>注册时间:1970-01-01<BR>最后登录:2008-09-06 </TD>
<TD vAlign=top width="80%" bgColor=#ffffff height="100%">
<TABLE style="TABLE-LAYOUT: fixed; WORD-WRAP: break-word" height="100%"
cellSpacing=0 cellPadding=4 width="99%" align=center>
<TBODY>
<TR>
<TD vAlign=top bgColor=#ffffff colSpan=6><A
href="http://bbs.avrvi.com/profile-htm-action-show-uid-2408.html"><IMG
alt=查看作者资料
src="带SPI接口的16位AD7705驱动程序 AVR与虚拟仪器论坛 AVRVi_com.files/profile.gif"
align=absMiddle></A> <A
href="http://bbs.avrvi.com/message-htm-action-write-touid-2408.html"><IMG
alt=发送短消息
src="带SPI接口的16位AD7705驱动程序 AVR与虚拟仪器论坛 AVRVi_com.files/message.gif"
align=absMiddle></A> <A
href="http://bbs.avrvi.com/sendemail-htm-action-tofriend-tid-6472.html"><IMG
alt=推荐此帖
src="带SPI接口的16位AD7705驱动程序 AVR与虚拟仪器论坛 AVRVi_com.files/emailto.gif"
align=absMiddle></A> <A
href="http://bbs.avrvi.com/post-htm-action-quote-fid-30-tid-6472-pid-tpc-article-0.html"><IMG
alt=引用回复这个帖子
src="带SPI接口的16位AD7705驱动程序 AVR与虚拟仪器论坛 AVRVi_com.files/quote.gif"
align=absMiddle></A> <A
href="http://bbs.avrvi.com/post-htm-action-modify-fid-30-tid-6472-pid-tpc-article-0.html"><IMG
src="带SPI接口的16位AD7705驱动程序 AVR与虚拟仪器论坛 AVRVi_com.files/edit.gif"
align=absMiddle></A> <BR><BR><SPAN
class=tpc_title>带SPI接口的16位AD7705驱动程序</SPAN><BR><BR><SPAN
class=tpc_content>在为“我心飞翔”设计的板子上,应用了双通道16位AD转换器,此AD转换精度高、速度快、具有自校准。经努力,调通了其中一路,现共享,但愿能起到抛砖引玉的作用。<BR>/****************************************<BR>*
AD7705在M16下驱动程序
*<BR>* 文 件 名:AD7705.c
*<BR>* 描
述:16位∑-Δ模数转换器 *<BR>* 作 者:铜河
*<BR>* 建立日期:2007年12月27日
*<BR>* 版 本:V2007.01
*<BR>*
修改日期:2007年12月27日
*<BR>* 控制芯片:Mega16
*<BR>* 时钟频率:7.3728MHz
*<BR>* 波 特 率:9600BPS
*<BR>* 联接方式:AD7705 ________
M16 *<BR>* 片
选:CS_7705 _______ PA4
*<BR>* 复 位:RESET _________ PA5
*<BR>* 数据有效:DRRY __________ PB3
*<BR>****************************************/<BR>#include
<iom16v.h><BR>#include <macros.h><BR>#include
"delay.h"<BR><BR>//控制端口定义<BR>//端口操作定义<BR>#define CS_7705
PA4
//AD7705的片选接在PA4<BR>#define
SET_CS_7705 PORTA |= 1<<CS_7705<BR>#define
CLR_CS_7705 PORTA &= ~(1<<CS_7705)<BR><BR>#define RET
PA5
//AD7705的复位接在PA5<BR>#define SET_RET PORTA
|= 1<<RET<BR>#define CLR_RET PORTA
&= ~(1<<RET)<BR><BR>#define DRRY
PB3
//AD7705的数据有效接在PB3<BR>#define DRRY_7705
(PINB & (1<<DRRY))<BR><BR>//SPI接口初始化函数<BR>void
spi_init(void)<BR> {<BR> DDRB |=
(1<<PB5)|(1<<PB7); //设置MOSI
和SCK 为输出<BR> DDRB &= ~(1<<PB6);
//MISO为输入<BR>
SPCR = (1<<SPE)|(1<<MSTR);
//使能SPI主机模式fck/4<BR>
}<BR><BR>//写入AD7705一字节函数<BR>//入口:data 需写入的字节数据<BR>void
wr_byte(unsigned char data)<BR> {<BR> SPDR =
data;
//启动数据传输<BR> while (!(SPSR &
(1<<SPIF))) //等待传输结束 <BR>
{<BR> ;<BR>
}<BR>
}<BR><BR>//读出AD7705数据函数<BR>//出口:读出的2字节数据<BR>unsigned int
rd_7705(void)<BR> {<BR> unsigned int temp;
//定义临时变量<BR> wr_byte(0x38);
//选择读数据寄存器,1通道<BR> SPDR = 0;
//启动数据传输<BR> while (!(SPSR &
(1<<SPIF))) //等待传输结束 <BR>
{ <BR>
;<BR> }<BR> temp
= SPDR<<8;
//读取高字节<BR> <BR> SPDR =
0;
//启动数据传输<BR> while
(!(SPSR & (1<<SPIF))) //等待传输结束
<BR> {
<BR> ;<BR>
}<BR> temp |= SPDR;
//读取低字节<BR>
return(temp);<BR>
}<BR><BR>//判断有无数据函数<BR>//出口:读出的2字节数据<BR>unsigned int
ad7705(void)<BR> {<BR>
if(DRRY_7705==0)<BR> {<BR>
return(rd_7705());<BR>
}<BR> else<BR>
{<BR> return(0);<BR>
}<BR> }<BR><BR>//AD7705初始化函数<BR>void
init_7705(void)<BR> {<BR>
spi_init();<BR> DDRA |=
(1<<CS_7705)|(1<<RET); //定义端口方向<BR>
DDRB &= ~(1<<DRRY);<BR> PORTB|=
1<<DRRY;<BR> CLR_CS_7705;
//片选有效<BR> CLR_RET;
//复位端低有效<BR> delay_ms(500);
//保持500MS低电平<BR> SET_RET;
//复位端回复高<BR> delay_ms(1);<BR>
wr_byte(0x20);
//选择时钟寄存器<BR> wr_byte(0x0C);
//50HZ的转换频率<BR> wr_byte(0x10);
//选择设置寄存器<BR> wr_byte(0x44);
//自校准模式,增益为1,单极性<BR> }</SPAN><BR></TD></TR>
<TR vAlign=bottom bgColor=#ffffff>
<TD colSpan=6>
<TABLE cellSpacing=1 cellPadding=4 bgColor=#cccccc>
<TBODY>
<TR>
<TD class=t_one><A href="http://www.avrvi.com/index_avr.html"
target=_blank>本站原创AVR单片机新手入门教程!</A></TD></TR></TBODY></TABLE></TD></TR>
<TR vAlign=bottom bgColor=#ffffff>
<TD class=smalltxt colSpan=5><FONT color=red>[楼 主]</FONT> |
<B>Posted:</B> 01-28 23:06</TD>
<TD class=smalltxt align=right><A href="javascript:scroll(0,0)"><IMG
alt=顶端
src="带SPI接口的16位AD7705驱动程序 AVR与虚拟仪器论坛 AVRVi_com.files/top.gif"></A>
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -