<acronym id="xonnx"></acronym>
      <td id="xonnx"></td>
    1. <pre id="xonnx"></pre>

      1. 專注電子技術學習與研究
        當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

        基于MSP430正弦波方波在12864顯示程序

        作者:hkxiaoma   來源:互聯網   點擊數:  更新時間:2014年07月29日   【字體:



         

         

        //正弦波+方波顯示程序

        #include 
        #include
        #define  LCD_RS_High    P2OUT|=BIT2    // LCD_RS  高電平   顯示數據         P62
        #define  LCD_RS_Low     P2OUT&=~BIT2      // LCD_RS  低電平   指令數據  
        #define  LCD_RW_High   P2OUT|=BIT1  // LCD_RW  高電平   數據讀到DB0_DB7   P64
        #define  LCD_RW_Low     P2OUT&=~BIT1// LCD_RW  低電平   DB0_DB7 數據寫入IR DR
        #define  LCD_EN_High   P2OUT|=BIT0    // LCD_EN  高電平   高有效            P63
        #define  LCD_EN_Low     P2OUT&=~BIT0    // LCD_EN  低電平   使能信號
        #define LCD_PSB_High   P3OUT&=0xff  //  并口   高電平
        #define LCD_PSB_Low    P3OUT&=0xfe;  //  串口   低電平    P30
        //P67 懸空
        #define uchar unsigned char

        unsigned char  pic1[]=      // 圖片代碼
        {
          0x50,0x50,0xF0,0x00,0x70,0x50,0xD0,0x02,0xFF,0x42,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0xA1,0xA1,0xE1,0x00,0xE1,0xA1,0xA1,0x00,0xFF,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x03,0x02,0x02,0x00,0x02,0x02,0x03,0x00,0xFF,0x21,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x1F,0x00,0x17,0x15,0x1D,0x00,0xFF,0x84,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x5C,0x54,0x74,0x00,0xFF,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
          0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFB,0x8A,0xFA,0x02,0x02,0x02,0x02,0x02,
          0x02,0x02,0xFB,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0xEA,0xAB,0xBA,0x02,0x02,
          0x02,0x02,0x02,0x02,0x02,0xAA,0xAB,0xFA,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x3A,
          0x23,0xFA,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0xBA,0xAB,0xEA,0x02,0x02,0x02,0x02,
          0x02,0x02,0x02,0xFA,0xAB,0xEA,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x0A,0x0B,0xFA,
          0x02,0x02,0x02,0x02,0x02,0x02,0x02,0xFA,0xAB,0xFA,0x02,0x02,0x02,0x02,0x02,0x02,
          0x02,0xBA,0xAB,0xFA,0x02,0x02,0x02,0x02,0x02,0x02,0xFA,0x02,0xFB,0x8A,0xFA,0x02,
          0x02,0x02,0x02,0x02,0x02,0xFA,0x03,0x02,0xFA,0x02,0x02,0x02,0x02,0x07,0x02,0x00
        };
        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;
         
          P1DIR=0x00;   
          LCD_RS_Low;          //  指令數據
          LCD_RW_High;
          LCD_EN_High;
         
         
          result = P1IN&0x80;   // 讀取數據口數據
          LCD_EN_Low;
         
          return(result);
        }

        void LCD_WCMD(unsigned char cmd)
                                
          while(lcd_busy());
         
          P1DIR=0xff;          // OUT;
          LCD_RS_Low;          //  指令數據
          LCD_RW_Low;
          //   LCD_EN_Low;
          LCD_EN_High;
          P1OUT = cmd;
         
         
          LCD_EN_Low;
        }

        void LCD_WDAT(unsigned char dat)
                                
          while(lcd_busy());
         
          P1DIR=0xff;           // OUT;
          LCD_RS_High;          //  數據
          LCD_RW_Low;
          //   LCD_EN_Low;
         
          LCD_EN_High;
          P1OUT = dat;
         
         
          LCD_EN_Low;
        }
        unsigned char ReadByte(void)
        {
          unsigned char byReturnValue ;
          while(lcd_busy());
          P1DIR=0xff;
          P1OUT = 0xff;
          P1DIR=0x00;
          LCD_RS_High; ;
          LCD_RW_High; ;
          LCD_EN_Low ;
          LCD_EN_High ;
          byReturnValue=P1IN ;
          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 juxingbo(void)//顯示矩形波
        {
          uchar i,j,colour=1,flag=0;
          uchar zhan=12;//為電平'1'的時間長度
          uchar high=25;//高電平的位置
          uchar low=40;//低電平的位置
          for(i=0;i<128;i++)
          {
            if(i%zhan==0)
            {
              for(j=high;j<=low;j++)
                DrawPoint(i,j,colour);
              if(flag==0)
                flag=1;
              else
                flag=0;
            }
            else
            {
              if(flag==0)
                j=high;
              else
                j=low;
              DrawPoint(i,j,colour);
            }
            delay_ms(5000);
            delay_ms(5000);
          }
        }

        void  main( void )
        {
          //char i;
          //unsigned char x1,y1,colour=1 ;//////////////////////////
          WDTCTL = WDTPW + WDTHOLD;     // Stop watchdog timer to prevent time out reset
          Clock_init();                 // 時鐘初始化
          P2DIR|=BIT2+BIT1+BIT0;
          LCD_PSB_High;                // 液晶顯示  并口方式 
          LCD_init();
          //-----------------------------------------------------------------------------
          //                              顯示字符
          //---------------------------------------------------------------------------
          Display(0,1,"西安理工大學");
          Display(1,1,"電子實驗小組");
          Display(2,1,"正弦波顯示");
          Display(3,0,"2014年07月25日");        // 第四行要顯示的內容
         
         
          while(1)
          {
            clrgdram();
            ClrScreen();
           
            juxingbo();                                      //方波顯示
            delay_ms(5000);
            //_BIS_SR(LPM0_bits);
           
          }
        }

         

        關閉窗口

        相關文章

        欧美性色欧美精品视频,99热这里只有精品mp4,日韩高清亚洲日韩精品一区二区,2020国自产拍精品高潮