#include "msp430x44x.h"
#include <math.h>
typedef unsigned int WORD;
typedef unsigned char BYTE;
const BYTE CHAR_X[11][5]=
{
0x3E,0x51,0x49,0x45,0x3E,
0x00,0x42,0x7F,0x40,0x00,
0x42,0x61,0x51,0x49,0x66,
0x23,0x41,0x45,0x4B,0x31,
0x18,0x14,0x52,0x7F,0x50,
0x27,0x45,0x45,0x45,0x39,
0x3C,0x4A,0x49,0x49,0x30,
0x03,0x71,0x09,0x05,0x03,
0x36,0x49,0x49,0x49,0x36,
0x06,0x49,0x49,0x29,0x1E,
0x7E,0x11,0x11,0x11,0x7E,
};
//****************************************************************************
typedef signed char INT8S; //-128 to 127
typedef unsigned char INT8U; //0 to 255
typedef int INT16S; //-32768 to 32767
typedef unsigned int INT16U; //0 to 65535
typedef long INT32S; //-2(31) to 2(31)-1
typedef unsigned long INT32U; //0 to 2(32)-1
typedef float FP32;
typedef double FP64;
#define P2_0_RS 0x01
#define P2_1_RW 0x02
#define P2_2_EN 0x04
#define P2_3_CS1 0x08
#define P2_3_CS2 0x40
#define P2_3_RST 0x80
#define P3_0_DB0 0x01
#define P3_1_DB1 0x02
#define P3_2_DB2 0x04
#define P3_3_DB3 0x08
#define P3_4_DB4 0x10
#define P3_5_DB5 0x20
#define P3_6_DB6 0x40
#define P3_7_DB7 0x80
/*const BYTE CHAR_0[5]={0x3E,0x51,0x49,0x45,0x3E};
const BYTE CHAR_1[5]={0x00,0x42,0x7F,0x40,0x00};
const BYTE CHAR_2[5]={0x42,0x61,0x51,0x49,0x66};
const BYTE CHAR_3[5]={0x23,0x41,0x45,0x4B,0x31};
const BYTE CHAR_4[5]={0x18,0x14,0x52,0x7F,0x50};
const BYTE CHAR_5[5]={0x27,0x45,0x45,0x45,0x39};
const BYTE CHAR_6[5]={0x3C,0x4A,0x49,0x49,0x30};
const BYTE CHAR_7[5]={0x03,0x71,0x09,0x05,0x03};
const BYTE CHAR_8[5]={0x36,0x49,0x49,0x49,0x36};
const BYTE CHAR_9[5]={0x06,0x49,0x49,0x29,0x1E};
const BYTE CHAR_A[5]={0x7E,0x11,0x11,0x11,0x7E};
const BYTE CHAR_B[5]={0x7F,0x49,0x49,0x49,0x36};
const BYTE CHAR_E[5]={0x41,0x7F,0x49,0x5D,0x63};
*/
//****************************************************************************
void port_ini( void )
{
P3DIR = 0xFF;
P3OUT = 0x00;
P2DIR = 0xFF;
P2OUT = P2_3_CS1 | P2_3_CS2 | P2_3_RST;
P2OUT &=~P2_3_RST;
_NOP();
_NOP();
P2OUT |= P2_2_EN;
_NOP();
_NOP();
P2OUT &=~P2_2_EN;
_NOP();
_NOP();
P2OUT |= P2_3_RST;
_NOP();
_NOP();
}
//****************************************************************************
void write_command( BYTE nByte )
{
P3DIR = 0xFF;
P2OUT |= P2_3_CS1+P2_3_CS2;
P2OUT &=~(P2_0_RS+P2_1_RW);
P3OUT = nByte;
P2OUT |= P2_2_EN;
P2OUT &=~P2_2_EN;
}
//****************************************************************************
void write_char( BYTE nByte, BYTE CS1, BYTE CS2 )
{
P3DIR = 0xFF;
if(CS1) P2OUT |= P2_3_CS1;
else P2OUT &=~P2_3_CS1;
if(CS2) P2OUT |= P2_3_CS2;
else P2OUT &=~P2_3_CS2;
P2OUT |= P2_0_RS;
P2OUT &=~P2_1_RW;
P3OUT = nByte;
P2OUT |= P2_2_EN;
P2OUT &=~P2_2_EN;
}
//****************************************************************************
void clear_lcd( void )
{
BYTE i,j;
for(i=0;i<8;i++)
{
write_command(i|0xB8);
write_command(0x40);
for(j=0;j<128;j++)
{
if(j<=63) write_char(0,1,0);
else write_char(0,0,1);
_NOP();
}
}
}
//****************************************************************************
void display_char( BYTE *chr, BYTE nRow, BYTE nCol )
{
BYTE i,tmpCol;
write_command(0xB8|nRow);
tmpCol=nCol;
for(i=0;i<5;i++)
{
if(tmpCol<=63)
{
write_command(0x40|tmpCol);
write_char(chr[i],1,0);
}
else
{
write_command(0x40|(tmpCol-64));
write_char(chr[i],0,1);
}
tmpCol++;
}
}
//**display adxl345 ->x y z**************************************************************************
void display_int(int x,char line,char start_point)
{
if(!(x&0x8000))
{
display_char((BYTE *)&CHAR_X[0],line,start_point);
display_char((BYTE *)&CHAR_X[(int)(x/1000)],line,start_point+7);
display_char((BYTE *)&CHAR_X[(int)((x%1000)/100)],line,start_point+14);
display_char((BYTE *)&CHAR_X[(int)((x%100)/10)],line,start_point+21);
display_char((BYTE *)&CHAR_X[(int)(x%10)],line,start_point+28);
}
else
{
x =~(x-0x0001);
display_char((BYTE *)&CHAR_X[10],line,start_point);
display_char((BYTE *)&CHAR_X[(int)(x/1000)],line,start_point+7);
display_char((BYTE *)&CHAR_X[(int)((x%1000)/100)],line,start_point+14);
display_char((BYTE *)&CHAR_X[(int)((x%100)/10)],line,start_point+21);
display_char((BYTE *)&CHAR_X[(int)(x%10)],line,start_point+28);
}
}
//****************************************************************************
void display_spi(char integer,char line ,char start_point)
{
display_char((BYTE *)&CHAR_X[(int)(integer%10)],line,start_point+14);
display_char((BYTE *)&CHAR_X[(int)((integer%100)/10)],line,start_point+7);
display_char((BYTE *)&CHAR_X[(int)(integer/100)],line,start_point);
//display_char((BYTE *)&CHAR_X[0],line,start_point);
}
//****************************************************************************
void display_integer(char integer,char line ,char start_point)
{
display_char((BYTE *)&CHAR_X[integer],line,start_point);
}
//****************************************************************************
void DelayMS(unsigned int m) //每次延时约8000个时钟周期,每次约为1Ms
{
unsigned int i=m, j=1350;
while(i--)
{
j=1350;
while (j--);
}
}
//显示偏离磁北角度 ,azimuth为弧度输入
void display_angle(double azimuth ,char line ,char start_point,char symbol)
{
//int tmp=0;
if(symbol)
azimuth =azimuth*180/3.1415926; //角度
else
{
azimuth =azimuth*180/3.1415926;///+5;
if(azimuth>360)
azimuth =azimuth -360;
}
if(azimuth>=0)
{
display_char((BYTE *)&CHAR_X[0],line,start_point);
display_char((BYTE *)&CHAR_X[(int) (azimuth/100)],line,start_point+7);
display_char((BYTE *)&CHAR_X[(int) ((((int) azimuth)%100)/10)],line,start_point+14);
display_char((BYTE *)&CHAR_X[(int)(((int)(azimuth))%10)],line,start_point+21);
display_char((BYTE *)&CHAR_X[(int)(((int)(azimuth*10))%10)],line,start_point+28);
//display_char((BYTE *)&CHAR_X[(int)(((int)(azimuth*100))%10)],line,start_point+35);
// tmp= (int) azimuth;
//display_char((BYTE *)&CHAR_X[0],line,start_point);
//display_char((BYTE *)&CHAR_X[(int) (tmp/100)],line,start_point+7);
//display_char((BYTE *)&CHAR_X[(int) ((tmp%100)/10)],line,start_point+14);
//display_char((BYTE *)&CHAR_X[(int)(tmp%10)],line,start_point+21);
}
else
{
azimuth =fabs(azimuth);
display_char((BYTE *)&CHAR_X[10],line,start_point);
display_char((BYTE *)&CHAR_X[(int) (azimuth/100)],line,start_point+7);
display_char((BYTE *)&CHAR_X[(int) ((((int) azimuth)%100)/10)],line,start_point+14);
display_char((BYTE *)&CHAR_X[(int)(((int)(azimuth))%10)],line,start_point+21);
display_char((BYTE *)&CHAR_X[(int)(((int)(azimuth*10))%10)],line,start_point+28);
//display_char((BYTE *)&CHAR_X[(int)(((int)(azimuth*100))%10)],line,start_point+35);
}
}
/*
//显示x,y,z
void display_xyz(int x, char line ,char start_point)
{
if(!(x & 0x8000))
{
display_char((BYTE *)&CHAR_X[(int)(x%10)],line,start_point+28);
display_char((BYTE *)&CHAR_X[(int)((x%100)/10)],line,start_point+21);
display_char((BYTE *)&CHAR_X[(int)((x%1000)/100)],line,start_point+14);
display_char((BYTE *)&CHAR_X[(int)(x/1000)],line,start_point+7);
display_char((BYTE *)&CHAR_X[0],line,start_point);
}
else
{
x =~(x-0x0001);
display_char((BYTE *)&CHAR_X[(int)(x%10)],line,start_point+28);
display_char((BYTE *)&CHAR_X[(int)((x%100)/10)],line,start_point+21);
display_char((BYTE *)&CHAR_X[(int)((x%1000)/100)],line,start_point+14);
display_char((BYTE *)&CHAR_X[(int)(x/1000)],line,start_point+7);
display_char((BYTE *)&CHAR_X[10],line,start_point);
}