?? cm320240.h
字號:
#include <picture.h>
sbit lcd_rs=P3^7;
sbit lcd_wr=P3^6;
sbit lcd_rd=P1^0;
sbit lcd_cs1=P3^5;
sbit lcd_busy=P3^4;
sbit I_U=P1^1; // =high 測電壓; =low 測電流。初始狀態(tài)為 high
/*=========================================================================
函數(shù)功能:向DDRAM發(fā)送顯示數(shù)據(jù)
=========================================================================*/
void lcd_datawrite(unsigned char wrdata)
{
while(lcd_busy==1);
P2=wrdata;
lcd_cs1=0;
lcd_rd=1;
lcd_rs=1;
lcd_wr=0;
;
;
;
;
lcd_wr=1;
lcd_rs=1;
lcd_cs1=1;
}
/*========================================================================
函數(shù)功能:向緩存器發(fā)送指令
========================================================================*/
void lcd_regwr(unsigned char regnada)
{
DATA_BUS=regnada;
lcd_cs1=0;
lcd_rs=0;
lcd_wr=0;
;
;
;
;
lcd_wr=1;
lcd_rs=1;
lcd_cs1=1;
}
/*==============================================================================
函數(shù)功能:向緩存器指定地址寫入指令
==============================================================================*/
void LCD_CmdWrite(unsigned char rgname,unsigned char rgdata )
{
lcd_regwr(rgname);
lcd_regwr(rgdata);
}
/*================================================================================
函數(shù)功能:讀出指定緩存器數(shù)據(jù)
入口參數(shù):huancun_address 緩存器地址
出口參數(shù):huancun_R_data 緩存器地址里的數(shù)據(jù)
=================================================================================*/
unsigned char LCD_Cmd_Read(unsigned char huancun_address)
{
unsigned char huancun_R_data;
lcd_regwr(huancun_address);
DATA_BUS = 0xFF;
PRT2CF = 0x00;
lcd_cs1 = 0;
lcd_wr = 1;
lcd_rs = 0;
lcd_rd = 0;
huancun_R_data = DATA_BUS;
lcd_rd = 1;
lcd_rs = 1;
lcd_cs1 = 1;
PRT2CF = 0xFF;
return(huancun_R_data);
}
/*================================================================================
函數(shù)功能:讀出DDRAM位置數(shù)據(jù)
入口參數(shù):無
出口參數(shù):無
=================================================================================*/
unsigned char LCD_R_DDRAM(void)
{
unsigned char Data;
while(lcd_busy);
DATA_BUS = 0xFF;
PRT2CF = 0x00;
lcd_cs1 = 0;
lcd_rs = 1;
lcd_rd = 0;
Data = DATA_BUS;
lcd_rd = 1;
lcd_cs1 = 1;
PRT2CF = 0xFF;
return (Data);
}
/*=================================================================================
函數(shù)功能:坐標(biāo)
入口函數(shù):x,y屏幕絕對坐標(biāo)
出口函數(shù):無
=================================================================================*/
void LCD_C_XY(unsigned int x, unsigned int y)
{
LCD_CmdWrite(0x60, (x & 0x3f));
LCD_CmdWrite(0x70, (y & 0xff));
}
/*================================================================================
函數(shù)功能:寫字符串到DDRAM
入口參數(shù):address 首地址 X,Y坐標(biāo) ,mode 1正常 0反顯
出口參數(shù):無
================================================================================*/
void LCD_WString_DDRAM(unsigned char x,unsigned char y,bit mode,unsigned char *address)
{
LCD_CmdWrite(WCCR,0x69);
LCD_CmdWrite(0x00,0xCD); //進入文字模式
LCD_C_XY(x,y);
if(mode)
LCD_CmdWrite(0x10, 0xE9);
else
LCD_CmdWrite(0x10, 0xC8); //反顯
while(*address)
{
lcd_datawrite(*(address++));
}
}
/*================================================================================
函數(shù)功能:在屏幕任意坐標(biāo)畫一個點
入口參數(shù):PointX Pointy 屏幕坐標(biāo) Mode 1 點亮 0 熄滅
出口參數(shù):無
=================================================================================*/
LCD_Pixel(unsigned int PointX, unsigned int PointY,bit Mode)
{
unsigned char dat;
dat = LCD_Cmd_Read(0x00);
LCD_CmdWrite(0x00,dat&0xF7); //進入繪圖模式
LCD_C_XY((PointX/8),PointY);
dat = 0x80>>(PointX%8);
if(!Mode)
dat=((~dat)&LCD_R_DDRAM());
else
dat=(dat|LCD_R_DDRAM());
lcd_datawrite(dat); //送顯示數(shù)據(jù)
}
/*================================================================================
函數(shù)功能:畫水平一條虛線
================================================================================*/
void Draw_dashed(unsigned char x1,unsigned char y1,unsigned char x2)
{
unsigned int temp,i;
temp=x2-x1;
LCD_CmdWrite(WCCR,0x69);
LCD_CmdWrite(0x00,0xC5);
LCD_C_XY(x1,y1);
for(i=0;i<temp;i++)
lcd_datawrite(0x0F);
LCD_CmdWrite(0x00,0xCD);
}
/*================================================================================
函數(shù)功能:在屏幕任意坐標(biāo)畫一線段
入口參數(shù):
出口參數(shù):
=================================================================================*/
void Line( unsigned int x1,unsigned int y1, unsigned int x2, unsigned int y2,bit Mode)
{
unsigned int x,y;
double k,b;
if( abs(y1-y2) <= abs(x1-x2) ) // |k|<=1
{
k=(float)(y2-y1) / (float)(x2-x1) ;
b=y1-k*x1;
if( x1 <= x2 )
{
for(x=x1;x<=x2;x++)
{
y=k*x+b;
LCD_Pixel(x, y, Mode);
}
}
else
{
for(x=x2;x<=x1;x++)
{y=k*x+b;
LCD_Pixel(x, y, Mode);
}
}
}
else // abs(y1-y2) > abs(x1-x2) |K|>1
{
k=(float)(x2-x1) / (float)(y2-y1) ;
b=x1-k*y1;
if( y1 <= y2 )
{
for(y=y1;y<=y2;y++)
{x=k*y+b;
LCD_Pixel( x , y,Mode );
}
}
else
{
for(y=y2;y<=y1;y++)
{x=k*y+b;
LCD_Pixel( x , y,Mode );
}
}
}
}
/*===============================================================================
函數(shù)功能:在屏幕上顯示一副圖片
入口函數(shù):(x,y)坐標(biāo) width 圖片寬度,以字節(jié)為單位 0~40 high 圖片高度 0~240 address 圖片首址
出口函數(shù):
===============================================================================*/
void LCD_Display_PIC(unsigned char x,unsigned char y,unsigned char width,unsigned char high,unsigned char *address)
{
unsigned char W_variable,H_variable;
LCD_CmdWrite(WLCR, 0xC5); //進入圖形模式
LCD_CmdWrite(WCCR, 0x69); //光標(biāo)禁止自動移位
for(H_variable=0;H_variable<high;H_variable++)
for(W_variable=0;W_variable<width;W_variable++)
{
LCD_C_XY(x+W_variable,y+H_variable);
lcd_datawrite(*(address++));
}
LCD_CmdWrite(0x00, 0xCD);
}
/*==============================================================================
函數(shù)功能:特殊字符顯示
入口參數(shù):SIZE 大小 WIDE 1加粗 0 正常 address 首址
出口參數(shù):無 size 00 1倍 05 2倍 0A 3倍 0f 4倍
==============================================================================*/
void special_char_Dis(unsigned char x,unsigned char y,unsigned char size,unsigned char *address)
{
LCD_CmdWrite(0x00, 0xCD); //進入文字模式
LCD_CmdWrite(0x10, 0xE9); //字符加粗
LCD_CmdWrite(0xF1, size<<4); //字符放大
LCD_C_XY(x,y);
while(*address)
{
lcd_datawrite(*(address++));
}
LCD_CmdWrite(WCCR, 0x69);
}
/*===============================================================================
函數(shù)功能:自動添充全屏
入口函數(shù):無
出口函數(shù):無
================================================================================*/
void LCD_FillOn(void)
{
unsigned char temp;
temp = LCD_Cmd_Read(FNCR);
temp |= cSetb3;
LCD_CmdWrite(FNCR, temp);
}
/*================================================================================
函數(shù)功能:清屏
入口參數(shù):huancun_address 緩存器地址,huancun_data 將要寫入緩存器指定地址的數(shù)據(jù)
出口參數(shù):無
=================================================================================*/
void LCD_Clear(void)
{
LCD_CmdWrite(PNTR, 0x00);
LCD_FillOn();
delay(1000);
}
/*================================================================================
函數(shù)功能:清除屏幕任意區(qū)域
================================================================================*/
void Clear_Screen(unsigned char x,unsigned char y,unsigned char width,unsigned char high)
{
unsigned char W_variable,H_variable;
LCD_CmdWrite(WLCR, 0xC5); //進入圖形模式
LCD_CmdWrite(WCCR, 0x69); //光標(biāo)禁止自動移位
for(H_variable=0;H_variable<high;H_variable++)
for(W_variable=0;W_variable<width;W_variable++)
{
LCD_C_XY(x+W_variable,y+H_variable);
lcd_datawrite(0x00);
}
LCD_CmdWrite(WLCR, 0xCD); //進入圖形模式
LCD_CmdWrite(WCCR, 0x69); //光標(biāo)禁止自動移位
}
/*================================================================================
函數(shù)功能:LCD初始化
入口參數(shù):無
出口參數(shù):無
=================================================================================*/
void LCD_Initial(void)
{
lcd_busy = 0;
LCD_CmdWrite(WLCR, 0xC9); //Normal Power
LCD_CmdWrite(MISC, 0xF2); //8Mhz 1基準(zhǔn) 0x13
LCD_CmdWrite(0x02, 0x10);
LCD_CmdWrite(0x03, 0x80);
LCD_CmdWrite(WCCR, 0x6B); //光標(biāo)不自動移位,中英文字對齊 0x61
LCD_CmdWrite(0x11, 0x22);
LCD_CmdWrite(0x12, 0x91);
LCD_CmdWrite(AWRR, cAWRR); //設(shè)定工作窗口右邊位置 39
LCD_CmdWrite(AWBR, cAWBR); //設(shè)定工作窗口底邊位置 239
LCD_CmdWrite(AWLR, 0x00); //設(shè)定工作窗口左位置 0
LCD_CmdWrite(AWTR, 0x00); //設(shè)定工作窗口頂位置 0
LCD_CmdWrite(DWRR, cDWRR); //設(shè)定顯示窗口右邊位置 39
LCD_CmdWrite(DWBR, cDWBR); //設(shè)定顯示窗口底邊位置 239
LCD_CmdWrite(DWLR, 0x00); //設(shè)定顯示窗口左邊位置 0
LCD_CmdWrite(DWTR, 0x00); //設(shè)定顯示窗口頂邊位置0
LCD_CmdWrite(0x60, 0x00);
LCD_CmdWrite(0x61, 0x00);
LCD_CmdWrite(0x70, 0x00);
LCD_CmdWrite(0x71, 0x00);
LCD_CmdWrite(0x72, 0x00);
LCD_CmdWrite(0x80, 0x33);
LCD_CmdWrite(0x81, 0x00);
LCD_CmdWrite(0x91, 0x00);
LCD_CmdWrite(0x90, 0x04);
LCD_CmdWrite(0xA0, 0x00);
LCD_CmdWrite(0xA1, 0x00);
LCD_CmdWrite(0xA2, 0x00);
LCD_CmdWrite(0xA3, 0x00);
LCD_CmdWrite(0xB0, 0x27);
LCD_CmdWrite(0xB1, 0xEF);
LCD_CmdWrite(0xC0, 0x00);
LCD_CmdWrite(0xE0, 0x00);
LCD_CmdWrite(0xF0, 0xE8);
LCD_CmdWrite(0xF1, 0x0F);
LCD_Clear();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -