您的位置:首页 > 娱乐 > 八卦 > 【TB作品】msp430g2553单片机,秒表,LCD1602,Proteus仿真

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

2024/10/5 13:59:49 来源:https://blog.csdn.net/x1131230123/article/details/139428925  浏览:    关键词:【TB作品】msp430g2553单片机,秒表,LCD1602,Proteus仿真

功能

秒表

在这里插入图片描述

动图:

在这里插入图片描述

部分代码

这段代码是用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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com