📄 main.c
字号:
#include <MSP430X14X.h>
typedef unsigned char uchar;
typedef unsigned int uint;
#define t_3ms5 2300
#define t_1ms 666
uchar get_code[4] = {0};
uchar dat_code=0;
uint timer;
#include "msp430.c"
#include "12864.c"
#include "cry12864.h"
void delay(uint time) //10ms--10000
{
while(time--);
}
void dat_high()
{P1DIR |= BIT5;
P1OUT |= BIT5;
}
void dat_low()
{P1DIR |= BIT5;
P1OUT &= ~BIT5;
}
uchar rd_dat()
{ uchar stat;
P1DIR |= BIT5;
P1OUT |= BIT5;
P1DIR &= ~BIT5;
stat = P1IN;
return (stat);
}
uchar get_num()
{ uchar i,j,rd,dat=0;
_DINT(); //关闭中断
for(j=0;j<4;j++)
{ for(i=8;i>0;i--)
{dat>>=1;
do
rd=rd_dat();
while(!(rd & BIT5)); // wait high
set_timer_b0(); //检测高电平时间
do
rd=rd_dat();
while(rd & BIT5); // wait low
timer=TBR;
stop_timer_b0();
if(timer>t_1ms)dat=dat|0x80;
else dat=dat&0x7f;
}
get_code[j]=dat;
}
_EINT();
return(get_code[2]); //只显示键码部分
}
void main( void )
{ uchar rd;
WDTCTL = WDTPW + WDTHOLD;
Ini_Lcd();
dat_high();
set_timer_a0();
judge:
do
rd=rd_dat();
while(rd & BIT5); //wait low
delay(100);
rd=rd_dat();
if(rd & BIT5)goto judge; //xiao dou
do
rd=rd_dat();
while(!(rd & BIT5)); //wait high
set_timer_b0();
do
rd=rd_dat();
while(rd & BIT5); //wait low
timer=TBR;
stop_timer_b0();
if(timer<t_3ms5){delay(1000);goto judge;}//连续按下,重复标志
dat_code=get_num();
goto judge;
}
// CCRO 捕获比较中断处理
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A0 (void)
{
uchar dat_code1,dat_code2;
CCR0 = 1500; //重新载入CCR0捕获/比较数据寄存器数据
dat_code1=dat_code & 0x0F; //取键码的低四位
dat_code2=dat_code >> 4; //右移4次,高四位变为低四位
if(dat_code1>9)
{ dat_code1=dat_code1+0x37;}
else
dat_code1=dat_code1+0x30;
if(dat_code2>9)
{ dat_code2=dat_code2+0x37;}
else
dat_code2=dat_code2+0x30;
Write_Cmd(0x80);
Write_Data(dat_code2); //第一位数显示
Write_Data(dat_code1); //第二位数显示
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -