私は FreeScale 9S12C マイクロ コントローラーを使用しており、Code Warrior でコーディングしています。シーケンス 10011 の SEQ 検出器を作成しようとしています。シミュレーションを実行すると、プログラムが関数内で動かなくなり、DelayGate
他のすべては正常に表示されます。CRGFLG レジスタの最後のビットが、想定どおりに設定されていないようです。すべてのリアルタイムクロックサイクルの終わりに設定されるはずだと思います。を設定RTICTL = 0b01000000
したので、リアルタイム クロックの周期は 1.024 ms になります。したがって、私の予想される動作は、プログラムがDelayGate
約 1.024 ミリ秒の間留まる必要がありますが、プログラムは遅延ゲートにとどまり、決して終了しません。CRGFLG の最後のビットが何らかの理由でセットされないように見えますが、その理由はわかりません。誰でも私に提供できる助けをありがとう!これが私のコードです。私'
// Constants
#define CRYSTAL_CLOCK_FREQ 8000000L //set the clock to 8 MHz?
#define LED_COUNT_MAX 488 //(500 ms)/(1.024 ms) about 488
// Includes
#include <hidef.h> /* common defines & macros */
#include "derivative.h" /* derivative-specific */
// Prototypes
void SysInit(void);
void UpdateLED(void);
int input;
int state;
int nn = 5;
int value;
void Delay(int nn);
int UpdateStatetask(int input, int state);
void DelayGate(void);
int BeepFlag = 0;
int done = 0;
#endif
/*****************************************************
* main - Program main
****************************************************/
void main(void){
COPCTL = 0x00; // Disable the COP timer
RTICTL = 0b01000000; //8 MHz crystal, period of real time clock is 1.024 ms
PTT = 0x00; // initally all logical zero
DDRT = 0b11111100; // PT0 "0" input
//PT1 "1" input
//PT2 SEQ state 1 indication
// PT3 SEQ state 2 indication
// PT4 SEQ state 3 indicaiton
// PT5 SEQ state 4 indication
// PT6 SEQ detection
// PT7 LED Clock
PERT = 0b11111111; // enable pulling on all port T
PPST = 0b11111111; // pull-down to ground all port T
CLKSEL = 0x00;
PLLCTL = 0x00;
CRGINT = 0b10000000;
while (1){
UpdateLED();
DelayGate();
}
}
/**************************************************
* UpdateLED()
* When the LED count runs out, toggle and beep
*************************************************/
void UpdateLED(void){
static int state = 0;
int input;
int LedCount = LED_COUNT_MAX; //488*1.024 ms = 0.4997 s
if (--LedCount == 0){ //decrement LED count
LedCount = LED_COUNT_MAX;
PTT = 0b10000000; //turn on LED clock
}
if (PTT & 0x01 == 1){ //bitwise and, checking for clock LED
if(PTT & 0b00000001){ //"0" input
input = 0;
}
if(PTT & 0b00000010){ //"1" input
input = 1;
}
}
UpdateStatetask(input,state);
}
/**************************************************
* UpdateStatetask()
*************************************************/
int UpdateStatetask(input, state){
switch(state){
case 0:
PTT = 0b00000000; //state 0 no LEDs should light up
if (input == 0){ //SEQ = 10011
state = 0; //if "0" is entered at state zero stay at state zero
}
else if(input == 1){
state = 1; //if "1" is entered at state zero go to state 1
}
break;
case 1:
PTT = 0b00000100; //turn on LED indicating state 1
if (input == 0){ //if "0" is entered at state one go to state two
state = 2;
}
else if(input == 1){ //if "1" is entered at state one stay at state one
state = 1;
}
break;
case 2:
PTT ^= 0b00001100; //state 2 indication turn on 2 LED
if (input == 0){ //if "0" is entered at state two go to state three
state = 3;
}
else if(input == 1){ //if "1" is entered at state two go to state one
state = 1;
}
break;
case 3:
PTT = 0b00011100; //state 3 indication turn on 3 LED
if (input == 0){ //if "0" is entered at state three go to state zero
state = 0;
}
else if(input == 1){ //if "1" is entered at state three go to state four
state = 4;
}
break;
case 4:
PTT = 0b00111100; //state 4 indication turn on 4 LED
if (input == 0){ //if "0" is entered at state four go to state 2
state = 2;
}
else if(input == 1){//if "1" is entered at state four go to state 1
PTT = 0b01111100; //SEQ detection turn on 5 LED
state = 1;
}
break;
default:
state = 0;
break;
}
return state;
}
/**************************************************
* DelayGate
* Wait for timeout, then restart the RTI clock
*************************************************/
void DelayGate(void){
while ( (CRGFLG & 0x80) == 0){
;
}
CRGFLG = 0x80;
}
私が得る唯一の警告をコンパイルすると、
- 次の行では、関数呼び出しの結果は無視されます。
UpdateStatetask(input,state)
- これは、この行での古いスタイルの関数呼び出しです。
int UpdateStatetask(input, state){
これらの警告は、私が抱えている問題を引き起こすべきではありません。助けてくれてありがとう!