- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
有人可以看看我的代码吗?当我旋转电位器时,我试图让 8 个 LED 旋转,但四个 LED 一直保持亮着,根本不旋转。
#include <xc.h>
/********************************************************
* xx/xx/xx - Put date in place of the x's
*
********************************************************/
/********************************************************
* Function: main
*
* Description: D0 - D7 Display the results of the ADC
*
* Notes:
*
* RA0 - Input from RP1
*
*
*
* Returns: This routine contains an infinite loop
*
********************************************************/
/* Configuration Word */
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select bit (MCLR pin function is digital input, MCLR internally tied to VDD)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = OFF // Brown Out Detect (BOR disabled)
#pragma config IESO = OFF // Internal External Switchover bit (Internal External Switchover mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
void PORTA_init(void);
void ADC_Disp(void);
void Delay_LED_On(void);
int ADC_Value = 0;
const char PORTA_Value[8] = {
0b010000, // D0
0b100000, // D1
0b010000, // D2
0b000100, // D3
0b100000, // D4
0b000100, // D5
0b000100, // D6
0b000010}; // D7
const char TRISA_Value[8] = {
0b001111, // D0
0b001111, // D1
0b101011, // D2
0b101011, // D3
0b011011, // D4
0b011011, // D5
0b111001, // D6
0b111001}; // D7
main()
{
PORTA_init();
ANSEL = 1; // Just RA0 is an Analog Input
TRISA0 = 1; // Corresponding TRIS bit is set as input
ADCON0 = 0b00000001; // Turn on the ADC
// Bit 7 - Left Justified Sample
// Bit 6 - Use VDD
// Bit 4:2 - Channel 0
// Bit 1 - Do not Start
// Bit 0 - Turn on ADC
ADCON1 = 0b00010000; // Select the Clock as Fosc/8
ADC_Disp();
GO_DONE = 1; // Start A/D Conversion
while(1 == 1) // Loop Forever
{
if (GO_DONE == 0) // Is A/D Conversion complete?
{ ADC_Disp(); // Display A/D Conversion Results
ADC_Value = ADRESH; // Get new A/D value
GO_DONE = 1; // Start the next A/D Conversion
}
else // A/D Conversion still in progress
ADC_Disp();
}
}
/******** END OF main ROUTINE ***************************/
/********************************************************
* Function: PORT_init
*
* Description: Initializes PORTA to a known condition
*
* Notes: None
*
* Returns: None
*
********************************************************/
void PORTA_init(void)
{
PORTA = 0; // All PORTA Pins are low
CMCON0 = 7; // Turn off Comparators
ANSEL = 0; // Turn off ADC
return;
}
/******** END OF PORTA_init ****************************/
/********************************************************
* Function: ADC_Disp
*
* Description: Displays the value of A/D Conversion on D0 - D7
*
* Notes:
*
*
*
* Returns: None
*
********************************************************/
void ADC_Disp(void)
{
int i;
for (i = 0; i < 8; i++ )
{ // Loop through Each of the 8 LEDS
Delay_LED_On(); // Allows time for individual LEDs to light
if ((ADC_Value & (1 << i)) == 0)
PORTA = 0;
else
PORTA = PORTA_Value[i];
TRISA = TRISA_Value[i];
} //
return;
}
/******** END OF ADC_Disp *************************/
/********************************************************
* Function: delay_LED_On
*
* Description: Causes a delay in program execution
*
* Notes:
*
*
********************************************************/
void Delay_LED_On(void)
{
int j;
for (j = 0; j < 60; j++); // Display "On" Loop
return;
}
/******** END OF Delay_LED_On *************************/
最佳答案
对于您类的其他学生,这里使用 PICkit1 入门工具包对代码进行了测试,我怀疑它比您要求的要多一些:
/*
* File: main.c
* Author: dan1138
* Target: PIC16F684
* Compiler: XC8 v2.00
*
* Description:
*
* Display the upper 8-bits of the ADC conversion
* from analog input from RA0 on 8 charlieplexed LEDs
* connected to outputs RA1,RA2,RA4,RA5.
*
* PIC16F684
* +------------:_:------------+
* GND -> 1 : VDD VSS : 14 <- 5v0
* DRV5 <> 2 : RA5/T1CKI PGD/AN0/RA0 : 13 <> POT
* DRV4 <> 3 : RA4/AN3 PGC/AN1/RA1 : 12 <> DRV1
* VPP -> 4 : RA3/VPP AN2/RA2 : 11 <> DRV2
* <> 5 : RC5/CPP1 AN4/RC0 : 10 <>
* <> 6 : RC4/C2OUT AN5/RC1 : 9 <>
* <> 7 : RC3/AN7 AN6 RC2 : 8 <>
* +---------------------------:
* DIP-14
*
* 150 OHM
* DRV4 ----/\/\/\-------+-----------+-------------+-----------+
* : : : :
* : : : :
* --- --- : :
* LED1 / \ \ / LED0 : :
* --- --- : :
* : : : :
* 150 OHM : : --- ---
* DRV5 ----/\/\/\-------+-----------+ LED3 / \ \ / LED2
* : : --- ---
* : : : :
* --- --- : :
* LED5 / \ \ / LED4 : :
* --- --- : :
* : : : :
* 150 OHM : : : :
* DRV2 ----/\/\/\-------+-----------+-------------+-----------+
* : :
* : :
* --- ---
* LED7 / \ \ / LED6
* --- ---
* : :
* 150 OHM : :
* DRV1 ----/\/\/\-------+-----------+
*
*
* POT ----/\/\/\---+
* 1K :
* :
* v
* GND ----------/\/\/\-------- 5v0
* 10K
*
*
* Notes:
* Charlieplexing, see https://en.wikipedia.org/wiki/Charlieplexing
*
* Created on July 13, 2019, 6:09 PM
*/
#pragma config FOSC = INTOSCIO
#pragma config WDTE = OFF
#pragma config PWRTE = OFF
#pragma config MCLRE = OFF
#pragma config CP = OFF
#pragma config CPD = OFF
#pragma config BOREN = OFF
#pragma config IESO = OFF
#pragma config FCMEN = OFF
#include <xc.h>
#include <stdint.h>
#define _XTAL_FREQ (8000000ul)
/*
* Global data
*/
volatile unsigned char gLEDs;
void main(void)
{
/*
* Initialize this PIC
*/
INTCON = 0;
OSCCON = 0x70; /* Select 8MHz system oscillator */
__delay_ms(500); /* Give ICSP device programming tool a chance to get the PICs attention */
TRISA = 0xFF;
TRISC = 0x00;
ANSEL = 0;
OPTION_REG = 0b11000010; /* TIMER0 clock = FOSC/4, prescale 1:8 */
PORTA = 0;
PORTC = 0;
CMCON0 = 7;
TMR0 = 0;
TMR0IF = 0;
TMR0IE = 1;
gLEDs = 0b00000000;
GIE = 1;
/*
* Initialize ADC on channel 0
*/
ADCON0 = 0;
ADCON1 = 0;
TRISAbits.TRISA0 = 1; /* Make RA0 an input */
ANSELbits.ANS0 = 1; /* Enable AN0 on the RA0 input */
ADCON1bits.ADCS = 0b101; /* Select FOSC/16 as ADC clock source */
ADCON0bits.CHS = 0; /* Select AN0 as ADC input */
ADCON0bits.ADFM = 0; /* Select left justified data */
ADCON0bits.VCFG = 0; /* Select VDD as VREF source */
ADCON0bits.ADON = 1; /* Turn on ADC */
/*
* This is the application loop.
*
* Display 8-bit ADC value in charlieplexed LEDs
*/
while(1)
{
ADCON0bits.GO = 1; /* Start an ADC conversion */
while(ADCON0bits.GO); /* Wait for ADC conversion to finish */
gLEDs = ADRESH; /* Put ADC value in LED7 to LED0 */
}
}
/*
* Interrupt handlers
*/
void __interrupt() ISR_handler(void)
{
static uint8_t Timer0Ticks = 0;
static unsigned char State = 8;
unsigned char OutBits, HighBits;
if (TMR0IE && TMR0IF) { /* TIMER0 asserts and interrupt every 1.024 milliseconds */
TMR0IF=0;
if (Timer0Ticks == 0) { /* Select another LED every second TIMER0 interrupt */
Timer0Ticks = 1; /* to make LEDs a little brighter make this number larger until you don't like the flickering */
OutBits = 0b00000000;
HighBits = 0b00000000;
switch (--State)
{
case 7:
if (gLEDs & 0x80)
{
HighBits |= (1 << 1); /* Drive LED7, DRV1=H DRV2=L */
OutBits = ~((1<<1)|(1<<2));
}
break;
case 6:
if (gLEDs & 0x40)
{
HighBits |= (1 << 2); /* Drive LED6, DRV1=L DRV2=H */
OutBits = ~((1<<1)|(1<<2));
}
break;
case 5:
if (gLEDs & 0x20)
{
HighBits |= (1 << 2); /* Drive LED5, DRV5=L DRV2=H */
OutBits = ~((1<<5)|(1<<2));
}
break;
case 4:
if (gLEDs & 0x10)
{
HighBits |= (1 << 5); /* Drive LED4, DRV5=H DRV2=L */
OutBits = ~((1<<5)|(1<<2));
}
break;
case 3:
if (gLEDs & 0x08)
{
HighBits |= (1 << 2); /* Drive LED3, DRV4=L DRV2=H */
OutBits = ~((1<<4)|(1<<2));
}
break;
case 2:
if (gLEDs & 0x04)
{
HighBits |= (1 << 4); /* Drive LED2, DRV4=H DRV2=L */
OutBits = ~((1<<4)|(1<<2));
}
break;
case 1:
if (gLEDs & 0x02)
{
HighBits |= (1 << 5); /* Drive LED1, DRV4=L DRV5=H */
OutBits = ~((1<<4)|(1<<5));
}
break;
default:
if (gLEDs & 0x01)
{
HighBits |= (1 << 4); /* Drive LED0, DRV4=H DRV5=L */
OutBits = ~((1<<4)|(1<<5));
}
State = 8;
}
TRISA |= ((1<<5)|(1<<4)|(1<<2)|(1<<1)); /* Turn off all LED output drivers */
if (OutBits)
{
PORTA &= OutBits; /* Set both LED drivers to low */
TRISA &= OutBits; /* Turn on LED output drivers */
PORTA |= HighBits; /* Turn on just one of the two LEDs */
}
}
else
{
Timer0Ticks--;
}
}
}
关于c - ADC 模数转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57001144/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!