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

📄 msp430板上的12864液晶显示程序.c

📁 MSP430系列单片机适用小程序
💻 C
字号:

//说明:此程序用于展示,连续显示一屏,在暂停数秒,再显示下一屏,直到完,再重复开头显示
//
//12864第二版本程序,汉字显示有改进  
//449实验板DEMO程序        430F449
#include <msp430x44x.h>

#define uchar unsigned char
#define uint unsigned int

        uchar pre=0;


unsigned char  hzdot[] = {

0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
/*南   C3647 */
0x04,0xF4,0x14,0x54,0x74,0xDF,0x54,0x74,
0x54,0x14,0xF6,0x04,0x00,0x0F,0x00,0x01,
0x01,0x0F,0x01,0x01,0x05,0x08,0x07,0x00,

/*京   C3009 */
0x04,0x04,0x04,0x74,0x54,0x55,0xD6,0x54,
0x54,0x74,0x06,0x04,0x08,0x04,0x02,0x01,
0x04,0x08,0x07,0x00,0x01,0x02,0x06,0x00,

/*航   C2629 */
0x40,0xFC,0x56,0x45,0xFC,0x04,0x04,0xF5,
0x16,0xF4,0x04,0x04,0x08,0x07,0x01,0x08,
0x0F,0x00,0x0C,0x03,0x00,0x07,0x08,0x0E,

/*空   C3153 */
0x48,0x44,0xA4,0x94,0x84,0x85,0x86,0x94,
0x94,0xA4,0x64,0x0C,0x08,0x08,0x08,0x08,
0x08,0x0F,0x08,0x08,0x08,0x08,0x0C,0x08,


/*航   C2629 */
0x40,0xFC,0x56,0x45,0xFC,0x04,0x04,0xF5,
0x16,0xF4,0x04,0x04,0x08,0x07,0x01,0x08,
0x0F,0x00,0x0C,0x03,0x00,0x07,0x08,0x0E,

/*天   C4476 */
0x10,0x12,0x12,0x12,0x12,0xFE,0x92,0x12,
0x12,0x13,0x12,0x10,0x08,0x08,0x04,0x02,
0x01,0x00,0x00,0x01,0x02,0x04,0x0C,0x04,
/*大   C2083 */
0x08,0x08,0x08,0x08,0x88,0x7F,0x88,0x08,
0x08,0x08,0x0C,0x08,0x08,0x08,0x04,0x02,
0x01,0x00,0x00,0x01,0x02,0x04,0x0C,0x04,

/*学   C4907 */
0x20,0x18,0x29,0x2E,0x28,0xA9,0xAE,0x68,
0x2C,0x0B,0x98,0x08,0x01,0x01,0x01,0x01,
0x05,0x09,0x0F,0x01,0x01,0x01,0x01,0x01,
/*!   C0301 */
0x00,0x00,0x1C,0x7E,0x7E,0x1C,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00

};

unsigned int hantemp[40];

void delay(long v)
{
        while(v!=0)v--;
}

void wcode(uchar c,uchar cs1,uchar cs2)
   {       
        //先片选:CS1,CS2
        //D/I=0
        //R-W=0
        //数据
        //E:0-1-0
        
        if(cs1==1)
            P4OUT|=BIT4;
            else  P4OUT&=~BIT4;
        if(cs2==1)
            P4OUT|=BIT5;
            else  P4OUT&=~BIT5;
        P2OUT&=~BIT4;
        P2OUT&=~BIT5;
        P3OUT=c;
        P2OUT&=~BIT6;
        delay(3);
        P2OUT|=BIT6;
        delay(3);
        P2OUT&=~BIT6;
        
   }

void wdata(uchar c,uchar cs1,uchar cs2)
   {
        //先片选:CS1,CS2   :P35,P36   /P44 , P45
        //D/I=1         :P32            /P24
        //R-W=0         :P33            /P25
        //数据          :P2             /P3
        //E:0-1-0      :P34            /P26
        
        if(cs1==1)
            P4OUT|=BIT4;
            else  P4OUT&=~BIT4;
        if(cs2==1)
            P4OUT|=BIT5;
            else  P4OUT&=~BIT5;
        P2OUT|=BIT4;
        P2OUT&=~BIT5;
        P3OUT=c;
        P2OUT&=~BIT6;
        delay(3);
        P2OUT|=BIT6;
        delay(3);
        P2OUT&=~BIT6;
   }

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);
}

