📄 fg439_rtc.c
字号:
#include <msp430xG43x.h>
char* LCD = LCDMEM;
const char digit[10] =
{
0xB7, // "0" LCD segments a+b+c+d+e+f
0x12, // "1"
0x8F, // "2"
0x1F, // "3"
0x3A, // "4"
0x3D, // "5"
0xBD, // "6"
0x13, // "7"
0xBF, // "8"
0x3F // "9"
};
void main(void)
{
int i;
int rtc = 0;
int value;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
FLL_CTL0 |= DCOPLUS + XCAP14PF; // DCO+ set, freq = xtal x D x N+1
SCFI0 |= FN_4; // x2 DCO freq, 8MHz nominal DCO
SCFQCTL = 31; // (31+1) x 32768 x 2 = 2.048 MHz
IE2 |= BTIE; // Enable BT interrupt
P1DIR = 0xFF; // All P1.x outputs
P1OUT = 0; // All P1.x reset
P2DIR = 0xFF; // All P2.x outputs
P2OUT = 0; // All P2.x reset
P3DIR = 0xFF; // All P3.x outputs
P3OUT = 0; // All P3.x reset
P4DIR = 0xFF; // All P4.x outputs
P4OUT = 0; // All P4.x reset
P5DIR = 0xFF; // All P5.x outputs
P5OUT = 0; // All P5.x reset
P6DIR = 0xFF; // All P6.x outputs
P6OUT = 0; // All P6.x reset
LCDCTL = LCDSG0_1 + LCD4MUX + LCDON; // 4-Mux LCD, segments S0-S15
BTCTL = BT_fLCD_DIV128 | BT_ADLY_1000; // LCD clock freq is ACLK/256
P5SEL = 0xFC; // Select P5.2-7 as Com and Rxx
// Clear LCD memory to clear display
for (i=0; i<19; i++)
{
LCD[i] = 0;
}
while(1)
{
int i;
_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/ interrupts
rtc++;
value = rtc;
// Display contents of the variable value
for (i=0; i<5; i++)
{
LCD[i] = digit[value%10]; // Remainder = character in table
// to display
value /= 10; // Shifts right so next character
// can be displayed
}
}
}
// Basic Timer interrupt service routine
#pragma vector=BASICTIMER_VECTOR
__interrupt void basic_timer(void)
{
_BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits from 0(SR)
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -