?? lcd_12864.txt
字號:
?
+
#include<lcd.h>
//復(fù)位函數(shù)實現(xiàn)
void rst_bit ()
{
RST = 0; //低電瓶有效
}
//延時子函數(shù)
void delay(uchar ms) ////number=1 延遲100ms
{
int i,j;
while(ms--)
{
for(i = 0; i <= OUTCOUNT; i++)
{
for(j = 0; j <= INCOUNT; j++)
{
}
}
}
}
//LCD初始化
void interlize(uchar model)
{
RST = 1;
_nop_();
if(model == PAR)
{
PSW = 1;
}
else
{
PSW = 0;
}
}
//檢測忙標志
void check_busy()
{
LCD_DATA = 0xff;
RS = 0; //開通寫指令
RW = 1; //讀取端口的狀態(tài)
E = 1; //開通讀寫信號
while(LCD_DATA &= 0x80);
E = 0;
}
//寫指令子函數(shù)
void write_code(uchar com)
{
check_busy();
RS = 0; //選擇寫數(shù)據(jù)
RW = 0; //寫操作
LCD_DATA = com;
E = 1;
_nop_();
_nop_();
E = 0;
}
//寫數(shù)據(jù)子函數(shù)
void write_data(uchar dat)
{
check_busy();
RS = 1;
RW = 0;
LCD_DATA = dat;
E = 1;
_nop_();
_nop_();
E = 0;
}
//取字符字符子函數(shù)
void take_data( uchar *Cdata/*字符串地址*/, uchar icount/*intalized 16*/,uchar com/*intalized lcd address*/,int i/*intalize 0*/)
{
write_code(com);
while(icount--)
{
if(Cdata != '\0')
{
write_data(Cdata[i++]);
delay(1);
}
else
{
return
}
}
}
//清屏子函數(shù)
void clc()
{
write_code(0x01);
write_code(0x34);
write_code(0x30);
}
//重新設(shè)置屏幕屬性換子函數(shù)
void flash()
{
write_code(0x08); //關(guān)閉顯示
delay(1);
write_code(0x0c); //開顯示關(guān)光標 不閃爍
delay(1);
write_code(0x08); //關(guān)顯示
delay(1);
write_code(0x0c); //關(guān)顯示 關(guān)光標 不閃爍
delay(1);
write_code(0x08); //關(guān)顯示
delay(1);
}
//圖形顯示子函數(shù)
void dis_grah()
{
}
//對點陣圖形清屏
void dis_dot(uchar send_data1, uchar send_data2, uchar LCD_X, uchar LCD_Y, uchar icount1, uchar icount2, uchar icount3, uchar flag)
{
write_code(0x01); //清屏
icount3 = 2;
write_code(LCD_X);
//
while(icount3--)
{
icount2 = 32;
flag = 0;
LCD_Y = 0x80;
while(icount2--)
{
icount1 = 16;
write_code(0x34);
write_code(LCD_Y);
write_code(LCD_X);
write_code(0x30);
if(flag == 0)
{
while(icount1--)
{
write_data(send_data1);
}
LCD_Y++;
flag = 1;
}
else
{
while(icount1--)
{
write_data(send_data2);
}
LCD_Y++;
flag = 0;
}
}
LCD_X = 0x88;
}
//
write_code(0x36);
write_code(0x30);
}
//畫水漆直線子函數(shù)
void draw_xline(uchar x, uchar y, uchar line_data, uchar icount)
{
write_code(0x34);
write_code(y);
delay(1);
write_code(x);
write_code(0x30);
while(icount--)
{
write_data(line_data);
//delay(1);
}
write_code(0x36);
write_code(0x30);
}
/********************************************
* 功能:整數(shù)到字符串的轉(zhuǎn)換
* 參數(shù):
* str --- 轉(zhuǎn)換串的存儲首地址
* n --- 待轉(zhuǎn)換的整數(shù)
* base -- 按不同的數(shù)制轉(zhuǎn)換,支持2,8,10,16
* 返回:
* 正常返回轉(zhuǎn)換后的字符串首地址
* 錯誤返回空指針
*********************************************/
/*uchar * Itoa(uchar * str, uint n, uchar base)
{
char * q = str;
char * p = str;
// 只接受 2、8、10、16 進制數(shù)
if(base != 2 && base != 8 && base != 10 && base != 16)
return NULL;
while(n > 0)
{
uint tmp = n % base;
if(tmp >= 10)
*p++ = tmp - 10 + 'A';
else
*p++ = tmp + '0';
n /= base;
}
*p-- = '\0';
// 按求余轉(zhuǎn)換的定義,需要將余數(shù)反序
while(q < p)
{
*p ^= *q ^= *p ^= *q;
++q;
--p;
}
return str;
}*/
//畫點子函數(shù)
void show_dot(uchar x, uchar y)
{
uchar line_data;
if (x <= 15)
{
if( x<= 7)
{
line_data = 0x80>>x;
draw_xline(0x80,0x90-y,line_data,1);
}
else
{
line_data = 0x01<<(15-x);
draw_xline(0x80,0x90-y,line_data,2);
draw_xline(0x80,0x90-y,0x00,1);
//line_data_two(0x00,0x01,0x80,0x90-y,0,0,0);
}
}
else if(x > 15 && x <= 31 )
{
if(x <= 23)
{
line_data = 0x01<<(23-x);
draw_xline(0x81,0x80+(8-(23-y)),line_data,1);
}
else
{
line_data = 0x01<<(31-x);
draw_xline(0x81,0x90-(31-y),line_data,2);
draw_xline(0x81,0x90-(31-y),0x00,1);
}
}
else if(x > 31 && x <= 47)
{
if(x <= 39)
{
line_data = 0x01<<(39-x);
draw_xline(0x92,0x90+(8-(39-x)),line_data,1);
}
else
{
line_data = 0x01<<(47-x);
draw_xline(0x92,0x9f-(47-y-1),line_data,2);
draw_xline(0x92,0x9f-(47-y-1),0x00,1);
}
}
else if(x > 47 && x <= 63)
{
if(x <= 55)
{
line_data = 0x01<<(55-x);
draw_xline(0x93,0x9f-(8-(55-x)-1),line_data,1);
}
else
{
line_data = 0x01<<(63-x);
draw_xline(0x93,0x90+(63-y),line_data,2);
draw_xline(0x93,0x90+(63-y),0x00,1);
}
}
}
//發(fā)送兩個8位數(shù)畫縣
/*void line_data_two(uchar send_data1, uchar send_data2, uchar LCD_X, uchar LCD_Y, uchar icount1, uchar icount2, uchar icount3, uchar flag)
{
write_code(0x01); //清屏
icount3 = 1;
write_code(LCD_X);
//
while(icount3--)
{
icount2 = 2;
flag = 0;
LCD_Y = 0x80;
while(icount2--)
{
icount1 = 1;
write_code(0x34);
write_code(LCD_Y);
write_code(LCD_X);
write_code(0x30);
if(flag == 0)
{
while(icount1--)
{
write_data(send_data1);
}
LCD_Y++;
flag = 1;
}
else
{
while(icount1--)
{
write_data(send_data2);
}
LCD_Y++;
flag = 0;
}
}
LCD_X = 0x88;
}
//
write_code(0x36);
write_code(0x30);
}*/
//////////////////////////////////////////////////////////////////////////////////////////////LCD.C結(jié)束
/*******************************************************************************
* 標題:1286 液晶驅(qū)動(控制器TS7920)
* 文件:lcd_12864_driver.h
* 日期:2005-8-26
* 版本:v.0
* 作者:辛萬江
/********************************************************************************/
// 描述:
// 采用并口方式控制數(shù)據(jù)輸入輸出
/********************************************************************************/
#ifndef LCD_12864_DRIVER
#include<reg51.h>
#include<intrins.h>
#include<STDIO.H>
#include<STRING.H>
#include <STDLIB.H>
#include <CTYPE.H>
#include <FLOAT.H>
//控制引腳定義
sbit RS = P2^0; //數(shù)據(jù)/指令選擇
sbit RW = P2^1; //讀寫選擇
sbit E = P2^2; //讀寫適鼓?
sbit PSB = P2^3; //選擇數(shù)據(jù)傳輸模式并口或串口高并低串
sbit RST = P2^5;
//數(shù)據(jù)線
#define LCD_DATA P0
//
#define uchar unsigned char
#define uint unsigned int
#define true 1 //忙標志
#define false 0 //閑標志
#define INCOUNT 10 //延時函數(shù)參數(shù)設(shè)置(注意所用的晶振?德剩?
#define OUTCOUNT 50 // 180
#define PAR 1 //并口模式
#define SER 0 //串口模式
/////////////////////////////////////////////////////////////////函數(shù)定義
//復(fù)位函數(shù)
void rst_bit();
//初始化函數(shù)
void interlize(uchar model);
//寫指令子函數(shù)
void write_code(uchar com);
//寫數(shù)據(jù)子函數(shù)
void write_data(uchar dat);
//忙判斷
void check_busy ();
//延時子函數(shù)
void delay(uchar ms);
//清屏子函數(shù)
void clc();
//顯示圖形子函數(shù)
void dis_grah();
//顯示數(shù)據(jù)子函數(shù)
void dis_char_mumber();
//取數(shù)據(jù)子函數(shù)
void take_data(uchar *Cdata/*字符串地址*/, uchar/**/icount, uchar com/**/,int i);
//重新設(shè)置屏幕屬性換子函數(shù)
void flash();
//顯示點陣子函數(shù)
void dis_dot(uchar send_data1, uchar send_data2, uchar LCD_X, uchar LCD_Y, uchar icount1, uchar icount2, uchar icount3, uchar flag);
//調(diào)用半腳字符顯示
void show_half_char();
//調(diào)用漢字字庫顯示
void show_chinse();
//畫橫直線子函數(shù)
void draw_xline(uchar x, uchar y, uchar line_data, uchar icount);
//整型轉(zhuǎn)蛔址?
uchar * Itoa(uchar * str, uint n, uchar base);
//畫點子函數(shù)
void show_dot(uchar x, uchar y);
//發(fā)送兩個8位數(shù)畫縣
/*void line_data_two(uchar send_data1, uchar send_data2, uchar LCD_X, uchar LCD_Y, uchar icount1, uchar icount2, uchar flag);*/
#endif
////////////////////////////////////////////////////////////////////////////////////LCD.H結(jié)束
///下面是我的測試程序
/*******************************************************************************
* 標題:1286 液晶驅(qū)動(控制器TS7920)
* 文件:lcd_12864_driver.h
* 日期:2005-8-26
* 版本:v.0
* 作者:辛萬江
/********************************************************************************/
// 描述:
// 采用并口方式控制數(shù)據(jù)輸入輸出
/********************************************************************************/
#include<lcd.c>
/////////////////////////////////////////////////////////////////////////////////
uchar TAB[12] = "顯示結(jié)果:";
uchar code TAB2[]= "X= ";
uchar code TAB3[]= " 121111 ";
uchar code TAB4[]= "犯得上法121 ";
uchar buffer[3];
uchar buffer1[5];
float i = 16.89;
int j = 0;
void *pf;
uchar *fd;
//int i = 16;
uchar x = 0;
uint count;
/////////////////////////////////////////////////////////////////////////////////
main()
{
///////////////////////////////////////////////////準備工作設(shè)定顯示方式
rst_bit();
delay(2); //延時兩微妙
interlize(1); //采用并口模式
write_code(0x34); //34h擴充功能設(shè)定
write_code(0x30); //30h基本操作指令
write_code(0x01); //01h清楚顯示指令
write_code(0x06); //06h指定在資料讀仁? ,光標的移動方向
write_code(0x0c); //0ch開顯示,關(guān)光標,不閃爍
////////////////////////////////////////////////////準備工作完畢
//顯示漢字和字符
clc();
//點陣清屏
dis_dot(0x00,0x00,0x80,0x80,0,0,0,0);
//Itoa(temp, i, 10);
//strcat(TAB1,temp);
//char buffer[3];
//將FLOAT轉(zhuǎn)化為字符
fd = buffer1;
pf = &i;
for(j = 0 j < 4; j++)
{
*(fd+j) = *((char *)pf+j);
}
//sprintf(buffer, "%f", i);
buffer1[4] = '\0';
strcat(TAB,buffer1);
take_data(TAB,16,0x88,0);
//sprintf(TAB1 + 4, "%d",i);
//TAB1[6]='\0'
for(x = 0; x < 64; x++)
show_dot(x,x);
draw_xline(0x90,0x90,0xff,16);
//draw_xline(0x9f,0x9f,0xff,16);
//draw_xline(0x80,0x80,0xff,16);
//draw_xline(0x9f-18,0x80,0xff,16);
while(1);
}
//////////////////////////////////////////////////////////////////////////main結(jié)束
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -