您的位置 首页 主动

根据MSP430F149的使用实例

#includemsp430x14x.h>#includein430.h>#includestdio.h>#defineRS0x01//寄存器选择信号(1–Command,0–d

#include <msp430x14x.h>

#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
}

/**************************/
/* 树立自定义函数 */
/**************************/

void CGRAM(void)
{
unsigned char i,j;

WriteCom(0x40);
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
{
WriteDat(CGTAB[i][j]);
}
}
}

/*void Uart0Init(void)
{
//P3DIR=0x10; //发送端为输出,承受端为输入 P3.4—TX0; P3.5—RX0
//P3SEL=0xF0; //高4位是外部功用接口
P3SEL |= 0x30; // 将P3.4,5运用外围模块 = USART0 TXD/RXD
P3DIR |= 0x10; // 将P3.4设为输出(发),P3.5默以为输入(收)

U0CTL=0x10; //8 bit数据
U0MCTL=0x6D; //2400–0x6D, 9600–0x4A, 4800–0xEF
U0TCTL=0x10; //波特率时钟源选用ACLK
U0RCTL=0x00;

U0BR0=0x0D; //2400–x0D, 9600–0x03, 4800–0x06
U0BR1=0x00;
ME1=0xC0; //发送、承受答应
IE1=0x40; //承受中止答应

}*/

void Uart0Init(void)
{
//WDTCTL = WDTPW + WDTHOLD; // 中止WDT
UCTL0 = CHAR; // 设串口操控寄存器,设为8位字符格局

UTCTL0 = SSEL0; // 设串口操控寄存器所运用的时钟,挑选UCLK = ACLK

UBR00 = 0x03; // 波特率设置32k/2400 – 13.65 0x0D
UBR10 = 0x00;

UMCTL0 = 0x4A; // 波特率调整器设置 0x6B

ME1 |= UTXE0 + URXE0; // 模块答应寄存器设置,使能USART0 TXD/RXD

IE1 |= URXIE0; // 中止答应寄存器设置,接纳中止答应

P3SEL |= 0x30; // 将P3.4,5运用外围模块 = USART0 TXD/RXD
P3DIR |= 0x10; // 将P3.4设为输出(发),P3.5默以为输入(收)

_EINT(); // 大局中止使能

}

void SendData(void)
{
unsigned char i;
unsigned char zd[5];

for(i=0;i<5;i++)
{
zd[i]=0x50+i;
while ((IFG1 & UTXIFG0) == 0); // USART0发送UTXIFG0=1,表明UTXBUF预备好发送一下字符
TXBUF0 =zd[i]; // 将收到缓冲区字符送发送区
}
}

void InitMcu430(void)
{
unsigned char ti;

//_BIS_SR(OSCOFF); //Disable LFXT1
BCSCTL1&=~XT2OFF; // XT2OFF=0
//BCSCTL1|=XTS;
BCSCTL2|=SELS+SELM1;

do{
IFG1&=~OFIFG; //Clear OscFault flag
for(ti=255;ti>1;ti–);
}while((IFG1 & OFIFG)==OFIFG);
for(ti=255;ti>1;ti–);
IFG1&=~OFIFG;

//SCTL1&=~XTS;
//BCSCTL1|=0x30; //8分频
BCSCTL1&=0x8F; //1分频, ACLK=32768HZ

// ————————Setup Timer_A———————-
TACTL=0x01C4; //Timer_A操控寄存器:接连形式,输入时钟8分频,时钟源为ACLK,Timer暂停
CCTL0=0x8110; //捕获/比较操控寄存器0:捕获形式,下降沿捕获,异步捕获,选CCI0A
CCTL2=0x4110; //捕获/比较操控寄存器2:捕获形式,上升沿捕获,异步捕获,选CCI2A
CCR2=0;
// ———————————————————–

//WDTCTL = WDTPW+0x0019; //500ms timer,MCLK

WDTCTL =WDT_ADLY_250; //ACLK

P1DIR=0x00; //set P1 input
P2DIR=0xFF; //set P2,P3,P5 is output
P3DIR|=0x0F;
P4DIR=0xFF;
P5DIR=0xFF;

P1SEL=0x00;
P2SEL=0x00;
P3SEL=0x00;
P4SEL=0x00;
P5SEL=0x00;
P6SEL=0xFF; //P6 外部模块功用
P1SEL|=0x0A; //P1.3 外部模块功用
IE1=0x01; // WDTIE Enable

gb_Timer1s=0;
gb_Timer500ms=0;
gb_Flag=0;
gb_Time=0;
gb_cnt=0;
gb_zi=0x55;
ui=0;

_EINT();
}

