⑴ 求51單片機LCD12864串列顯示程序,只用SID口和SCLK口,能顯示輸出四行中文的,最好寫上main函數,謝謝
//LCD12864字型檔系列(控制器ST7920A),單片機:89S52,晶振:12M,
//串口連接 與 並口連接 ( 串口時 屏蔽 並行模塊)
//並行連接方式,P2.0-RS,P2.1-RW,P2.2-E
#include<reg52.h>
#include <intrins.h>
sbit RS=P3^2; //串口時為CS
sbit RW=P3^1; //串口為SID
sbit E=P3^0; //串口為時鍾SCLK
sbit stop=P2^2;
sbit PSB=P3^4;
sbit REST=P3^3;
//以下是用<at89x51.h>頭文件的定義
/*
#define RS P2_0
#define RW P2_1 //定義引腳
#define E P2_2
#define PSB P2_3
#define REST P2_4
#define Data P1
#include<at89x51.h>
*/
#define BF 0x80 //用於檢測LCM狀態字中的Busy標識
typedef unsigned int Uint;
typedef unsigned char Uchar;
//字元串例子
//"F1--English",也可以往裡面寫入漢字碼,一個漢字由兩個碼組成
const Uchar F1English[]={0x46,0x31,0x2d,0x2d,0x45,0x6e,0x67,0x6c,0x69,0x73,0x68,0x00};
const Uchar lengthF1=6; //字元串長度
//漢字,直接可以寫入字形
unsigned char code uctech[] = {"有限公司"};
const Uchar lengthCF3=8;
Uchar code TAB1[]={
/*-- 調入了一幅圖像:D:\公司的文件\程序圖片\未命名11.bmp --*/
/*-- 寬度x高度=128x64 --*/
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x05,0xAE,0x90,0x00,0x00,0x00,0x00,0x00,
0x95,0x55,0x48,0x80,0x00,0x00,0x00,0x00,
0x2B,0x55,0x00,0x00,0x00,0x00,0x00,0x00,
0xA8,0x00,0x22,0x15,0x20,0x00,0x00,0x00,
0x97,0xFB,0x00,0x00,0x00,0x00,0x00,0x00,
0x45,0x55,0x08,0xA0,0x00,0x00,0x00,0x0A,
0x6F,0xF4,0x00,0x00,0x00,0x00,0x00,0x00,
0xB2,0x80,0x40,0x00,0x04,0x40,0x00,0x00,
0xBA,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
0x4D,0x55,0x15,0x15,0x20,0x00,0x00,0x95,
0xD5,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xE8,0x40,0x40,0x00,0x00,0x00,0x4A,
0xAA,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0x2A,0x00,0x40,0x00,0x00,0x15,
0x54,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFD,0xD0,0xAA,0x01,0x00,0x00,0x25,
0x20,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0xB6,0x00,0x10,0x00,0x01,0x4A,
0x49,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0xFD,0xE8,0x40,0x00,0x00,0x11,
0x00,0x24,0x84,0x00,0x00,0x00,0x00,0x00,
0xAB,0xFF,0xFF,0x55,0x00,0x00,0x00,0x24,
0x02,0x49,0x5E,0xA0,0x00,0x00,0x00,0x00,
0x84,0xBF,0xFF,0xF4,0x88,0x00,0x00,0x00,
0x10,0x05,0xFF,0xF4,0x00,0x00,0x00,0x00,
0x29,0x0B,0xFF,0xFA,0x20,0x00,0x00,0x00,
0x02,0xBF,0xFF,0xFC,0x00,0x00,0x00,0x00,
0x44,0xA0,0x57,0xFD,0x80,0x00,0x00,0x00,
0x08,0x5F,0xFF,0xFF,0x80,0x00,0x00,0x00,
0x91,0x0A,0xAA,0xF6,0x50,0x00,0x00,0x00,
0x41,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,
0x44,0xA0,0x01,0x1B,0x84,0x00,0x00,0x00,
0x26,0xFF,0xFF,0xFF,0x90,0x00,0x00,0x00,
0x11,0x0A,0xAA,0x6D,0x68,0x00,0x00,0x00,
0x0B,0xFB,0xFF,0xEF,0xE0,0x00,0x00,0x00,
0xC4,0xA0,0x01,0x02,0x80,0x00,0x00,0x00,
0x43,0xF1,0xFE,0x63,0xF0,0x00,0x00,0x00,
0x15,0x55,0x54,0x55,0x6A,0x00,0x00,0x00,
0x9F,0xE3,0xFC,0x87,0x38,0x00,0x00,0x00,
0xCA,0xAB,0x91,0x00,0x90,0x00,0x00,0x00,
0x07,0xC1,0xFA,0x2A,0x80,0x00,0x00,0x00,
0x25,0xFF,0xFE,0x95,0x2A,0x00,0x00,0x00,
0x2F,0x13,0xFE,0xFC,0x10,0x00,0x00,0x00,
0x95,0xFF,0xFF,0xC0,0x50,0x00,0x00,0x00,
0x0F,0x41,0xFF,0xF3,0x80,0x00,0x00,0x00,
0x4F,0xFF,0xFF,0xF9,0x2A,0x00,0x00,0x00,
0x9F,0x08,0xFF,0xD4,0x00,0x00,0x00,0x00,
0xB3,0xFF,0xFF,0xFE,0x54,0x80,0x00,0x00,
0x1E,0xA0,0x7F,0xA0,0x00,0x00,0x00,0x00,
0x5F,0xFE,0x7F,0xFE,0xAA,0x00,0x00,0x00,
0x5F,0x57,0xFE,0x00,0x00,0x00,0x00,0x00,
0xAF,0xFD,0x7F,0xFF,0x94,0x80,0x00,0x00,
0x1F,0xFE,0xE8,0x00,0x00,0x00,0x00,0x00,
0x7F,0xFA,0x7F,0x5F,0xCA,0x00,0x00,0x00,
0x3F,0x55,0x00,0x00,0x00,0x00,0x00,0x00,
0xAF,0xF1,0x7F,0xDE,0xF5,0x40,0x00,0x00,
0x1A,0xA0,0x80,0x00,0x00,0x00,0x00,0x00,
0xDF,0xF2,0x3F,0xFC,0xC2,0x00,0x00,0x00,
0x50,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
0x2F,0xFA,0xBF,0xFF,0xF4,0xA0,0x00,0x00,
0x05,0x42,0x00,0x00,0x00,0x00,0x00,0x00,
0x97,0xFE,0x3F,0xFF,0xE3,0x00,0x00,0x00,
0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x68,0xFF,0xDF,0xD5,0x78,0x40,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x07,0x5F,0xFF,0x48,0x02,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xD0,0xAA,0xF4,0xA0,0xAA,0x40,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0A,0x45,0x09,0x05,0x11,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xA1,0x28,0xA0,0x00,0x44,0x40,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x08,0x42,0x04,0x52,0x12,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xA5,0x09,0x51,0x00,0x48,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x50,0x04,0x4A,0x12,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xAA,0x05,0x50,0x21,0x48,0x20,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x90,0x02,0x84,0x12,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xD4,0x05,0x48,0x10,0x48,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x81,0x20,0x00,0x02,0x02,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xA4,0x84,0x92,0x48,0x94,0x40,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x48,0x10,0x00,0x00,0x21,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
//這個是在串口時指令和數據之間的延時
/*
void delay10US(Uchar x)
{
Uchar k;
for(k=0;k<x;k++);
}
*/
const Uchar delay=250; //延時時間常數
static void Wait1ms(void)//延遲1 ms
{
Uchar cnt=0;
while (cnt<delay) cnt++;
}
//延遲n ms
void WaitNms(int n)
{
Uchar i;
for(i=1;i<=n;i++)
Wait1ms();
}
void stopint(void)//中斷程序
{
if(stop==0)
while(1);
}
//**************************************************************************//
//以下是並口時才開的
//讀忙標志,
void RDBF(void)
{
Uchar temp;
RS=0; // RS=0
RW=1; // RW=1
while(1)
{
P1=0xFF; //數據線為輸入
E=1;
temp=P1;
E=0; // E=0
if ((temp&0x80)==0) break;
}
}
//寫數據到指令寄存器
void WRCommand(Uchar comm)
{
RDBF();
RW=0;
P1=comm;
E=1;
E=0;
}
//寫數據到數據寄存器
void WRData(Uchar TEMP)
{
RDBF();
RS=1;
RW=0;
P1=TEMP;
E=1;
E=0;
stopint();
}
/////////////////////////////////////////////////////////////////////////////////
//以下是串口時開的讀寫時序
/*void SendByteLCD(Uchar WLCDData)
{
Uchar i;
for(i=0;i<8;i++)
{
if((WLCDData<<i)&0x80)RW=1;
else RW=0;
E=0;
E=1 ;
}
}
SPIWR(Uchar Wdata,Uchar WRS)
{
SendByteLCD(0xf8+(WRS<<1));
SendByteLCD(Wdata&0xf0);
SendByteLCD((Wdata<<4)&0xf0);
}
void WRCommand(Uchar CMD)
{
RS=0;
RS=1;
SPIWR(CMD,0);
delay10US(90);//89S52來模擬串列通信,所以,加上89S52的延時,
}
void WRData(Uchar Data)
{
RS=0;
RS=1;
SPIWR(Data,1);
}
*/
/*******************************************************************/
//初始化LCD-8位介面
void LCDInit(void)
{ // PSB=0; //串口
PSB=1;//並口時選這個,上一行取消
REST=1;
REST=0;
REST=1;
WRCommand(0x30); //基本指令集,8位並行
WRCommand(0x06); //啟始點設定:游標右移
WRCommand(0x01); //清除顯示DDRAM
WRCommand(0x0C); //顯示狀態開關:整體顯示開,游標顯示關,游標顯示反白關
WRCommand(0x02); //地址歸零
}
//顯示數組字元串(顯示半寬字型16*8點陣)
void ShowQQChar(Uchar addr,Uchar *english,Uchar count)
{
Uchar i;
WRCommand(addr); //設定DDRAM地址
for(i=0;i<count;)
{
WRData(english[i*2]);
WRData(english[i*2+1]);
i++;
}
}
//顯示連續字串(半寬字元)
void ShowNUMChar(Uchar addr,Uchar i,Uchar count)
{
Uchar j;
for(j=0;j<count;)
{
WRCommand(addr); //設定DDRAM地址
WRData(i+j);
j++;
WRData(i+j);
addr++;
j++;
}
}
//自定義字元寫入CGRAM
void WRCGRAM(Uchar data1,Uchar data2,Uchar addr)
{
Uchar i;
for(i=0;i<16;)
{
WRCommand(addr+i); //設定CGRAM地址
WRData(data1);
WRData(data1);
i++;
WRCommand(addr+i); //設定CGRAM地址
WRData(data2);
WRData(data2);
i++;
}
}
//顯示自定義的字元,並把這個字元填滿全屏16*16
void ShowCGChar(Uchar addr,Uchar i)
{
Uchar j;
for(j=0;j<0x20;)
{
WRCommand(addr+j); //設定DDRAM地址
WRData(0x00);
WRData(i);
j++;
}
}
void CLEARGDRAM(void)
{
Uchar j;
Uchar i;
WRCommand(0x34);
WRCommand(0x36);
for(j=0;j<32;j++)
{
WRCommand(0x80+j);
WRCommand(0x80);//X坐標
for(i=0;i<32;i++)//
{
WRData(0x00);
}
}
}
//寫入GDRAM 繪圖,Y是Y繪圖坐標,2個位元組一行,CLONG是圖形長度,以位元組
//為單位;HIGHT是圖形高度,TAB是圖形數據表.12864M的圖形顯示是相當於256*32點陣.
//由兩屏128*32上下兩屏組成,同一行的下屏的頭地址緊接上屏的未地址。
//繪圖在串口輸入時,會比在並口下的輸入要慢一些
void WRGDRAM(Uchar Y1,Uchar clong,Uchar hight,Uchar *TAB1)
{
Uint k;
Uchar j;
Uchar i;
WRCommand(0x34);
WRCommand(0x36);
for(j=0;j<hight;j++)//32
{ //先上半屏
WRCommand(Y1+j); //Y總坐標,即第幾行
WRCommand(0x80);//X坐標,即橫數第幾個位元組開始寫起
for(i=0;i<clong;i++)//
{
WRData(TAB1[clong*j+i]);
}
//後下半屏
for(k=0;k<clong;k++)//
{
WRData(TAB1[clong*(j+hight)+k]);
}
}
}
void menu(void)
{
LCDInit();
ShowNUMChar(0x80,0x01,0x0f);//顯示半寬特殊符號
ShowNUMChar(0x90,0x30,0x0f);//顯示半寬0~?數字標點
ShowNUMChar(0x88,0x41,0x0f);//顯示半寬A~P大寫
ShowNUMChar(0x98,0x61,0x0f);//顯示半寬a~p小寫
WaitNms(250); //等待時間
WaitNms(250); //等待時間
stopint();
WRCommand(0x01); //清除顯示DDRAM
WRCGRAM(0xff,0x00,0x40);//寫入橫
WRCGRAM(0x00,0xff,0x50);//寫入橫2
WRCGRAM(0xaa,0xaa,0x60);//寫入豎
WRCGRAM(0x55,0x55,0x70);//寫入豎2
ShowCGChar(0x80,0x00);//顯示橫並填滿
WaitNms(250); //等待時間
WaitNms(250); //等待時間
stopint();
WRCommand(0x01); //清除顯示DDRAM
ShowCGChar(0x80,02);//顯示橫2並填滿
WaitNms(250); //等待時間
WaitNms(250); //等待時間
stopint();
WRCommand(0x01); //清除顯示DDRAM
ShowCGChar(0x80,04);//顯示豎並填滿
WaitNms(250); //等待時間
WaitNms(250); //等待時間
stopint();
WRCommand(0x01); //清除顯示DDRAM
ShowCGChar(0x80,06);//顯示豎2並填滿
WaitNms(250); //等待時間
WaitNms(250); //等待時間
stopint();
WRCommand(0x01); //清除顯示DDRAM
WRCGRAM(0x00,0x00,0x40);//清CGRAM1
WRCGRAM(0x00,0x00,0x50);//清CGRAM2
WRCGRAM(0xaa,0x55,0x40);//寫入點
WRCGRAM(0x55,0xaa,0x50);//寫入點2
ShowCGChar(0x80,00);//顯示點並填滿
WaitNms(250); //等待時間
WaitNms(250); //等待時間
stopint();
WRCommand(0x01); //清除顯示DDRAM
ShowCGChar(0x80,02);//顯示點2並填滿
WaitNms(250); //等待時間
WaitNms(250); //等待時間
stopint();
WRCommand(0x01); //清除顯示DDRAM
ShowQQChar(0x80,uctech,lengthCF3);//顯示'有限公司',以下共四行
ShowQQChar(0x90,uctech,lengthCF3);
ShowQQChar(0x88,uctech,lengthCF3);
ShowQQChar(0x98,uctech,lengthCF3);
WaitNms(250); //等待時間
WaitNms(250); //等待時間
stopint();
WRCommand(0x01); //清除顯示DDRAM
}
void menu2(void)
{ CLEARGDRAM();
WRGDRAM(0x80,16,32,TAB1);
WaitNms(250); //等待時間
WaitNms(250); //等待時間
stopint();
}
//主函數
void main(void)
{
menu();//初始化及半寬字元和點橫豎漢字掃描
menu2();//繪圖顯示
for(;;)
{;}
}
⑵ 怎樣用51單片機和led8*8矩陣進行字元漢字顯示
8*8也就能顯示字元,顯示漢字比較吃力。
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code Table_of_Digits[]=
{
0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00, //0
0x00,0x00,0x00,0x21,0x7f,0x01,0x00,0x00, //1
0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00, //2
0x00,0x22,0x49,0x49,0x49,0x36,0x00,0x00, //3
0x00,0x0c,0x14,0x24,0x7f,0x04,0x00,0x00, //4
0x00,0x72,0x51,0x51,0x51,0x4e,0x00,0x00, //5
0x00,0x3e,0x49,0x49,0x49,0x26,0x00,0x00, //6
0x00,0x40,0x40,0x40,0x4f,0x70,0x00,0x00, //7
0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00, //8
0x00,0x32,0x49,0x49,0x49,0x3e,0x00,0x00, //9
0xff,0x81,0x81,0x81,0x81,0x81,0x81,0xff
};
uchar code xdat[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
uchar code ydat[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar i=0,j=0,t=0,Num_Index,key,xi,yi;
sbit we1=P1^1;
sbit we2=P1^3;
//主程序
void main()
{
//P1=0x80;
Num_Index=0; //從0 開始顯示
TMOD=0x01; //T0 方式0
TH0=(65536-2000)/256; //2ms 定時
TL0=(65536-2000)%256;
IE=0x82;
key=0;
xi=0;
yi=0;
EX0=1;
IT0=1;
TR0=1; //啟動T0
while(1);
}
//T0 中斷函數
void ext_int0() interrupt 0
{
key++;
key&=0x03;
}
void LED_Screen_Display() interrupt 1
{
TH0=(65536-2000)/256; //2ms 定時
TL0=(65536-2000)%256;
switch(key)
{
case 0:
P0=0xff;
we1=1;
P0=~Table_of_Digits[Num_Index*8+i];
we1=0;
P0=0xff; //輸出位碼和段碼
we2=1;
P0=xdat[i];
we2=0;
if(++i==8) i=0; //每屏一個數字由8 個位元組構成
if(++t==250) //每個數字刷新顯示一段時間
{
t=0;
if(++Num_Index==10) Num_Index=0; //顯示下一個數字
}
break;
case 1:
we1=1;
P0=~xdat[xi];
we1=0;
we2=1;
P0=ydat[yi];
we2=0;
if(++t==250) //每個數字刷新顯示一段時間
{
t=0;
yi++;
if(yi>7){yi=0;xi++;}
if(xi>7)xi=0;
}
break;
case 2:
we1=1;
P0=0x00;
we1=0;
P0=0xff; //輸出位碼和段碼
we2=1;
P0=xdat[i];
we2=0;
if(++t==250) //每個數字刷新顯示一段時間
{
if(++i==8) i=0; //每屏一個數字由8 個位元組構成
t=0;
}
break;
default:
key=0;
i=0;
j=0;
t=0;
xi=0;
yi=0;
Num_Index=0;
we1=1;
P0=0xff;
we1=0;
we2=1;
P1=0x80;
we2=0;
break;
}
}
⑶ 51單片機點陣顯示一個漢字
8x8的點陣太小,很難正常顯示一個漢字,通常,會使用4個8x8的點陣即16x16的點陣來顯示一個漢字。
單片機在通過點陣顯示漢字的時候,需要用到如下技術手段:
1、漢字取模
漢字取模,即把漢字對應16x16點陣的圖形用16進制數來描述,形成可以用於驅動顯示的數據。
例如下圖,的漢字「中」
該字的16x16點陣圖形中,每行有16個像素,可以編碼為2個位元組,每8個像素,對應一個位元組的高低位,則該字編碼的前2個位元組為0x01,0x80……,如此,可用32個位元組描述漢字的點陣圖形。
關於漢字取模有很多開源的軟體,你可以搜索下載並使用,將你的程序中所需要使用的漢字,全部處理成字模,再定義到程序中即可。(也可以使用漢字字型檔晶元,這里就不討論了)
2、掃描顯示
通常,驅動點陣設備時,為了節約單片機的管腳資源,會使用鎖存器一類的期間,即鎖存器輸出端與點陣連接,而輸入段由單片機控制,採用行、場掃描或分塊行、場掃描的方式驅動,具體你可以搜尋相關資料。
⑷ 51單片機LCD1602漢字
LCD1602隻允許顯示ASCII字元,漢子不在其中,不能顯示。漢子可以使用點陣型的LCD顯示,如LCD12864。
⑸ 51單片機怎麼用按鍵控制一個數碼管,按一下顯示一個數字,順序顯示
1、首先,要把代碼寫好,點亮數碼管。
⑹ 51單片機12864lcd顯示漢字
會用1602顯示英文,就可以用12864lcd顯示漢字,二者區別就在於,顯示漢字要送兩個位元組的代碼,其中首個位元組的值要大於128,而ASCI碼的值均小於128。
漢字的機器碼不用計算,編譯器會自動編譯,例如
unsigned char code table[]={ "我愛單片機"「hello」 };
顯示時,只要先送顯示的首地址即可,然後送數組里的內容即可
write_LCD_command(0x88);//第2 行首地址
for(i=0;i<16;i++)
{
write_LCD_data(tab[i]);
delay(5000);
}
⑺ 求51單片機驅動液晶12864的程序,要求是串口方式。程序里不要有繪圖反白之類的,只要能顯示漢字就行。
絕對好用的串口程序
sbit SID=P2^1; //12864數據
sbit SCLK=P2^2; //12864時鍾
init()
{
write(0,0x30); //8 位介面,基本指令集
write(0,0x0c); //顯示打開,游標關,反白關
write(0,0x01); //清屏,將DDRAM的地址計數器歸零
delaynms(10);
write(0,0x80); for(i=0;i<16;i++) write(1,datas11[i]);
write(0,0x90); for(i=0;i<16;i++) write(1,datas2[i]);
write(0,0x88); for(i=0;i<16;i++) write(1,datas3[i]);
write(0,0x98); for(i=0;i<16;i++) write(1,datas4[i]);
}
/**********************12864*************************/
void delaynms(unsigned int di) //延時
{
unsigned int da,db;
for(da=0;da<di;da++)
for(db=0;db<10;db++);
}
void sendbyte(unsigned char bbyte) //發送一個位元組
{
unsigned char i;
for(i=0;i<8;i++)
{
SID=bbyte&0x80; //取出最高位
SCLK=1;
SCLK=0;
bbyte<<=1; //左移
}
}
void write(bit start, unsigned char ddata) //寫指令或數據
{
unsigned char start_data,Hdata,Ldata;
if(start==0) start_data=0xf8; //寫指令
else start_data=0xfa; //寫數據
Hdata=ddata&0xf0; //取高四位
Ldata=(ddata<<4)&0xf0; //取低四位
sendbyte(start_data); //發送起始信號
delaynms(5); //延時是必須的
sendbyte(Hdata); //發送高四位
delaynms(1); //延時是必須的
sendbyte(Ldata); //發送低四位
delaynms(1); //延時是必須的
}
/*void lcdinit(void) //初始化LCD
{
delaynms(10); //啟動等待,等LCM講入工作狀態
//PSB=0; ; //串口驅動模式
// RESET=0; delaynms(1); RESET=1; // 復位LCD
// CS=1;
write(0,0x30); //8 位介面,基本指令集
write(0,0x0c); //顯示打開,游標關,反白關
write(0,0x01); //清屏,將DDRAM的地址計數器歸零
}*/
⑻ 51單片機編寫lcd1602顯示程序,第一行顯示自己的姓名,第二行顯示學號
1、首先我們打開Keil μVision編譯器,新建一個工程,然後保存在硬碟上的位置,然後選擇Atmel-AT89C51單片機為模型,並啟動器添加STARTUP.A51文件,然後在當前目錄下新建一個C文件,並將其添加入工作路徑。
⑼ 怎麼編寫單片機——TFT彩屏漢字程序
你現在看到的這兩個函數LCD_ShowString()ChineseChar()是你在上層調用的,具體的函數定義你要去看底層是怎麼實現的。我先簡單介紹下著兩個函數
LCD_ShowString(12,60,colors[0],colors[7],"-");應該是講屏幕上x=12,y=60的地方顯示一個「-」字元,字元顏色應該是你定義的colors[0],TFT屏的背景顏色是colors[7],這兩個是你函數庫自己定義的,可以改。
ChineseChar(20,60,1,colors[0],colors[7],1); //帶 這個函數和上面那個函數大致相同,至於為什麼會顯示「帶」,是因為最後那個1,這個程序你應該定義一個數組,在這個數組裡面對你所要顯示的字全部編碼並存在這個數組中,最後你只需用想調用數組下標那樣調用這個漢子。
至於你想顯示班級、姓名 只需用把班級姓名進行編碼就可以調用這個ChineseChar()函數進行顯示
其實很簡單的,只需用該幾步就可以達到你想要的,不難~~
⑽ 用keil51單片機C語言編寫程序,使液晶顯示器顯示16*16點陣漢字,請問怎麼編寫,謝謝!
#include"at89x51.h"
unsigned char code led[]={0x10,0x04,0x10,0x03,0xD0,
0x00,0xFF,0xFF,0x90,0x00,
0x18,0x1D,0xF7,0x13,0x14,
0x11,0x54,0x15,0x94,0x19,
0x14,0x51,0x14,0x91,0xF6,
0x7F,0x04,0x11,0x00,0x01,
0x00,0x00,
0x04,0x04,0x04,0x02,0x04,
0x01,0xC4,0xFF,0x3F,0x00,
0x04,0x20,0x04,0x10,0x04,
0x08,0xE4,0x3F,0x04,0x42,
0x1F,0x41,0x84,0x40,0xC4,
0x40,0x06,0x40,0x04,0x70,
0x00,0x00};
unsigned char i=0,j=0,time_50ms=0;
delay();
main()
{
TMOD=0X01;
TH0=0X3C;
TL0=0XB0;
TR0=1;
ET0=1;
EA=1;
while(1)
{
P1=i;
P2=led[32*j+2*i];
P3=led[32*j+2*i+1];
delay();
i++;
if(i==16)
i=0;
if(time_50ms==20)
{
time_50ms=0;
j++;
if(j==2)
j=0;
}
}
}
int_T0() interrupt 1
{
TH0=0X3C;
TL0=0XB0;
time_50ms++;
}
delay()
{
unsigned char t1;
for(t1=0;t1<100;t1++);
}