我遇到一个显示一些奇怪行为的静态变量的问题.希望有人可以提供帮助,这里是代码:
void digitRefresh(void){
static char digitenabled=1;
sprintf(digits, "%d", number+10000);
switch (digitenabled) {
case 1: digitDecode(digits[1] - 48);
CATHODE_1 = ENABLE;
break;
case 2: digitDecode(digits[2] - 48);
CATHODE_2 = ENABLE;
break;
case 3: digitDecode(digits[3] - 48);
CATHODE_3 = ENABLE;
break;
case 4: digitDecode(digits[4] - 48);
CATHODE_4 = ENABLE;
break;
}
delay_ms(DIGIT_DELAY);
disableAllCathodes();
return;
Run Code Online (Sandbox Code Playgroud)
}
顺便说一下数字被定义为 char digits[5];
正如您所看到的,我正在定义一个本地静态变量,因此当多次调用此函数时,我可以跳转到程序的不同位置.
我刮胡子的问题是在第二行代码中.当sprintf被执行时,var digitenabled以某种方式将其值更改为零.你可以在代码中看到它之前的一个,但是在sprint之后我放了一个断点,由于某种原因它是零.
如果我不通过注释来使用sprintf,则问题就会消失,变量会按预期运行(不清除并在再次调用函数时保留该值).
sprintf做错了吗?所以变量消失了?有任何想法吗 ?
这是在使用XC8编译器的微控制器PIC16F1847上.谢谢
我正在使用 16F1703 PIC mcu,我想通过触摸按钮(A1)开始一个 7 段液晶循环(0-9)循环,之后如果我触摸按钮(A1)两次,我想要图片进入睡眠模式。
为此,我实现了这个:
#include <test_interrupt.h>
byte const DataExit[10]={0b01000100,
0b01011111,
0b01100010,
0b01001010,
0b01011001,
0b11001000,
0b11000000,
0b01011110,
0b01000000,
0b01001000};
byte const bitMask[8]={1,2,4,8,16,32,64,128};
//show seven numbers
void segmentCycle(void){
int i, j;
for(i=0;i<10;i++){
for (j=0; j<8;j++){
output_low(CLK);
output_bit(DATA,DataExit[i] & bitMask[j]);
output_high(CLK);
}
delay_ms(7000);
output_low(CLR);
delay_ms(6000);
output_high(CLR);
}
}
#INT_IOC
void IOC_isr(void)
{
segmentCycle();
sleep();
}
void main()
{
port_a_pullups(0x02);
enable_interrupts(INT_IOC_A1);
enable_interrupts(INT_IOC_A1_H2L);
enable_interrupts(GLOBAL);
while(TRUE);
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我触摸按钮,有时它会启动,否则不会。你有什么建议?
我正在使用 ccs 编译器。
我在mikroC中编写了一个函数,用于扫描4x4键盘中的按键
void scan_key()
{
PORTB = 0B11111110;
if ( PORTB == 0b11101110){
Row = 1;
Column = 1;
return;
}
if ( PORTB == 0b11011110){
Row = 2;
Column = 1;
return;
}
if ( PORTB == 0b10111110){
Row = 3;
Column = 1;
return;
}
if ( PORTB == 0b01111110){
Row = 4;
Column = 1;
return;
}
PORTB = 0B11111101;
if ( PORTB == 0b11101101){
Row = 1;
Column = 2;
return;
}
if ( PORTB == 0b11011101){ …
Run Code Online (Sandbox Code Playgroud) 我使用 MPLAB X IDE(一种用于微控制器的软件)来编译我的代码,但出于某种原因,它一直说至少有两个错误(特别是在粗体区域)。我试着寻找,但我仍然不确定为什么会这样,所以任何帮助将不胜感激。
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <math.h>
#include <p18f4620.h>
#pragma config OSC = INTIO67
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config BOREN = OFF
#define delay 5
// Prototype Area to place all the references to the routines used in the program
void Init_ADC(void);
unsigned char Get_Full_ADC(void);
void Flash_LED(unsigned char);
void main(void)
{
unsigned int ADC_Result; // local variable to store the result
Init_ADC(); // initialize the A2D converter
TRISB …
Run Code Online (Sandbox Code Playgroud) 我不知道是否有一个程序可以将ASM转换为C.我检查了谷歌,我已经读过IDA Pro可以做到但我不知道如何做.无论如何,你能帮我把这个用ASM编写的代码转换成C吗?我不擅长集会,所以我希望你能帮助我.谢谢 :)
这是代码:
#define CALIBRATIONTIME .10 ;Number Of Times To Measure Signal During Calibration
;**********************************************************************************************
;Calibrate() - Measures A Period From The Input(GP0) Reference Signal
; - Updates Osccal Value
; - Updates E^2
;**********************************************************************************************
CALIBRATE
movlw CALIBRATIONTIME
movwf COUNTER ;Calibration Counter
LOW0
btfsc INPUT0 ;Wait To Sample Low Edge #0 (Makes Sure We Are Synchronized First Time Through)
goto LOW0
HIGH1
btfss INPUT0 ;Wait To Sample High Edge #1
goto HIGH1
clrf TMR0 ;Start Timer (Timer Will Be …
Run Code Online (Sandbox Code Playgroud) 有没有string
在CCS?
我可以用吗:
string myString = "My String"; // Error
Run Code Online (Sandbox Code Playgroud)
还是不?
我是初学者,我想知道这段代码有什么问题.我想计算在portA中按下按钮的次数.然后使用portC中的LEDS显示此值.谢谢