⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fc430_es417_iar.c

📁 lcdcdode cor customized
💻 C
📖 第 1 页 / 共 2 页
字号:
  LCDCTL = LCDON + LCDSG0_3 + LCD4MUX;      // 4mux LCD, segs0-15 = outputs
  BTCTL = BT_fLCD_DIV128 + BTDIV + BTIP2;   // LCD frame freq = ACLK/128
  IE2 |= BTIE;                              // Enable Basic Timer interrupt
  clearLCD();                               // Clear the LCD completely
  displayAllAccessories();                  // Show all accessory segments
}

void clearLCD(void)
{
  int i;

  for (i = 0; i < 17; i++)                  // Zero out entire LCD mem map
    LCD[i] = 0;                             // Zero out the current byte
}

void toggleAntenna(void)
{
  LCDM10 ^= 0x10;                           // Toggle the antenna segment
}

void displayValue( int value, int start )
{
  int i;
  int sign = 0;

  if (value < 0) {                          // Check for negative value
    value = ~value + 1;                     // Convert to 2's complement
    sign = 1;                               // Flag need for negative sign
  }

  i = 6 - start;                            // Figure out start position
  while (value > 9) {                       // Keep stripping digits
    LCD[i] = LCD_Table[value%10];           // Strip off leftmost digit
    value /= 10;                            // Divide value by 10
    i++;                                    // Increment index value
  }
  LCD[i] = LCD_Table[value];                // Fetch digit data from Table

  if (sign)                                 // Check if neg. sign needed
    LCD[i-1] = LCD_Table[17];               // Set the segment
}

void displayTemp(void)
{
  int start = 6;

  LCDM1 = 0;                                // Clear LCD memory byte
  LCDM2 = 0;                                // Clear LCD memory byte
  LCDM3 = 0;                                // Clear LCD memory byte

  if( unitMode == ENGLISH)
     displayValue(currentDegF, start);      // Display temp in deg F on LCD
  else
    displayValue(currentDegC, start);       // Display temp in deg C on LCD
}

void displayTach(int rpm)
{
  int start = 3;

  LCDM4 = 0;                                // Clear LCD memory
  LCDM5 = 0;                                // Clear LCD memory
  LCDM6 = 0;                                // Clear LCD memory
  LCDM7 = 0;                                // Clear LCD memory
  displayValue(rpm, start);                 // Display the actual RPM value
}

void displayLevel(FanLevel level)
{
  LCDM8 = 0;                                // Clear LCD memory byte
  LCDM9 &= ~0x0F;                           // Clear all level bar segments
  switch(level) {                           // Check the actual level
    case  FANSLEVEL0:
      LCDM8 |= 0x00;                        // Don't set any bar segment
    break;
    case  FANSLEVEL1:
      LCDM8 |= 0x10; LCDM9 |= 0x03;         // Set first bar segment
    break;
    case  FANSLEVEL2:
      LCDM8 |= 0x20; LCDM9 |= 0x07;         // Set first two bar segments
    break;
    case  FANSLEVEL3:
      LCDM8 |= 0x40; LCDM9 |= 0x0F;         // Set first three bar segments
    break;
    case  FANSLEVEL4:
      LCDM8 |= 0x88; LCDM9 |= 0x0F;         // Set first four bar segments
    break;
    case  FANSLEVEL5:
      LCDM8 |= 0x0F; LCDM9 |= 0x0F;         // Set all five bar segments
    break;
    default: break;
  }
}

void displayAllAccessories( void )
{
  LCDM8  = 0xFF;                            // S15:S14
  LCDM9  = 0xFF;                            // S17:S16
  LCDM10 = 0xFF;                            // S19:S18
  LCDM11 = 0xF7;                            // S21:S20
}

void displayUpArrow(void)
{
  LCDM9 &= 0x0F;                            // Clear all arrow segments 1st
  LCDM9 |= BIT4;                            // Toggle UP arrow segment
}

void displayDownArrow(void)
{
  LCDM9 &= 0x0F;                            // Clear all arrow segments 1st
  LCDM9 |= BIT6;                            // Toggle DOWN arrow segment
}

