【TB作品】msp430g2553单片机,秒表,LCD1602,Proteus仿真

发布于:2024-06-05 ⋅ 阅读:(54) ⋅ 点赞:(0)

功能

秒表

在这里插入图片描述

动图:

在这里插入图片描述

部分代码

这段代码是用C语言编写的,用于在基于德州仪器MSP430微控制器的平台上实现一个简易的电子秒表功能。

#include <msp430.h>
#include "LCD.h"

unsigned int    second      = 0;
unsigned int    millisecond100  = 0;
char        Stopwatch_open  = 0;

int main( void )
{
    unsigned char display_str[15], str_count;

    WDTCTL = WDTPW | WDTHOLD;       /* stop watchdog timer */

    if ( CALBC1_1MHZ == 0xFF )      /* If calibration constant erased */
    {
        while ( 1 )
            ;               /* do not load, trap CPU!! */
    }
    DCOCTL  = 0;                    /* Select lowest DCOx and MODx settings */
    BCSCTL1 = CALBC1_1MHZ;          /* Set range */
    DCOCTL  = CALDCO_1MHZ;          /* Set DCO step + modulation * / */

    Port_init();                    /* lcd */
    LCD_init();                     /* lcd */


    LCD_write_str( 0, 0, "Stopwatch" );
    _EINT();
    while ( 1 )
    {
        /*按键输入 */
        P1DIR   &= ~BIT3;
        P1SEL   &= ~BIT3;
        P1REN   |= BIT3;
        P1OUT   |= BIT3;
        if ( !(P1IN & BIT3) )
        {
            while ( !(P1IN & BIT3) )
                ;
            Stopwatch_open = !Stopwatch_open;      /* 开始或者暂停 */
        }
        delay_ms( 10 );

        str_count           = 0;
        display_str[str_count++]    = (second / 60) % 100 / 10 + '0';
        display_str[str_count++]    = (second / 60) % 10 + '0';
        display_str[str_count++]    = ':';
        display_str[str_count++]    = (second % 60) % 100 / 10 + '0';
        display_str[str_count++]    = (second % 60) % 10 + '0';
        display_str[str_count++]    = '.';
        display_str[str_count++]    = (millisecond100) % 10 + '0';
        display_str[str_count++]    = 0;
        Port_init(); /* lcd */
        LCD_write_str( 0, 1, display_str );
    }
}


#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A( void )
{
    static char num2 = 0;
    if ( Stopwatch_open )
    {
        num2 = (num2 + 1) % 10;
        if ( num2 == 9 )
        {
            millisecond100++;
            if ( millisecond100 == 10 )
            {
                millisecond100 = 0;
                second++;
            }
        }
    }
}



全部代码

在这里插入图片描述

https://docs.qq.com/sheet/DUEdqZ2lmbmR6UVdU?tab=BB08J2

网站公告

今日签到

点亮在社区的每一天
去签到