void DisChar(unsigned char Dt)
{
unsigned char Dx[2],i;
Dx[0]=Dt/10;
Dx[1]=Dt%10;
WriteCom(0x86); //set CGRAM address(0x80-0x8F :First line, 0xc0-0xCF :Second line)
for(i=0;i<2;i++)
{
WriteDat(0x30+Dx[i]);
}
}

void DisCharzz(unsigned char Dt)
{
unsigned char Dx[2],i;
Dx[0]=Dt/10;
Dx[1]=Dt%10;
WriteCom(0x80); //set CGRAM address(0x80-0x8F :First line, 0xc0-0xCF :Second line)
for(i=0;i<2;i++)
{
WriteDat(0x30+Dx[i]);
}
}

void DisUartChar(void)
{
char s2[16],i;
i=0;
WriteCom(0xC0); //set CGRAM address(0x80-0x8F :First line, 0xc0-0xCF :Second line)

sprintf(s2,”%3.2f”,fx.a); //Y_1210
while(s2[i]!=\0) { WriteDat(s2[i]); i++; }
}

/*
void DisInt(unsigned char num,unsigned long int Dn)
{
unsigned char s2[6];
unsigned long int temp;

//set CGRAM address(0x80-0x8F :First line, 0xc0-0xCF :Second line)
WriteCom(0xC0+(num-1)*8);
WriteDat(0x30+num); //”1:” or “2:”
WriteDat(0x3A);

s2[0]=Dn/100000; WriteDat(0x30+s2[0]); // if(s2[0]!=0) WriteDat(0x30+s2[0]); else WriteDat(0x20);
temp=Dn%100000;
s2[1]=temp/10000; WriteDat(0x30+s2[1]); //if(s2[1]!=0) WriteDat(0x30+s2[1]); else WriteDat(0x20);
temp=temp%10000;
s2[2]=temp/1000; WriteDat(0x30+s2[2]); //if(s2[2]!=0) WriteDat(0x30+s2[2]); else WriteDat(0x20);
temp =temp%1000;
s2[3]=temp/100; WriteDat(0x30+s2[3]);
temp =temp%100;

s2[4]=temp/10; WriteDat(0x30+s2[4]);
s2[5]=temp%10; WriteDat(0x30+s2[5]);
}*/

void DisInt(unsigned char num,unsigned int Dn)
{
unsigned char s2[5];
unsigned int temp;

//set CGRAM address(0x80-0x8F :First line, 0xc0-0xCF :Second line)
if(num<2) WriteCom(0x80);
else WriteCom(0xc0);
WriteDat(0x30+num); //”1:” or “2:”
WriteDat(0x3A);

s2[0]=Dn/10000; WriteDat(0x30+s2[0]);//if(s2[0]!=0) WriteDat(0x30+s2[0]); else WriteDat(0x20);
temp=Dn%10000;
s2[1]=temp/1000; WriteDat(0x30+s2[1]);//if(s2[1]!=0) WriteDat(0x30+s2[1]); else WriteDat(0x20);
temp=temp%1000;
s2[2]=temp/100; WriteDat(0x30+s2[2]);//if(s2[2]!=0) WriteDat(0x30+s2[2]); else WriteDat(0x20);
temp =temp%100;
s2[3]=temp/10; WriteDat(0x30+s2[3]);
s2[4]=temp%10; WriteDat(0x30+s2[4]);

}

void DisLongInt(void)
{
char s2[15],i;

i=0;
WriteCom(0x80);
WriteDat(0x52); //显现”Result:”
WriteDat(0x65);
WriteDat(0x73);
WriteDat(0x75);
WriteDat(0x6c);
WriteDat(0x74);
WriteDat(0x3a);

WriteCom(0xc0);
//WriteDat(0x30+num); //”1:” or “2:”
//WriteDat(0x3A);
sprintf(s2,”%lu”,MeasureData); //Y_1210
while(s2[i]!=\0) { WriteDat(s2[i]); i++; }

}
/*
void DisIntNum(unsigned char num,unsigned int Dn)
{
unsigned char s2[5];
unsigned int temp;

//set CGRAM address(0x80-0x8F :First line, 0xc0-0xCF :Second line)
WriteCom(0x80+(num-1)*9);
WriteDat(0x30+num); //”1:” or “2:”
WriteDat(0x3A);

s2[0]=Dn/10000; WriteDat(0x30+s2[0]);//if(s2[0]!=0) WriteDat(0x30+s2[0]); else WriteDat(0x20);
temp=Dn%10000;
s2[1]=temp/1000; WriteDat(0x30+s2[1]);//if(s2[1]!=0) WriteDat(0x30+s2[1]); else WriteDat(0x20);
temp=temp%1000;
s2[2]=temp/100; WriteDat(0x30+s2[2]);//if(s2[2]!=0) WriteDat(0x30+s2[2]); else WriteDat(0x20);
temp =temp%100;
s2[3]=temp/10; WriteDat(0x30+s2[3]);
s2[4]=temp%10; WriteDat(0x30+s2[4]);

}*/