void rotateArrows(void)
{
  static int arrowState = 0;

  switch( arrowState ) {
    case 0:
      LCDM9 &= 0x0F;                        // Clear all arrow segments 1st
      LCDM9 |= BIT4;                        // Set corresponding arrow
    break;
    case 1:
      LCDM9 &= 0x0F;                        // Clear all arrow segments 1st
      LCDM9 |= BIT5;                        // Set corresponding arrow
    break;
    case 2:
      LCDM9 &= 0x0F;                        // Clear all arrow segments 1st
      LCDM9 |= BIT6;                        // Set corresponding arrow
    break;
    case 3:
      LCDM9 &= 0x0F;                        // Clear all arrow segments 1st
      LCDM9 |= BIT7;                        // Set corresponding arrow
    break;
    default: arrowState = 0;                // Reset the arrow state
  }

  arrowState++;                             // Increment state counter
  if(arrowState >= 4)                       // Check if at end of state
    arrowState = 0;                         // Wrap around
}
			
void rotateAccessories(void)
{
  static int accessoryState = 0;

  switch( accessoryState ) {
    case 0:
      LCDM8 = 0x12;	                    // S15:S14
      LCDM9 = 0x81;	                    // S17:S16
      LCDM10 = 0x9F;	                    // S19:S18
      LCDM11 = 0x10;	                    // S21:S20		
    break;
    case 1:
      LCDM8 = 0x12;	                    // S15:S14
      LCDM9 = 0x81;	                    // S17:S16
      LCDM10 = 0xDF;	                    // S19:S18
      LCDM11 = 0x20;	                    // S21:S20
    break;
    case 2:
      LCDM8 = 0x22;	                    // S15:S14
      LCDM9 = 0x13;	                    // S17:S16
      LCDM10 = 0xDF;	                    // S19:S18
      LCDM11 = 0x24;	                    // S21:S20
    break;
    case 3:
      LCDM8 = 0x22;	                    // S15:S14
      LCDM9 = 0x13;	                    // S17:S16
      LCDM10 = 0xFD;	                    // S19:S18
      LCDM11 = 0x24;	                    // S21:S20
    break;
    case 4:
      LCDM8 = 0x42;	                    // S15:S14
      LCDM9 = 0x17;	                    // S17:S16
      LCDM10 = 0xFD;	                    // S19:S18
      LCDM11 = 0x46;	                    // S21:S20
    break;
    case 5:
      LCDM8 = 0x42;	                    // S15:S14
      LCDM9 = 0x27;	                    // S17:S16
      LCDM10 = 0xFD;	                    // S19:S18
      LCDM11 = 0x46;	                    // S21:S20
    break;
    case 6:
      LCDM8 = 0x82;	                    // S15:S14
      LCDM9 = 0x2F;	                    // S17:S16
      LCDM10 = 0x0D;	                    // S19:S18
      LCDM11 = 0x47;	                    // S21:S20
    break;
    case 7:
      LCDM8 = 0x82;	                    // S15:S14
      LCDM9 = 0x2F;	                    // S17:S16
      LCDM10 = 0x09;	                    // S19:S18
      LCDM11 = 0x83;	                    // S21:S20
    break;
    case 8:
      LCDM8 = 0x0B;	                    // S15:S14
      LCDM9 = 0x4F;	                    // S17:S16
      LCDM10 = 0x19;	                    // S19:S18
      LCDM11 = 0x83;	                    // S21:S20
    break;
    case 9:
      LCDM8 = 0x0B;	                    // S15:S14
      LCDM9 = 0x4F;	                    // S17:S16
      LCDM10 = 0x99;	                    // S19:S18
      LCDM11 = 0x81;	                    // S21:S20
    break;
    case 10:
      LCDM8 = 0x0E;	                    // S15:S14
      LCDM9 = 0x4F;	                    // S17:S16
      LCDM10 = 0x90;	                    // S19:S18
      LCDM11 = 0x11;	                    // S21:S20
    break;
    case 11:
      LCDM8 = 0x0E;	                    // S15:S14
      LCDM9 = 0x8F;	                    // S17:S16
      LCDM10 = 0xD0;	                    // S19:S18
      LCDM11 = 0x11;	                    // S21:S20
    break;
    default:
      accessoryState = 0;                   // Reset state to beginning
    }
	
    accessoryState++;                       // Increment state counter
    if (accessoryState >= 12)               // Check if at end of states
      accessoryState = 0;                   // Wrap around
}

