PIC18F452 AD采样

代码

/* 
 * File:   MAIN.c
 * Author: Administrator
 *
 * Created on May 24, 2024, 10:32 AM
 */

#include <xc.h>

//?????
 //CONFIG1L
#pragma config OSC = XT          // VREG Sleep Enable bit (Ultra low-power regulator is Disabled (Controlled by REGSLP bit)),?????????
#pragma config OSCS = OFF     // LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power mode during Sleep),???? LF-INTOSC ???????
#pragma config PWRT = OFF         // SOSC Power Selection and mode Configuration bits (Digital (SCLKI) mode),SOSC ??????????,?? ? SCLKI?????? RC0 ? RC1 ? I/O ????
#pragma config BOR = ON           // Extended Instruction Set (Disabled)???????????????????????? ??????

// CONFIG1H
//#pragma config BORV = 20            // Oscillator (HS oscillator (Medium power, 4 MHz - 16 MHz))?HS????????
#pragma config WDT = OFF           // PLL x4 Enable bit (Enabled),??PLL???????4?????32MHz
#pragma config WDTPS = 128           // Fail-Safe Clock Monitor (Disabled)????????????
#pragma config CCP2MUX = ON            // Internal External Oscillator Switch Over Mode (Disabled)???????

// CONFIG2L
#pragma config STVR = ON         // Power Up Timer (Disabled)??????????
#pragma config LVP = ON      // Brown Out Detect (Enabled in hardware, SBOREN disabled)????????????
#pragma config BORV = 3             // Brown-out Reset Voltage bits (1.8V)??????????1.8v
#pragma config CP0 = OFF     // BORMV Power level (ZPBORMV instead of BORMV is selected)???ZPBORMV???BORMV

// CONFIG2H
#pragma config CP1 = OFF      // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled),???????
//#pragma config WDTEN = SWDTDIS      // Watchdog Timer (WDT enabled in hardware; SWDTEN bit disabled),?????WDT???SWDTEN?
#pragma config CP2 = OFF         // Watchdog Postscaler (1:256)???????1:256?????1.024s

// CONFIG3H
#pragma config CP3 = OFF    // ECAN Mux bit (ECAN TX and RX pins are located on RB2 and RB3, respectively)?1 = CANTX ? CANRX ?????? RB2 ? RB3 ?
#pragma config CPB = OFF   // MSSP address masking (7 Bit address masking mode)?1 = ?? 7 ???????
#pragma config CPD = OFF      // Master Clear Enable (MCLR Enabled, RE3 Disabled)???MCLR????

// CONFIG4L


// CONFIG6L
#pragma config WRT0 = OFF       // Table Write Protect 00800-01FFF (Disabled)?????
#pragma config WRT1 = OFF       // Table Write Protect 02000-03FFF (Disabled)?????
#pragma config WRT2 = OFF       // Table Write Protect 04000-05FFF (Disabled)?????
#pragma config WRT3 = OFF       // Table Write Protect 06000-07FFF (Disabled)?????

// CONFIG6H
#pragma config WRTC = OFF       // Config. Write Protect (Disabled)???????????
#pragma config WRTB = OFF       // Table Write Protect Boot (Disabled)?????????
#pragma config WRTD = OFF       // Data EE Write Protect (Disabled)???EEPROM?????

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protect 00800-01FFF (Disabled)??????
#pragma config EBTR1 = OFF      // Table Read Protect 02000-03FFF (Disabled)??????
#pragma config EBTR2 = OFF      // Table Read Protect 04000-05FFF (Disabled)??????
#pragma config EBTR3 = OFF      // Table Read Protect 06000-07FFF (Disabled)??????

// CONFIG7H
#pragma config EBTRB = OFF      // Table Read Protect Boot (Disabled)?????????

//void TMR1_ISR(void);
//void delay(void);
unsigned char j,flag;
unsigned char n;
//#pragma interrupt chk_isr
unsigned    long    i;
//#pragma code    My_Hiprio_Int=0x08

//#pragma code
int main(int argc, char** argv) {
    PORTD=0;
    TRISD=0;
    TRISAbits.RA0=1;
    ADCON0=0X81;
    ADCON1=0X0E;
    INTCONbits.TMR0IF=0;
    T0CON=0XC7;
    
    while(1)
    {
       
        while(INTCONbits.TMR0IF==0);
        INTCONbits.TMR0IF=0;
        ADCON0bits.GO=1;
        while(ADCON0bits.DONE==1);
        PORTD=ADRESH;
        
    }
    return (0);
}

运行效果图

  • 23
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值