微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > C8051F320AD采集电压

C8051F320AD采集电压

时间:10-02 整理:3721RD 点击:
/////////////////////////////////////
//  Generated Initialization File  //
/////////////////////////////////////
#include "C8051F320.h"
#include"intrins.h"
// Peripheral specific initialization functions,
// Called from the Init_Device() function
void ADC_Init()
{
    AMX0N     = 0x1F;
    ADC0CN    = 0x80;
}
void Port_IO_Init()
{
    // P0.0  -  Unassigned,  Open-Drain, Digital
    // P0.1  -  Unassigned,  Open-Drain, Digital
    // P0.2  -  Unassigned,  Open-Drain, Digital
    // P0.3  -  Unassigned,  Open-Drain, Digital
    // P0.4  -  Unassigned,  Open-Drain, Digital
    // P0.5  -  Unassigned,  Open-Drain, Digital
    // P0.6  -  Unassigned,  Open-Drain, Digital
    // P0.7  -  Skipped,     Open-Drain, Analog
    // P1.0  -  Skipped,     Open-Drain, Analog
    // P1.1  -  Unassigned,  Open-Drain, Digital
    // P1.2  -  Unassigned,  Open-Drain, Digital
    // P1.3  -  Unassigned,  Open-Drain, Digital
    // P1.4  -  Unassigned,  Open-Drain, Digital
    // P1.5  -  Unassigned,  Open-Drain, Digital
    // P1.6  -  Unassigned,  Open-Drain, Digital
    // P1.7  -  Unassigned,  Open-Drain, Digital
    // P2.0  -  Unassigned,  Open-Drain, Digital
    // P2.1  -  Unassigned,  Open-Drain, Digital
    // P2.2  -  Unassigned,  Open-Drain, Digital
    // P2.3  -  Unassigned,  Open-Drain, Digital

    P0MDIN    = 0x00;
    P1MDIN    = 0xFE;
    P2MDIN    = 0xF0;
    P0SKIP    = 0xFF;
    P1SKIP    = 0x01;
    P2SKIP    = 0x0F;
    XBR1      = 0x40;
}
void Oscillator_Init()
{
    OSCICN    = 0x83;
}
void Voltage_Reference_Init()
{
    REF0CN    = 0x03;
}




// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
    Oscillator_Init();
        Port_IO_Init();
        Voltage_Reference_Init();
        ADC_Init();
}

void main(void)
{
        unsigned char i;
        float v;
       
        PCA0MD &= ~0x40;                       // 关闭看门狗
        Init_Device();

        while(1)
        {
                AD0BUSY=1;               
                while(AD0BUSY)        ;
               
                v= (ADC0L+ADC0H*256)/1024.0*2.44;
                 
        }
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top