單片機源程序如下:
#include"reg52.h"
#include"math.h"
#include"intrins.h"
#include"function.h"
#define DB P0
sbit RS = P1^4;
sbit RW = P1^5;
sbit E = P1^6; void busy(void)//RS=0;RW=1;wait=0閑;wait!=0忙
{
uchar wait;
RS = 0;
RW = 1;
E = 1;
for(;;)
{
wait = DB;
wait &= 0x80;
if(wait == 0)break;
}
E = 0;
}
/************************************************************************************
寫指令函數
************************************************************************************/
void w_code(uchar c)//RS=0;RW=0;E下降沿
{
busy();
RS = 0;
RW = 0;
DB = c;
E = 1;
E = 0;
DB = 0xff;
}
/************************************************************************************
寫數據函數
************************************************************************************/
void w_data(uchar d)//RS=1;RW=0;E下降沿
{
busy();
RS = 1;
RW = 0;
DB = d;
E = 1;
E = 0;
DB = 0xff;
}
/************************************************************************************
讀數據函數
************************************************************************************/
uchar r_data(void)//RS=1;RW=1;E下降沿
{
uchar rd_lcd;
busy();
RS = 1;
RW = 1;
E = 1;
rd_lcd = DB;
E = 0;
return rd_lcd;
}
/************************************************************************************
寫DGRAM:x_lcd橫坐標,y_lcd縱坐標
************************************************************************************/
void address(uchar x_lcd,uchar y_lcd)//
{
w_code(y_lcd);//垂直坐標
w_code(x_lcd);//水平坐標
}
/************************************************************************************
初始化液晶屏
0:字庫 1:繪圖
************************************************************************************/
void lcd_rst(bit a)
{
if(a)
{
w_code(0x01);// 清屏
w_code(0x32);// 功能設置---8BIT控制界面,繪圖顯示ON
w_code(0x36);// 功能設置---8BIT控制界面,擴充指令集
}
else
{
w_code(0x30);// 功能設置---8BIT控制界面,基本指令集
w_code(0x0c);//顯示打開,光標關,反白顯示關
w_code(0x01);// 清除屏幕顯示,將DDRAM的地址計數器歸零
}
}
/************************************************************************************
---------------------------寫整屏點陣數據
---------------------------x :圖像數據的起始地址
************************************************************************************/
void write_lcd_full(uint x )
{
uchar i,j,a;
j = 0x80; //Y地址寄存器
for(a = 0;a < 32;a++)
{
w_code(j);
j++;
w_code(0x80);//X地址寄存器
for(i = 0;i < 16;i ++)
{
w_data(logo[x]);
x++;
}
}
j = 0x80; //Y地址寄存器
for(a = 0;a < 32;a++)
{
w_code(j);
j++;
w_code(0x88);//X地址寄存器
for(i = 0;i < 16;i ++)
{
w_data(logo[x]);
x++;
}
}
}
Keil代碼和原理圖下載:
Keil代碼.7z
(748.24 KB, 下載次數: 85)
2022-9-28 03:30 上傳
點擊文件名下載附件
|