⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd12864.c

📁 用MSP430单片机编写的程序
💻 C
字号:
#include <msp430x14x.h>
#define PORT_DATA_OUT P5OUT
#define PORT_DATA_IN  P5IN
#define CS1 BIT0       //P6
#define CS2 BIT1       //P6
#define EN_LIGHT BIT2  //P6
#define RST BIT4       //P4
#define D_I BIT5       //P4
#define R_W BIT6       //P4
#define EL  BIT7       //P4
#define pi 3.1415926
#include <math.h>
#include <stdlib.h>
#define uchar unsigned char
#define uint unsigned int
//编码表
uchar hzdot[] = {
/*--0  0--*/
0xF8,0x04,0x04,0x04,0xF8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,
/*--1  1--*/
0x00,0x08,0xFC,0x00,0x00,0x00,0x00,0x02,0x03,0x02,0x00,0x00,
/*--2  2--*/
0x18,0x84,0x44,0x24,0x18,0x00,0x03,0x02,0x02,0x02,0x02,0x00,
/*--3  3--*/
0x08,0x04,0x24,0x24,0xD8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,
/*--4  4--*/
0x40,0xB0,0x88,0xFC,0x80,0x00,0x00,0x00,0x00,0x03,0x02,0x00,
/*--5  5--*/
0x3C,0x24,0x24,0x24,0xC4,0x00,0x01,0x02,0x02,0x02,0x01,0x00,
/*--6  6--*/
0xF8,0x24,0x24,0x2C,0xC0,0x00,0x01,0x02,0x02,0x02,0x01,0x00,
/*--7  7--*/
0x0C,0x04,0xE4,0x1C,0x04,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
/*--8  8--*/
0xD8,0x24,0x24,0x24,0xD8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,
/*--9  9--*/
0x38,0x44,0x44,0x44,0xF8,0x00,0x00,0x03,0x02,0x02,0x01,0x00,
/*--   10--*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--,  11--*/
0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x06,0x00,0x00,0x00,0x00,
/*--.  12--*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,
/*--° 13--*/
0x00,0x0E,0x0A,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--'  14--*/
0x08,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--:  15--*/
0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
/*--=  16--*/
0x90,0x90,0x90,0x90,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--N  17--*/
0x04,0xFC,0x30,0xC4,0xFC,0x04,0x02,0x03,0x02,0x00,0x03,0x00,
/*--S  18--*/
0x18,0x24,0x24,0x44,0x8C,0x00,0x03,0x02,0x02,0x02,0x01,0x00,
/*--E  19--*/
0x04,0xFC,0x24,0x74,0x0C,0x00,0x02,0x03,0x02,0x02,0x03,0x00,
/*--W  20--*/
0x1C,0xE0,0x3C,0xE0,0x1C,0x00,0x00,0x03,0x00,0x03,0x00,0x00,
/*--L  21--*/
0x04,0xFC,0x04,0x00,0x00,0x00,0x02,0x03,0x02,0x02,0x02,0x03,
/*--Q  22--*/
0xF8,0x84,0x84,0x04,0xF8,0x00,0x01,0x02,0x02,0x07,0x05,0x00,
/*--k  23--*/
0x04,0xFC,0x80,0xE0,0x20,0x20,0x02,0x03,0x02,0x00,0x03,0x02,
/*--m  24--*/
0xE0,0x20,0xE0,0x20,0xC0,0x00,0x03,0x00,0x03,0x00,0x03,0x00,
/*--C  25--*/
0xF8,0x04,0x04,0x04,0x0C,0x00,0x01,0x02,0x02,0x02,0x01,0x00,
/*-->  26--*/
0xFC,0xF8,0x70,0x20,0x01,0x00,0x00,0x00,
/*--θ  0--*/
0x00,0x00,0x00,0xFC,0x22,0x22,0x22,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,
/*--π  1--*/
0x00,0x00,0x90,0x08,0xF8,0x08,0xF8,0x08,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,
/*--φ  2--*/
0x00,0x00,0xE0,0x10,0x10,0xFE,0x10,0x10,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x01,0x07,0x01,0x01,0x00,0x00,0x00,0x00,
/*--:  3--*/
0x00,0x00,0x00,0x00,0x8C,0x8C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
/*--东  4--*/
0x02,0x22,0x32,0xAA,0x26,0xFB,0x22,0x62,0xA2,0x22,0x02,0x00,0x02,0x02,0x01,0x00,
0x04,0x07,0x00,0x00,0x00,0x01,0x02,0x00,
/*--西  5--*/
0x01,0xF9,0x09,0x89,0x7F,0x09,0xFF,0x89,0x89,0xF9,0x01,0x00,0x00,0x07,0x05,0x04,
0x04,0x04,0x04,0x04,0x04,0x07,0x00,0x00,
/*--南  6--*/
0x02,0xFA,0x0A,0x5A,0x6A,0xCF,0x6A,0x5A,0x0A,0xFA,0x02,0x00,0x00,0x07,0x00,0x01,
0x01,0x07,0x01,0x05,0x04,0x07,0x00,0x00,
/*--北  7--*/
0x08,0x08,0x08,0xFF,0x00,0x00,0xFF,0x10,0x10,0x08,0x88,0x00,0x02,0x02,0x01,0x07,
0x00,0x00,0x07,0x04,0x04,0x04,0x07,0x00,
/*--中  8--*/
0x00,0x7C,0x44,0x44,0x44,0xFF,0x44,0x44,0x44,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,
};
void Init_Sys(void);                        // I/O初始化
void Time(void);                            // 时钟
int long temp;
int long IntDegF;
int long IntDegC;
/* ************************* */
//         延  时
/* ************************* */
void delay(long v)
{
//    uint ul;
        while(v--!=0)
        {
      //    for(ul=0;ul<200;ul++)
          {
            ;
          }
        };
}
/* ************************* */
//         写指令
//
/* ************************* */
void wcode(uchar c,uchar cs1,uchar cs2)    // 写指令
   {       
        //先片选:CS1,CS2
        //D/I=0
        //R-W=0
        //数据
        //E:0-1-0
        
        if(cs1==1)
            P6OUT|=CS1;
            else  P6OUT&=~CS1;
        if(cs2==1)
            P6OUT|=CS2;
            else  P6OUT&=~CS2;
        P4OUT&=~D_I;
        P4OUT&=~R_W;
        PORT_DATA_OUT=c;
        P4OUT&=~EL;
        delay(3);
        P4OUT|=EL;
        delay(3);
        P4OUT&=~EL;
        delay(3);
   }
