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

📄 fet4xx_rtcwlcd_sb.c

📁 MSP430 examples or customized
💻 C
📖 第 1 页 / 共 2 页
字号:
void Inc_Month (void);


//-------------------------------------------------------------------------------
//             Increment clock values every second
//-------------------------------------------------------------------------------
void UpdateClock (void)
{
//????              setc                             ;entry every second
              SEC = __bcd_add_short(1, SEC);         // increment seconds, add carry bit
              if (SEC == 0x60)
              {  SEC = 0;
                 MIN = __bcd_add_short(1, MIN);      // increment minutes if set carry
                 if (MIN == 0x60)                // sixty minutes elapsed?
                 {   MIN = 0;                    // yes, clear minutes
                     HOUR = __bcd_add_short(1, HOUR);   // increment hour
                     if (HOUR == 0x24)              // 24 hours elapsed?
                     {   HOUR = 0;
                        DAY = __bcd_add_short(1, DAY);   // increment DAY
                        if (MONTH == 0x02)
                        {   if (((YEAR & 0x03)==0) && (DAY == 0x29)) Inc_Month();     //Test for leap year (2 lowest bits == 0)
                            else if (((YEAR & 0x03)!=0) && (DAY == 0x28)) Inc_Month();
                        }
                        else
                        {   if (MONTH < 0x08)
                            {   if (((MONTH & 0x01)==0x01) && (DAY == 0x31)) Inc_Month();
                            else if (((MONTH & 0x01)!=0x01) && (DAY == 0x30)) Inc_Month();
                            }
                            else
                            {   if (((MONTH & 0x01)==0x01) && (DAY == 0x30)) Inc_Month();
                                else if (((MONTH & 0x01)!=0x01) && (DAY == 0x31)) Inc_Month();
                            }
                        }
                    }
                 }
              }
              sys_status |= ReInit;           //set flag to request reinit
}

void Inc_Month (void)
{
        DAY = 0x01;                      // Set day to 1
        MONTH = __bcd_add_short(1, MONTH);       // increment MONTH
        if (MONTH == 0x13)
        { MONTH = 0x01;
          YEAR = __bcd_add_short(1, YEAR);      // increment YEAR
        }
}


//-------------------------------------------------------------------------------
//             Display clock values contained in RAM Bytes MIN & HOUR.
//             CPU Registers R12, R13 and R14 used temporarily.
//-------------------------------------------------------------------------------
void Dis_Clock (void)
{
              Display_BCD(SEC,1);          // call routine to display seconds
              Display_BCD(MIN,1+2);        // call routine to display minutes
              Display_BCD(HOUR,1+4);       // call routine to display hours

              if (SEC & 0x01)
              {  LCDM3 |= colon;     // toggle Colon
                 LCDM5 |= colon;     // toggle Colon
              }
}





void Dis_Date (void)
{
              Display_BCD(YEAR,1);         // call routine to display seconds
#if   date_format == MMDDYY      // US Format
              Display_BCD(DAY,1+2);        // call routine to display day
              Display_BCD(MONTH,1+4);      // call routine to display month
#else               // European Format
              Display_BCD(MONTH,1+2);      // call routine to display month
              Display_BCD(DAY,1+4);        // call routine to display day
#endif
              if (SEC & 0x01)
              {LCDM3 |= colon;    // toggle Colon
               LCDM5 |= colon;    // toggle Colon
              }
}

//Write an BCD value into the Display
//The BCD value consists of 2 Digits
//R12 contains the the BCD value
//R14 indicates the possition on the LCD where the values should be displayed
//  0 is the right border / one digit are two steps
void Display_BCD (unsigned char data, unsigned char pos)
{
              LCDMEM[pos]   = (unsigned char)(LCD_Tab[(data & 0x0F)]      & 0xFF);

              data = data >> 4;
              LCDMEM[pos+1]   = (unsigned char)(LCD_Tab[(data & 0x0F)]      & 0xFF);
}

//-------------------------------------------------------------------------------
//             Display 1 digit on static LCD. CPU Registers R12, R14 are used
//             for the parameters
//             R12 is char (R15 in CROSSWORKS)
//             R14 is position
//             pos = 0 means right aligned digit / 1 digit are 2 steps
//-------------------------------------------------------------------------------
void Char2LCD (unsigned char data, unsigned char pos)
{
              data -= '0';                     // subtract offset of char '0'
              BCD2LCD (data, pos);
}


void BCD2LCD (unsigned char data, unsigned char pos)
{
              //data = data << 1;                // transform for word table
              Direct2LCD ((unsigned int) LCD_Tab[data], pos);
}


void Direct2LCD (unsigned int data, unsigned char pos)
{
              LCDMEM[(pos)] = (unsigned char)( data      & 0xFF);
}


//-------------------------------------------------------------------------------
void setPoint (unsigned char pos)
{
              LCDMEM[(pos)] |= dp;
}

//-------------------------------------------------------------------------------
void setColon (unsigned char pos)
{
              LCDMEM[(pos)] |= colon;
}


//-------------------------------------------------------------------------------
void SetArrow(unsigned char data)
{
              LCDM9 &= ~0xF0;                  // Turn off all arrows
              LCDM9 |= (data << 4) & 0xF0;     // Turn set arrows
}

//-------------------------------------------------------------------------------
void SetupClock (void)   // Configure modules and control registers
{
              int i;
#if   (LCD_SIZE == 7)
              LCDCTL = LCDON+LCD4MUX+LCDP2+LCDP0; // Softbaugh LCD 4Mux, S0-S31
#else
              LCDCTL = LCDON+LCD4MUX+LCDP2        // STK LCD 4Mux, S0-S15
#endif

#ifdef P5SEL_
              P5SEL = 0FCh                        // Enable R(LCD) + COM Lines
#endif

//SetupBT
              BTCTL = BT_ADLY_1000;            // Basic Timer interrupt = 1 second
              BTCTL |=BTFRFQ1;                 // Set fLCD = ACLK / 128
              IE2 |= BTIE;                     // enable Basic Timer interrupt

//ClearLCD
              for (i=20; i != 0; i--) LCDMEM[i] =0;
}

//-------------------------------------------------------------------------------
//             Basic Timer causes 1 second interrupt. Mode bits changed on stack
//             so CPU is returned in active upon return from the interrupt
//-------------------------------------------------------------------------------

#ifdef __IAR_SYSTEMS_ICC__
#if __VER__ < 200
interrupt[BASICTIMER_VECTOR] void BT_ISR(void)
#else
#pragma vector=BASICTIMER_VECTOR
__interrupt void BT_ISR( void )
#endif
#endif

#ifdef __CROSSWORKS_MSP430
void BT_ISR(void)   __interrupt[BASICTIMER_VECTOR]
#endif

{
              UpdateClock();               // update hours and minutes each
                                           // second even if not displayed
              DisplayNextData();           // Switch to next display mode
                                           // every few seconds
              LPM3_EXIT;    // back to active mode after ISR
}

#endif  // PCB == SB_BOARD

⌨️ 快捷键说明

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