新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > XS128單片機實驗:諾基亞5110液晶顯示

        XS128單片機實驗:諾基亞5110液晶顯示

        作者: 時間:2016-12-01 來源:網絡 收藏
        /*********包含的頭文件*****************************/
        #include /* common defines and macros */
        #include "derivative.h" /* derivative-specific definitions */
        #include "WQ.h"
        #include "Font6_8.h"
        #include "Bitmap.h"
        #include "Font16_16.h"
        #include "Font8_16.h"
        /****************宏定義*****************************/
        #define SCLK PTM_PTM4
        #define SDIN PTM_PTM3
        #define LCD_DC PTM_PTM5
        #define LCD_CE PTM_PTM2
        #define LCD_RES PTM_PTM1
        #define LED PTM_PTM0
        /****************函數申明***************************/
        void LCD_int(void);
        void LCD_write_byte(uchar dt,uchar command);
        void LCD_write_char(uchar *font);
        void LCD_set_XY(uchar x,uchar y);
        void LCD_clear(void);
        /*1.**************************************************/
        // LCD_write_byte: 使用spi接口寫數據到LCD
        // 輸入參數:dt 寫入的數據
        // 使用I/o口模擬SPI總線通訊發送一個字節數據到LCD顯示
        // Command : 寫數據/命令選擇
        // Data : 2013、4、26
        /***************************************************/
        void LCD_write_byte(uchar dt,uchar command) {
        uchar i;
        LCD_CE=0; //使能LCD
        delay_us(40); //延時30us;
        if(command==0) //判斷發送數據還是發送命令
        LCD_DC=0;
        else
        LCD_DC=1;
        delay_us(40); //延時30us;


        for(i=0;i<8;i++){
        if(dt&0x80)
        SDIN=1; // 發送高位
        else
        SDIN=0;
        delay_us(40); //延時30us;
        SCLK=0;
        dt=dt<<1;
        SCLK=1;
        }
        LCD_CE=1; //關閉LCD
        }
        /*2.*************************************************/
        // 函 數 :LCD_set_xy
        // 功 能 :設置LCD坐標函數
        // 說 明 :x:橫坐標 Y縱坐標
        // Date: 2013/4/26
        /*************************************************/
        void LCD_set_XY(uchar x,uchar y){
        LCD_write_byte(0x40|y,0); //列 按位或設置y坐標
        LCD_write_byte(0x80|x,0); //行 按位或 設置x坐標
        }
        /*3.********************************************/
        // LCD_write_char() ;顯示英文字符
        // 輸入參數:C :顯示的字符
        // Date: 2013/4/26
        /********************************************/
        void LCD_write_char (uchar *font) {
        uint i;
        for(i=0;i<6;i++)
        LCD_write_byte(font[i],1);

        }
        /*4.*********************************************/
        //函數:LCD_clear
        // 功能:清屏
        // 參數:無
        // Date:2013/4/26
        /************************************************/
        void LCD_clear(void) {
        uint i;
        LCD_write_byte(0x0c,0);
        LCD_write_byte(0x80,0);
        for(i=0;i<504;i++) {
        LCD_write_byte(0,1);
        }
        }
        /*************************************************/
        // LCD_init: LCD初始化
        // 輸入參數無
        // Date :2013、4、26
        /************************************************/
        void LCD_int(void) {
        LCD_RES=0;
        delay_ms(2);
        LCD_RES=1;
        LCD_write_byte(0x21,0);//初始化LCD,功能設定使用擴充指令
        LCD_write_byte(0xd0,0);//設定液晶偏置電壓;
        LCD_write_byte(0x20,0);//使用基本指令
        LCD_write_byte(0x0c,0);//設定顯示模式,正常顯示
        }

        /****************************************************/
        // 主函數:void mian
        // 功 能:在諾基亞5110液晶屏上顯示字符
        // 作 者:wangqi
        // 時 間;2013、4、26
        /****************************************************/
        void main(){
        unsigned char A[6]={0x00,0x7c,0x12,0x11,0x12,0x7c};
        unsigned char B[6]={0x00,0x7f,0x49,0x49,0x49,0x36};
        DDRM = 0xFF;
        LCD_int();
        LCD_clear();
        LED=1;
        delay_s(5);
        LED=0;
        while(1){

        LCD_set_XY(0,1);
        LCD_write_char(A);
        delay_ms(100);
        LCD_set_XY(10,1);
        LCD_write_char(A);
        delay_ms(100);
        LCD_set_XY(0,3);
        LCD_write_char(B);
        delay_ms(100);
        LCD_set_XY(10,4) ;
        LCD_write_char(B);
        }
        }


        評論


        技術專區

        關閉
        主站蜘蛛池模板: 浮山县| 彭山县| 平昌县| 河北区| 高碑店市| 喀喇| 芜湖县| 视频| 东安县| 凤庆县| 富锦市| 都江堰市| 茌平县| 竹山县| 惠来县| 玛纳斯县| 揭阳市| 彭州市| 岐山县| 金平| 怀仁县| 阳高县| 宜兰县| 司法| 安康市| 资阳市| 松溪县| 昆山市| 青海省| 梁平县| 马边| 丁青县| 桐乡市| 荔浦县| 赤城县| 随州市| 彭州市| 永仁县| 合水县| 含山县| 夏邑县|