?? lcd.h
字號:
#include <msp430x24x.h>
#define uchar unsigned char
#define BIT(x) (1<<(x))
#define Lcd_Bus_OUT P4OUT //MCU P4<--信號-->LCM
#define Lcd_Bus_IN P4IN //MCU P4<--信號-->LCM
#define LCD_DIR P4DIR //P4口的輸入輸出方向
#define CPORT P5OUT //控制端
#define RS 2 //并行的指令/數(shù)據(jù)選擇信號;串行的片選信號
#define RW 1 //并行的讀/寫選擇信號;串行的數(shù)據(jù)口
#define E 0 //并行的使能信號;串行同步時鐘
unsigned char Command;//狀態(tài)
unsigned char LCDData;//數(shù)據(jù)
unsigned char COUNT3,COUNT2,COUNT1,COUNT,LCD_X,LCD_Y;
unsigned char temp;
unsigned char clear[]={
/*-- 調(diào)入了一幅圖像128×64清空圖像ROM*/
/*-- 寬度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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
unsigned char t[]={
/*-- 調(diào)入了一幅圖像:D:\My Documents\單片機實驗\C語言\有用程序\工業(yè)手機串口通訊實驗\第2步.工業(yè)手機串口通訊實驗實現(xiàn)圖形顯示\小人.bmp --*/
/*-- 寬度x高度=128x64 橫向取模 左邊圖片 --*/
0x02,0xAA,0xAA,0x00,0x00,0x00,0x00,0x00,0x0D,0x55,0x54,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x05,0x40,0x10,0x00,0x00,0x00,0x20,0x00,0x03,0x80,0x60,0x00,0x00,0x00,
0x22,0xAA,0xA1,0xC0,0x70,0x00,0x00,0x00,0x27,0xFF,0xE3,0xC1,0xC0,0x00,0x00,0x00,
0x27,0xFF,0xF1,0xC1,0x80,0x40,0x00,0x00,0x27,0x7F,0xE3,0xC7,0x01,0x80,0x00,0x00,
0x06,0x3F,0xF1,0xC7,0x01,0xC1,0x00,0x00,0x27,0x3F,0xE3,0xC7,0x07,0x07,0x00,0x00,
0x23,0xFF,0xF1,0xC7,0x07,0x16,0x14,0x00,0x27,0xFF,0xE3,0xC7,0x07,0x1C,0x18,0x00,
0x23,0xFF,0xF1,0xC7,0x07,0x0E,0x0C,0x50,0x27,0xFF,0xE3,0xC7,0x07,0x06,0x00,0xE0,
0x27,0xFF,0xF1,0xC7,0x03,0x43,0x00,0x70,0x27,0x55,0x43,0xC7,0x01,0x80,0x00,0xF0,
0x21,0x00,0x01,0xC5,0x80,0xC0,0x00,0x70,0x20,0x00,0x01,0xC1,0x80,0x00,0x00,0xF0,
0x1F,0xFF,0xFF,0xE0,0xD0,0x00,0x00,0x78,0x3F,0xFF,0xFF,0x70,0x60,0x00,0x35,0xF8,
0x15,0x55,0x55,0x70,0x30,0x00,0x00,0x3C,0x00,0x00,0x00,0xF0,0x00,0x00,0x80,0x3C,
0x80,0x00,0x00,0x70,0x00,0x00,0x40,0x1C,0x00,0x01,0xF8,0xF0,0x00,0x00,0xA5,0x3C,
0x80,0x80,0xFC,0x70,0x00,0x00,0x5F,0x5C,0x49,0x24,0xA8,0xE0,0x00,0x00,0xBF,0x3C,
0xBF,0xFF,0xFF,0xF0,0x00,0x00,0x5F,0x9C,0x7F,0xFF,0xFF,0x80,0x00,0x00,0x80,0x3C,
0x3F,0xFF,0xFF,0xC0,0x00,0x00,0x75,0xDC,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xDC,
0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xDC,0x00,0x00,0x00,0x00,0x00,0x00,0xF1,0xDC,
0x00,0x00,0x00,0x00,0x00,0x00,0x7D,0xDC,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xDC,
0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xDC,0x00,0xD5,0x55,0x40,0x00,0x00,0xB3,0x3C,
0x00,0x00,0x00,0x54,0x00,0x00,0x8C,0xDC,0x02,0x00,0x00,0x38,0x00,0x00,0x9D,0xDC,
0x02,0x2D,0x55,0x1C,0x00,0x00,0x9A,0xDC,0x02,0x7F,0xFE,0x3C,0x00,0x00,0xAA,0xBC,
0x00,0x7F,0xFF,0x1C,0x00,0x00,0x4C,0xDC,0x02,0x73,0xFE,0x3C,0x00,0x00,0x9D,0xDC,
0x02,0x71,0x06,0x1C,0x00,0x00,0x4A,0xDC,0x02,0x73,0xFC,0x3C,0x00,0x00,0xA9,0x3C,
0x00,0x73,0xFF,0x1C,0x00,0x00,0xAE,0xDC,0x02,0x7B,0xFE,0x3C,0x00,0x00,0x99,0xDC,
0x02,0x3F,0xFD,0x1C,0x00,0x00,0x0C,0xDC,0x02,0x7B,0xFE,0x3C,0x00,0x00,0xC9,0x3C,
0x02,0x7A,0xAB,0x1C,0x00,0x00,0x3F,0xFC,0x02,0x75,0x54,0x3C,0x00,0x00,0x7F,0xE0,
0x02,0x30,0x00,0x1C,0x00,0x00,0x3F,0xF0,0x02,0x00,0x00,0x1C,0x00,0x00,0x00,0x70,
0x00,0xAD,0xDE,0xF8,0x10,0x10,0x20,0x30,0x01,0xFF,0xFF,0xE0,0x60,0x60,0x60,0x70,
0x05,0x77,0x77,0xF8,0x78,0x78,0x78,0x70,0x0E,0x66,0x67,0x39,0x99,0x99,0x9C,0x70,
0x0F,0x55,0x55,0x1C,0xCC,0xCC,0xCC,0xE0,0x3D,0x99,0x9C,0x9D,0xD9,0xD9,0xDC,0x80,
0x18,0xCC,0xCC,0x7B,0x87,0x87,0x8B,0xC0,0x80,0x00,0x02,0x76,0x06,0x06,0x06,0x00,
0x40,0x00,0x01,0xE3,0x03,0x03,0x03,0x00,0xA2,0x49,0x23,0xC0,0x00,0x00,0x00,0x00,
0x3F,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,
};
//延時子程序
void delay(unsigned int t)
{
unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<2;j++); //t*15 us
}
void busy()
{ unsigned char temp;
do{
LCD_DIR=0xff; //LCD數(shù)據(jù)端口為輸出狀態(tài)
delay(100);
Lcd_Bus_OUT=0xff;
LCD_DIR=0x00; //LCD數(shù)據(jù)端口為輸入狀態(tài)
CPORT|=BIT(E);
delay(50);
temp=Lcd_Bus_IN;
CPORT&=~BIT(E); //???
}while(temp&0x80); //Lcd_Bus&0x80
}
//寫指令代碼
void WriteCommand()
{
CPORT&=~BIT(RS); //RS=0;
CPORT|=BIT(RW); //rw=1;
busy();
CPORT&=~BIT(RW);
LCD_DIR=0xff; //設(shè)置為輸出
delay(100);
Lcd_Bus_OUT=Command; //寫指令
CPORT|=BIT(E);
CPORT&=~BIT(E);
}
//寫顯示數(shù)據(jù)
void WriteData(){
CPORT&=~BIT(RS);
CPORT|=BIT(RW);
busy();
CPORT|=BIT(RS);
CPORT&=~BIT(RW);
LCD_DIR=0xff; //設(shè)置為輸出
delay(100);
Lcd_Bus_OUT=LCDData;
CPORT|=BIT(E);
CPORT&=~BIT(E);
}
//初始化程序
void LCDInit()
{
delay(20);
Command=0x30;//選擇基本指令集
WriteCommand();
delay(10);
Command=0x30;//選擇8bit數(shù)據(jù)流
WriteCommand();
delay(5);
Command=0x0c;//開顯示(無游標.不反白)
WriteCommand();
delay(10);
Command=0x01;//清DDRAM,清顯示并設(shè)地址指針為00H
WriteCommand();
delay(10);
Command=0x06;//設(shè)定游標方向及顯示移位
WriteCommand();
delay(10);
}
//顯示字符串
void HZdisp(unsigned char *s)
{
while(*s!='\0')
{
LCDData=*s;
WriteData();
s++;
delay(200);
}
}
//LCD清屏
void clearLCD()
{
Command=0x01;
WriteCommand(); //清除顯示
Command=0x06;
WriteCommand();
delay(50);
}
//顯示漢字或字符
void Test(unsigned char *disdata,unsigned char coordinate,unsigned char rid) //數(shù)據(jù)和坐標,清屏與否
{
if(rid==1) clearLCD();
Command=coordinate;
WriteCommand(); //寫指令
HZdisp(disdata);
}
//設(shè)定圖片顯示地址
void address_set(unsigned char LCD_x,unsigned char LCD_y) //圖片的橫向和縱向地址
{
Command=0x36; //擴充指令集動作,繪圖ON;注意基本指令集動作中不能開繪圖
WriteCommand();
Command=LCD_y;
WriteCommand();
Command=LCD_x;
WriteCommand();
Command=0x30; //關(guān)繪圖
WriteCommand();
}
void Photoclear(const uchar *picture,unsigned char LCD_X,unsigned char LCD_Y)
{ uchar a,Line,Row,Byte;//共16(2位)大塊,每大塊共32(0-31)行,每次寫16字節(jié)的數(shù)據(jù)
Line=2; /*寫數(shù)據(jù)的格式如下:從左上角(0x80,0x80)開始,分為兩大塊,先寫第一大塊(0-8)的第0行的128(8×16,*/
Row=32; /*1次寫1個字(8位),共寫16次)個數(shù)據(jù),行號加1,列號不變,再寫0-8塊的第1行的128個數(shù)據(jù),依此類推*/
Byte=8; /*寫第二大塊時,列號加8,但行仍從第0行開始寫,即行地址要復(fù)原為原地址重復(fù)寫第一塊的過程寫第二大塊液晶*/
a=LCD_Y;
for (;Line!=0;Line--)
{ LCD_Y=a; //注意寫第二大塊時,列號加8,但行仍從第0行開始寫
Row=32;
for (;Row!=0;Row--)
{ Byte=8; //Byte=8,只寫左邊;Byte=16,寫整塊
address_set(LCD_X,LCD_Y);
for (;Byte!=0;Byte--)
{ LCDData=*picture++;
WriteData();
}
LCD_Y++;//列加1
}
LCD_X=0X88; //行以
}
Command=0x36; //開繪圖
WriteCommand();
Command=0x30;
WriteCommand(); //關(guān)繪圖
}
/* 圖片顯示 */
/*寫數(shù)據(jù)的格式如下:從左上角(0x80,0x80)開始,分為兩大塊,先寫第一大塊(0-8)的第0行的128(8×16,
1次寫1個字(8位),共寫16次)個數(shù)據(jù),行號加1,列號不變,再寫0-8塊的第1行的128個數(shù)據(jù),依此類推。寫第
二大塊時,列號加8,但仍從第0行開始寫,即行地址要復(fù)原為原地址重復(fù)寫第一塊的過程寫第二大塊液晶。
*/
void Photo(const uchar *picture,unsigned char LCD_X,unsigned char LCD_Y)
{ uchar a,Line,Row,Byte;//共16(2位)大塊,每大塊共32(0-31)行,每次寫16字節(jié)的數(shù)據(jù)
Line=2; /*寫數(shù)據(jù)的格式如下:從左上角(0x80,0x80)開始,分為兩大塊,先寫第一大塊(0-8)的第0行的128(8×16,*/
Row=32; /*1次寫1個字(8位),共寫16次)個數(shù)據(jù),行號加1,列號不變,再寫0-8塊的第1行的128個數(shù)據(jù),依此類推*/
Byte=8; /*寫第二大塊時,列號加8,但行仍從第0行開始寫,即行地址要復(fù)原為原地址重復(fù)寫第一塊的過程寫第二大塊液晶*/
a=LCD_Y;
for (;Line!=0;Line--)
{ LCD_Y=a; //注意寫第二大塊時,列號加8,但行仍從第0行開始寫
Row=32;
for (;Row!=0;Row--)
{ Byte=8; //Byte=8,只寫左邊;Byte=16,寫整塊
address_set(LCD_X,LCD_Y);
for (;Byte!=0;Byte--)
{ LCDData=*picture++;
WriteData();
}
LCD_Y++;//列加1
}
LCD_X=0X88; //行以
}
Command=0x36; //開繪圖
WriteCommand();
Command=0x30;
WriteCommand(); //關(guān)繪圖
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -