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

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

        LCD12864指定位置反白顯示程序

        作者:佚名   來源:本站原創   點擊數:  更新時間:2014年03月31日   【字體:

            /*********************************************************************** 
            工    程:ST7920驅動的12864液晶的3線串行驅動模式 
            創建日期:2007年9月16日 
            創 建 人:朱海峰 
            郵    箱:ntzhf100@163.com      QQ:543376422 
            引腳定義:RS(CS)=====>PB5 
                      RW(SID)====>PB6 
                      EN(SCLK)===>PB7 
                      PSB為硬件控制,接高電平為8位或4位的并行模式,接低電平為串行模式 
                      本例程使用3線串行模式 
            ************************************************************************/  
            #include <iom128v.h>  
            #include <macros.h>  
              
            #define uchar unsigned char  
            #define uint unsigned int   
            #define nop()   NOP()  
            #define xtal 8  
            #define CS   PB5  
            #define SID  PB6  
            #define SCLK PB7  
              
            #define Set_CS()    DDRB |= (1<<CS);PORTB |= (1<<CS)  
            #define Set_SID()   DDRB |= (1<<SID);PORTB |= (1<<SID)  
            #define Set_SCLK()  DDRB |= (1<<SCLK);PORTB |= (1<<SCLK)  
              
            #define Clr_CS()    DDRB |= (1<<CS);PORTB &=~(1<<CS)  
            #define Clr_SID()   DDRB |= (1<<SID);PORTB &=~(1<<SID)  
            #define Clr_SCLK()  DDRB |= (1<<SCLK);PORTB &=~(1<<SCLK)  
              
              
               
            //====================================================================  
            //函數聲明  
            void Delay(uint ms);            //延時子程序  
            void W_1byte(uchar RW, uchar RS, uchar W_data);  
            void Write_8bits(uint W_bits);  
            void LCD_Init(void);  
            void Char_Set_XY(uchar x, uchar y, uchar *p);  
            void Set_Draw(void);  
            //設定哪一行,從那一個位置開始到那一個位置結束使用反白  
            //x=液晶屏上漢字的位置(1~8);end_x=漢字結束的地址(1~8);y=1~4行  
            //clear=1:清除反白;clear=0:設置反白;  
            void Set_White(uchar x,uchar y,uchar end_x,uchar clear);      
            void Draw_Pic(uchar x, uchar y, const uchar *Draw);  
            /* 
            /******************************************************************** 
            ********************************************************************/  
            const uchar PIC1[64][16]={  
            /*--  調入了一幅圖像:C:\Documents and Settings\Administrator\桌面\atmel.bmp  --*/  
            /*--  寬度x高度=128x64  --*/  
              
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,  
            0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,  
            0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,  
            0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,  
            0x00,0x00,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,  
            0x00,0x00,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,  
            0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,  
            0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,  
            0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,  
            0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,  
            0x00,0x00,0x00,0x07,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x07,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x3F,0xE7,0xFC,0xFF,0xFF,0xFF,0xE0,0xFF,0xFF,0xCF,0xF8,0x00,0x00,0x00,  
            0x00,0x00,0x3F,0xE7,0xFC,0xFF,0xFF,0xFF,0xF0,0xFF,0xFF,0xCF,0xF8,0x00,0x00,0x00,  
            0x00,0x00,0x7F,0xE7,0xFC,0xFF,0xFF,0xFF,0xF8,0xFF,0xFF,0xCF,0xF8,0x00,0x00,0x00,  
            0x00,0x00,0x7F,0xE7,0xFC,0xFF,0xFF,0xFF,0xFC,0xFF,0xFF,0xCF,0xF8,0x00,0x00,0x00,  
            0x00,0x00,0xFF,0xE7,0xFC,0xFF,0xBF,0xEF,0xFC,0xFF,0xFF,0xCF,0xF8,0x00,0x00,0x00,  
            0x00,0x00,0xFF,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xF8,0x00,0x00,0x00,  
            0x00,0x01,0xFF,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xF8,0x00,0x00,0x00,  
            0x00,0x03,0xFF,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xF8,0x00,0x00,0x00,  
            0x00,0x03,0xFF,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xF8,0x00,0x00,0x00,  
            0x00,0x07,0xFF,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFC,0x00,0x0F,0xF8,0x00,0x00,0x00,  
            0x00,0x07,0xFF,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xF8,0x00,0x00,0x00,  
            0x00,0x0F,0xFF,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xF8,0x00,0x00,0x00,  
            0x00,0x0F,0xFF,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xF8,0x00,0x00,0x00,  
            0x00,0x1F,0xFF,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xF8,0x00,0x00,0x00,  
            0x00,0x1F,0xFF,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xF8,0x00,0x00,0x00,  
            0x00,0x3F,0xFF,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xF8,0x00,0x00,0x00,  
            0x00,0x3F,0xFF,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xF8,0x00,0x00,0x00,  
            0x00,0x7F,0xFF,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xF8,0x00,0x00,0x00,  
            0x00,0xFF,0xFF,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xF8,0x00,0x00,0x00,  
            0x00,0xFF,0xFF,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFC,0x00,0x0F,0xF8,0x00,0x00,0x00,  
            0x01,0xFF,0xBF,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFE,0x00,0x0F,0xF8,0x00,0x00,0x00,  
            0x01,0xFF,0x3F,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xFF,0xF8,0x00,0x00,  
            0x03,0xFF,0x3F,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xFF,0xF8,0x00,0x00,  
            0x03,0xFE,0x3F,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xFF,0xF0,0x00,0x00,  
            0x07,0xFE,0x3F,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xFF,0xF0,0x00,0x00,  
            0x07,0xFF,0x3F,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xFF,0xE0,0x00,0x00,  
            0x0F,0xFF,0x3F,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xFF,0xE0,0x00,0x00,  
            0x0F,0xFF,0x3F,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xFF,0xC0,0x00,0x00,  
            0x1F,0xFF,0x3F,0xE7,0xFC,0xFF,0xBF,0xE7,0xFC,0xFF,0xFF,0xCF,0xFF,0xC0,0x00,0x00,  
            0x1F,0xFF,0x3F,0xE7,0xFC,0xFF,0x1F,0xE7,0xFC,0xFF,0xFF,0xCF,0xFF,0x80,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3E,0x00,0x00,  
            0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x63,0x00,0x00,  
            0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFD,0x00,0x00,  
            0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0xB6,0x80,0x00,  
            0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0xBE,0x80,0x00,  
            0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0xB6,0x80,0x00,  
            0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0xF7,0x00,0x00,  
            0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x63,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00  
            };   
              
            //==================================================================      
              
            const uchar PIC2[64][16]={  
            /*--  調入了一幅圖像:C:\Documents and Settings\Administrator\桌面\AVR.BMP  --*/  
            /*--  寬度x高度=128x64  --*/  
              
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x43,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xBD,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x27,  
            0x00,0x00,0x1F,0xFF,0x83,0xFF,0xE0,0x00,0x00,0xFF,0xF8,0x3F,0xFF,0xFF,0x01,0x3C,  
            0x00,0x00,0x3F,0xFF,0x81,0xFF,0xF0,0x00,0x01,0xFF,0xF0,0x7F,0xFF,0xFF,0xC1,0x3E,  
            0x00,0x00,0x3F,0xFF,0xC1,0xFF,0xF0,0x00,0x01,0xFF,0xF0,0x7F,0xFF,0xFF,0xE0,0xA7,  
            0x00,0x00,0x3F,0xFF,0xC1,0xFF,0xF0,0x00,0x03,0xFF,0xE0,0x7F,0xFF,0xFF,0xF0,0xE7,  
            0x00,0x00,0x7F,0xFF,0xE0,0xFF,0xF8,0x00,0x03,0xFF,0xE0,0xFF,0xFF,0xFF,0xF8,0x7E,  
            0x00,0x00,0x7F,0xFF,0xE0,0xFF,0xF8,0x00,0x03,0xFF,0xE0,0xFF,0xFF,0xFF,0xF8,0x00,  
            0x00,0x00,0x7F,0xFF,0xE0,0x7F,0xFC,0x00,0x07,0xFF,0xC1,0xFF,0xFF,0xFF,0xFC,0x00,  
            0x00,0x00,0xFF,0xFF,0xF0,0x7F,0xFC,0x00,0x07,0xFF,0xC1,0xFF,0xFF,0xFF,0xFC,0x00,  
            0x00,0x00,0xFF,0xFF,0xF0,0x7F,0xFE,0x00,0x0F,0xFF,0x83,0xFF,0xFF,0xFF,0xFE,0x00,  
            0x00,0x01,0xFF,0xFF,0xF8,0x3F,0xFE,0x00,0x0F,0xFF,0x83,0xFF,0xE0,0x7F,0xFE,0x00,  
            0x00,0x01,0xFF,0xFF,0xF8,0x3F,0xFE,0x00,0x1F,0xFF,0x07,0xFF,0xC0,0x3F,0xFE,0x00,  
            0x00,0x03,0xFF,0xFF,0xF8,0x3F,0xFF,0x00,0x1F,0xFF,0x07,0xFF,0xC0,0x3F,0xFE,0x00,  
            0x00,0x03,0xFF,0xFF,0xFC,0x1F,0xFF,0x00,0x1F,0xFE,0x07,0xFF,0xC0,0x3F,0xFE,0x00,  
            0x00,0x03,0xFF,0xFF,0xFC,0x1F,0xFF,0x80,0x3F,0xFE,0x0F,0xFF,0x80,0x3F,0xFE,0x00,  
            0x00,0x07,0xFF,0xFF,0xFE,0x0F,0xFF,0x80,0x3F,0xFE,0x0F,0xFF,0x80,0x3F,0xFE,0x00,  
            0x00,0x07,0xFF,0x9F,0xFE,0x0F,0xFF,0x80,0x7F,0xFC,0x1F,0xFF,0x00,0x7F,0xFE,0x00,  
            0x00,0x07,0xFF,0x9F,0xFF,0x07,0xFF,0xC0,0x7F,0xFC,0x1F,0xFF,0x00,0xFF,0xFC,0x00,  
            0x00,0x0F,0xFF,0x8F,0xFF,0x07,0xFF,0xC0,0x7F,0xF8,0x1F,0xFF,0x01,0xFF,0xFC,0x00,  
            0x00,0x0F,0xFF,0x0F,0xFF,0x03,0xFF,0xC0,0xFF,0xF8,0x3F,0xFF,0xFF,0xFF,0xF8,0x00,  
            0x00,0x0F,0xFF,0x0F,0xFF,0x83,0xFF,0xE0,0xFF,0xF8,0x3F,0xFF,0xFF,0xFF,0xF8,0x00,  
            0x00,0x1F,0xFF,0x07,0xFF,0x83,0xFF,0xE1,0xFF,0xF0,0x7F,0xFF,0xFF,0xFF,0xF0,0x00,  
            0x00,0x1F,0xFE,0x07,0xFF,0xC1,0xFF,0xF1,0xFF,0xF0,0x7F,0xFF,0xFF,0xFF,0xE0,0x00,  
            0x00,0x3F,0xFE,0x07,0xFF,0xC1,0xFF,0xF3,0xFF,0xE0,0x7F,0xFF,0xFF,0xFF,0xC0,0x00,  
            0x00,0x3F,0xFE,0x03,0xFF,0xC0,0xFF,0xFB,0xFF,0xE0,0xFF,0xFF,0xFF,0xFF,0x80,0x00,  
            0x00,0x7F,0xFC,0x03,0xFF,0xE0,0xFF,0xFB,0xFF,0xC0,0xFF,0xFF,0xFF,0xFF,0x00,0x00,  
            0x00,0x7F,0xFC,0x03,0xFF,0xE0,0x7F,0xFF,0xFF,0xC1,0xFF,0xFF,0xFF,0xFC,0x00,0x00,  
            0x00,0x7F,0xF8,0x01,0xFF,0xF0,0x7F,0xFF,0xFF,0x81,0xFF,0xFF,0xFF,0xE0,0x00,0x00,  
            0x00,0xFF,0xFF,0xFF,0xFF,0xF8,0x3F,0xFF,0xFF,0x83,0xFF,0xFF,0xFF,0xC0,0x00,0x00,  
            0x00,0xFF,0xFF,0xFF,0xFF,0xF8,0x3F,0xFF,0xFF,0x83,0xFF,0xF3,0xFF,0xC0,0x00,0x00,  
            0x00,0xFF,0xFF,0xFF,0xFF,0xF8,0x3F,0xFF,0xFF,0x03,0xFF,0xE3,0xFF,0xE0,0x00,0x00,  
            0x01,0xFF,0xFF,0xFF,0xFF,0xFC,0x1F,0xFF,0xFF,0x07,0xFF,0xE3,0xFF,0xE0,0x00,0x00,  
            0x01,0xFF,0xFF,0xFF,0xFF,0xFC,0x1F,0xFF,0xFE,0x07,0xFF,0xC3,0xFF,0xE0,0x00,0x00,  
            0x03,0xFF,0xFF,0xFF,0xFF,0xFE,0x1F,0xFF,0xFE,0x0F,0xFF,0xC1,0xFF,0xF0,0x00,0x00,  
            0x03,0xFF,0xFF,0xFF,0xFF,0xFE,0x0F,0xFF,0xFE,0x0F,0xFF,0x81,0xFF,0xF0,0x00,0x00,  
            0x03,0xFF,0xFF,0xFF,0xFF,0xFE,0x0F,0xFF,0xFC,0x0F,0xFF,0x81,0xFF,0xF8,0x00,0x00,  
            0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0xFF,0xFC,0x1F,0xFF,0x81,0xFF,0xF8,0x00,0x00,  
            0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0xFF,0xF8,0x3F,0xFF,0x00,0xFF,0xF8,0x00,0x00,  
            0x0F,0xFF,0xC0,0x00,0x1F,0xFF,0x83,0xFF,0xF8,0x3F,0xFF,0x00,0xFF,0xF8,0x00,0x00,  
            0x0F,0xFF,0x80,0x00,0x0F,0xFF,0x83,0xFF,0xF0,0x3F,0xFE,0x00,0xFF,0xFC,0x00,0x00,  
            0x0F,0xFF,0x80,0x00,0x0F,0xFF,0xC3,0xFF,0xF0,0x7F,0xFE,0x00,0x7F,0xFC,0x00,0x00,  
            0x1F,0xFF,0x00,0x00,0x0F,0xFF,0xC1,0xFF,0xF0,0x7F,0xFC,0x00,0x7F,0xFC,0x00,0x00,  
            0x1F,0xFF,0x00,0x00,0x07,0xFF,0xC1,0xFF,0xE0,0x7F,0xFC,0x00,0x7F,0xFE,0x00,0x00,  
            0x1F,0xFF,0x00,0x00,0x07,0xFF,0xE0,0xFF,0xE0,0xFF,0xF8,0x00,0x7F,0xFE,0x00,0x00,  
            0x3F,0xFE,0x00,0x00,0x03,0xFF,0xE0,0xFF,0xC0,0xFF,0xF8,0x00,0x3F,0xFE,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00  
            };  
              
            /********************************************************************/  
              
            void main()  
            {  
                uchar i = 0;  
                PORTB = 0XFF;           //  
                DDRB = 0XFF;            //PB口全部設為輸出模式  
                Clr_CS();  
                Clr_SID();  
                Clr_SCLK();  
                LCD_Init();  
                Delay(50);  
                LCD_Init();             //初始化兩邊是關鍵,否則液晶上電重起將不能顯示  
                while(1)  
                {     
                    nop();  
                    nop();  
                    Delay(500);  
                    Char_Set_XY(0,0,"ST7920_3_wires");  
                    Char_Set_XY(2,1,"反白練習");  
                    Char_Set_XY(0,2,"可以單字反白或不");  
                    Char_Set_XY(3,3,"反白");  
                    Delay(2000);  
                    Delay(2000);  
                    Set_Draw();  
                    Delay(100);  
                    Set_White(1,1,7,0);         //第1行,第1個漢字位置到第8漢字位置反白  
                    Set_White(3,2,6,0);         //第2行,第3個漢字位置到第6漢字位置反白  
                    Set_White(1,3,8,0);         //第3行,第1個漢字位置到第8漢字位置反白  
                    Set_White(4,4,5,0);         //第4行,第4個漢字位置到第5漢字位置反白  
                    Delay(2000);  
                    Delay(2000);  
                    Set_White(4,1,4,1);         //第1行,第4個漢字位置等取消反白  
                    Set_White(5,2,5,1);         //第2行,第5個漢字位置等取消反白  
                    Set_White(6,3,6,1);         //第3行,第6個漢字位置等取消反白  
                    Set_White(4,4,4,1);         //第4行,第4個漢字位置等取消反白  
                    Delay(2000);  
                    Delay(2000);  
                    Set_White(1,1,1,1);         //  
                    Set_White(3,2,3,1);         //  
                    Set_White(2,3,2,1);         //  
                    Set_White(5,4,5,1);         //  
                    Delay(2000);  
                    Delay(2000);  
                    Set_White(1,1,8,1);         //第1行,第1個漢字位置到第8漢字位置取消反白  
                    Set_White(1,2,8,1);         //第2行,第1個漢字位置到第8漢字位置取消反白  
                    Set_White(1,3,8,1);         //第3行,第1個漢字位置到第8漢字位置取消反白  
                    Set_White(1,4,8,1);         //第4行,第1個漢字位置到第8漢字位置取消反白  
                      
                    Delay(2000);  
                    Delay(2000);  
                    W_1byte(0,0,0x30);      //基本指令集,,繪圖顯示OFF  
                    W_1byte(0,0,0x01);      //清除顯示  
                    W_1byte(0,0,0x01);      //清除顯示  
                    W_1byte(0,0,0x01);      //清除顯示  
                    Set_Draw();  
                    Delay(100);  
                    Draw_Pic(0,0,*PIC1);    //先替換液晶內部RAM中的數據,再開顯示  
                    W_1byte(0,0,0x36);      //8BIT控制界面,擴充指令集,,繪圖顯示ON  
                    Delay(5000);  
                    W_1byte(0,0,0x34);      //繪圖顯示OFF,主要解決畫圖時拖尾的現象,即先  
                                            //替換好液晶內部RAM中的數據在開顯示。                                     
                    Draw_Pic(0,0,*PIC2);  
                    W_1byte(0,0,0x36);      //8BIT控制界面,擴充指令集,繪圖顯示ON  
                    Delay(5000);  
                                            //畫完圖后要顯示文字要重新設置成普通模式     
                    W_1byte(0,0,0x30);      //基本指令集,,繪圖顯示OFF  
                    W_1byte(0,0,0x01);      //清除顯示  
                      
                }  
            }  
            /******************************************************************/  
            void LCD_Init(void)  
            {  
                uchar cmd;  
                cmd=0x30;           //功能設置 8位數據,基本指令  
                W_1byte(0,0,cmd);  
                Delay(2);  
                cmd=0x0C;           //顯示狀態 ON,游標OFF,反白OFF  
                W_1byte(0,0,cmd);   //寫指令  
                Delay(2);  
                cmd=0x01;           //清除顯示  
                W_1byte(0,0,cmd);   //寫指令  
                Delay(2);  
                cmd=0x02;           //地址歸位  
                W_1byte(0,0,cmd);   //寫指令  
                Delay(2);  
                cmd=0x80;           //設置DDRAM地址  
                W_1byte(0,0,cmd);   //寫指令  
                Delay(2);           //延時  
            }  
            /******************************************************************* 
            函 數 名:W_1byte 
            入口參數:RW、RS、W_data 
            出口參數:無 
            建立日期:2007年3月3日 
            修改日期: 
            函數作用:寫一個字節的數據到12864液晶,包括指令和數據 
            說    明:RW=1,從液晶讀數據到MCU;RW=0,寫一個數據到液晶; 
                     (一般RW都設為0,即只向液晶寫數據,不讀數據) 
                      RS=1,寫入的是數據;RS=0,寫入的是指令; 
                      一般模式:RW=0,RS=1;寫數據 
                                RW=0,RS=0;寫指令 
            ********************************************************************/  
            void W_1byte(uchar RW, uchar RS, uchar W_data)  
            {  
                uint H_data,L_data,S_ID = 0xf8;  //11111RWRS0  
                if(RW == 0)  
                {  
                    S_ID &=~ 0x04;  
                }  
                else                    //if(RW==1)  
                {  
                    S_ID |= 0X04;  
                }  
                if(RS == 0)  
                {  
                    S_ID &=~ 0x02;  
                }  
                else                    //if(RS==1)  
                {  
                    S_ID |= 0X02;  
                }  
                H_data = W_data;  
                H_data &= 0xf0;         //屏蔽低4位的數據  
                L_data = W_data;        //xxxx0000格式  
                L_data &= 0x0f;         //屏蔽高4位的數據  
                L_data <<= 4;         //xxxx0000格式  
                Set_CS();  
                Write_8bits(S_ID);      //發送S_ID  
                Write_8bits(H_data);    //發送H_data  
                Write_8bits(L_data);    //發送L_data  
                Clr_CS();     
            }  
            /******************************************************************** 
            函 數 名:Write_8bits 
            入口參數:W_bits 
            出口參數:無 
            建立日期:2007年3月3日 
            修改日期: 
            函數作用:負責串行輸出8個bit位 
            說    明: 
            ********************************************************************/  
            void Write_8bits(uint W_bits)  
            {  
                uint i,Temp_data;  
                for(i=0; i<8; i++)  
                {  
                    Temp_data = W_bits;  
                    Temp_data <<= i;  
                    if((Temp_data&0x80)==0)  
                    {  
                        Clr_SID();  
                    }  
                    else  
                    {  
                        Set_SID();  
                    }   
                    nop();  
                    Set_SCLK();  
                    nop();  
                    nop();  
                    Clr_SCLK();  
                    nop();  
                    Clr_SID();  
                }  
            }  
            /******************************************************************** 
            函 數 名:Delay 
            入口參數:ms 
            出口參數:無 
            建立日期:2007年3月3日 
            修改日期: 
            函數作用:毫秒級的延時程序,當晶振為12Mhz時,xtal=12; 
            說    明: 
            ********************************************************************/  
            void Delay(uint ms)   
            {   
                uint i;   
                while(ms--)      
               {   
                 for(i=1;i<(uint)(xtal*143-2);i++)   
                     ;   
               }     
            }  
            //===================================================================*/  
            /******************************************************************** 
            函 數 名:Char_Set_XY 
            入口參數:x,y,*p 
            出口參數:無 
            建立日期:2007年8月26日 
            修改日期: 
            函數作用: 
            說    明: 
            ********************************************************************/  
            void Char_Set_XY(uchar x, uchar y, uchar *p)   
            {   
                 if(y == 0)  
                {  
                    W_1byte(0,0,(0x80+x));    
                }  
                if(y == 1)  
                {  
                    W_1byte(0,0,(0x90+x));  
                }  
                if(y == 2)  
                {  
                    W_1byte(0,0,(0x88+x));  
                }  
                if(y == 3)  
                {  
                    W_1byte(0,0,(0x98+x));  
                }  
                while(*p != 0)  
                {  
                    W_1byte(0,1,*p++);  
                }  
            }  
            //===================================================================*/  
              
            /******************************************************************** 
            函 數 名:Set_Draw( 
            入口參數:無 
            出口參數:無 
            建立日期:2007年8月26日 
            修改日期: 
            函數作用: 
            說    明: 
            ********************************************************************/  
            void Set_Draw(void)  
            {  
                //W_1byte(0,0,0x01);            //清屏  
                Delay(20);                  //延時  
                //W_1byte(0,0,0x34);            //8BIT控制界面,擴充指令集,,繪圖顯示OFF  
                W_1byte(0,0,0x36);  
                Delay(20);                  //延時  
            }  
            //===================================================================*/  
            /******************************************************************** 
            函 數 名:Draw_Pic  128*64 
            入口參數:x,y,*Draw 
            出口參數:無 
            建立日期:2007年8月26日 
            修改日期: 
            函數作用: 
            說    明: 
            ********************************************************************/  
            /*************************************************/  
              
            void Draw_Pic(uchar x, uchar y, const uchar *Draw)  
            {  
                uchar i, j, temp_x, temp_y;     //  
                temp_x = x;                     //  
                temp_y = y;                     //  
                temp_x |= 0x80;                 //  
                temp_y |= 0x80;                 //  
                for(i=0;i<32;i++ )               //上半屏32行  
                {  
                    W_1byte(0,0,temp_y++);      //設置繪圖區的Y地址坐標0  
                    W_1byte(0,0,temp_x);        //設置繪圖區的X地址坐標0  
                    for(j=0;j<16;j++)            //  
                    {  
                         W_1byte(0,1,*Draw++);  //  
                    }  
                }  
                  
                temp_x = 0x88;                  //  
                temp_y = 0x80;                  //  
                j = 0;                          //  
                for(;i<64;i++ )  
                {  
                    W_1byte(0,0,temp_y++);      //設置繪圖區的Y地址坐標  
                    W_1byte(0,0,temp_x);        //設置繪圖區的X地址坐標  
                    for(j=0;j<16;j++)  
                    {  
                         W_1byte(0,1,*Draw++);  //  
                    }  
                }  
                   
            }  
            /**************************************************/  
            /**************************************************/  
            void Set_White(uchar x,uchar y,uchar end_x,uchar clear)  
            {  
                uchar i, j, white_x, white_y,white_end_x,clr_x,clr_y;       //  
                white_end_x = (end_x-x+1);  
                white_end_x <<= 1;  
                if(y==1)  
                {  
                    white_x = (0x80+x-1);  
                    white_y = 0x80;  
                    clr_x = 0x80;  
                    clr_y = 0x80;  
                }  
                else if(y==2)  
                {  
                    white_x = (0x80+x-1);  
                    white_y = 0x90;  
                    clr_x = 0x80;  
                    clr_y = 0x90;  
                }  
                else if(y==3)  
                {  
                    white_x = (0x88+x-1);  
                    white_y = 0x80;  
                    clr_x = 0x88;  
                    clr_y = 0x80;  
                }  
                else if(y==4)  
                {  
                    white_x = (0x88+x-1);  
                    white_y = 0x90;  
                    clr_x = 0x88;  
                    clr_y = 0x90;  
                }  
                if(clear==0)//要反白時,先將整行的液晶全部清成不反白(此處行指y)  
                {  
                    for(i=0;i<16;i++ )           //16行  
                    {  
                        W_1byte(0,0,clr_y++);   //設置繪圖區的Y地址坐標0  
                        W_1byte(0,0,clr_x);     //設置繪圖區的X地址坐標0  
                        for(j=0;j<16;j++)        //  
                        {  
                            W_1byte(0,1,0x00);  //清成不反白  
                            nop();  
                        }  
                    }  
                }  
                nop();  
                for(i=0;i<16;i++ )               //16行,因為是16*16漢字  
                {  
                    W_1byte(0,0,white_y++);     //設置繪圖區的Y地址坐標0  
                    W_1byte(0,0,white_x);       //設置繪圖區的X地址坐標0  
                    for(j=0;j<white_end_x;j++)   //  
                    {  
                         if(clear==1)  
                         {  
                            W_1byte(0,1,0x00); //取消這一行的8個點的反白,液晶地址自動加1  
                                               //(此處行指一個一個液晶點所組成的行)  
                         }  
                         else  
                         {  
                            W_1byte(0,1,0xff); //反白這一行的8個點,液晶地址自動加1  
                                               //(此處行指一個一個液晶點所組成的行)  
                         }  
                         nop();  
                    }  
                }  
            }  
            /*************************************************/

        關閉窗口

        相關文章

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