打印

【TI 技术资料分享】msp430+12864

[复制链接]
463|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
胡斯哲|  楼主 | 2015-3-14 17:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 胡斯哲 于 2015-3-14 17:48 编辑

12864并口显示图片
#include  <msp430x14x.h>
#include <math.h>

#define  LCD_RS_High   P6OUT|=0x04   // LCD_RS  高电平   显示数据         P62
#define  LCD_RS_Low    P6OUT&=0xfb   // LCD_RS  低电平   指令数据   



#define  LCD_RW_High   P6OUT|=0x10   // LCD_RW  高电平   数据读到DB0_DB7   P64
#define  LCD_RW_Low    P6OUT&=0xef   // LCD_RW  低电平   DB0_DB7 数据写入IR DR


#define  LCD_EN_High   P6OUT|=0x08   // LCD_EN  高电平   高有效            P63
#define  LCD_EN_Low    P6OUT&=0xf7   // LCD_EN  低电平   使能信号

#define LCD_PSB_High   P3OUT|=0x01;  //  并口   高电平
#define LCD_PSB_Low    P3OUT&=0xfe;  //  串口   低电平    P30

//P67 悬空
unsigned char  pic1[]=      // 图片代码
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFC,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x3F,0xFF,0xBC,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFC,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xF8,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xF8,0x10,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFC,0x10,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0x5B,0xB0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x18,0x30,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x10,0x30,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x30,0x20,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x03,0xFC,0xF0,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x40,0x20,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x90,0x27,0xC0,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x01,0x93,0xFC,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x01,0x10,0x20,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x03,0xFC,0x3C,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x10,0x06,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x10,0x84,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x03,0xFC,0x2C,0x00,0x00,0x00,0x37,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x10,0x38,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x10,0x10,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x10,0x06,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x3F,0x0F,0xFF,0xFF,0xFF,0xBF,
0x00,0x00,0x00,0x00,0x00,0x0F,0xE0,0x00,0x00,0x00,0x7F,0x4F,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x3F,0xF8,0x00,0x00,0x00,0xFF,0x0F,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x3F,0xFC,0x00,0x00,0x00,0x7F,0x0F,0xFF,0xFF,0xFF,0xBF,
0x00,0x00,0x00,0x00,0x00,0xFF,0xFE,0x00,0x00,0x00,0xFF,0x07,0xFF,0x7F,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x03,0xFF,0xFE,0x00,0x00,0x00,0x7F,0x01,0xCF,0x7F,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0x00,0x00,0x01,0xFF,0x10,0x00,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0x00,0x00,0x00,0xFF,0x03,0x87,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0x80,0x00,0x01,0xFF,0x1F,0xC7,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0x80,0x00,0x03,0xFD,0x1F,0xC7,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0x80,0x00,0x01,0xFC,0x3F,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xC0,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0x80,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xC0,0x00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xEF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

};

void delay_ms(unsigned int timer)
{
  unsigned int i;
    for(i=0;i<1000;i--)
       for(;timer>0;timer--)
         ;
}


unsigned char lcd_busy()
{                          
    unsigned char result;
   
     P4DIR=0x00;   
     LCD_RS_Low;          //  指令数据
     LCD_RW_High;
     LCD_EN_High;
        

     result = P4IN&0x80;   // 读取数据口数据
     LCD_EN_Low;
     
     return(result);
}
/*写命令到液晶*/
void LCD_WCMD(unsigned char cmd)
{                          
  while(lcd_busy());

     P4DIR=0xff;          // OUT;
     LCD_RS_Low;          //  指令数据
     LCD_RW_Low;
  //   LCD_EN_Low;
     LCD_EN_High;
     P4OUT = cmd;
   

     LCD_EN_Low;
}
/*写数据到液晶*/
void LCD_WDAT(unsigned char dat)
{                          
   while(lcd_busy());
   
     P4DIR=0xff;           // OUT;
     LCD_RS_High;          //  数据
     LCD_RW_Low;
  //   LCD_EN_Low;
     
     LCD_EN_High;
     P4OUT = dat;
     
   
     LCD_EN_Low;
}
unsigned char ReadByte(void)
{
    unsigned char byReturnValue ;
    while(lcd_busy());
    P4DIR=0xff;
    P4OUT = 0xff;
    P4DIR=0x00;
    LCD_RS_High; ;
    LCD_RW_High; ;
    LCD_EN_Low ;
    LCD_EN_High ;
    byReturnValue=P4IN ;
    LCD_EN_Low ;
   
    return byReturnValue ;
}

/*显示的字符串*/
void Display(unsigned char X,unsigned char Y,unsigned char *string)
{

   if (X==0)
     {X=0x80;}
   else if (X==1)
     {X=0x90;}
   else if (X==2)
     {X=0x88;}
   else if (X==3)
     {X=0x98;}

     LCD_WCMD(X+Y);
   
   while(*string )
    {                         //显示字符
      LCD_WDAT(*string++);
    }

}
void Display_number(unsigned char X,unsigned char Y,unsigned char number)
{
    if (X==0)
     {X=0x80;}
   else if (X==1)
     {X=0x90;}
   else if (X==2)
     {X=0x88;}
   else if (X==3)
     {X=0x98;}

     LCD_WCMD(X+Y);
     LCD_WDAT(48+number);
}
/*时钟初始化*/
void Clock_init()
{
   unsigned char t;
   BCSCTL1 = RSEL0 + RSEL1 + RSEL2;         // XT2on, max RSEL
   BCSCTL1&=~XT2OFF;                        //打开XT2振荡器
   do
   {
      IFG1 &= ~OFIFG;                       // 清除振荡器失效标志
      for (t = 255; t > 0; t--);            // 延时,等待XT2起振
   }
   while ((IFG1 & OFIFG) != 0);             // 判断XT2是否起振
   
   BCSCTL2 |= SELS+SELM_2;                  // SMCLK = XT2
}
/*液晶初始化*/
void LCD_init()
{
   LCD_WCMD(0x34);      //扩充指令操作
   LCD_WCMD(0x30);      //基本指令操作
   LCD_WCMD(0x0C);      //显示开,关光标
   LCD_WCMD(0x01);      //清除LCD的显示内容
      
}

