您当前的位置:五五电子网电子知识单片机-工控设备51单片机c8051f005_DA测试程序 正文
c8051f005_DA测试程序

c8051f005_DA测试程序

点击数:7711 次   录入时间:03-04 11:37:01   整理:http://www.55dianzi.com   51单片机

//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <c8051f000.h>                 // SFR declarations
#include <stdio.h>

//-----------------------------------------------------------------------------
// 16-bit SFR Definitions for ’F00x
//-----------------------------------------------------------------------------

sfr16 DP       = 0x82;                 // data pointer
sfr16 TMR3RL   = 0x92;                 // Timer3 reload value
sfr16 TMR3     = 0x94;                 // Timer3 counter
sfr16 ADC0     = 0xbe;                 // ADC0 data
sfr16 ADC0GT   = 0xc4;                 // ADC0 greater than window
sfr16 ADC0LT   = 0xc6;                 // ADC0 less than window
sfr16 RCAP2    = 0xca;                 // Timer2 capture/reload
sfr16 T2       = 0xCC;                 // Timer2
sfr16 DAC0     = 0xd2;                 // DAC0 data
sfr16 DAC1     = 0xd5;                 // DAC1 data
//-----------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------
void SYSCLK_Init (void);
//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------

void main (void){
   WDTCN = 0xde;                       // dISAble watchdog timer
   WDTCN = 0xad;
   SYSCLK_Init ();                    // initialize oscillator
   REF0CN = 0x03;                        // Reference Control Register
//----------------------------------------------------------------------------
// DAC Configuration
//----------------------------------------------------------------------------
    DAC0CN = 0x80;                      // DAC0 Control Register
    DAC1CN = 0x80;                      // DAC1 Control Register
    while(1)
    {
    DAC0L = 0xAB;                      // DAC0 Low Byte Register
    DAC0H = 0x0C;                        // DAC0 High Byte Register
    DAC1L = 0xAB;                      // DAC1 Low Byte Register
    DAC1H = 0x0C;                      // DAC1 High Byte Register
    }
}
//-----------------------------------------------------------------------------
// Initialization Subroutines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Oscillator Configuration
//-----------------------------------------------------------------------------
void SYSCLK_Init (void)
{
   int i;                              // delay counter

   OSCXCN = 0x67;                      // start external oscillator with
                                       // 18.432MHz Crystal

   for (i=0; i < 256; i++) ;           // XTLVLD blanking interval (>1ms)

   while (!(OSCXCN & 0x80)) ;          // Wait for crystal osc. to settle

   OSCICN = 0x88;                      // select external oscillator as SYSCLK
                                       // source and enable missing cLOCk
                                       // detector

[1] [2] [3] [4] [5] [6]  下一页


本文关键字:程序  51单片机单片机-工控设备 - 51单片机