dac1230.c

来自「8051单片机实现DA转换」· C语言 代码 · 共 38 行

C
38
字号
/********************************************************************/
/********************************************************************/
/*****                                                          *****/
/*****        L A B C E N T E R    E L E C T R O N I C S        *****/
/*****                                                          *****/
/*****       LABCENTER INTEGRATED SIMULATION ARCHITECTURE       *****/
/*****                                                          *****/
/*****        Simple test program for DAC1230 and 80C51         *****/
/*****                                                          *****/
/********************************************************************/
/********************************************************************/

#include <reg51.h>

unsigned char xdata DACOUT _at_ 0xF000;

void main(void)
 { unsigned int i, data_word, steps; 
   // Simple staircase generation.
   data_word = 0x0000;
   // we want 
   steps = 0xfff/32;
   while (1)
    { // Data words have to be presented byte per byte, hi byte first. The low byte should be left justified.
      // This is a feature of DAC1230.
      //  |  HI Byte | LO BYTE  |      
      //  |MSB-------|---LSBxxxx|
      DACOUT = (data_word >> 4) & 0xff; 
      DACOUT = (data_word << 4) & 0xf0;
      // do a step every 50ms (with actual crystal value).
      for (i=0; i<10000; i++);
      // increment data_word of the programmed step
      data_word += steps;
      if (data_word & 0xf000)
         data_word = 0;      
    }
 }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?