我正在使用带有mplabv8.70的pic16F690,一个pickit 2和高科技的PICC PRO c编译器.
我的问题是该中断是否能够使用其中的getch函数,因为该getch函数使用RCIF标志,该标志也是用于触发EUSART中断的标志.
她是我的代码,对不起很长,但是这里的人似乎不喜欢把片段/部分放在整个事情上.它复用了一个4位7段LED显示屏,并获得了RPM值的EUSART信号,但是我希望它能够继续显示,即使它没有接收到EUSART,然后在它因此中断时有效地"更新".全局变量.如果有一个明显更好的方式,那么我很高兴被告知我的方式是错的.
//#include _LEGACY_HEADERS //Added for compiler versions 9.81+
#include <stdio.h> //For the printf function
#include <htc.h> //Compiler header file
//#include "usart.h" //USART header file
//#include "pause.h"
//#include "SerialIn.h"
//#include "Display.h"
__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT & UNPROTECT & BORDIS & IESODIS & FCMDIS); //Configure the PIC with generic set up
#define BAUD 2400
#define FOSC 4000000L
#define baudsetting ((int)(FOSC/(64UL * BAUD) -1))
#define RX_PIN TRISB5
#define TX_PIN …Run Code Online (Sandbox Code Playgroud) 我需要从一个字节读取一个特定的位.我想测试的值是0或1.
unsigned char Buffer[0]=2;
//or binary 0b00000010
Run Code Online (Sandbox Code Playgroud)
我如何从缓冲区中读取n位.如果它是0或1?例如,如果字节中的7位是0或1
在使用 PIC24FJ128GB204 的 MPLAB X 中学习嵌入式 C。
到目前为止,我主要听说在嵌入式设备上应该尽可能多地使用无符号类型(尤其是?),所以我开始使用 uint8_t 数组来保存字符串。但是,如果我从 stdlib.h 调用 itoa,它需要一个指向有符号字符 (int8_t) 数组的指针:
extern char * itoa(char * buf, int val, int base);
当我在无符号数组上使用 itoa 后尝试编译时,这一点特别清楚:
main.c:317:9: warning: pointer targets in passing argument 1 of 'itoa' differ in signedness
c:\program files (x86)\microchip\xc16\v1.36\bin\bin\../..\include/stdlib.h:131:15: note: expected 'char *' but argument is of type 'unsigned char *'
Run Code Online (Sandbox Code Playgroud)
在其他平台上搜索 itoa 的实现,这似乎是常见的情况。
这是为什么?
(我还注意到大多数实现都需要值/指针/基数,而出于某种原因,来自 Microchip 的 stdlib.h 首先需要指针。我花了一段时间才意识到这一点。)
我试图对 PIC 16f877A 微控制器进行编程,以将伺服电机旋转 0 到 180 度,但每次我尝试构建该程序时,都会收到错误“成员引用基类型‘易失性无符号字符’不是结构或联合” “.我正在使用带有 xc8 编译器的 MPLAB。我找不到问题。
#include<xc.h>
void Rotation0()
{
int i;
for(i=0;i<50;i++)
{
PORTB.F0 = 1;
__delay_us(800);
PORTB.F0 = 0;
__delay_us(19200);
}
}
void Rotation90()
{
int i;
for(i=0;i<50;i++)
{
PORTB.F0 = 1;
__delay_us(1500);
PORTB.F0 = 0;
__delay_us(18500);
}
}
void Rotation180()
{
int i;
for(i=0;i<50;i++)
{
PORTB.F0 = 1;
__delay_us(2200);
PORTB.F0 = 0x00;
__delay_us(17800);
}
}
void main()
{
TRISB = 0;
PORTB = 0x00;
do
{
Rotation0();
__delay_ms(2000);
Rotation90();
__delay_ms(2000);
Rotation180(); …Run Code Online (Sandbox Code Playgroud) 在MPLAB IDE是什么数据类型(的大小int,unsigned int,float,unsigned float,char...)?
unsigned char rtc_time[6] = { pThis->hoursTens, pThis->hoursUnits, pThis->minutesTens, pThis->minutesUnits, pThis->secondsTens, pThis->secondsUnits };
Run Code Online (Sandbox Code Playgroud)
不编译.我收到错误(6次):需要持续表达
每个变量都声明为unsigned char.我已经尝试过(const)而没有运气.
This is in MPLAB X IDE, C language, using Hi-Tech-PICC compiler v9.65PL1.
What is the problem?
It works when I define the variable as below, but I need to use the variables above.
unsigned char rtc_time[6] = { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6 };
Run Code Online (Sandbox Code Playgroud) 有没有办法让C18编译器在编译期间抛出自己的自定义错误消息?
例如,考虑具有两个用户定义设置的情况:
#define SETTING_A 0x80
#define SETTING_B 0x3f
Run Code Online (Sandbox Code Playgroud)
假设这些设置不能同时存在 0x00.当用户将两个设置都设置为时,有没有办法让编译器抛出错误(或至少是一个警告)0x00?
我想将两个字节组合成一个无符号长变量,我当前的代码不起作用.我使用的是MPLAB C18编译器,这是我的代码.
unsigned long red = 0;
BYTE t[2];
t[0] = 0x12;
t[1] = 0x33;
red = 100 * t[0] + t[1];
printf("%lu", red);
Run Code Online (Sandbox Code Playgroud)
请让我知道为什么我没有得到1233作为我的输出.
我正在尝试编程PIC16F887并遇到这个有趣的问题.我希望LED能够一次闪烁并永久停止,但是它会重新开始并且永远不会停止,尽管看门狗被禁用.这是代码.提前致谢.
我在MPLAB v8.84中编写了这个,并使用PICkit2和Hi-Tech C编译器进行编程.
#include <htc.h>
#include <pic.h>
#define _XTAL_FREQ 800000
//__CONFIG(0x3FF5);
//functions
void INITgeneral(void);
void ledshow (void);
void main(void) {
INITgeneral();
ledshow();
return;
}
void INITgeneral(void)
{
TRISA = 0;
TRISB = 0;
TRISC = 0;
TRISD = 0;
TRISE = 0;
PORTA = 0;
PORTB = 0;
PORTC = 0;
PORTD = 0;
PORTE = 0;
}
void ledshow(void)
{
__delay_ms(400);
RD0 = 1;
__delay_ms(400);
RD0 = 0;
}
Run Code Online (Sandbox Code Playgroud) 我的面包板上有一个简单的PIC16F18877电路设置,我已成功获得一个LED在无限while循环内闪烁.我试图将相同的代码放在一个for只应执行5次的循环中,但LED会一直闪烁.
我的代码(带XC8编译器的MPLAB):
#include <xc.h>
#define _XTAL_FREQ 8000000
int main()
{
TRISD1 = 0;
for (int i = 0; i < 5; i++)
{
RD1 = 1;
__delay_ms(500);
RD1 = 0;
__delay_ms(500);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)