void DisStartScr(void)
{
unsigned char zj;
zj=3;

WriteCom(0x84); //set CGRAM address
WriteDat(0x42); //display “BHP9505” B
WriteDat(0x48); //H
WriteDat(0x50); //P
WriteDat(0x39); //9
//WriteCom(0xc0); //set CGRAM address
WriteDat(0x35); //5
WriteDat(0x30); //0
WriteDat(0x35); //5
//zj=0;
while(zj>0) //延时3秒
{
if((gb_Flag&BIT_0)==BIT_0) //用BIT_0来表明一秒守时到
{
zj–;
gb_Flag&=~BIT_0;
}
} //Y_1210
WriteCom(0x01); //Clr Screen
WriteCom(0x81);
WriteDat(0x57); //display “WAIT 09 SECOND”
WriteDat(0x41);
WriteDat(0x49);
WriteDat(0x54);
WriteDat(0x20); //空格
WriteCom(0x89);
WriteDat(0x53);
WriteDat(0x45);
WriteDat(0x43);
WriteDat(0x4f);
WriteDat(0x4e);
WriteDat(0x44);
}

void Dis_Ready(void)
{
//display “ready”
WriteCom(0x85); //set CGRAM address
WriteDat(0x52); //R
//WriteCom(0x87); //set CGRAM address
WriteDat(0x65); //e
//WriteCom(0xC0); //set CGRAM address
WriteDat(0x61); //a
//WriteCom(0xC1); //set CGRAM address
WriteDat(0x64); //d
//WriteCom(0x8a); //set CGRAM address
WriteDat(0x79); //y
}

void Ready(void)
{
unsigned char zi,zj;
zj=11;
zi=9;
while(zj>0)
{
if((gb_Flag&BIT_0)==BIT_0) //用BIT_0来表明一秒守时到
{
DisChar(zi); //display zi on LED
zi–;
zj–;
gb_Flag&=~BIT_0;
}
}
WriteCom(0x01); //Clr Screen
//Dis_Ready();
}

void DisProcessBar(void)
{
unsigned char zs,za,tempFlag;
zs=16;
za=0;
tempFlag=1;

while(zs>0)
{
if((gb_Flag&BIT_1)==BIT_1) //用BIT_1来表明500ms守时到
{
WriteCom(0x80+za); //set CGRAM address
WriteDat(0x06); //滚动条
gb_Flag&=~BIT_1;
za++;
zs–;
//if(tempFlag==1) { if(za>7) { za=0x40; tempFlag=0; } }
}
}
zs=16;
za=0;
tempFlag=1;
while(zs>0)
{
if((gb_Flag&BIT_1)==BIT_1) //用BIT_1来表明500ms守时到
{
WriteCom(0x80+za); //set CGRAM address
WriteDat(0x07); //空白条
gb_Flag&=~BIT_1;
za++;
zs–;
//if(tempFlag==1) {if(za<0x40) { za=0x07; tempFlag=0; } }
}
}
}

