完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
//******************************************************************************
// MSP430F4250 Experimenter's Board Real time Clock in Low-power mode // // MSP430F4250 // --------------- // /|| XIN|- // | | | 32kHz // --|RST XOUT|- // | | // // // Built with IAR Embedded Workbench Version: 3.42A //****************************************************************************** #include void LCD_CHECK(void); void RTC_Tick(unsigned int TickMins); // RTC void RTC_Dec(unsigned int TickMins); // RTC void Disp_BCD(unsigned long Value); #define a 0x01 #define b 0x02 #define c 0x04 #define d 0x80 #define e 0x40 #define f 0x10 #define g 0x20 const char char_gen[] = { // definitions for digits a+b+c+d+e+f, // Displays "0" b+c, // Displays "1" a+b+d+e+g, // Displays "2" a+b+c+d+g, // Displays "3" b+c+f+g, // Displays "4" a+c+d+f+g, // Displays "5" a+c+d+e+f+g, // Displays "6" a+b+c, // Displays "7" a+b+c+d+e+f+g, // Displays "8" a+b+c+d+f+g, // Displays "9" 0, // Blank 0, // Blank 0, // Blank 0, // Blank 0, // Blank 0 // Blank }; // Global vars for RTC static unsigned char Secs = 0x00; // RTC, default time 12:00:00 static unsigned char Mins = 0x00; static unsigned char Hrs = 0x12; void main(void) { volatile unsigned int i; WDTCTL = WDTPW + WDTHOLD; // Stop WDT FLL_CTL0 |= XCAP14PF; // Set load cap for 32k xtal // LFXT1 startup delay do { IFG1 &= ~OFIFG; // Clear OSCFault flag for (i = 0x47FF; i > 0; i--); // Time for flag to set } while (IFG1 & OFIFG); // OSCFault flag still set? // Basic Timer BTCTL = BT_ADLY_1000; // 1s BT Interrupt IE2 |= BTIE; // Enable BT interrupt // Ports P1OUT = 0; // All P1.x reset P1IES = 0xC0; // P1.0, P1.1 hi/low edge P1DIR = 0x3F; // P1.0/1 = input (switches) P6OUT = 0; // All P6.x reset P6DIR = 0xFF; // All P6.x outputs P5SEL = 0x1C; // Set COM pins for LCD P1IE |=BIT6+BIT7; // LCD_A LCDACTL = LCDON + LCD4MUX + LCDFREQ_128; // 4mux LCD, ACLK/128 LCDAPCTL0 = 0x0F; // Segs S0-S15 = outputs LCDAVCTL0 = LCDCPEN; // Enable LCDA charge pump LCDAVCTL1 = VLCD_3_26; // to 3.26V LCD_CHECK(); // Misc. initialization // The following code is needed to ensure a clean POR-like start // when coming out of a WDT reset. while (1) // repeat forever { IFG2 &= ~BTIFG; // Clear pending interrupt IE2 |= BTIE; // Enable BT interrupt // wait for event, hold CPU in low-power mode 3 __bis_SR_register(LPM3_bits + GIE); __disable_interrupt(); IE2 &= ~BTIE; // Disable BT interrupt } } //------------------------------------------------------------------------------ // LCD Test Code //------------------------------------------------------------------------------ void LCD_CHECK() { volatile unsigned int i; int j; const unsigned int delay = 10000; // SW delay for LCD stepping for( j = 0; j < 12; j ++) { LCDMEM[j] = 0; // Clear LCD } for( j = 0; j < 11; j ++) { LCDMEM[j] = 0xFF; // All segments on for (i = delay; i>0; i--); // Delay } for (i = delay; i>0; i--); // Delay for( j = 0; j < 12; j ++) { LCDMEM[j] = 0; // Clear LCD } } //------------------------------------------------------------------------------ // Advance RTC counter variables // // TickMins == 0 --> advance seconds // TickMins == 1 --> advance minutes //------------------------------------------------------------------------------ void RTC_Tick(unsigned int TickMins) { Secs = __bcd_add_short(Secs, 1); if ((Secs == 0x60) || TickMins) { Secs = 0x00; Mins = __bcd_add_short(Mins, 1); if (Mins == 0x60) { Mins = 0x00; Hrs = __bcd_add_short(Hrs, 1); if (Hrs == 0x13) Hrs = 0x01; } } } //------------------------------------------------------------------------------ // Decrement RTC counter variables // // TickMins == 0 --> decrement seconds // TickMins == 1 --> decrement minutes //------------------------------------------------------------------------------ void RTC_Dec(unsigned int TickMins) { Secs = __bcd_add_short(Secs, 0x9999); if ((Secs == 0x99) || TickMins) { Secs = TickMins ? 0x00 : 0x59; Mins = __bcd_add_short(Mins, 0x9999); if (Mins == 0x99) { Mins = 0x59; Hrs = __bcd_add_short(Hrs, 0x9999); if (Hrs == 0x00) Hrs = 0x12; } } } //------------------------------------------------------------------------------ // Displays the BCD number 'Value' on the LCD display. 7 digits are output. //------------------------------------------------------------------------------ void Disp_BCD(unsigned long Value) { char *pLCD = (char *)&LCDM1; int i; for (i = 0; i < 6; i++) // Process 7 digits { *pLCD++ = char_gen[Value & 0x0f]; // Segments to LCD Value >>= 4; // Process next digit } } //------------------------------------------------------------------------------ // PORT1 interrupt handler //------------------------------------------------------------------------------ #pragma vector=PORT1_VECTOR __interrupt void Port1_ISR (void) { volatile unsigned int i, j; for (i = 10000; i > 0; i--); // Button debounce delay j = 10000; // Initial delay do { if (!(P1IN & 0x80)) RTC_Tick(1); if (!(P1IN & 0x40)) RTC_Dec(1); Disp_BCD(((long)Hrs << 16) + ((long)Mins << 8) + Secs); for (i = j; i > 0; i--); // Variable delay if (j > 1200) j -= 200; } while ((P1IN & 0xC0) != 0xC0); P1IFG &= ~0xC0; // P1.0/P1.1 IFGs Cleared } //------------------------------------------------------------------------------ // Basic Timer interrupt service routine //------------------------------------------------------------------------------ #pragma vector=BASICTIMER_VECTOR __interrupt void basic_timer(void) { volatile unsigned int i; RTC_Tick(0); // Advance RTC seconds Disp_BCD(((long)Hrs << 16) + ((long)Mins << 8) + Secs); LCDM7 |= 0x02; // Enable left colon if (Secs & 0x01) LCDM7 |= 0x01; // Toggle right colon } 求大神详解 |
|
相关推荐 |
|
只有小组成员才能发言,加入小组>>
3018个成员聚集在这个小组
加入小组2901 浏览 1 评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
3418 浏览 2 评论
请问怎么把下面51单片机的代码改成msp430 g2 pocket的代码,还有改下时间变成30秒
2329 浏览 1 评论
4787 浏览 1 评论
2560 浏览 1 评论
1299浏览 3评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
3418浏览 2评论
2901浏览 1评论
1466浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-14 06:47 , Processed in 1.184868 second(s), Total 46, Slave 38 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号