CRGFLG寄存器,最后一位没有设置

时间:2017-03-16 09:34:25

标签: scale delay microcontroller codewarrior

我正在使用FreeScale 9S12C微控制器并在Code Warrior编码。我正在尝试为Sequence 10011创建一个SEQ检测器。当我进行模拟时,程序卡在函数DelayGate中,其他一切看起来都没问题。似乎CRGFLG寄存器中的最后一位永远不会像它应该的那样设置。我相信它应该在每个实时时钟周期结束时设置。我设置RTICTL = 0b01000000,因此实时时钟的周期应为1.024 ms。所以我的预期行为是程序应该保持在DelayGate大约1.024毫秒而不是退出,但程序永远停留在延迟门,永远不会退出。似乎CRGFLG中的最后一位从未因某种原因而被设置,我不知道为什么。感谢任何人都可以提供给我的帮助!这是我的代码。我使用的是8 MHz晶振。

// 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;
}

当我编译唯一的警告时,我得到的是

    此行上的
  1. 函数调用结果被忽略UpdateStatetask(input,state)
  2. 这是此行中的旧函数调用int UpdateStatetask(input, state){
  3. 这些警告不应该导致我遇到的问题。谢谢你的帮助!

0 个答案:

没有答案