- /**********************TS-51A單片機開發板例程************************
- * Copyright (c) 2013,52探索 單片機開發板
- * All rights reserved
- *
- * 文件名稱:led.c
- * 功能描述:本程序驅動12864顯示一副圖片
- *
- * 當前版本:1.0
- * 作 者:52探索
- * 完成日期:2013-5-29
- *
- * 取代版本:無
- * 改進內容:無
- * 使用環境:TS-51A開發板 + STC89C52 + 11.0592M晶振 + Keil C51 V9.0
- * QQ : 10903659
- * QQ群 :336397723 336398729 336398900
- ******************************************************************/
- #include <reg51.h>
- #include <intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define LCD_data P0 //數據口
- #define delayNOP(); {_nop_();_nop_();_nop_();_nop_();};
- sbit LCD_RS = P2^0; //寄存器選擇輸入
- sbit LCD_RW = P2^1; //液晶讀/寫控制
- sbit LCD_EN = P2^2; //液晶使能控制
- sbit LCD_PSB = P2^3; //串/并方式控制
- unsigned char code zhu[]= //圖片代碼
- {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xD4,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x03,0x50,0x00,0x50,0x80,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x3C,0x04,0x00,0xA0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x40,0x01,0x0B,0x15,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x40,0x00,0x88,0x00,0x00,0x06,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x01,0x80,0x00,0x60,0x00,0x00,0x05,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x03,0x90,0x00,0x01,0xB6,0x36,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x00,0x01,0xFE,0x36,0x00,0x00,0x00,
- 0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x02,0x20,0x00,0x01,0xB6,0x36,0x00,0x00,0x00,
- 0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x02,0xA0,0x00,0x03,0x6F,0xFF,0x00,0x00,0x00,
- 0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x1D,0x00,0x00,0x00,0x00,0x2C,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0xC0,0x00,0x00,0x00,0x28,0x00,0x00,0x00,
- 0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0A,0x80,0x40,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x10,0x80,0x00,0x00,0x1F,0x08,0x47,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x01,0x20,0x00,0x00,0x3D,0x13,0x0C,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x08,0x10,0x00,0x00,0x27,0xA0,0x18,0x06,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x02,0x10,0x00,0x00,0x3F,0x80,0x38,0xC7,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x04,0x03,0xE0,0x00,0x33,0x90,0x3F,0xC7,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x03,0xB0,0x00,0x33,0x10,0x7F,0x87,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x08,0x24,0xF0,0x0C,0x0E,0x00,0xFF,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x07,0xF0,0xC2,0x00,0x00,0xFE,0x1F,0x81,0xB3,0xE6,0xD8,0xF0,0x00,
- 0x00,0x00,0x08,0x46,0x71,0x06,0x00,0x08,0x3F,0x1F,0x01,0xF6,0x67,0xF9,0xB0,0x00,
- 0x00,0x00,0x00,0x03,0x20,0x98,0x00,0x00,0x3F,0xFF,0x01,0xB6,0xC6,0xD9,0x80,0x00,
- 0x00,0x00,0x08,0x40,0xC0,0x24,0x00,0x04,0x3F,0x1F,0x03,0x7F,0xFD,0xBE,0xFC,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x1E,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x01,0x0E,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x87,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x02,0x08,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x88,0x00,0x01,0x8C,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x01,0x8E,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x01,0x00,0x00,0x01,0xB6,0x06,0xDB,0x6C,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0x06,0xDB,0x6C,0x00,
- 0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x40,0x00,0x01,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x94,0xA4,0x68,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x02,0x19,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x42,0x00,0x10,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x20,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x14,0x00,0x0A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- };
- /*
- * 功 能:11.0592M 下 延時1毫秒
- * 參 數:要延時的毫秒數
- * 返回值:無
- */
- void delay(unsigned int ms)
- {
- while(ms--)
- {
- unsigned char i;
- for(i=0; i<250; i++)
- {
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- }
- }
- }
- /*
- * 功 能:檢查LCD12864是否忙
- * 參 數:無
- * 返回值:返回1:LCD出于忙狀態
- */
- bit lcd_busy()
- {
- bit result;
- LCD_RS = 0;
- LCD_RW = 1;
- LCD_EN = 1;
- delayNOP();
- result = (bit)(P0&0x80);
- LCD_EN = 0;
- return(result);
- }
- /*
- * 功 能:寫指令到LCD
- * 參 數:要寫入的指令
- * 返回值:無
- */
- void lcd_wcmd(uchar cmd)
- {
- while(lcd_busy());
- LCD_RS = 0;
- LCD_RW = 0;
- LCD_EN = 0;
- _nop_();
- _nop_();
- P0 = cmd;
- delayNOP();
- LCD_EN = 1;
- delayNOP();
- LCD_EN = 0;
- }
- /*
- * 功 能:LCD寫數據
- * 參 數:要寫入的數據
- * 返回值:無
- */
- void lcd_wdat(uchar dat)
- {
- while(lcd_busy());
- LCD_RS = 1;
- LCD_RW = 0;
- LCD_EN = 0;
- P0 = dat;
- delayNOP();
- LCD_EN = 1;
- delayNOP();
- LCD_EN = 0;
- }
- /*
- * 功 能:LCD初始化
- * 參 數:無
- * 返回值:無
- */
- void lcd_init(void)
- {
- LCD_PSB = 1; //并口方式
- lcd_wcmd(0x34); //擴充指令操作
- delay(5);
- lcd_wcmd(0x30); //基本指令操作
- delay(5);
- lcd_wcmd(0x0C); //顯示開,關光標
- delay(5);
- lcd_wcmd(0x01); //清除LCD的顯示內容
- delay(5);
- }
- /*
- * 功 能:在整個液晶屏幕上畫圖
- * 參 數:圖片的點陣數據
- * 返回值:無
- */
- void Draw_PM(const unsigned char *ptr)
- {
- uchar i, j, k;
- lcd_wcmd(0x34); //打開擴展指令集
- i = 0x80;
-
- for(j=0; j<32; j++)
- {
- lcd_wcmd(i++);
- lcd_wcmd(0x80);
- for(k=0; k<16; k++)
- {
- lcd_wdat(*ptr++);
- }
- }
- i = 0x80;
- for(j=0; j<32; j++)
- {
- lcd_wcmd(i++);
- lcd_wcmd(0x88);
- for(k=0; k<16; k++)
- {
- lcd_wdat(*ptr++);
- }
- }
- lcd_wcmd(0x36); //打開繪圖顯示
- lcd_wcmd(0x30); //回到基本指令集
- }
- void main(void)
- {
-
- lcd_init(); //初始化LCD
- Draw_PM(zhu); //顯示可愛豬的圖片
- while(1);
- }
復制代碼
|