/* ************************* */
//         写数据
//
/* ************************* */
void wdata(uchar c,uchar cs1,uchar cs2)
   {
             
        if(cs1==1)
            P6OUT|=CS1;
            else  P6OUT&=~CS1;
        if(cs2==1)
            P6OUT|=CS2;
            else  P6OUT&=~CS2;
        P4OUT|=D_I;
        P4OUT&=~R_W;
        PORT_DATA_OUT=c;
        P4OUT&=~EL;
        delay(3);
        P4OUT|=EL;
        delay(3);
        P4OUT&=~EL;
        delay(3);
   }
/* ************************* */
//        设置开始行和列
//
/* ************************* */
void set_startline(uchar i)
{
        i=0xc0+i;
        wcode(i,1,1);
}

void set_adr(uchar x,uchar y)
{
        x=x+0xb8;y=y+0x40;
        wcode(x,1,1);
        wcode(y,1,1);
}
//              CS1=1                  CS2=1
// Y=     0   1  ... 62  63      0   1  ... 62  63   行号
//       DB0 DB0 DB0 DBO DBO    DBO DBO DBO DBO DBO   0
//        ↓  ↓  ↓  ↓  ↓     ↓  ↓  ↓  ↓  ↓   ↓
// X=0   DB7 DB7 DB7 DB7 DB7    DB7 DB7 DB7 DB7 DB7   7
//       DB0 DB0 DB0 DB0 DB0    DB0 DB0 DB0 DB0 DB0   8
//  ↓    ↓  ↓  ↓  ↓  ↓     ↓  ↓  ↓  ↓  ↓   ↓
//       DB7 DB7 DB7 DB7 DB7    DB7 DB7 DB7 DB7 DB7   55
// X=7   DB0 DBO DBO DBO DBO    DBO DBO DBO DBO DBO   56
//        ↓  ↓  ↓  ↓  ↓     ↓  ↓  ↓  ↓  ↓   ↓
//       DB7 DB7 DB7 DB7 DB7    DB7 DB7 DB7 DB7 DB7   63
/* ************************* */
//    设置电池小图标页和列
//
/* ************************* */
void set_bet(void)
{unsigned char x, y;
        x=0xbf;y=0x7c;
        wcode(x,1,1);      // 页地址
        wcode(y,1,1);      // 列地址
}
/* ************************* */
//  设置黑箭头小图标页和列
//
/* ************************* */
void set_row(void)
{unsigned char x, y;
        x=0xbf;y=0x7d;
        wcode(x,1,1);      // 页地址
        wcode(y,1,1);      // 列地址
}
/* ************************* */
//  设置黑交叉小图标页和列
//
/* ************************* */
void set_jiaocha(void)
{unsigned char x, y;
        x=0xbf;y=0x7e;
        wcode(x,1,1);      // 页地址
        wcode(y,1,1);      // 列地址
}
/* ************************* */
//  设置黑三角小图标页和列
//
/* ************************* */
void set_three(void)
{unsigned char x, y;
        x=0xbf;y=0x7f;
        wcode(x,1,1);      // 页地址
        wcode(y,1,1);      // 列地址
}
/* ************************* */
//         显示开关
//
/* ************************* */
void dison_off(uchar o)
{
        o=o+0x3e;
        wcode(o,1,1);
}
/* ************************* */
//        整屏清除
//
/* ************************* */
void clr(void)
{ uchar loop,i;
	for(i=0;i<8;i++)
		{
		set_adr(i,0);
		set_startline(0);
		for(loop=0;loop<64;loop++)
			{ wdata(0,1,0);
			}
		set_adr(i,0);
		set_startline(0);
		for(loop=0;loop<64;loop++)
			{wdata(0,0,1);
			}
		 }
}
/* ************************* */
//         写符号
//
/* ************************* */
void asc(uchar p,uchar lline,uchar x)     /*  p,显示开始行(0---3),开始列(0---19)*/
{
	uchar i,y;
	uchar ss=0;
	if(x>9)
	    {
	    x=x-10;
	    ss=1;
            y=x*6;
	    }
           else y=4+x*6;
        set_adr(2*lline,y);
	set_startline(0);
	for(i=0;i<6;i++)
	{
	wdata(*(hzdot+p*12+i),!ss,ss);
	}
	set_adr(2*lline+1,y);
	set_startline(0);
	for(i=6;i<12;i++)
	{
	wdata(*(hzdot+p*12+i),!ss,ss);
	}
}
/* ************************* */
//         写汉字
//
/* ************************* */
void han(uchar p,uchar lline,uchar x)     /*  p,显示开始行(0---3),开始列(0---9)*/
{
	
	uchar i,y;
	uchar ss=0;
	if(x>4)
	    {
	    x=x-5;
	    ss=1;
            y=x*12;
	    }
           else y=4+x*12;
       	set_adr(2*lline,y);
        set_startline(0);
        for(i=0;i<12;i++)
	{
	wdata(*(hzdot+p*24+320+i),!ss,ss);
	}
        set_adr(2*lline+1,y);
        set_startline(0);
        for(i=12;i<24;i++)
	{
	wdata(*(hzdot+p*24+320+i),!ss,ss);
	}
}
/* ************************* */
//         写指针
//
/* ************************* */
void hand(uchar lline)     /*显示开始行(0---3)*/
{
	
	uchar i;
	uchar ss=0;
      	set_adr(2*lline,0);
        set_startline(0);
        for(i=0;i<4;i++)
	{
	wdata(*(hzdot+312+i),!ss,ss);
	}
        set_adr(2*lline+1,0);
        set_startline(0);
        for(i=4;i<8;i++)
	{
	wdata(*(hzdot+312+i),!ss,ss);
	}
}
/* ************************* */
//        清除指针
//
/* ************************* */
void clrhand(void)
{ uchar loop,i;
	for(i=0;i<8;i++)
		{
		set_adr(i,0);
		set_startline(0);
		for(loop=0;loop<4;loop++)
			{ wdata(0,1,0);
			}
		 }
}
//------------------------------------------------------------------------------
void main(void)
{
  Init_Sys();                               // Initialize system
  Time();
  P4OUT = RST;
  delay(3);
  P4OUT &= ~RST;
  delay(3);
  P4OUT = RST;
  dison_off(0);
  clr();
  dison_off(1);
  han(1,0,0);
  han(2,0,1);
  asc(10,0,4);
  asc(10,0,5);
  han(3,0,3);
  han(4,0,4);
  han(5,0,5);
  while(1);
}
//-----------------------------------------------------------------------------
// setup I/O
//-----------------------------------------------------------------------------
void Init_Sys(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog
  P1OUT = 0x0F;
  P1DIR = 0xF0;                             // P1.0/P1.3 input, all other output
  P1IES = 0xFF;                             // H->L edge detect for buttons
  P2OUT = 0x10;                             // P2 output register
  P2DIR = 0xFF;                             // P2 output  
}
//--------------------------------------------------------------------------
// Time
//--------------------------------------------------------------------------
void Time(void)
{
  unsigned long int i;
  BCSCTL1 &= ~XT2OFF;                   // XT2= HF XTAL
  do 
  {
  IFG1 &= ~OFIFG;                       // Clear OSCFault flag
  for (i = 0xFF; i > 0; i--);           // Time for flag to set
  }
  while ((IFG1 & OFIFG));               // OSCFault flag still set?                
  BCSCTL2 |= SELM_2 + SELS;             // MCLK= SMCLK= XT2 (safe)
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -