基于MSP430F149的应用实例
/**************************/
/* 建立自定义函数 */
/**************************/
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]);
}*/
MSP430F149应用实 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)