void ReadData(void)
{
unsigned char zs,za,temp,tempFlag,key;
unsigned int bDat0_L,bDat0_H,bDat1_L,bDat1_H,j; //,Flag_CO1,Flag_CO2,i
unsigned long int Counter1,Counter2;

Counter1=0;
Counter2=0;
zs=16;
za=0;
tempFlag=1;
StopFlag=0;
//for(j=0;j<50000;j++) //消除按键颤动,预备丈量
// for(i=0;i<5;i++);
P4DIR=0x00;
P5DIR=0xCF;
P5OUT |= START; //=1
for(j=0;j<100;j++);
//START、RD信号置为0
P5OUT |=RES; //=1
P5OUT &=~RES; //=0
P5OUT |=RES; //=1

P5OUT |= RD; //=1
P5OUT &= ~RD; //=0 铲除标志位CO1,CO2
P5OUT |= RD; //=1
gb_Flag&=~BIT_7; //计数时(16秒守时),显现滚动条时用
P5OUT &= ~START; //=0 开端计数
//##################################################################33
//DisProcessBar(); //显现滚动条,占16秒时刻
//P5DIR &=0xCF;
while(zs>0) //显现滚动条,得出进位标志
{
key =P1IN;
key &=BIT_0;

temp=P5IN;
if((temp & CO2)==CO2)
{
Counter2++; //关于wDat0,
P5OUT |= RD; //=1
P5OUT &= ~RD; //=0 铲除标志位CO1,CO2
P5OUT |= RD; //=1
}
if((temp & CO1)==CO1)
{
Counter1++;
P5OUT |= RD; //=1
P5OUT &= ~RD; //=0 铲除标志位CO1,CO2
P5OUT |= RD; //=1
}
if((gb_Flag&BIT_1)==BIT_1) //用BIT_1来表明500ms守时到
{
WriteCom(0x80+za); //set CGRAM address
WriteDat(0x06); //滚动条
gb_Flag&=~BIT_1;
za++;
zs–;
//if(tempFlag==1) { if(za>7) { za=0x40; tempFlag=0; } }
//DisIntNum(1,Counter1);
//DisIntNum(2,Counter2);
}
key =P1IN;
key &=BIT_0;
if(key!=BIT_0)
//if((key!=BIT_0)&&(keyok ==BIT_0)) //上升沿退出丈量
{
WriteCom(0x01); //Clr Screen
WriteCom(0x80); //set CGRAM address
WriteDat(0x4F); //display “OPERATING ERROR”
WriteDat(0x50);
WriteDat(0x45);
WriteDat(0x52);
WriteDat(0x41);
WriteDat(0x54);
WriteDat(0x49);
WriteDat(0x4E);
WriteDat(0x47);
WriteDat(0x20);
WriteDat(0x45);
WriteDat(0x52);
WriteDat(0x52);
WriteDat(0x4F);
WriteDat(0x52);

gb_Timer1s=0;
gb_Flag|=BIT_4;

while(StopFlag==0);
WriteCom(0x01); //Clr Screen
WriteCom(0x80); //set CGRAM address
WriteDat(0x50); //display “PLEASE RESET”
WriteDat(0x4C);
WriteDat(0x45);
WriteDat(0x41);
WriteDat(0x53);
WriteDat(0x45);
WriteDat(0x20);
WriteDat(0x52);
WriteDat(0x45);
WriteDat(0x53);
WriteDat(0x45);
WriteDat(0x54);
//WriteDat(0x52);
while(1);
}
}
zs=16;
za=0x0; //za=0x47;
tempFlag=1;
while(zs>0)
{
key=P1IN;
key &=BIT_0;
temp=P5IN;
if((temp & CO2)==CO2)
{
Counter2++; //关于wDat0,
P5OUT |= RD; //=1
P5OUT &= ~RD; //=0 铲除标志位CO1,CO2
P5OUT |= RD; //=1
}
if((temp & CO1)==CO1)
{
Counter1++;
P5OUT |= RD; //=1
P5OUT &= ~RD; //=0 铲除标志位CO1,CO2
P5OUT |= RD; //=1
}

if((gb_Flag&BIT_1)==BIT_1) //用BIT_1来表明500ms守时到
{
WriteCom(0x80+za); //set CGRAM address
WriteDat(0x07); //空白条
gb_Flag&=~BIT_1;
za++;
zs–;
//if(tempFlag==1) { if(za>7) { za=0x40; tempFlag=0; } }
//DisIntNum(1,Counter1);
//DisIntNum(2,Counter2);

}
key =P1IN;
key &=BIT_0;
if(key!=BIT_0)
//if((key!=BIT_0)&&(keyok ==BIT_0)) //上升沿退出丈量
{
WriteCom(0x01); //Clr Screen
WriteCom(0x80); //set CGRAM address
WriteDat(0x4F); //display “OPERATING ERROR”
WriteDat(0x50);
WriteDat(0x45);
WriteDat(0x52);
WriteDat(0x41);
WriteDat(0x54);
WriteDat(0x49);
WriteDat(0x4E);
WriteDat(0x47);
WriteDat(0x20);
WriteDat(0x45);
WriteDat(0x52);
WriteDat(0x52);
WriteDat(0x4F);
WriteDat(0x52);

gb_Timer1s=0;
gb_Flag|=BIT_4;

while(StopFlag==0);
WriteCom(0x01); //Clr Screen
WriteCom(0x80); //set CGRAM address
WriteDat(0x50); //display “PLEASE RESET”
WriteDat(0x4C);
WriteDat(0x45);
WriteDat(0x41);
WriteDat(0x53);
WriteDat(0x45);
WriteDat(0x20);
WriteDat(0x52);
WriteDat(0x45);
WriteDat(0x53);
WriteDat(0x45);
WriteDat(0x54);
//WriteDat(0x52);
while(1);
}
}

//P5DIR=0xFF;
//#######################################################################
P5OUT |= START; //=1 中止计数,读取12位计数器的数据

P5OUT &= ~A1; //=0
P5OUT &= ~A0; //=0
bDat0_L =P4IN; //先读取低8位

P5OUT &= ~A1; //=0
P5OUT |= A0; //=1
bDat0_H =P4IN; //再读取高4位
bDat0_H &= 0x0F;

P5OUT |= A1; //=1
P5OUT &= ~A0; //=0
bDat1_L =P4IN; //先读取低8位
P5OUT |= A1; //=1
P5OUT |= A0; //=1
bDat1_H =P4IN; //再读取高2位
bDat1_H &= 0x03;

P5OUT |= START; //=1 中止计数,读取12位计数器的数据
//P5OUT &=~RES; //=0
//DisInt(1,bDat0_L);
//DisInt(2,bDat0_H);
//gb_Flag&=~BIT_7; //计数时(16秒守时),显现滚动条时用
//DisProcessBar(); //显现滚动条,占16秒时刻
wDat0 =(Counter1*4096+bDat0_H *256 + bDat0_L)/16; //组合成一个16位数

wDat1 =(Counter2*1024+bDat1_H *256 + bDat1_L)/16; //组合成一个16位数bDat1_L;//

MeasureData=wDat0-wDat1;
MeasureData=6532267;
}

