- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试让 PIC24 与 ADC 转换器配合使用,使用电位计作为音量旋钮,但为此,我需要读出 ADC,而代码不允许我这样做 build 。请参阅问题底部。接线正确。
MPlab 在 main.c 中没有显示任何错误,但是当我构建项目时,user.c 中出现了一些错误。
我将 PIC24FJ64GB002 连接到板上,并带有一些按钮和 mdog 显示屏。
main.c
#include <p24FJ64GB002.h>
//#include <pic.h>
#include "DogM.h"
#include <stdlib.h>
#include <time.h>
#include <p24fxxxx.h>
//#include <user.c>
_CONFIG1( JTAGEN_OFF & //JTAG port is disabled
GCP_OFF & //GSP Memory Code Protection OFF
GWRP_OFF & //GCC Flash Write Protection OFF
//COE_OFF & //
FWDTEN_OFF & //Watchdog Timer OFF
ICS_PGx1) //debug over PGD1 and PGC1
_CONFIG2( FNOSC_FRCPLL & //Internal FRC with PLL
OSCIOFNC_ON & //RA3 is clk out (fosc/2)
POSCMOD_NONE & //Primary oscillator disabled
I2C1SEL_PRI) //Use default SCL1/SDA1 pins
#define VREG33_DIR TRISAbits.TRISA0
#define VREG33_EN LATAbits.LATA0
#define MODE_LED_DIR TRISAbits.TRISA1
#define MODE_LED LATAbits.LATA1
#pragma code
int main(void)
{
// Set up the hardware of the display
InitApp();
mdog_Init(0x81, 0x19);
init_adc();
clearDisplay();
// Initscreen clears a internal bitmap used
// in drawScreen to send out to the display
initScreen();
// Beware writeString will write directly to the display
// the internal bitmap is not modified.
CLKDIVbits.RCDIV0=0; //clock divider to 0
AD1PCFG = 0xFFFF; // Default all pins to digital
OSCCONbits.SOSCEN=0; //Disables the secondary oscilator
MODE_LED_DIR = 0; //sets the Mode LED pin RA1 as output
MODE_LED = 0; //turns LED off
VREG33_DIR =0; //sets teh VREG pin RA0 as output
VREG33_EN = 1; //turns on the voltage regulator
unsigned long int i,voltage;
//////////////////////////////////////////////////////////////
///////////////ADC config//////////////////////////////////
AD1PCFGbits.PCFG12=0; //configure RB12 as analog
AD1CON1bits.SSRC = 0b111; // SSRC<3:0> = 111 implies internal
// counter ends sampling and starts
// converting.
AD1CON3 = 0x1F02; // Sample time = 31Tad,
// Tad = 2 Tcy
AD1CHS =12; //ADC channel select 12
AD1CON1bits.ADON =1; // turn ADC on
///FOREVER LOOP///////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
while(1)
{
//this just gives us a little delay between measurements
i =0xFFFFF; //sets i to 1048575
while (i--); //delay function
//start a measurement with the ADC
AD1CON1bits.DONE=0; //resets DONE bit
AD1CON1bits.SAMP=1; //start sample
while(AD1CON1bits.DONE==0); //wait for conversion to finish
//get the measurement and use it to control the LED
voltage = ADC1BUF0; //get the voltage measurement
//if (voltage > 0x1D1) MODE_LED = 1; //enable LED if measurement is > 3volts
//else MODE_LED = 0; //disable LED if less than 3volts
writeString(boldFont, 0x0, 0x3, "Hallo");
}
}
用户.c
/******************************************************************************/
/* Files to Include */
/******************************************************************************/
/* Device header file */
#if defined(__PIC24E__)
#include <p24Exxxx.h>
#elif defined (__PIC24F__)
//#include <p24Fxxxx.h>
#include <p24FJ64GB002.h>
#elif defined(__PIC24H__)
#include <p24Hxxxx.h>
#endif
//#include "user.h" /* variables/params used by user.c */
/******************************************************************************/
/* User Functions */
/******************************************************************************/
/* <Initialize variables in user.h and insert code for user algorithms.> */
/* TODO Initialize User Ports/Peripherals/Project here */
/**
* Initialize the Analog to Digital Converter.
*/
/**/void init_adc(void)
{
TRISAbits.TRISA1 = 0b1; // set pin as input
ANCON0bits.ANSEL1 = 0b1; // set pin as analog
ADCON1bits.VCFG = 0b00; // set v+ reference to Vdd
ADCON1bits.VNCFG = 0b0; // set v- reference to GND
ADCON1bits.CHSN = 0b000;// set negative input to GND
ADCON2bits.ADFM = 0b1; // right justify the output
ADCON2bits.ACQT = 0b110;// 16 TAD
ADCON2bits.ADCS = 0b101;// use Fosc/16 for clock source
ADCON0bits.ADON = 0b1; // turn on the ADC
}
/**
* Preform an analog to digital conversion.
* @param channel The ADC input channel to use.
* @return The value of the conversion.
*/
/* uint16_t adc_convert(uint8_t channel)
{
ADCON0bits.CHS = channel; // select the given channel
ADCON0bits.GO = 0b1; // start the conversion
while(ADCON0bits.DONE); // wait for the conversion to finish
return (ADRESH<<8)|ADRESL; // return the result
} */
void InitApp(void) {
// Setup analog functionality and port direction
AD1PCFGL = 0xFFFF; // Make analog pins digital
// Initialize peripherals
// set up I/O ports
TRISB = 0x0000; // all pins as output
LATB = 0x0; // all set to 0
// CN interrupts
CNEN1 = 0; /* Disable all CN */
CNEN2 = 0;
init_adc();
CNEN1bits.CN2IE = 1;
CNEN1bits.CN3IE = 1;
CNEN2bits.CN29IE = 1;
CNEN2bits.CN30IE = 1;
IPC4bits.CNIP0 = 1;
IPC4bits.CNIP1 = 0;
IPC4bits.CNIP2 = 0;
IFS1bits.CNIF = 0;
IEC1bits.CNIE = 1;
}
构建时记录:
"D:\Program Files (x86)\Microchip\xc16\v1.23\bin\xc16-gcc.exe" user.c -o build/default/production/user.o -c -mcpu=24FJ64GB002 -MMD -MF "build/default/production/user.o.d" -g -omf=elf -O0 -I"Dogm128x64" -msmart-io=1 -msfr-warn=off
user.c: In function 'init_adc':
user.c:30:5: error: 'ANCON0bits' undeclared (first use in this function)
user.c:30:5: note: each undeclared identifier is reported only once for each function it appears in
user.c:31:5: error: 'ADCON1bits' undeclared (first use in this function)
user.c:34:5: error: 'ADCON2bits' undeclared (first use in this function)
user.c:37:5: error: 'ADCON0bits' undeclared (first use in this function)
make[2]: *** [build/default/production/user.o] Error 255
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: Leaving directory `D:/Dropbox/HvA/Embedded/Potmeter'
make[1]: Leaving directory `D:/Dropbox/HvA/Embedded/Potmeter'
BUILD FAILED (exit value 2, total time: 254ms)
最佳答案
我认为@ElderBug是对的。你把所有的名字都混在一起。该错误告诉您该名称不存在。然后检查是否有其他名称,例如 AD1CON0bits
。
Microchip 为每个外设提供了手册引用。它比普通数据表提供更多提示。
对于您的 MCU,您可以在这里找到它:http://ww1.microchip.com/downloads/en/DeviceDoc/39705b.pdf
关于c - PIC24读取ADC错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28171807/
我将 ADC 与 DMA(STM32F4,ide STM32CubeIDE)一起使用,我认为我了解它是如何工作的,但仍然有一个难题。根据我的理解,MCU 仅在 DMA 传输完成时调用,基本上 MCU
我正在开展一个项目,其中涉及 STM32H743 核板和 16 个 ADC 输入的使用。 显然,这些模拟输入一次使用一次;通过轮询机制读取值并配置下一个输入...配置 ADC channel ,启动
1 指令语法 adc <Xd>, <Xn>, <Xm> 2 指令语义 adc就是带「进位」加法,指令中的c就是英文carry。 整个指令等价于: (Xd
ATtiny88初体验(五):ADC ADC模块介绍 ATtiny88单片机包含一个10bit分辨率的ADC模块,拥有8个通道,最大采样率15kSPS,转换时间14us。ATtiny88的
我正在尝试在 STM32L476 Nucleo 板上调出一个 ADC。我想我已经配置好了,但我一定是漏掉了一步。我知道这可以使用 HAL API 和 CubeMX 来完成,但我更喜欢在启动新板时进行寄
mov eax, ptr_to_num1 ; little endian mov ebx, ptr_to_num2 ; little endian xor ecx, ecx xor edx, edx
.MODEL SMALL .STACK 1000 .DATA MSGA DB 13,10,"Input first number: ","$" MSGB DB 13,10,"Input second
我目前正在对 PIC 微 Controller 进行编程。 当按照我的方式创建结构时,每次我尝试访问该结构的变量的地址是否都会更改? 还是像静态变量一样,意味着地址在编译时确定,并且在整个程序中不会更
大家好,我正在开发一个项目,我必须计算 ADC 读数的移动平均值。从 ADC 输出的数据代表正弦波。 这是我用来获取给定信号的移动平均值的代码。 longNew = (8 bit data from
我希望在每次转换结束后调用 ADC 中断服务程序。但是它没有被调用。 这是我的代码: #define RCC_APB2ENR (*((volatile unsigned long*) 0x4002
有人可以看看我的代码吗?当我旋转电位器时,我试图让 8 个 LED 旋转,但四个 LED 一直保持亮着,根本不旋转。 #include /******************************
目的是将最新的 10 个 ADC 读数存储在一个数组中,然后计算它们的平均值以供其他地方使用。每次更新时删除最旧的。 关于 LED 时序,如果 ADC 读数在下面写的边界内,它必须将时序从 1s 切换
我正在尝试将音频ADC(wm8782 / pcm1803a)与Beagle Black连接。我已经对文件 davinci-evm , wm8782.c 和BB-BONE-AUDI-01设备树覆盖文件进
我正在尝试在简单的连续转换模式下通过 STM32F411RE 配置 ADC。我使用 CubeMX 生成基于 HAL 驱动程序的代码,这是生成的代码中初始化 ADC 的部分内容: /* ADC1 ini
我只是对我用 C 编写的反汇编 32 位程序进行一些分析。以下是反汇编程序输出的一部分: 41153c 02 00 add al, [eax] 41153e 00 00 add [eax]
我一直在运行Blarggs CPU tests通过我的 Gameboy 模拟器,op r,r 测试表明我的 ADC 指令工作不正常,但 ADD 是。我的理解是两者之间的唯一区别是在添加之前将现有的进位
我正在使用Renesas RX62N ;我的屏幕使用 ADC 单元 1,我的代码使用单元 0。 难道两个ADC单元不能一起工作吗?当我分别运行“ADC”和“显示代码”时,它工作正常,但一旦我尝试将它们
描述很长,抱歉。我用粗体突出显示了问题。 我目前正在尝试建立一个 driverlib 机制来执行以下操作: 大约每 20 个 RTC 预分频器 1 事件,检查是否应进行 ADC 测量。 如果需要,请设
我正在努力让 ADC 与我的设备配合使用。我正在使用 dsPIC33FJ128GP802,并尝试通过手动采样和转换缓慢启动。 我的代码发布在下面,我已经设置了 ADC 的每个寄存器,然后尝试仅采样一次
我的板上有一个 adc 模块。我在信号发生器上创建了一个正弦波。我将这个发生器的输出提供给一个 adc 引脚。最后我定期读取这个引脚的值。我尝试在我的软件上创建一个正弦波。 x = t, y = As
我是一名优秀的程序员,十分优秀!