新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 自制51單片機常用頭文件(T6963C)

自制51單片機常用頭文件(T6963C)

作者: 時間:2016-11-10 來源:網絡 收藏
#include "reg51.h"

#define uint unsigned int
#define uchar unsigned char

本文引用地址:http://m.butianyuan.cn/article/201611/317354.htm

code uchar CCTAB [1024]={
/*-- 寬度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,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,
0x00,0xF0,0x00,0x00,0x15,0x2A,0x00,0x00,0xF0,0x00,0x00,0xA8,0xA0,0x00,0x7C,0x00,
0x00,0xF0,0x00,0x00,0x00,0x55,0x00,0x03,0xC0,0x1F,0x00,0x54,0x00,0x00,0x7C,0x00,
0x00,0xF1,0xFF,0xFF,0x94,0xAA,0x0F,0xC7,0x80,0x11,0x80,0xA8,0xA9,0xFC,0x7C,0x00,
0x00,0xF3,0xFF,0xFF,0xA8,0x55,0x03,0xFF,0xF8,0x60,0xC0,0x51,0x54,0xFE,0x7C,0x00,
0x00,0xF3,0x00,0x00,0x14,0xAA,0x0F,0xFF,0xC0,0xDC,0x40,0x02,0xAA,0x06,0x7C,0x00,
0x00,0xF2,0x01,0x40,0x28,0x50,0x01,0xFF,0xFF,0xBE,0x41,0x45,0x54,0x06,0x7C,0x00,
0x00,0xF0,0xA2,0xA0,0x00,0x07,0xDF,0xFF,0x00,0x7E,0x62,0xA2,0xAA,0x06,0x7C,0x00,
0x00,0xF1,0x51,0x40,0x00,0x18,0xFF,0xFE,0x00,0x7E,0x21,0x45,0x54,0x06,0x7C,0x00,
0x00,0xF0,0xA2,0x80,0x00,0x21,0x9F,0xFC,0x00,0x1F,0x22,0xA2,0xAA,0x06,0x7C,0x00,
0x00,0xF1,0x50,0x00,0x00,0x46,0x3F,0xFC,0x00,0x07,0x21,0x45,0x54,0x06,0x7C,0x00,
0x00,0xF0,0xA2,0xA0,0x00,0x5C,0x7F,0x78,0x00,0x03,0x20,0x02,0xA8,0x06,0x7C,0x00,
0x00,0xF0,0x05,0x50,0x00,0x38,0xEE,0x78,0x00,0x00,0x60,0x01,0x50,0x06,0x7C,0x00,
0x00,0xF2,0x0A,0xA0,0x00,0x30,0xDC,0x70,0x00,0x00,0x30,0x00,0x00,0x06,0x7C,0x00,
0x00,0xF5,0x15,0x50,0x00,0x61,0x98,0x70,0x00,0x00,0x18,0x00,0x00,0x06,0x7C,0x00,
0x00,0xF2,0xAA,0xA0,0x00,0xC1,0x38,0x60,0x00,0x00,0x0C,0x00,0x00,0x00,0x7C,0x00,
0x00,0xF5,0x15,0x50,0x01,0x82,0x30,0x60,0x00,0x00,0x04,0x00,0x00,0x14,0x7C,0x00,
0x00,0xF0,0x2A,0xA0,0x53,0x02,0x20,0x40,0x00,0x00,0x06,0x00,0x00,0x2A,0x7C,0x00,
0x00,0xF3,0x15,0x40,0xA2,0x00,0x20,0x40,0x00,0x00,0x0E,0x00,0x0A,0x14,0x7C,0x00,
0x00,0xF3,0x2A,0x80,0x56,0x00,0x00,0x40,0x00,0x00,0x1F,0x00,0x15,0x2A,0x7C,0x00,
0x00,0xF3,0x15,0x00,0xA4,0x00,0x00,0x00,0x00,0x00,0x39,0x00,0x0A,0x14,0x7C,0x00,
0x00,0xF3,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x15,0x00,0x7C,0x00,
0x00,0xF3,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x0A,0x15,0x7C,0x00,
0x00,0xF3,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x00,0x2A,0xFC,0x00,
0x00,0xF3,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x0E,0x80,0x00,0x55,0x7C,0x00,
0x00,0xF3,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x28,0xAA,0xFC,0x00,
0x00,0xF3,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x50,0x55,0x7C,0x00,
0x00,0xF3,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x28,0xAA,0xFC,0x00,
0x00,0xF3,0x00,0x14,0x08,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x50,0x55,0x7C,0x00,
0x00,0xF3,0x00,0x28,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0xAA,0xFC,0x00,
0x00,0xF3,0x05,0x14,0x07,0xFC,0x0F,0xFF,0xF0,0x80,0x18,0xC0,0x00,0x55,0x7C,0x00,
0x00,0xF3,0x0A,0xA8,0x0C,0x1C,0x08,0x00,0x1F,0x80,0x78,0xC0,0x00,0x2A,0x7C,0x00,
0x00,0xF3,0x15,0x00,0x0C,0x08,0x08,0x00,0x1C,0x80,0x78,0xC0,0x00,0x00,0x7C,0x00,
0x00,0xF3,0x0A,0x80,0x0A,0x10,0x04,0x00,0x0C,0x80,0x72,0xC0,0x00,0x06,0x7C,0x00,
0x00,0xF3,0x15,0x15,0x19,0xC0,0x03,0x00,0x03,0x00,0x3E,0xC0,0x00,0x06,0x7C,0x00,
0x00,0xF3,0x0A,0x2A,0x90,0x3E,0x00,0xFF,0xFC,0x00,0x7C,0x81,0x40,0x06,0x7C,0x00,
0x00,0xF3,0x00,0x55,0x50,0x3D,0x00,0x00,0x00,0x00,0x7C,0x80,0xA0,0x06,0x7C,0x00,
0x00,0xF3,0x28,0xAA,0x90,0x1F,0x00,0x00,0x00,0x00,0x79,0xA9,0x40,0x06,0x7C,0x00,
0x00,0xF3,0x54,0x55,0x53,0x1C,0x1C,0x01,0x50,0x00,0x3D,0x50,0xA0,0x06,0x7C,0x00,
0x00,0xF3,0x28,0xAA,0x9C,0x08,0x03,0x82,0xA8,0x00,0x7F,0x28,0x00,0x06,0x7C,0x00,
0x00,0xF3,0x50,0x55,0x19,0x08,0x00,0x71,0x50,0x00,0x7A,0x50,0x00,0x06,0x7C,0x00,
0x00,0xF3,0x00,0xAA,0x2A,0x08,0x7C,0x0C,0x00,0x00,0x66,0x01,0x50,0x06,0x7C,0x00,
0x00,0xF3,0x00,0x54,0x4D,0x08,0x03,0x02,0x00,0x00,0x0C,0x02,0xA8,0x06,0x7C,0x00,
0x00,0xF3,0xFF,0x28,0x16,0x08,0x38,0xC1,0x00,0x00,0x18,0x85,0x55,0xFE,0x7C,0x00,
0x00,0xF1,0xFF,0x80,0x87,0x08,0x06,0x30,0x00,0x00,0x31,0x4A,0xA9,0xFC,0x7C,0x00,
0x00,0xF0,0x00,0x00,0x29,0xCC,0x01,0x08,0x80,0x00,0xE2,0x85,0x54,0x00,0x7C,0x00,
0x00,0xF0,0x00,0x00,0x00,0x7E,0x00,0x84,0x00,0x03,0x81,0x4A,0xA8,0x00,0x7C,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

uchar column; // 橫坐標
uchar line; // 縱坐標
uchar code1; // 代碼寄存器

sbit LCD_WR = P3^2; // 寫操作信號
sbit LCD_RD = P3^3; // 讀操作信號
sbit LCD_CD = P3^4; // 通道選擇信號
sbit LCD_DATA = P1; // 數(shù)據端口

//指令&數(shù)據讀寫狀態(tài)
void CheckRW(void)
{
do
{
LCD_DATA = 0XFF; // LCD_DATA口置"1"
LCD_CD = 0X01; // 指令寫入通道
LCD_RD = 0X00; // RD=0
ACC = LCD_DATA; // 讀操作
LCD_RD = 0X01; // RD=1
}

while ((ACC&0x03) != 0X03); // 低電平忙
}
//數(shù)據自動寫狀態(tài)
void AutoWrite(void)
{
do
{
LCD_DATA = 0XFF; // LCD_DATA口置"1"
LCD_CD= 0X01; // 指令寫入通道
LCD_RD = 0X00; // RD=0
ACC = LCD_DATA; // 讀操作
LCD_RD = 0X01; // RD=1
}
while((ACC&0X08)!= 0x08); // 低電平忙
}
//數(shù)據寫入函數(shù)
void WriteData(uchar uData)
{
CheckRW(); // 指令&數(shù)據讀寫狀態(tài)
ACC = uData; // 暫存累加器
LCD_CD = 0X00; // 數(shù)據寫入通道
LCD_DATA = ACC; // 讀取數(shù)據
LCD_WR = 0X00; // WR=0
LCD_WR = 0X01; // WR=1
}
//無參指令寫入函數(shù)
void WriteCom(uchar Command)
{
CheckRW(); // 檢測指令讀寫狀態(tài)
LCD_DATA = Command; // 指令寫入
LCD_WR = 0X00; // WR=0
LCD_WR = 0X01; // WR=1
}
//單參數(shù)指令寫入函數(shù)
void WriteCom1(uchar Par,uchar Com)
{
CheckRW(); // 檢測指令讀寫
WriteData(Par); // 數(shù)據寫入
CheckRW(); // 檢測指令讀寫
WriteCom(Com); // 指令寫入
}
//雙參數(shù)指令寫入函數(shù)
void WriteCom2(uchar Par1,uchar Par2,uchar Comd)
{
CheckRW(); // 檢測指令讀寫
WriteData(Par1); // 數(shù)據寫入
CheckRW(); // 檢測指令讀寫
WriteData(Par2); // 數(shù)據寫入
CheckRW(); // 檢測指令讀寫
WriteCom(Comd); // 指令寫入
}

//LCM初始化函數(shù)
void LcmInit( void )
{
WriteCom2(0x00,0x00,0x40); // 設置文本顯示區(qū)首地址
WriteCom2(0x10,0x00,0x41); // 設置文本顯示區(qū)寬度
WriteCom2(0x00,0x08,0x42); // 設置圖形顯示區(qū)首地址0x0800
WriteCom2(0x10,0x00,0x43); // 設置圖形顯示區(qū)寬度
WriteCom(0xA7); // 設置光標形狀 8x8方塊
WriteCom(0x80); // 顯示方式設置 文本xor圖形
WriteCom(0x98); // 顯示開關設置 文本開,圖形開,光標閃爍關
}
//清顯示存儲器函數(shù)
void LcmClear( uchar FillByte )
{
uint i = 8192; // 此處僅清8K RAM,如果32K RAM都使用,請修改i=32768

WriteCom2(0x00,0x08,0x24);
WriteCom(0xB0); // 進入自動寫

while(i--)
{
AutoWrite(); // 數(shù)據自動寫狀態(tài)
WriteData( FillByte ); // 寫入數(shù)據
}

WriteCom(0xB2); // 退出自動寫
}
//設定顯示地址函數(shù)
void LocateXY(uchar x,uchar y,uchar mode)
{
if (mode) // mode=1為圖形方式
{
y += 0x08; // 如果圖形模式要加上圖形區(qū)首地址0x0800
column = x;
line = y;
}
else
{
; // 否則什么都不做
}
}
//圖形寫入函數(shù)
void WriteTX( void )
{
uint i = 0;

LocateXY(0x00,0x00,1); // 計算圖形顯示區(qū)首地址為0800H
WriteCom2(column,line,0x24); // 設置顯示RAM地址

while (i < 1024)
{
WriteCom1(CCTAB[i++],0xC0);
}
}
//主程序
void main( )
{
P3 = 0X1C; // 間接控制方式控制線初始化
LcmInit (); // 初始化
LcmClear (0X00); // 清屏
WriteTX(); // 圖形演示

while(1)
{
;
}
}



評論


技術專區(qū)

關閉