コード例 #1
0
/* ---------- 育成ギアからの信号 ---------- */
DM_SIG_INT()
{
  if (ctx.state == IDLE) {
    IR_RCV_INT_DISABLE();
    BIT_SET(GR_LED_PIN);
    ctx.state = XMIT;
  }
  if (BIT_READ(DM_SIG_PIN) != 0) {
    IR_LED_OFF();
  } else {
    IR_LED_ON();
  }
  ctx.count++;
  if (ctx.count >= 36) {
    ctx.count = 0;
    IR_LED_OFF();
    BIT_CLR(GR_LED_PIN);
    ctx.state = IDLE;
    _delay_us(500);
    IR_RCV_INT_FLG_CLR();
    IR_RCV_INT_ENABLE();
  }
}
コード例 #2
0
/* ---------- main ---------- */
int main(void)
{
  ctx.state = IDLE;
  ctx.count = 0;
  ctx.timeout = 0;
  DDRB  = (1<<GR_LED_PIN) | (1<<RE_LED_PIN);
  PORTB = (1<<DM_SIG_PIN) | (1<<IR_RCV_PIN); // プルアップ
  MCUCR = (1<<ISC00); // 論理変化割り込み
  PCMSK = (1<<DM_SIG_PIN);
  GIMSK = (1<<INT0) | (1<<PCIE);
  TCCR0A = (1<<COM0A0) | (1<<WGM01) | (1<<WGM00);
  TCCR0B = (1<<WGM02) | (1<<CS00);
  OCR0A = 126; // 38kHz
  _delay_ms(500); // 受光モジュールが安定するまで待機
  sei();

  while (1) {
    _delay_us(1000);
    if (ctx.state == IDLE) {
      ctx.timeout = 200;
    } else {
      ctx.timeout--;
    }
    if (ctx.timeout == 0) {
      cli();
      ctx.state = IDLE;
      ctx.count = 0;
      BIT_CLR(GR_LED_PIN);
      BIT_CLR(RE_LED_PIN);
      BIT_SET(DM_SIG_PIN);
      INPUT_MODE(DM_SIG_PIN);
      IR_LED_OFF();
      IR_RCV_INT_FLG_CLR();
      DM_SIG_INT_FLG_CLR();
      IR_RCV_INT_ENABLE();
      DM_SIG_INT_ENABLE();
      sei();
    }
  }
  return 0;
}
コード例 #3
0
ファイル: main.c プロジェクト: dapryor/Embedded
void main(void){
//==============================================================================
// Main Program
// 
// Description: This function contains the while loop that runs continuously
// to act for the operating system. It also calls all the functions to
// initialize the system.
//
// Passed : no variables passed
// Locals: no variables declared
// Returned: no values returned
// Globals:     volatile unsigned int Time_Sequence;
//              volatile char one_time;
//              char* display_1
//              char* display_2
//              char* display_3
//              char* display_4
//              slow_input_down
//              control_state[CNTL_STATE_INDEX]
//              char big
//              char size_count;
//              char posL1
//              char posL2
//              char posL3
//              char posL4
//
// Author: David Pryor
// Date: Feb 2016
// Compiler: Built with IAR Embedded Workbench Version: V4.10A/W32 (6.4.1)
//==============================================================================
  Init_Ports();                             // Initialize Ports
  Init_Clocks();                            // Initialize Clock System 
  Init_Conditions();
  Time_Sequence = SWITCH_OFF;               // 
  Init_Timers();                            // Initialize Timers
  Init_LEDs();                              // Initialize LEDs
  Init_LCD();                               // Initialize LCD
  Init_ADC();                               // Initialize ADC
  Init_Serial_UCA1(0);                      // BAUD rate 9600
  Init_Serial_UCA0(1);                      // BAUD rate 9600
  Five_msec_Delay(1);
  PJOUT |= IOT_STA_MINIAP; //turning on miniap (only works this way)
  IR_LED_OFF();
  lcd_BIG_mid();
  display_1 = "  David   ";
  display_2 = "Project  8";  
  display_3 = "  Pryor   ";
  display_4 = "";
  Display_Process();



//------------------------------------------------------------------------------
// Begining of the "While" Operating System
//------------------------------------------------------------------------------
  while(ALWAYS) {                            // Can the Operating system run
    
    ADC_Process();              // call sampling function
    if(MainFG){
        Menu_Process();
    }
    else if(BaudMenuFG==TRUE){
        Baud_Menu(); 
    }
    else if(IOTMenuFG==TRUE){
        IOT_Menu();
    }
    
    if(StartCommandFG){ //StartCommandFG is true once "." has been received
        commandTree();
    }
    printMacAddress(); //prints mac address to screen
    macFG=FALSE; //turn off command to print mac address
    clearReceiveBuffer();
    parseIOTData();
  }
//------------------------------------------------------------------------------
}
コード例 #4
0
ファイル: adc.c プロジェクト: dapryor/Embedded
void IR_Calibration(void){
  //==============================================================================
  // COMMANDTREE
  // 
  // Description: This function is used as a command tree for input commands
  //
  // Passed : no variables passed
  // Locals:    proceed
  // Returned: no values returned
  // Globals:   ADC_Left_Detector
  //            ADC_Right_Detector
  //            thresholdL
  //            thresholdR
  //            left_calibration_black
  //            right_calibration_black
  //            left_calibration_white
  //            right_calibration_white
  //            display_1
  //            display_2
  //            display_3
  //            display_4
  //            switch_two_pressed
  //
  // Author: David Pryor
  // Date: April 2016
  // Compiler: Built with IAR Embedded Workbench Version: V4.10A/W32 (6.4.1)
  //============================================================================== 
  int proceed = RESET;
  ADC_Process();              // call sampling function
  
  IR_LED_ON();
  Five_msec_Delay(FOR_ONE_SECOND);
  display_1 = "White Test";
  display_2 = "Press SW2";
  display_3 = "";  
  display_4 = "";
  Display_Process();
  while(proceed == FALSE){
    if(switch_two_pressed){
      proceed = TRUE;
      switch_two_pressed = FALSE;
    }
  }
  ADC_Process();              // call sampling function
  right_calibration_white = ADC_Right_Detector;
  left_calibration_white = ADC_Left_Detector;
  proceed = RESET;
  
  display_1 = "Black Test";
  display_2 = "Press SW2";
  display_3 = "";  
  display_4 = "";
  Display_Process();
  while(proceed == FALSE){
    if(switch_two_pressed){
      proceed = TRUE;
      switch_two_pressed = FALSE;
    }
  }
  ADC_Process();              // call sampling function
  right_calibration_black = ADC_Right_Detector;
  left_calibration_black = ADC_Left_Detector;
    
  IR_LED_OFF();
  thresholdR = ((right_calibration_black + right_calibration_white)/HALF)+THRESHOLD_SENSITIVITY;
  thresholdL = ((left_calibration_black + left_calibration_white)/HALF)+THRESHOLD_SENSITIVITY;
  
}