最近学了一段时间的msp430单片机,感觉这款低功耗的单片机很有意思,虽然还没有彻底弄明白它的具体操作,但是一些简单的程序已经能够实现了,下面是我写的一个MSP430比较综合一点的程序,和大家分享一下:
主程序:
#include<msp430x24x.h>
#include"liushui.h"
#include"juzhen.h"
#define uchar unsigned char
#define uint unsigned int
#define rs_0 P6OUT&=~BIT4;
#define rs_1 P6OUT|=BIT4;
#define rw_0 P6OUT&=~BIT5;
#define rw_1 P6OUT|=BIT5;
#define e_0 P6OUT&=~BIT6
#define e_1 P6OUT|=BIT6;
#define wei1_0 P6OUT&=~BIT0;
#define wei1_1 P6OUT|=BIT0;
#define wei2_1 P6OUT|=BIT1;
#define wei3_0 P6OUT&=~BIT2;
#define wei3_1 P6OUT|=BIT2;
#define wei4_0 P6OUT&=~BIT3;
#define wei4_1 P6OUT|=BIT3;
uint j,t,count1,count2,count3,count4=99;
uchar temp1,temp2;
const uchar table1[]={" shizhong dabao "};
const uchar table2[]="0123456789";
const uchar table3[]=" 15:45:00 ";
void delay2(uint x)
{
uint y;
while(x--)
for(y=120;y>0;y--);
}
void w_com(uchar com)
{
rs_0;
P2OUT=com;
delay2(1);
e_1;
e_0;
}
void w_dat(uchar dat)
{
rs_1;
P2OUT=dat;
delay2(1);
e_1;
e_0;
}
void init_1602()
{
w_com(0x38);
w_com(0x0c);
w_com(0x06);
w_com(0x01);
w_com(0x80);
}
void keyscan2()
{
if(P1IN==0xfe)
{
delay2(1);
while(P1IN==0xfe);
count2++;
if(count2==60)
count2=0;
temp1=count2/10;
temp2=count2;
w_com(0x86+0x40);
w_dat(table2[temp1]);
delay2(5);
w_com(0x87+0x40);
w_dat(table2[temp2]);
}
if(P1IN==0xfd)
{
delay2(1);
while(P1IN==0xfd);
count3++;
if(count3==24)
count3=0;
temp1=count3/10;
temp2=count3;
w_com(0x83+0x40);
w_dat(table2[temp1]);
delay2(5);
w_com(0x84+0x40);
w_dat(table2[temp2]);
}
}
void shuma()
{
temp1=count4/10;
temp2=count4;
wei1_0;
P5OUT=count5;
delay2(1);
wei1_1;
|