admin 管理员组文章数量: 887021
2024年1月24日发(作者:springmvc注解的作用)
实验名称:数模转换器DAC0832设计实验
学生姓名: xx 学号: xx 班级: 测控xx班 时间:
课程名称:微机机原理及应用 教师: 成绩:
一、实验目的
1)了解DAC0832芯片引脚、内部结构及工作原理;
2)掌握应用单片机I/O端口控制DAC0832实现数模转换的方法;
二、实验内容
1. 通过单片机I/O端口控制DAC0832实现数模转换,控制方式采用单缓冲方式,通过按键TRI/SIN选择输出,分别产生锯齿波、方波、正弦波。
1)
2)
绘制DAC0832与单片机接口电路原理图;
参考PPT课件内容,设计程序,实现信号选择输出功能;
2. 扩展功能:增加按键,通过按键控制调节输出信号的频率变化。
接口电路图设计参考下图所示:
三、设计参考:
正弦信号数据表:
uchar code sine_tab[256]=
{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,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,0xde,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,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 ,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,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};
四.实验报告
①实现调频功能的中断程序:
void int0() interrupt 0//外部中断0,用以控制调节延时程序次数,达到调节频率的作用
{
counter++; //外部中断0触发一次,延时程序调用次数加1
}
②延时程序:
void delay()
{
③锯齿波程序:
#include
sbit MR=P2^7;
void main (void)
}
} //延时子程序
int i;
for(i=0;i<10;i++)
{
{
int num;
int j;
MR=0;
while(1){
for(num =0; num <=255; num++)
{
P1=num;
for(j=0;j delay(); //调用延时子程序 } } } 运行截图: 调频前: 调频后: ④正弦波程序 #include sbit MR=P2^7; void main (void) { unsigned char code sine_tab[256]= //正弦波字表 {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,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,0xde,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,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,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,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 }; int num; int j; MR=0; while(1){ for(num =0; num <=255; num++) { } } } 运行截图: 调频前: P1=sine_tab[num]; for(j=0;j delay(); //调用延时子程序 调频后: ⑤方波程序: #include sbit MR=P2^7; void main (void) { int num; int j; MR=0; while(1){ int b; for(num=0;num<=255;b++) { if(num<128) { P1=0x00; } else { P1=0xFF;//当num大于或等于128时,P1输出0xFF对应高电平 for(j=0;j } for(j=0;j delay(); delay(); } } 调频前: 调频后: 主程序 #include sbit MR=P2^7; sbit P2_0=P2^0; sbit P2_1=P2^1; int counter=0;//设置延时程序次数变量counter,调节频率 unsigned char code sine_tab[256]= //正弦波字表 {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,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,0xde,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,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,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,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}; //正弦转换字符 void delay() { } }//延时子程序 void int0() interrupt 0//外部中断0,用以控制调节延时程序次数,达到调节频率的作用 { counter++;//外部中断0触发一次,延时程序调用次数加1 } void main() { int num; int j; int i; for(i=0;i<10;i++) { EA=1;//中断总允许使能 EX0=1;//外部中断0使能 IT0=1;//外部中断0下降沿触发 MR=0;//P2^7输出低电平,芯片正常工作 while(1) { } { P1=sine_tab[num];//P1端口输出正弦波字符数组 for(j=0;j } } if(P2_0==0&&P2_1==1) //P2_1为高电平,P2_0为低电平输出锯齿波 { for(num=0;num<256;num++) { P1=num; //P1直接输出num } for(j=0;j delay(); //调用延时子程序 if(P2_0==1&&P2_1==0)//P2_1为低电平,P2_0为高电平输出正弦波 delay(); //调用延时子程序 if((P2_0==0&&P2_1==0)||(P2_0==1&&P2_1==1))//P2_1为低电平P2_0为低电平以及P2_1为高电平P2_0为高电平时输出矩形波 for(num=0;num<256;num++) { if(num<128)//当num小于128时,P1输出0x00对应低电平 { P1=0x00; for(j=0;j delay(); } else { } } } P1=0xFF;//当num大于或等于128时,P1输出0xFF对应低电平 for(j=0;j } delay(); 五.总结 在该实验的设计过程中,首先单独写出锯齿波、正弦波以及方波的程序,并写出延时程序以及外部中断0程序。其中,中断程序的功能为实现波形的调频功能,通过控制外部中断的触发次数counter来改变延时程序的调用次数从而实现调频功能。在最后的程序整合过程中,通过控制开关P2_0及P2_1端口的高低电平来实现不同波形的输出(P2_1为低电平,P2_0为高电平输出正弦波,P2_1为高电平,P2_0为低电平输出锯齿波,P2_1为低电平P2_0为低电平以及P2_1为高电平P2_0为高电平时输出方波),此功能通过if语句的查询方式实现。
版权声明:本文标题:单片机数模转换器DAC0832设计实验报告(附程序) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/free/1706061032h500203.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论