void SYS_init()
{
  volatile unsigned int  i;                 // Volatile var used for delay

  WDTCTL = WDTPW + WDTHOLD;                 // Disable the Watchdog
  FLL_CTL0 |= XCAP18PF;                     // Set load cap for xtal
  for(i = 0; i < 10000; i++);               // Delay for FLL to lock
  P1SEL &= ~(ACTIVITY);                     // Set I/O function
  P1DIR |= (ACTIVITY);                      // Set output direction
  P2SEL = 0xFF;                             // Set segment outputs for LCD
  P2DIR = 0xFF;                             // Set output direction
  P2SEL &= ~(TACH);                         // Set I/O function
  P2DIR &= ~(TACH);                         // Set input direction
  P2IE  |= (TACH);                          // Enable Port 2 interrupt
  P2IES |= (TACH);                          // Generate ints falling edge
  WDTCTL = WDT_ADLY_1000;                   // Disable the Watchdog
  IE1 |= WDTIE;                             // Enable Watchdog intterupt
}

void setStatusLED( Status status)
{
  switch (status) {                         // Check the status value
    case OK:                                // Blink (toggle) the LED
      status = OK;                          // Set status variable
      P1OUT ^= ACTIVITY;                    // Toggle the port pin
    break;
    case ALARM:                             // Turn LED ON
      status = ALARM;                       // Set status variable
      P1OUT &= ~ACTIVITY;                   // Reset the port pin
    break;
    default: break;
  }
}

void updateTach(void)
{
  P2IE &= ~(TACH);                          // Disable tachometer interrupt
  _NOP();                                   // Wait 1 instruction cycle
                                            // Convert pulse count to RPM
  tachRPM = (tachCount/PULSESPERREVOLUTION)*60;
  P2IE |= (TACH);                           // Re-enable tachometer interrupt
  tachCount = 0;                            // Reset the pulse counter
}

void refreshTach()
{
  if (tachRPM == 0)                         // Check if fan(s) stopped
     setStatusLED(ALARM);                   // Set ALARM LED
  else
     setStatusLED(OK);                      // Clear ALARM LED

   updateTach();                            // Refresh tachometer readings
   displayTach(tachRPM);                    // Display RPM on LCD

  if (tachRPM > lastRPM)                    // Check if current RPM > last
     displayUpArrow();                      // Yes, display UP arrow
  else
     displayDownArrow();                    // No, display DOWN arrow
  lastRPM = tachRPM;                        // Save RPM history for future
}

// PORT2 Interrupt Service Routine
#pragma vector=PORT2_VECTOR
__interrupt void isrPORT2(void)
{
  if (P2IFG & TACH) {                       // Tachometer pulse detected ?
    tachCount++;                            // Increment tach counter
    P2IFG &= ~TACH;                         // Clear interrupt flag
  }
}

// TIMER0_A1 Interrupt Service Routine
#pragma vector=TIMER0_A1_VECTOR
__interrupt void isrTIMER0_A1(void)
{
  LPM0_EXIT;                                // Exit out of LPM0
  TA0CCTL1 &= ~CCIFG;                       // Clear TA0CCR1 interrupt flag
}

// BASICTIMER Interrupt Service Routine
#pragma vector=BASICTIMER_VECTOR
__interrupt void isrBT(void)
{
  toggleAntenna();                          // Toggle antenna segment
}

// WDT Interrupt Service Routine
#pragma vector=WDT_VECTOR
__interrupt void isrWDT(void)
{
  LPM0_EXIT;                                // Exit out of LPM0
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -