基于MSP430F149的应用实例
#include
#include
#define RS 0x01//寄存器选择信号(1--Command, 0--data)
#define RW 0x02//读/写选择信号
#define EN 0x04//使能信号
#define BIT_0 0x01
#define BIT_1 0x02
#define BIT_2 0x04
#define BIT_3 0x08
#define BIT_4 0x10
#define BIT_5 0x20
#define BIT_6 0x40
#define BIT_7 0x80
#define START 0x01 //CPLD 选择
#define RD 0x02
#define A0 0x04
#define A1 0x08
#define CO1 0x10
#define CO2 0x20
#define RES 0x40
#define DATA_DIS_TIME 4 //测量完成后,数据停留显示4秒,然后清除,显示Ready
//{0x00,0x00,0x00,0x1F,0x08,0x04,0x04,0x00},/*"7",0*/
/*-----------建立自定义演示用字符库-----------*/
const unsigned int CGTAB[8][8]={0x08,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0x02, /* "年""代码=0 */
0x0f,0x09,0x0f,0x09,0x0f,0x09,0x11,0x00, /* "月"代码=1 */
0x1f,0x11,0x11,0x1f,0x11,0x11,0x1f,0x00, /* "日"代码=2 */
0x11,0x0a,0x04,0x1f,0x04,0x1f,0x04,0x00, /* "¥"代码=3 */
0x0e,0x00,0x1f,0x0a,0x0a,0x0a,0x13,0x00, /* "元"代码=4 */
0x18,0x18,0x07,0x08,0x08,0x08,0x07,0x00, /* "℃"代码=5 */
0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE, /* "滚动条"代码=6 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; /* "空白条"代码=7 */
unsigned char gb_Flag,ReceiveData;
unsigned char StopFlag;
unsigned char gb_Time,gb_cnt,gb_zi;
unsigned int gb_Timer1s;
unsigned char gb_Timer500ms;
unsigned long int MeasureData,wDat0,wDat1;
unsigned char ui,udata[4];
unsigned char ReadyMeaFlag;
union FtoByte{
float a;
unsigned char b[4];
}fx;
void DisChar(unsigned char Dt);
void DisUartChar(void);
//extern void write_eeprom(unsigned char ctrl_addres,unsigned char addres,unsigned char value);
//extern unsigned char read_eeprom(unsigned char ctrl_addres,unsigned char addres);
//extern void IIC_Send(unsigned char sDATA);
//extern unsigned char IIC_Recive(void);
extern void RW24XX(unsigned char *DataBuff,unsigned char ByteQuantity,unsigned int Address,
unsigned char ControlByte);
/*串口0接受中断响应程序*/
interrupt [0x12] void Uart0(void)
{
ReceiveData=U0RXBUF; //接受数据
IFG1=0x00; //清除中断标志位
fx.b[ui]=ReceiveData;
ui++;
if(ui>3)
{ DisUartChar(); //显示接收到的字符
ui=0;
}
}
/*Timer_A0捕获下降沿中断响应程序*/
interrupt [0x0C] void Time_A0(void)
{
CCTL2&=0xFFFE;
if(gb_Flag&BIT_2)
{
gb_Flag&=~BIT_2; //去抖动
gb_Flag|=BIT_1; //有按键按下
}
}
/*WDT 定时中断响应程序(定时:250ms)*/
interrupt [0x14] void WDT(void)
{
if((gb_Flag&BIT_7)==BIT_7)
{
if(++gb_Timer1s==4)
{
gb_Timer1s=0;
gb_Flag|=BIT_0;
}
}
else
{
if(++gb_Timer500ms==2)
{
gb_Timer500ms=0;
gb_Flag|=BIT_1;
}
if((gb_Flag&BIT_6)==BIT_6) //显示测量数据
if(++gb_Timer1s==DATA_DIS_TIME*4) { gb_Flag&=~BIT_6; gb_Flag|=BIT_5; }
if((gb_Flag&BIT_4)==BIT_4) //测量中,有键按下
if(++gb_Timer1s==8) { gb_Flag&=~BIT_4; StopFlag=1; }
}
//if(++gb_cnt ==6) { gb_cnt=0; P2OUT=gb_zi; gb_zi=~gb_zi;}} //一秒定时到
//if((++gb_Time)>25) { gb_Flag|=BIT_2; gb_Time=0; } /*去抖动*/
}
/*向LCD写指令函数*/
void WriteCom(unsigned char ch)
{
unsigned char busy;
P2DIR=0xFF;
P3DIR|=0x0F;
P3OUT&=~RS; /*RS=0*/
P3OUT|=RW; /*R/W=1 */
//P2OUT=0xFF;
P2DIR=0x00;
//P3OUT|=EN; /*EN=1 */
do{
P3OUT|=EN; /*EN=1 */
busy=P2IN;
P3OUT&=~EN; /*EN=0 */
busy&=0x80;
//P3OUT&=~EN; /*EN=0 */
}while(busy==0x80);
P3OUT&=~RW; /*R/W=0*/
P2DIR=0xFF;
P2OUT=ch; //Write command
P3OUT|=EN; /*EN=1 */
P3OUT&=~EN; /*EN=0 */
}
void WriteDat(unsigned char ch) /*向LCD写数据函数*/
{
unsigned char busy;
//P2DIR=0xFF;
P3DIR|=0x0F;
P3OUT&=~RS; /*RS=0*/
P3OUT|=RW; /*R/W=1 */
//P2OUT=0xFF;
P2DIR=0x00;
//P3OUT|=EN; /*EN=1 */
do{
P3OUT|=EN; /*EN=1 */
busy=P2IN;
P3OUT&=~EN; /*EN=0 */
busy&=0x80;
//P3OUT|=EN; /*EN=1 */
//P3OUT&=~EN; /*EN=0 */
}while(busy==0x80);
P3OUT|=RS; /*RS=1, Write data*/
P3OUT&=~RW; /*R/W=0*/
P2DIR=0xFF;
P2OUT=ch;//0x62; //Write into data
P3OUT|=EN; /*EN=1 */
P3OUT&=~EN; /*EN=0 */
}
void InitHd44780(void)
{
unsigned char i,j;
P2DIR=0xFF;
P3DIR|=0x0F;
P2OUT=0x30;
//WriteCom(0x30);
P3OUT&=~RS; /*RS=0*/
P3OUT&=~RW; /*R/W=0 */
for(i=0;i<3;i++)
{
//P2OUT=0x30;
P3OUT|=EN; /*EN=1 */
P3OUT&=~EN; /*EN=0 */
for(j=0;j<100;j++);
}
//WriteCom(0x38); //set run mode,8 bit data-port(no 4 bit)
P2OUT=0x38;
P3OUT|=EN; /*EN=1 */
P3OUT&=~EN; /*EN=0 */
WriteCom(0x38); //set run mode,8 bit data-port(no 4 bit)
WriteCom(0x01); //Clr Screen
WriteCom(0x06); //Set input mode
WriteCom(0x0C); //set displa mode
}
MSP430F149应用实 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)