Listing for "Digital countdown timer may never need battery replacement", EDN Magazine, June 23, 2005 #include "msp430x41x.h" ;****************************************************************************** ; MSP430F412 Demo: Ultra-Low Power Digital Countdown Timer ; ; 3.5 digit, Static LCD ; VARITRONIX ; /|\ MSP430x41x MCU # VI-302-DP ; | --------------- -------------- ; +-o\-+(100k)-----| RST COM2 | | | ; | | COM1 | | | ; \|/ | COM0 |-----|COM | ; | SEG0 |-----|21 | ; | SEG1 |-----|20 | ; | . |-----|. | ; | . |-----|. | ; | SEG23|-----|3 | ; | | | | ; | | -------------- ; --------------- ; ; M.Buccini ; Texas Instruments, Inc ; March 2005 ;****************************************************************************** ORG 0F000h ; Program Start RESET mov.w #300h,SP ; Initialize '412 stackpointer StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop Watchdog Timer SetupFLL bis.b #XCAP18PF,&FLL_CTL0 ; Select load Caps SetupLCD mov.b #LCDSG0_3+LCDON+LCDSTATIC,&LCDCTL ; Static LCD, segs0-23 SetupBT mov.b #BT_fLCD_DIV256+BT_ADLY_1000,&BTCTL; fLCD= ACLK/256, 1 sec bis.b #BTIE,&IE2 ; Enable Basic Timer interrupt SetupPx mov.b #0FFh,&P1DIR ; P1.x output clr.b &P1OUT ; mov.b #0FFh,&P2DIR ; P2.x output direction clr.b &P2OUT ; mov.b #0FFh,&P5DIR ; R5.x outputs clr.b &P5OUT ; mov.b #0FFh,&P6DIR ; P6.x output direction clr.b &P6OUT ; ClearLCD mov.w #20,R15 ; Clear 20 bytes of LCD RAM Clear1 clr.b LCDMEM-1(R15) ; Clear LCD RAM to clear dec.w R15 ; All 20 bytes of LCD RAM? jnz Clear1 ; Not done? mov.w #01459h,&200h ; ; Mainloop call #Display ; bis.w #LPM3+GIE,SR ; clrc ; dadd.b #099h,&200h ; jc Mainloop ; mov.b #059h,&200h ; clrc ; dadd.b #099h,&201h ; jc Mainloop ; ; mov.w #0000h,&200h ; call #Display ; TimeOut xor.b #LCDON,&LCDCTL ; bis.w #LPM3+GIE,SR ; jmp TimeOut ; ; Display mov.w &200h,R14 ; Copy BCD value mov.w #LCDM1,R15 ; R15 points to first LCD location OutLCD mov.w R14,R13 ; Copy BCD value in R14 to R13 and.b #0Fh,R13 ; R13 = Nibble mov.b LCD_Tab(R13),R13 ; R13 = LCD segment information mov.b R13,0(R15) ; Segments a & b to LCD rra.w R13 ; mov.b R13,1(R15) ; Segments c & d to LCD rra.w R13 ; mov.b R13,2(R15) ; Segments e & f to LCD rra.w R13 ; mov.b R13,3(R15) ; Segments g & h to LCD rra.w R14 ; Right Shift rra.w R14 ; Right Shift rra.w R14 ; Right Shift rra.w R14 ; Right Shift add.b #04h,R15 ; R15 points to next LCD location cmp.b #LCDM13,R15 ; jne OutLCD ; bit.w #00001h,R14 ; Third digit jnc Disp_end ; bis.b #010h,&LCDM12 ; Disp_end bis.b #010h,&LCDM4 ; ":" ret ; ; BT_ISR bic.w #LPM3,0(SP) ; Exit LPM3 on reti reti ; ; LCD_Tab DB 077h ; "0" DB 012h ; "1" DB 03Dh ; "2" DB 03Bh ; "3" DB 05Ah ; "4" DB 06Bh ; "5" DB 06Fh ; "6" DB 013h ; "7" DB 07Fh ; "8" DB 07Bh ; "9" ; ORG 0FFFEh ; MSP430 RESET Vector DW RESET ; ORG 0FFE0h ; BT Vector DW BT_ISR ; END