Пример #1
0
/**
 * @brief ¿ªÆôLCD±³¹â 
 * @return   none        
 * @date    2013/8/8
 * @note
 * @code
 * @endcode
 * @pre
 * @see 
 */
void LCDBackLightON(void) {
  unsigned int addr = modulelist[GPIO_LCDBACKLIGHT_MODULE].baseAddr;
   if (GPIO_DIR_INPUT == GPIODirModeGet(addr,GPIO_LCDBACKLIGHT_PIN)){
       GPIODirModeSet(addr, GPIO_LCDBACKLIGHT_PIN, GPIO_DIR_OUTPUT);
   }
       GPIOPinWrite(addr, GPIO_LCDBACKLIGHT_PIN, 0);
}
Пример #2
0
/**
 * @brief ¹Ø±ÕLCD±³¹â 
 * @return   none        
 * @date    2013/8/8
 * @note
 * @code
 * @endcode
 * @pre
 * @see 
 */
void LCDBackLightOFF(void)
{
   if (GPIO_DIR_INPUT == GPIODirModeGet(modulelist[GPIO_LCDBACKLIGHT_MODULE].baseAddr,
                                        GPIO_LCDBACKLIGHT_PIN)){
      GPIODirModeSet(modulelist[GPIO_LCDBACKLIGHT_MODULE].baseAddr,GPIO_LCDBACKLIGHT_PIN,GPIO_DIR_OUTPUT);
   }  
   GPIOPinWrite(modulelist[GPIO_LCDBACKLIGHT_MODULE].baseAddr, GPIO_LCDBACKLIGHT_PIN,1);
}
Пример #3
0
/**************************************************************************************************
 * @fn      HalAdcRead
 *
 * @brief   Read the ADC based on given channel and resolution
 *
 * @param   channel - channel where ADC will be read
 * @param   resolution - the resolution of the value
 *
 * @return  16 bit value of the ADC in offset binary format.
 *
 *          Note that the ADC is "bipolar", which means the GND (0V) level is mid-scale.
 *          Note2: This function assumes that ADCCON3 contains the voltage reference.
 **************************************************************************************************/
uint16 HalAdcRead (uint8 channel, uint8 resolution)
{
  int16  reading = 0;

#if (HAL_ADC == TRUE)
  uint8   i, resbits;
  uint8   adcChannel = 1;
  uint32  padConfig, dirConfig;
  halIntState_t s;
  
  /*
   * If Analog input channel is AIN0..AIN7, make sure corresponing PA pin is 
   * setup. Only port A can be used as input to the ADC. If any pin on port A 
   * is to be used as an ADC input, the appropriate register, IOC_PAx_OVER, 
   * must be set to analog (that is, bit 0 must be set to 1). 
   */
  
  /* Hold off interrupts */
  HAL_ENTER_CRITICAL_SECTION(s);
      
  switch (channel)
  {
  case HAL_ADC_CHN_AIN0:
  case HAL_ADC_CHN_AIN1:
  case HAL_ADC_CHN_AIN2:
  case HAL_ADC_CHN_AIN3:
  case HAL_ADC_CHN_AIN4:
  case HAL_ADC_CHN_AIN5:
  case HAL_ADC_CHN_AIN6:
  case HAL_ADC_CHN_AIN7:
    adcChannel <<= channel;
  break;
  case HAL_ADC_CHN_A0A1:
    adcChannel = HAL_BITS_CHN_A0A1;
    break;
  
  case HAL_ADC_CHN_A2A3:
    adcChannel = HAL_BITS_CHN_A2A3;
    break;
  case HAL_ADC_CHN_A4A5:
    adcChannel = HAL_BITS_CHN_A4A5;
    break;
  case HAL_ADC_CHN_A6A7:
    adcChannel = HAL_BITS_CHN_A6A7;
    break; 
  default:
    adcChannel = 0;
    break;
  } 
  
  /* save the current pad setting of the PortA pin */
  padConfig = IOCPadConfigGet(GPIO_A_BASE, adcChannel);
  
  /* save the current gpio setting of the PortA pin */
  dirConfig = GPIODirModeGet(GPIO_A_BASE, adcChannel);
  
  /* set the PortA pin to Analog */
  IOCPadConfigSet(GPIO_A_BASE, adcChannel, IOC_OVERRIDE_ANA);
  
  /* set the PortA pin direction to input */
  GPIODirModeSet(GPIO_A_BASE, adcChannel, GPIO_DIR_MODE_IN);

  /* Convert resolution to decimation rate */
  switch (resolution)
  {
    case HAL_ADC_RESOLUTION_8:
      resbits = HAL_ADC_DEC_064;
      break;
    case HAL_ADC_RESOLUTION_10:
      resbits = HAL_ADC_DEC_128;
      break;
    case HAL_ADC_RESOLUTION_12:
      resbits = HAL_ADC_DEC_256;
      break;
    case HAL_ADC_RESOLUTION_14:
    default:
      resbits = HAL_ADC_DEC_512;
      break;
  }

  /* writing to this register starts the extra conversion */
  ADCCON3 = channel | resbits | adcRef;

  /* Wait for the conversion to be done */
  while (!(ADCCON1 & HAL_ADC_EOC));
  
  /* Set the pad configuration to previous value*/
  IOCPadConfigSet(GPIO_A_BASE, adcChannel, padConfig);
 
  /* Set the GPIO direction to previous value*/
  GPIODirModeSet(GPIO_A_BASE, adcChannel, dirConfig);
  
  /* Read the result */
  reading = (int16) (ADCL);
  reading |= (int16) (ADCH << 8);
  
  /* Enable interrupts */
  HAL_EXIT_CRITICAL_SECTION(s);

  /* Treat small negative as 0 */
  if (reading < 0)
    reading = 0;

  switch (resolution)
  {
    case HAL_ADC_RESOLUTION_8:
      reading >>= 8;
      break;
    case HAL_ADC_RESOLUTION_10:
      reading >>= 6;
      break;
    case HAL_ADC_RESOLUTION_12:
      reading >>= 4;
      break;
    case HAL_ADC_RESOLUTION_14:
    default:
      reading >>= 2;
    break;
  }
#else
  /* unused arguments */
  (void) channel;
  (void) resolution;
#endif

  return ((uint16)reading);
}