/*------------------------------------------------
                      清屏
------------------------------------------------*/
void ClrScreen()
{
   LCD_WCMD(0x01);
   delay_ms(15);
}
/*------------------------------------------------
                 设置到绘图模式
------------------------------------------------*/
void SetGraphicMode()
{
   LCD_WCMD(0x36);       //选择8bit数据流 图形模式
   delay_ms(20);

}
/*------------------------------------------------
                   显示图片
------------------------------------------------*/
void LCD_PutGraphic(unsigned char  *img)
{
   int i,j;
//显示上半屏内容设置
   for(i=0;i<32;i++)            
    {
      LCD_WCMD(0x80 + i); //SET  垂直地址 VERTICAL ADD
      LCD_WCMD(0x80);     //SET  水平地址 HORIZONTAL ADD
      for(j=0;j<16;j++)
       {
         LCD_WDAT(*img);
         img++;
       }
    }
//显示下半屏内容设置
        for(i=0;i<32;i++)            
    {
            LCD_WCMD(0x80 + i); //SET 垂直地址 VERTICAL ADD
            LCD_WCMD(0x88);     //SET 水平地址 HORIZONTAL ADD
            for(j=0;j<16;j++)
       {
                       LCD_WDAT(*img);
                       img++;
       }
    }  
           
}
/*-------------------------------------------------------------------
                                增加画点子程序
-------------------------------------------------------------------*/
void DrawPoint(unsigned char X,unsigned char Y,unsigned char Color)
{
    unsigned char Row,Tier,Tier_bit ;
    unsigned char ReadOldH,ReadOldL ;
    LCD_WCMD(0x34);
    LCD_WCMD(0x36);
    Tier=X>>4 ;
    Tier_bit=X&0x0f ;
    if(Y<32)
    {
        Row=Y ;
    }
    else
    {
        Row=Y-32 ;
        Tier+=8 ;
    }
    LCD_WCMD(Row+0x80);
    LCD_WCMD(Tier+0x80);
    ReadByte();
    ReadOldH=ReadByte();
    ReadOldL=ReadByte();
    LCD_WCMD(Row+0x80);
    LCD_WCMD(Tier+0x80);
    if(Tier_bit<8)
    {
        switch(Color)
        {
            case 0 :
            ReadOldH&=(~(0x01<<(7-Tier_bit)));
            break ;
            case 1 :
            ReadOldH|=(0x01<<(7-Tier_bit));
            break ;
            case 2 :
            ReadOldH^=(0x01<<(7-Tier_bit));
            break ;
            default :
            break ;
        }
        LCD_WDAT(ReadOldH);
        LCD_WDAT(ReadOldL);
    }
    else
    {
        switch(Color)
        {
            case 0 :
            ReadOldL&=(~(0x01<<(15-Tier_bit)));
            break ;
            case 1 :
            ReadOldL|=(0x01<<(15-Tier_bit));
            break ;
            case 2 :
            ReadOldL^=(0x01<<(15-Tier_bit));
            break ;
            default :
            break ;
        }
        LCD_WDAT(ReadOldH);
        LCD_WDAT(ReadOldL);
    }
    LCD_WCMD(0x30);
}

//----------------------------------------------
//                        清整个GDRAM空间
//-----------------------------------------------
void clrgdram()
{
    unsigned char x,y ;
    for(y=0;y<64;y++)
    for(x=0;x<16;x++)
    {
        LCD_WCMD(0x34);
        LCD_WCMD(y+0x80);
        //行地址
        LCD_WCMD(x+0x80);
        //列地址
        LCD_WCMD(0x30);
        LCD_WDAT(0x00);
        LCD_WDAT(0x00);
    }
}
void  main( void )
{
//char i;
unsigned char x1,y1,colour=1 ;
  WDTCTL = WDTPW + WDTHOLD;     // Stop watchdog timer to prevent time out reset
  Clock_init();                 // 时钟初始化

  P6DIR=0x1c;
  P3DIR=0x01;
  LCD_PSB_High;                // 液晶显示  并口方式  
  
  LCD_init();
/*-----------------------------------------------------------------------------
                              显示字符
-----------------------------------------------------------------------------*/
  /*Display(0,0,"电子园");
  Display(1,0,"www.cepark.com");
  Display(2,1,"2013年06月4日");
  Display(3,5,"numen");        // 第四行要显示的内容
  */
  /*-----------------------------------------------------------------------------
                              显示图片
-----------------------------------------------------------------------------*/
/* ClrScreen();                                                  //清屏
  SetGraphicMode();                                             //设置成绘图模式
  LCD_PutGraphic(pic1);                                         //调入一幅图画
  for(i=0;i<20;i++)
  delay_ms(200);*/
  /*----------------------------------------------
                        打点程序
----------------------------------------------*/
  clrgdram();
  ClrScreen();
  for(x1=0;x1<128;x1++)
  {
      y1=10*sin(0.314*x1)+20; //T=2pi/w
      DrawPoint(x1,y1,colour);
        
  }
  delay_ms(5000);
  _BIS_SR(LPM0_bits);

}

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

141

主题

1431

帖子

6

粉丝