⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 curves_to_blocks.c

📁 Use the on-board potentiometer to simulate an analog input,this input converted into a meaningful di
💻 C
字号:
#include <p18f4520.h>



void ISR  (void);

#pragma code low_pri_section=0x08
void my_interrupt_vector (void)
{
_asm
goto ISR
_endasm
}

#pragma code


#pragma interruptlow ISR
void ISR(void)
{
PORTD = ADRESH; (PORTD to receive digital inputs)
PIR1bits.ADIF= 0; //reset flag


}


void main(void)
{
TRISA = 0b11111111;//Set to input(receive analog inputs )
TRISD = 0b00000000;//Set to output
ADCON1 = 0b00001110;//12 pins to digital input

ADCON0=0b00000000;//channel 0(select channel 0 (AN0) as the ADC input channel)


ADCON1bits.VCFG1 = 0;//internal voltage as referance voltage
ADCON1bits.VCFG0 = 0;(use the internal voltage of the microcontroller as its reference voltage)

ADCON2bits.ADCS2 = 1;//clock frequency
ADCON2bits.ADCS1 = 0;
ADCON2bits.ADCS0 = 0;(codes for selecting a conversion clock frequency of Fosc/4)

ADCON2bits.ACQT2 = 1;//acquisition time
ADCON2bits.ACQT1 = 1;
ADCON2bits.ACQT0 = 0;(to set the acquisition time to 16TAD)

ADCON2bits.ADFM  = 0;// Left justified(1.	ADFM: A/D Result Format Select bit
                                                                                                         2.	1 = Right justified
                                                                                                         3.	0 = Left justified        )

RCONbits.IPEN = 1;//enable priority
INTCONbits.GIE=1;
PIE1bits.ADIE = 1;//setting priortiy
IPR1bits.ADIP = 1;//High priority
ADCON0bits.GO = 1;// A/D conversion in progress
ADCON0bits.ADON = 1; //turn on(turn on the A/D module )
PORTD=0x0;

while(1)
{
ADCON0bits.GO = 1;
}
}

⌨️ 快捷键说明

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