저는 IR 센서 ('펄스 폭 변조'사용)의 데이터를 복조하려고하는 임베디드 시스템 프로젝트에서 작업하고 있습니다. 아래의 코드는 IR 센서가 펄싱을 시작할 때까지 대기 한 다음 각각의 고저 펄스의 폭 (지속 시간)을 측정합니다. 이 코드에서0에서 증가하는 정수가 음수가됩니다.
, 내가 정수 증가하고있어 루프가 있습니다
irPulseSet irReadPulse()
{
irPulseSet outputPulseSet;
int pulseCount = 0;
int finished = 0;
while(1)
{
int lowPulse = 0;
int highPulse = 0;
while(bit_is_clear(irSensorPin , irSensorPinNo))
{
highPulse++;
_delay_us(20);
}
while(!bit_is_clear(irSensorPin , irSensorPinNo))
{
if (lowPulse > 3250)
{
finished = 1;
break;
}
lowPulse++;
_delay_us(20);
}
if (finished)
break;
outputPulseSet.pulses[pulseCount][0] = highPulse * 20;
outputPulseSet.pulses[pulseCount][1] = lowPulse * 20;
pulseCount++;
}
// Assign pulse count to output pulse set
outputPulseSet.pulseCount = pulseCount;
return outputPulseSet;
}
이 임베디드 시스템 프로젝트, 내 자원이 한정되어 있기 때문에를, 나는 LCD 내 디버깅을하고 있어요 (회로가 컴퓨터에 접속 될 수 없기 때문에) 표시
인쇄
int irPrintPulses(irPulseSet pulseSet)
{
int counter;
for(counter = 0; counter <= pulseSet.pulseCount; counter++)
{
LCDClearScreen();
char printStr[100];
sprintf(printStr , "H%iL%i;%i " , pulseSet.pulses[counter][0] , pulseSet.pulses[counter][1] , counter );
LCDSendString(printStr);
_delay_ms(1000);
}
_delay_ms(5000);
LCDClearScreen();
LCDSendString("Finished pulse print!");
_delay_ms(1000);
LCDClearScreen();
return 0;
}
lowPulse
INT 때로는 부정적인 것으로 보인다 각 펄스 (E g 값 : -1054
). 나는 그것이 처음으로 0
으로 정의 된대로 완전히 혼란 스럽습니다. 그리고 나는 그 모든 것을 늘리므로, 그것이 어떻게 부정적이 될 수 있습니까?
로컬 변수로'highPulse'와'lowPulse'를 재 선언하면 어떤 차이가 있습니까? 그들의 유형은 무엇입니까? –
@StephenC 그들은 int 형이고, 나는 지역 선언을 시도했지만 여전히 부정적이다. – user2166351
lowPulse가 음수라는 것을 어떻게 알 수 있습니까? 전체 코드를 게시 할 수 있습니까? –