/*主程序*/
void main(void)
{
unsigned char key,iic_value,LanguageFlag,kj;
unsigned int pi;

//WDTCTL = WDTPW + WDTHOLD; // 中止WDT
InitMcu430();
P1DIR=0x06; //p1.1,p1.2–OUT
P2DIR=0xFF;
P3DIR|=0x0F;
P4DIR=0x00;
P5DIR=0xFF;
kj=0;
InitHd44780();//初始化液晶
CGRAM(); //树立自定义字符库

Uart0Init(); //初始化串口0
SendData(); //发送 0x50 0x51

LanguageFlag=0x11;
RW24XX(&LanguageFlag,1,0×0007,0xA0);
RW24XX(&kj,1,0×0007,0xA1);
DisCharzz(LanguageFlag); //kj=23;
DisChar(kj);
//write_eeprom(0xa0,0x02,0x20);
//iic_value = read_eeprom(0xa0,0x02);
//DisChar(iic_value);
// IIC_Send(0x20);
// iic_value=IIC_Recive();
// DisChar(iic_value);

ReadyMeaFlag=0;

gb_Flag|=BIT_7; //启动时,显现倒计时用
gb_Flag|=BIT_0;
gb_Flag&=~BIT_6;
gb_Flag&=~BIT_5;
gb_Flag&=~BIT_4;
//DisStartScr();
//DisChar(iic_value);

//Ready(); //倒计时16秒
gb_Flag&=~BIT_7; //计数时(16秒守时),显现滚动条时用
//DisProcessBar(); //显现滚动条

//Dis_Ready(); //待机时,显现 “ready”

while(1){
key =P1IN;
key &=BIT_0;
for(pi=0;pi<25000;pi++)
key =P1IN;
key &=BIT_0;

if(key!=BIT_0) ReadyMeaFlag=1; //低电平,表明抽屉摆开,预备丈量

if((key==BIT_0)&&(ReadyMeaFlag==1)) //高电平,表明抽屉合上,开端丈量
{
WriteCom(0x01); //Clr Screen
ReadData();
DisLongInt(); //显现丈量数据
gb_Timer1s=0;
gb_Flag|=BIT_6; //开端延时,等候几秒后铲除显现数据,显现”Ready”
ReadyMeaFlag=0;
}
if((gb_Flag&BIT_5)==BIT_5)
{
WriteCom(0x01); //Clr Screen
Dis_Ready();
gb_Flag&=~BIT_5;
}
}
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/ziliao/zhudong/273046.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部