51/AVR单片机技术驿站!  <在线翻译>     便利工具    特色网址   无弹窗、无插件的绿色站点...  英才招聘   学历查询  喜欢>>收藏我站 

当前位置:首页 > 单片机技术文章 > 51单片机 > 详细内容
dac0832引脚图电路及程序
发布时间:2009/6/29  阅读次数:8208  字体大小: 【】 【】【

2.输出三角波与正弦波程序.

#include<AT89X52.H>
unsigned char flag;     //波型输出标置变量
bit time;                        
unsigned char sin(unsigned char x)
{
unsigned char code sin_tab[]={125,128,131,134,138,141,144,147,150,153,156,159,
                 162,165,168,171,174,177,180,182,185,188,191,193,196,198,201,203,
     206,208,211,213,215,217,219,221,223,225,227,229,231,232,234,235,
     237,238,239,241,242,243,244,245,246,246,247,248,248,249,249,250,
     250,250,250,250,250,250,250,249,249,248,248,247,246,246,245,244,
     243,242,241,239,238,237,235,234,232,231,229,227,225,223,221,219,
     217,215,213,211,208,206,203,201,198,196,193,191,188,185,182,180,
     177,174,171,168,165,162,159,156,153,150,147,144,141,138,134,131,
     128,125,122,119,116,112,109,106,103,100,97,94,91,88,85,82,79,76,73,
     70,68,65,62,59,57,54,52,49,47,44,42,39,37,35,33,31,29,27,25,27,29,27,25,23,21,
     19,18,16,15,13,12,11,9,8,7,6,5,4,4,3,2,2,1,1,0,0,0,0,0,0,0,0,1,1,2,
     2,3,4,4,5,6,7,8,9,11,12,13,15,16,18,19,21,23,25,27,29,31,33,35,37,
     39,42,44,47,49,52,54,57,59,62,65,68,70,73,76,79,82,85,88,97,94,97,
     100,103,106,109,112,116,119,122};
     return sin_tab[x];
     }
void DAC0832(unsigned char x)
{
   P2=x;
}
void main()
{
unsigned char i;
TMOD=0X02;               //定时器0用于控制输出波的频率
TH0=256-40;
ET0=1;         //按键接于外部中断0,与中断1
IT0=1;
IT1=1;
EX0=1;
EX1=1;
EA=1;
TR0=1;
flag=0;         //开始时无输出
i=0;
  while(1)
     {
           if(time==1)
         {
             time="0";
       if(i>249)
             i="0";
       else
             i++;
      switch(flag)         //当按键1的为输出三角波,按键2时输出正弦波
         {
               case 0:DAC0832(0);break;
         case 1:
                         if(i>125)
                 DAC0832(250-i);
             else
                 DAC0832(i);
                 break;
        case 2:
                         DAC0832(sin(i));
             break;
        default:   break;
         }
           }
       }
}
void time0() interrupt 1
{
   time="1";
}
  
  void int0() interrupt 0
  {                  //按键1接于外部中断0
       flag="1";
}
  
   void int1() interrupt 2         //按键2接于外部中断1
   {
       flag="2";
}

  

我要评论
  • 匿名发表
  • [添加到收藏夹]
  • 发表评论:(匿名发表无需登录,已登录用户可直接发表。) 登录状态:未登录
最新评论
所有评论[0]
    暂无已审核评论!

网站导航 管理登陆 ┊ 免责声明 问题反馈  友链说明
本站部分内容来自网络共享资源,如有冒犯您的权利请来信告之删除或纠正!
不得对本站进行复制、盗链或镜像,转载内容须获得同意或授权;欢迎友情链接、站务合作!

    我要报警 Alexa
 mcusy_cn#126.com (请把#改成@) 交流:522422171
本站学习交流群:138..158(高级群1-)、77930286(高级群2)、61804809(群3)
Copyright© MCUSY All Rights Reserved
本站网警备案号: WZ36040002485
  ICP备案证书号:粤ICP备09034963号