📄 scx.txt
字号:
#include <msp430x14x.h>
#define FUN_NONE 0
#define FUN1 1
#define FUN2 2
#define FUN3 3
char buffer[8]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
char buffer2[16]={0x89,0x86,0xC7,0xC7,0xC0,0xFF,0xFF,0xFF,0x89,0x86,0xC7,0xC7,0xC0,0xFF,0xFF,0xFF};
char buffer3[8]={0xC0,0xC0,0xBF,0xC0,0xC0,0xBF,0xC0,0xC0};
typedef struct {
unsigned char hour;
unsigned char minute;
unsigned char second;
} TIME;
TIME clock={0,0,0};
void display_clock(TIME);
char key1_pressed(void);
char key2_pressed(void);
void display_clear(void);
void display(char);
char function_select(void);
void main(void)
(
unsigned int time=0,times=1;
unsigned int i,have_key=0;//设按键标志位//
unsigned long j;
char fun_temp,fun_temp1;
WDTCTL=WDTPW+WDTHOLD;
P1DIR=0xF8;//P1.0,P1.1,P1.2为输入,外接开关//
P2DIR=0xF8;
P3DIR=0xC0;
P4DIR=0x01;
P5DIR=0x8E;
P5SEL=0x0A;
UCTL1&=0xFE;
UCTL1=CHAR+SYNC+MM;
UTCTL1=SSEL1+STC;
UBR01=0X02;
UBR11=0;
UMCTL1=0;
ME2=USPIE1;
while (1) {
aa: fun_temp=function_select();
if(fun_temp==FUN1{
display(buffer);
fun_temp1=FUN1;
}
if(fun_temp==FUN2){
display_clear();
fun_temp1=FUN2;
}
if(fun_temp==FUN3){
display(buffer3);//计时显示复位//
TACTL=TASSEL0+TACLR;
CCTL0=CCIE;
CCR0=32768;
TACTL&=0xFFCF;
_EINT();
fun_temp1=FUN3;
}
if(fun_temp==FUN_NONE){
display_clear();//qing led shu ma guan //
fun_temp1=FUN_NONE;
}
//main//
if(fun_temp1==FUN1)while(1){
fun_temp1=FUN_NONE;
if(function_select()!=FUN1)break;
if(key1_pressed()){
have_key=1;
time++;
if(time==5)
time=1;
}
if(have_key){
for(i=0;i<time*500;i++);
P3OUT^=0xC0;
P5OUT^=0x84;
}
}
if(fun_temp1==FUN2){
fun_temp1=FUN_NONE;
while(1){
if(function_select()!=FUN2)break;
i=0;
for(i=0;i<8;i++){
display(buffer2+8-i);
for(j=0;j<50000;j++)
if(function_select()!=FUN2)goto aa;
}
}
}
if(fun_temp1==FUN3){
fun_temp1=FUN_NONE;
while(1){
if(function_select()!=FUN3){
TACTL&=0xFFCF;
break;
}
if(key_pressed()){
times++;
if(times==255)times=0;//xian zhi yue jie//
if(times%2){
TACTL&=0xFFCF;//ji shi kai shi hou an ji ci S1 ci zhan ting//
}
else{
TACTL|=0X0010;
}
}
if(key2_pressed()){
clock.hour=0;//an S2 qing chu//
clock.minute=0;
TACTL&=0XFFCF;
times=1;
display_clock(clock);
)
}
}
}
/*****************************
*定时器溢出中断
*****************************/
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A(void)
{
clock.second++;
if(clock.second>59){
clock.second=0;
clock.minute++;
}
if(clock.minute>59){
clock.minute=0;
clock.hour++;
}
if(clock.hour>99) clock.hour=0;
display_clock(clock);
}
/****************************
*按键状态检查
****************************/
char key1_pressed(void){
if(!(P2IN&BIT0)){
while(!(P2IN&BIT0));
return 1;
}
else return 0;
}
/****************************
*清除LED和数码管显示
****************************/
void display_clera(void){
P3OUT=OXC0;//QING LED//
P5OUT=0X84;
display(buffer);
}
/****************************
*数码管输出串显示
****************************/
void display(char *buf){
signed char i;
char buf_temp[8];
for(i=0;i<8;i++) buf_temp[i]=buf[i];
for(i=0;i>=0;i--){
TXBUF1=buf_temp[i];
while(!(UTCTL1&0X01))
}
}
/****************************
*及时输出显示
****************************/
void display_clock(TIME tclock)
{
char led_list[10]={0xC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90};
char buffer_temp[8];
unsigned char tempa,tempb;
//填充分分隔符//
buffer_temp[2]=0xBF;
buffer_temp[5]=0xBF;
//显示//
tempa=tclock.second/10;
tempb=(tclock.second-tempa*10);
buffer_temp[6]=led_list[tempa];
buffer_temp[7]=led_list[tempb];
//分钟//
tempa=tclock.minute/10;
tempb=(tclock.minute-tempa*10);
buffer_temp[3]=led_list[tempa];
buffer_temp[4]=led_list[tempb];
//小时//
tempa=tclock.hour/10;
tempb=(tclock.hour-tempa*10);
buffer_temp[0]=led_list[tempa];
buffer_temp[1]=led_list[tempb];
display(buffer_temp);
}
/*****************************
*huo qu hao ma
*****************************/
char function_select(void)
if(!(P1IN&0X01))return FUN1;
if(!(P1IN&0X01))return FUN1;
if(!(P1IN&0X01))return FUN1;
return FUN_NONE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -