单片机实验四.doc

上传人:豆**** 文档编号:33571283 上传时间:2022-08-11 格式:DOC 页数:10 大小:52KB
返回 下载 相关 举报
单片机实验四.doc_第1页
第1页 / 共10页
单片机实验四.doc_第2页
第2页 / 共10页
点击查看更多>>
资源描述

《单片机实验四.doc》由会员分享,可在线阅读,更多相关《单片机实验四.doc(10页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、如有侵权,请联系网站删除,仅供学习与交流单片机实验四【精品文档】第 10 页实验四 D/A转换一、实验目的1、熟悉DAC0832 内部结构及引脚。2、掌握D/A转换与接口电路的方法。二、实验原理1、 DAC0832的引脚及功能DAC0832是8分辨率的D/A转换集成芯片。与微处理器完全兼容。这个DA芯片以其价格低廉、接口简单、转换控制容易等优点,在单片机应用系统中得到广泛的应用。D/A转换器由8位输入锁存器、8位DAC寄存器、8位D/A转换电路及转换控制电路构成。2 DAC0832的主要特性参数如下:分辨率为8位;电流稳定时间1us;可单缓冲、双缓冲或直接数字输入;只需在满量程下调整其线性度;

2、单一电源供电(+5V+15V);低功耗,200mW。3 DAC0832结构: D0D7:8位数据输入线,TTL电平,有效时间应大于90ns(否则锁存器的数据会出错);ILE:数据锁存允许控制信号输入线,高电平有效;CS:片选信号输入线(选通数据锁存器),低电平有效;WR1:数据锁存器写选通输入线,负脉冲(脉宽应大于500ns)有效。由ILE、CS、WR1的逻辑组合产生LE1,当LE1为高电平时,数据锁存器状态随输入数据线变换,LE1的负跳变时将输入数据锁存;XFER:数据传输控制信号输入线,低电平有效,负脉冲(脉宽应大于500ns)有效;WR2:DAC寄存器选通输入线,负脉冲(脉宽应大于500

3、ns)有效。由WR1、XFER的逻辑组合产生LE2,当LE2为高电平时,DAC寄存器的输出随寄存器的输入而变化,LE2的负跳变时将数据锁存器的内容打入DAC寄存器并开始D/A转换。IOUT1:电流输出端1,其值随DAC寄存器的内容线性变化;IOUT2:电流输出端2,其值与IOUT1值之和为一常数;Rfb:反馈信号输入线,改变Rfb端外接电阻值可调整转换满量程精度;Vcc:电源输入端,Vcc的范围为+5V+15V;VREF:基准电压输入线,VREF的范围为-10V+10V;AGND:模拟信号地DGND:数字信号地4 DAC0832的工作方式:根据对DAC0832的数据锁存器和DAC寄存器的不同的

4、控制方式,DAC0832有三种工作方式:直通方式、单缓冲方式和双缓冲方式正弦波表格:/ 正弦波一周期内采样256次unsigned char code sin= 0x80,0x83,0x86,0x89,0x8D,0x90,0x93,0x96,0x99,0x9C,0x9F,0xA2,0xA5,0xA8,0xAB,0xAE,0xB1,0xB4,0xB7,0xBA,0xBC,0xBF,0xC2,0xC5,0xC7,0xCA,0xCC,0xCF,0xD1,0xD4,0xD6,0xD8,0xDA,0xDD,0xDF,0xE1,0xE3,0xE5,0xE7,0xE9,0xEA,0xEC,0xEE,0xEF

5、,0xF1,0xF2,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFD,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFD,0xFD,0xFC,0xFB,0xFA,0xF9,0xF8,0xF7,0xF6,0xF5,0xF4,0xF2,0xF1,0xEF,0xEE,0xEC,0xEA,0xE9,0xE7,0xE5,0xE3,0xE1,0xDF,0xDD,0xDA,0xD8,0xD6,0xD4,0xD1,0xCF,0xCC,0xCA,0xC7

6、,0xC5,0xC2,0xBF,0xBC,0xBA,0xB7,0xB4,0xB1,0xAE,0xAB,0xA8,0xA5,0xA2,0x9F,0x9C,0x99,0x96,0x93,0x90,0x8D,0x89,0x86,0x83,0x80,0x80,0x7C,0x79,0x76,0x72,0x6F,0x6C,0x69,0x66,0x63,0x60,0x5D,0x5A,0x57,0x55,0x51,0x4E,0x4C,0x48,0x45,0x43,0x40,0x3D,0x3A,0x38,0x35,0x33,0x30,0x2E,0x2B,0x29,0x27,0x25,0x22,0x20,0x1E

7、,0x1C,0x1A,0x18,0x16,0x15,0x13,0x11,0x10,0x0E,0x0D,0x0B,0x0A,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0D,0x0E,0x10,0x11,0x13,0x15,0x16,0x18,0x1A,0x1C,0x1E,0x20,0x22,0x25

8、,0x27,0x29,0x2B,0x2E,0x30,0x33,0x35,0x38,0x3A,0x3D,0x40,0x43,0x45,0x48,0x4C,0x4E,0x51,0x55,0x57,0x5A,0x5D,0x60,0x63,0x66,0x69,0x6C,0x6F,0x72,0x76,0x79,0x7C,0x80;三、 实验内容1、产生连续方波信号,最大幅度为2V,频率为100Hz。#include#include#define uchar unsigned char#define DAC0832 XBYTE 0x7fffvoid delay(void);void main(void)u

9、char i;while(1)DAC0832=0;delay();DAC0832=100;delay();void delay()uchar i,j;for(i=0;i10;i+)for(j=0;j120;j+);2、产生连续锯齿波信号,频率为100Hz。#include#include#define uchar unsigned char#define DAC0832 XBYTE 0x7fffvoid delay(void);void main(void)uchar i;while(1)for(i=0;i0xff;i+)DAC0832=i;delay();void delay()uchar

10、i,j;for(i=0;i8;i+);3、产生连续三角波信号,周期为5ms。#include#include#define uchar unsigned char#define DAC0832 XBYTE 0x7fffvoid delay(void);void main(void)uchar i;while(1)for(i=0;i0;i-)DAC0832=i;delay();void delay()uchar i,j;for(i=0;i2;i+);4、产生连续正弦波信号,频率为200Hz。#include#include#define uchar unsigned char#define DA

11、C0832 XBYTE 0x7fffvoid delay(void);unsigned char code sin= 0x80,0x83,0x86,0x89,0x8D,0x90,0x93,0x96,0x99,0x9C,0x9F,0xA2,0xA5,0xA8,0xAB,0xAE,0xB1,0xB4,0xB7,0xBA,0xBC,0xBF,0xC2,0xC5,0xC7,0xCA,0xCC,0xCF,0xD1,0xD4,0xD6,0xD8,0xDA,0xDD,0xDF,0xE1,0xE3,0xE5,0xE7,0xE9,0xEA,0xEC,0xEE,0xEF,0xF1,0xF2,0xF4,0xF5,0

12、xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFD,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFD,0xFD,0xFC,0xFB,0xFA,0xF9,0xF8,0xF7,0xF6,0xF5,0xF4,0xF2,0xF1,0xEF,0xEE,0xEC,0xEA,0xE9,0xE7,0xE5,0xE3,0xE1,0xDF,0xDD,0xDA,0xD8,0xD6,0xD4,0xD1,0xCF,0xCC,0xCA,0xC7,0xC5,0xC2,0xBF,0xBC,0

13、xBA,0xB7,0xB4,0xB1,0xAE,0xAB,0xA8,0xA5,0xA2,0x9F,0x9C,0x99,0x96,0x93,0x90,0x8D,0x89,0x86,0x83,0x80,0x80,0x7C,0x79,0x76,0x72,0x6F,0x6C,0x69,0x66,0x63,0x60,0x5D,0x5A,0x57,0x55,0x51,0x4E,0x4C,0x48,0x45,0x43,0x40,0x3D,0x3A,0x38,0x35,0x33,0x30,0x2E,0x2B,0x29,0x27,0x25,0x22,0x20,0x1E,0x1C,0x1A,0x18,0x16,0

14、x15,0x13,0x11,0x10,0x0E,0x0D,0x0B,0x0A,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0D,0x0E,0x10,0x11,0x13,0x15,0x16,0x18,0x1A,0x1C,0x1E,0x20,0x22,0x25,0x27,0x29,0x2B,0x2E,0

15、x30,0x33,0x35,0x38,0x3A,0x3D,0x40,0x43,0x45,0x48,0x4C,0x4E,0x51,0x55,0x57,0x5A,0x5D,0x60,0x63,0x66,0x69,0x6C,0x6F,0x72,0x76,0x79,0x7C,0x80;void main(void)uchar i;while(1)for(i=0;i0xff;i+)DAC0832=sini;DAC0832=sini;/yanshiDAC0832=sini;/yanshiDAC0832=sini;/yanshi/delay();/ void delay()/ uchar i,/ for(i

16、=0;i1;i+);5、在单片机的外部扩展一个4个按键的键盘。要求:按下K0,产生连续方波信号;按下K1,产生连续锯齿波信号;按下K2,产生连续三角波信号;按下K3,产生连续正弦波信号。#include#include#define uchar unsigned char#define DAC0832 XBYTE 0x7fffvoid delay(void);sbit k0=P10;sbit k1=P11sbit k2=P12;sbit k3=P13;unsigned char code sin= 0x80,0x83,0x86,0x89,0x8D,0x90,0x93,0x96,0x99,0x9

17、C,0x9F,0xA2,0xA5,0xA8,0xAB,0xAE,0xB1,0xB4,0xB7,0xBA,0xBC,0xBF,0xC2,0xC5,0xC7,0xCA,0xCC,0xCF,0xD1,0xD4,0xD6,0xD8,0xDA,0xDD,0xDF,0xE1,0xE3,0xE5,0xE7,0xE9,0xEA,0xEC,0xEE,0xEF,0xF1,0xF2,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFD,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF

18、F,0xFE,0xFD,0xFD,0xFC,0xFB,0xFA,0xF9,0xF8,0xF7,0xF6,0xF5,0xF4,0xF2,0xF1,0xEF,0xEE,0xEC,0xEA,0xE9,0xE7,0xE5,0xE3,0xE1,0xDF,0xDD,0xDA,0xD8,0xD6,0xD4,0xD1,0xCF,0xCC,0xCA,0xC7,0xC5,0xC2,0xBF,0xBC,0xBA,0xB7,0xB4,0xB1,0xAE,0xAB,0xA8,0xA5,0xA2,0x9F,0x9C,0x99,0x96,0x93,0x90,0x8D,0x89,0x86,0x83,0x80,0x80,0x7

19、C,0x79,0x76,0x72,0x6F,0x6C,0x69,0x66,0x63,0x60,0x5D,0x5A,0x57,0x55,0x51,0x4E,0x4C,0x48,0x45,0x43,0x40,0x3D,0x3A,0x38,0x35,0x33,0x30,0x2E,0x2B,0x29,0x27,0x25,0x22,0x20,0x1E,0x1C,0x1A,0x18,0x16,0x15,0x13,0x11,0x10,0x0E,0x0D,0x0B,0x0A,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x02,0x01,0x00,0x00,0x00,0x0

20、0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0D,0x0E,0x10,0x11,0x13,0x15,0x16,0x18,0x1A,0x1C,0x1E,0x20,0x22,0x25,0x27,0x29,0x2B,0x2E,0x30,0x33,0x35,0x38,0x3A,0x3D,0x40,0x43,0x45,0x48,0x4C,0x4E,0x51,0x55,0x57,0x5A,0x5D,0x60,0x63,0x66,0x69,0x6

21、C,0x6F,0x72,0x76,0x79,0x7C,0x80;void fanbo();void juchibo();void sabjiaobo();void zhengxuanbo();void main(void)void fanbo()uchar i;while(1)DAC0832=0;delay();DAC0832=100;delay();void juchibo()uchar i;while(1)for(i=0;i0xff;i+)DAC0832=i;void sabjiaobo()uchar i;while(1)for(i=0;i0;i-)DAC0832=i;void zheng

22、xuanbo()uchar i;while(1)for(i=0;i0xff;i+)DAC0832=sini; void delay() uchar i,j;for(i=0;i10;i+)for(j=0;j120;j+);6、 在单片机的外部扩展一个2个按键的键盘。要求:输出方波的初始频率为 10Hz。要求用“增加K0”、“减小K1”2个按钮改变方波给定频率,按钮每按下一次,给定频率改变的步进步长为1Hz。频率范围为2Hz-1000Hz。7、 (选做题) 在单片机的外部扩展一个2个按键的键盘。要求:输出方波的初始频率为 10Hz。要求用“增加K0”、“减小K1”2个按钮改变方波给定频率,按钮每按下一次,给定频率改变的步进步长为1Hz,当按钮持续按下的时间超过2秒后,给定频率以10 次/秒的速度连续增加(减少),输出方波的频率要求在数码管上显示。频率范围为2Hz-1000Hz。提交实验报告内容要求: 1实验目的。2实验内容。题1-6编程。3请写出实验过程中曾出现的问题和你的解决方法,你对实验有何感想和体会?

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 高考资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