void dison_off(uchar o)
{
        o=o+0x3e;
        wcode(o,1,1);
}

void reset(void)
{
        //RST=0,1       :P37
        P3OUT&=~BIT7;
        delay(50);
        P3OUT|=BIT7;
        delay(50);
}

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 full(void)
{ uchar loop,i;

	for(i=0;i<8;i++)
		{

		set_adr(i,0);
		set_startline(0);
		for(loop=0;loop<64;loop++)
			{ wdata(0xff,1,0);
			}

		set_adr(i,0);
		set_startline(0);
		for(loop=0;loop<64;loop++)
			{wdata(0xff,0,1);
			}
		 }
  }

void han1(uchar *p,uchar lline,uchar x)     /*  p,点阵开始,显示开始行(0---3),开始列(0---9)*/
	{
	uchar i,y,css;
	uchar ss=0x0;
        y=x*12;
        if(ss==1)
           css=0;
           else css=1;
 	set_adr(2*lline,y);
	set_startline(0);
	for(i=0;i<12;i++)
		{
		wdata(*(p+i),css,ss);
		}
	y=x*12+64;
	set_adr(2*lline+1,y);
	set_startline(0);
	
	for(i=12;i<24;i++)
		{
		wdata(*(p+i),css,ss);
		}
   }
          
/*   distype 正显与反显  p,点阵开始,显示开始行(0---3),开始列(0---9)*/
 /*  p,点阵开始,显示开始行 lline(0---3),开始列 x (0--9)*/
void han(uchar distype,uchar *p,uchar lline,uchar x)
	{
	uchar i,y;
	uchar ss=0;
	if(x>4)
	    {
	    x=x-5;
	    ss=1;
            y=x*12;
	    }
      else y=4+x*12;
        if(distype==1)
          {
         	set_adr(2*lline,y);
	        set_startline(0);
	        for(i=0;i<12;i++)
		        {
		        wdata(*(p+i),!ss,ss);
		        }
	        set_adr(2*lline+1,y);
	        set_startline(0);
	        for(i=12;i<24;i++)
		        {
		        wdata(*(p+i),!ss,ss);
		        }
           }
          else
          {
         	set_adr(2*lline,y);
	        set_startline(0);
	        for(i=0;i<12;i++)
		        {
		        wdata(~(*(p+i)),!ss,ss);
		        }
	        set_adr(2*lline+1,y);
	        set_startline(0);
	        for(i=12;i<24;i++)
		        {
		        wdata(0x1f&(~(*(p+i))),!ss,ss);
		        }
          }
	}




void qq(void)
        {
            uchar i=4;
            for(i=0;i<40;i++)
               {
                han(1,hzdot+hantemp[i]*24,i/10,i%10);
                }
        }



interrupt[TIMERA0_VECTOR] void Timer_A (void)
{
 
  

  uchar x,i;
 
CCR0 += 5000;                // Add Offset to CCR0
 x=x+1;
 if(x==60)
       {
       x=0;
       for(i=0;i<40;i++)
         {hantemp[i]=i+pre*40;

         }
       pre=pre+1;
       }
   if(pre==6)
     pre=0;

}


main(void)
{
	uchar i;

	 WDTCTL = WDTPW + WDTHOLD;     // Stop WDT
//         TACTL = TASSEL1 + TACLR;      // SMCLK, clear TAR
  //        CCTL0 = CCIE;                 // CCR0 interrupt enabled
    //      CCR0 = 5000;
     //     P1DIR |= BIT0;                // P1.0 output
      //    TACTL |= MC1;                 // Start Timer_A in continuous mode
        //  _EINT();                      // 
        for(i=0;i<40;i++)
        hantemp[i]=i;
        P2DIR=0xFF;  
        P4DIR=0XFF;
        P3DIR=0XFF;
        reset();
	dison_off(1);
        clr();
        delay(50000);
        full();
        qq();
while(1)
        {
         

         delay(60000);

         dison_off(1);

        }
}

⌨️ 快捷键说明

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