12864液晶不带字库的用C语言和51单片机编程

12864液晶不带字库的用C语言和51单片机编程,第1张

#include<reg51h>

#include<absacch>

#define uchar unsigned char

#define datawr 0x1200 //写数据通道

#define comwr 0x1000 //写控制命令通道

#define datare 0x1300 //读数据通道

#define comre 0x1100 //读忙通道

uchar code disp_data[]={" 浙江大学 " //第一行,第一页

"04级通信工程一班" //第三行

" 宁波理工学院 " //第二行

" 竞赛小组 " //第四行

"128X64液晶显示器" //第一行,第二页

" 测试程序 " //第三行

" 07年07月25日 " //第二行

" Tornado "}; //第四行

void set12864();

void write_command(uchar command);

void write_page(uchar data_add);

void read_page(uchar data_add);

void delays(uchar cont);

void main()

{

while(1)

{

set12864(); //初始化12864

write_page(0); //写入一页数据

read_page(0x30); //读出一页数据到内部RAM

delays(2); //延时2s

write_page(64); //写入下一页数据

delays(2); //延时2s

}

}

//初始化12864子程序

void set12864()

{

write_command(0x30); //功能设定控制字

write_command(0x0c); //显示开关控制字

write_command(0x01); //清除屏幕控制字

write_command(0x06); //进入设定点控制字

}

//写控制命令子程序

void write_command(uchar command)

{

bit flag="1"; //12864空闲标志位

while(flag) //检查12864是否空闲

flag="XBYTE"[comre]&0x80;

XBYTE[comwr]=command; //空闲传送控制字

}

//写一页子程序

void write_page(uchar data_add)

{

bit flag="1"; //12864空闲标志位

uchar num="64"; //64个循环,连续写入32个汉字或是64个西文字符

write_command(0x80);

for(;num>0;num--)

{

while(flag) //检查12864是否空闲

flag="XBYTE"[comre]&0x80;

XBYTE[datawr]=disp_data[data_add++]; //空闲传送数据

}

}

//读一页子程序

void read_page(uchar data_add)

{

bit flag="1"; //12864空闲标志位

uchar num="64"; //64个循环,连续写入32个汉字或是64个西文字符

write_command(0x80);

for(;num>0;num--)

{

while(flag) //检查12864是否空闲

flag="XBYTE"[comre]&0x80;

DBYTE[data_add++]=XBYTE[datare]; //空闲传送数据

}

}

//延时cont秒子程序

void delays(uchar count)

{

unsigned char h,i,j,k;

do

{

for(h=5;h>0;h--)

for(i=4;i>0;i--)

for(j=116;j>0;j--)

for(k=214;k>0;k--);

}while(--count);

}

这是图象显示程序:

#include<reg51h>

#include<absacch>

#define uchar unsigned char

#define uint unsigned int

#define datawr 0x1200 //写数据通道

#define comwr 0x1000 //写控制命令通道

#define datare 0x1300 //读数据通道

#define comre 0x1100 //读忙通道

uchar code disp_data[] = // 数据表

{

0x00,0x01,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,

0x00,0x01,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,

0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,

0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,

0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,

0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,

0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,

0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x80,0x00,0x00,0x00,

0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0xFF,0xFF,0xFF,

0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x07,0xFF,0xFF,

0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x0B,0xFF,

0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x1F,

0x01,0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,

0x01,0xFF,0xFF,0xFF,0xF3,0x79,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,

0x03,0xFF,0xFF,0xFF,0xE6,0x62,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE1,0x60,0x00,0x68,

0x01,0xFF,0xFF,0xFE,0x00,0x60,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE1,0x00,0x00,0x0E,

0x01,0xFF,0xFF,0xF8,0x00,0x4B,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x8E,0x08,0x79,

0x07,0xFF,0xFF,0xF0,0x00,0x41,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE6,0xC0,0x07,0x61,

0xC3,0xFF,0xFE,0xC0,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xED,0xEF,0x3F,

0x83,0xFF,0xFE,0x60,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

0xC0,0xFF,0xFD,0xFC,0x6C,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

0xF0,0x7F,0xF3,0xFF,0xFE,0x60,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

0xFF,0xFF,0xF3,0xFF,0xFF,0x50,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC9,

0xFB,0xFF,0xF1,0xF8,0x8C,0xD8,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFB,0x6F,0xD9,

0xC2,0x3F,0xF8,0x40,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xF6,0xDF,0x1E,0xFF,

0xFF,0x7F,0xFC,0x38,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0x64,0x2F,0x6F,0xFF,

0xFD,0x7B,0xFC,0x1F,0xE0,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0x5F,0x7C,0xEE,0xFF,

0xC7,0xFF,0xBC,0x0F,0xFF,0x00,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xDF,0xFE,0xEF,0xFF,

0xFF,0xE7,0xDC,0x07,0xE7,0xF8,0x12,0x7F,0xFF,0xFF,0xFF,0xFF,0x47,0xFF,0xFF,0xFF,

0xFF,0xE7,0x80,0x03,0xF4,0x00,0x00,0x5F,0xFF,0xFF,0xFE,0xFE,0xE3,0xFF,0xFF,0xFF,

0xFF,0xFE,0xC0,0x01,0xC0,0x00,0x00,0x1B,0xFF,0xFF,0xFB,0xFF,0xFF,0xFF,0xFF,0xFF,

0x7F,0xEE,0xC0,0x00,0xC0,0x00,0x00,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

0xFE,0x98,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xFF,0xEF,0xFF,0xFF,0xFF,0xFF,0xFF,

0x20,0x0E,0x60,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x8F,0xFF,0xFF,0xFF,0xFF,0xFF,

0x05,0x80,0xE0,0x00,0x00,0x00,0x00,0x01,0xFF,0xFD,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

0x09,0x80,0xA0,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,

0x85,0x2A,0xC0,0x00,0x00,0x00,0x00,0x01,0xFF,0xFB,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,

0xBF,0xF3,0xC0,0x00,0x00,0x00,0x00,0x00,0xFF,0xF7,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,

0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x01,0xFF,0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,

0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0xFF,0xC0,0xFF,0xFF,0xFF,0xFF,0xC0,0x1F,

0xFF,0xFF,0x80,0x00,0x40,0x00,0x00,0x00,0xFF,0x80,0xFF,0xFF,0xFF,0x80,0x07,0xFF,

0xFF,0xFF,0xC0,0x00,0xC0,0x00,0x00,0x01,0xFF,0x01,0xFF,0xFF,0xF8,0x00,0xFF,0xFF,

0xFF,0xFF,0xE0,0x63,0x80,0x00,0x00,0x01,0xFE,0x01,0xFF,0x18,0x00,0x3F,0xFF,0xFF,

0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x01,0xCC,0x01,0xFE,0x00,0x07,0xFF,0xFF,0xFF,

0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x07,0xA0,0x03,0xFC,0x00,0xFF,0xFF,0xFF,0xFF,

0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x05,0xC0,0x03,0xC8,0x00,0x7F,0xFF,0xFF,0xFF,

0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x88,0x0C,0x07,0xFF,0xFF,0xFF,

0xFF,0xFF,0xFC,0x00,0x0C,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0xC0,0x7F,0xFF,0xFF,

0xFF,0xFF,0xF8,0x07,0x0F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x0F,0xFF,0xFE,

0xFF,0xFF,0xD0,0x07,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x03,0xFF,0xF8,

0xFF,0xFC,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xC0,

0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0xFF,0xF8,

0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x1F,0xFE,

0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x78,0x02,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,

0xFF,0x00,0x00,0x00,0x00,0x00,0x03,0xF0,0x78,0x00,0x00,0x00,0x00,0x00,0x02,0xFF,

0xFE,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,

0xF0,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,

0xE0,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,

0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x27,

0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,

0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,

0x80,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01

};

void set12864();

void setxy(uchar x,uchar y);

void write_command(uchar command);

void write_16byte(uint data_add);

void delays(uchar count);

void main()

{

uchar x,y,i;

while(1)

{

y="0x80"; //设置液晶上半部分坐标

x="0x80";

delays(2); //延时2s

set12864(); //初始化12864

delays(2);

for(i=0;i<32;i++) //写入液晶上半图象部分

{ //写入坐标

setxy(x,y);

write_16byte(i16); //连续写入16字节数据

y++; //y轴地址加1

}

y="0x80"; //设置液晶下半部分坐标

x="0x88";

for(i=0;i<32;i++) //写入液晶下半图象部分

{

setxy(x,y); //写入坐标

write_16byte((32+i)16);//连续写入16字节数据

y++; //y轴地址加1

}

write_command(0x34); //写入扩充指令命令

write_command(0x36); //显示图象

}

}

//初始化12864子程序

void set12864()

{

write_command(0x30); //功能设定控制字

write_command(0x0c); //显示开关控制字

write_command(0x01); //清除屏幕控制字

write_command(0x06); //进入设定点控制字

}

//设置绘图坐标

void setxy(uchar x,uchar y)

{

write_command(0x34); //写入扩充指令命令

write_command(y); //写入y轴坐标

write_command(x); //写入x轴坐标

write_command(0x30); //写入基本指令命令

}

//写控制命令子程序

void write_command(uchar command)

{

bit flag="1"; //12864空闲标志位

while(flag) //检查12864是否空闲

flag="XBYTE"[comre]&0x80;

XBYTE[comwr]=command; //空闲传送控制字

}

void write_16byte(uint data_add)

{

bit flag="1"; //12864空闲标志位

uchar num="16"; //16个循环,连续写入16个字节

for(;num>0;num--)

{

while(flag) //检查12864是否空闲

flag="XBYTE"[comre]&0x80;

XBYTE[datawr]=disp_data[data_add++]; //空闲传送数据

}

}

//延时count秒子程序

void delays(uchar count)

{

unsigned char h,i,j,k;

do

{

for(h=5;h>0;h--)

for(i=4;i>0;i--)

for(j=116;j>0;j--)

for(k=214;k>0;k--);

}while(--count);

}

#include <reg51h>

#include <stringh>

#include "ds1302h"

#include "menuh"

#include "lcd12864h"

#define uchar unsigned char

#define uint unsigned int

sbit led=P3^7;

uchar temp,keyval;

uchar usern=0;   //用户序号

//struct mlist nuser;

uchar disdat[16];

void displaykey()

{

keyval=0xff;

P1=0xfe;

temp=P1;

temp&=0xf0;

if(temp!=0xf0)//判断是否有键盘按下,真 为有

{

delay(50);

temp=P1; 

temp=temp&0xf0;

if(temp!=0xf0)//判断是否有键盘按下,真 为有

{

temp=P1;

switch (temp)

{

  case 0xee:keyval='0';break;

  case 0xde:keyval='1';break;

  case 0xbe:keyval='2';break;

  case 0x7e:keyval='3';break;

default: break;

}

}

}

while((P1&0xf0) != 0xf0);

//判断第二行键盘

P1=0xfd;

temp=P1;

temp=temp&0xf0;

if(temp!=0xf0)

{

delay(50);

temp=P1; 

temp=temp&0xf0;

if(temp!=0xf0)//判断是否有键盘按下,真 为有

{

temp=P1;

switch (temp)

{

  case 0xed:keyval='4';break;

  case 0xdd:keyval='5';break;

  case 0xbd:keyval='6';break;

  case 0x7d:keyval='7';break;

default: break;

}

}

}

while((P1&0xf0) != 0xf0);

//判断第三行键盘

P1=0xfb;

temp=P1;

temp=temp&0xf0;

if(temp!=0xf0)

{

delay(50);

temp=P1; 

temp=temp&0xf0;

if(temp!=0xf0)//判断是否有键盘按下,真 为有

{

temp=P1;

switch (temp)

{

  case 0xeb:keyval='8';break;

  case 0xdb:keyval='9';break;

  case 0xbb:keyval='a';break;

  case 0x7b:keyval='b';break;

default:break;

}

}

}

while((P1&0xf0) != 0xf0);

//判断第四行键盘

P1=0xf7;

temp=P1;

temp=temp&0xf0;

if(temp!=0xf0)

{

delay(50);

temp=P1; 

temp=temp&0xf0;

if(temp!=0xf0)//判断是否有键盘按下,真 为有

{

temp=P1;

switch (temp)

{

  case 0xe7:keyval='c';break;

    case 0xd7:keyval='d';break;

case 0xb7:keyval='e';break;

  case 0x77:keyval='f';break;

default:break;

}

}

}

while((P1&0xf0) != 0xf0);

}

void distime(void)

{

uchar cal="年月日";

disdat[0]='2';

disdat[1]='0';

disdat[2]='0'+TIME[6]/16;      //年

disdat[3]='0'+(TIME[6]&0x0f);

disdat[4]=cal[0];

disdat[5]=cal[1];

disdat[6]='0'+TIME[4]/16;      //月

disdat[7]='0'+(TIME[4]&0x0f);

disdat[8]=cal[2];

disdat[9]=cal[3];

disdat[10]='0'+TIME[3]/16;      //日

disdat[11]='0'+(TIME[3]&0x0f);

disdat[12]=cal[4];

disdat[13]=cal[5];

disdat[14]=0;

displaystr(1,2,disdat);

disdat[0]='0'+TIME[2]/16;      //时

disdat[1]='0'+(TIME[2]&0x0f);

disdat[2]=':';

disdat[3]='0'+TIME[1]/16;      //分

disdat[4]='0'+(TIME[1]&0x0f);

disdat[5]=':';

disdat[6]='0'+TIME[0]/16;      //秒

disdat[7]='0'+(TIME[0]&0x0f);

disdat[8]=0;

displaystr(4,4,disdat);

}

void init_timer(void)

{

TMOD=0x20;

TH1=0xfd;

TL1=0xfd;

TR1=1;

SCON=0x40;

}

main()

{

uchar num;

InitLCD();//初始LCD  

Ds1302Init();

init_timer();

ClearScreen(0);

delay(200);

num=0;

while(1)

{

Ds1302ReadTime();

distime();  

displaykey();

delay(200);

}

}

//如果只是要话一个点的话简单,这里是个串口程序

#include <reg52h>

#include <intrinsh>

#define uchar unsigned char

#define uint unsigned int

/LCD接口定义/

sbit SID = P1^0; //串行数据

sbit SCLK = P1^1; //串行同步时钟

/汉字地址表/

uchar code addr_tab[]={

0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,//第一行汉字位置

0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,//第二行汉字位置

0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,//第三行汉字位置

0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,//第四行汉字位置

};

/n(ms)延时子程序/

void delayms(uint t) //约延时n(ms)

{

uint i;

while(t--)

{

for(i=0;i<125;i++);

}

}

/串行发送一个字节/

void SendByte(uchar Dbyte)

{

uchar i;

for(i=0;i<8;i++)

{

SCLK = 0;

Dbyte=Dbyte<<1; //左移一位

SID = CY; //移出的位给SID

SCLK = 1;

SCLK = 0;

}

}

/写指令/

void Lcd_WriteCmd(uchar Cbyte )

{

//delayms(1);

SendByte(0xf8); //11111,RW(0),RS(0),0

SendByte(0xf0&Cbyte); //高四位

SendByte(0xf0&Cbyte<<4); //低四位(先执行<<)

}

/写数据/

void Lcd_WriteData(uchar Dbyte )

{

//delayms(1);

SendByte(0xfa); //11111,RW(0),RS(1),0

SendByte(0xf0&Dbyte); //高四位

SendByte(0xf0&Dbyte<<4); //低四位(先执行<<)

}

/初始化LCD/

void Lcd_Init(void)

{

delayms(3);

Lcd_WriteCmd(0x30); //选择基本指令集

delayms(1);

Lcd_WriteCmd(0x30); //选择8bit数据流

delayms(1);

Lcd_WriteCmd(0x0c); //开显示(无游标、不反白)

delayms(1);

Lcd_WriteCmd(0x01); //清除显示,并且设定地址指针为00H

delayms(2);

}

void pic_Disp(uchar x,uchar y) //显示一个点

{

Lcd_WriteCmd(0x34); //切换到扩充指令,

Lcd_WriteCmd(0x34);//关闭图形显示

Lcd_WriteCmd(0x80+y); //行地址

Lcd_WriteCmd(0x80+x); //列地址,如果是下半屏这里多加8

Lcd_WriteData(0); //写数据 D15-D8

Lcd_WriteData(1); //写数据 D7-D0

Lcd_WriteCmd(0x36);//打开图形显示

}

void main()

{

Lcd_Init();

pic_Disp(1,1);

while(1);

}

给你测试了,行可行

顶层文件 万年历C

#include<reg51h>

#include "LCD1602h"

#include "DS1302h"

#define uchar unsigned char

#define uint unsigned int

sbit speaker=P2^4;

bit key_flag1=0,key_flag2=0;

SYSTEMTIME adjusted;

uchar sec_add=0,min_add=0,hou_add=0,day_add=0,mon_add=0,yea_add=0;

uchar data_alarm[7]={0};

/键盘控制/

int key_scan() //扫描是否有键按下

{ int i=0;

uint temp;

P1=0xf0;

temp=P1;

if(temp!=0xf0)

i=1;

else

i=0;

return i;

}

uchar key_value() //确定按键的值

{

uint m=0,n=0,temp;

uchar value;

uchar v[4][3]={'2','1','0','5','4','3','8','7','6','b','a','9'} ;

P1=0xfe; temp=P1; if(temp!=0xfe)m=0;

P1=0xfd;temp=P1 ;if(temp!=0xfd)m=1;

P1=0xfb;temp=P1 ;if(temp!=0xfb)m=2;

P1=0xf7;temp=P1 ;if(temp!=0xf7)m=3;

P1=0xef;temp=P1 ;if(temp!=0xef)n=0;

P1=0xdf;temp=P1 ;if(temp!=0xdf)n=1;

P1=0xbf;temp=P1 ;if(temp!=0xbf)n=2;

value=v[m][n];

return value;

}

/设置闹铃函数/

void naoling(void)

{

uchar i=0,l=0,j;

init1602();

while(key_flag2&&i<12)

if(key_scan()){j=key_value();write_data(j);if(i%2==0)data_alarm[l]=(j-'0')10;else {data_alarm[l]+=(j-'0');l++;}i++;delay(600);}

write_com(0x01);

}

uchar according(void)

{ uchar k;

if(data_alarm[0]==adjustedYear&&data_alarm[1]==adjustedMonth&&data_alarm[2]==adjustedDay&&data_alarm[3]==adjustedHour&&data_alarm[4]==adjustedMinute&&data_alarm[5]==adjustedSecond)

k=1;

else k=0;

return k;

}

void speak(void)

{uint i=50;

while(i)

{speaker=0;

delay(1);

speaker=1;

delay(1);

i--;

}

}

void alarm(void)

{uint i=10;

while(i)

{

speak();

delay(10);

i--;

}

}

/修改时间 *** 作/

void reset(void)

{

sec_add=0;

min_add=0;

hou_add=0;

day_add=0;

mon_add=0;

yea_add=0 ;

}

void adjust(void)

{

if(key_scan()&&key_flag1)

switch(key_value())

{case '0':sec_add++;break;

case '1':min_add++;break;

case '2':hou_add++;break;

case '3':day_add++;break;

case '4':mon_add++;break;

case '5':yea_add++;break;

case 'b':reset();break;

default: break;

}

adjustedSecond+=sec_add;

adjustedMinute+=min_add;

adjustedHour+=hou_add;

adjustedDay+=day_add;

adjustedMonth+=mon_add;

adjustedYear+=yea_add;

if(adjustedSecond>59) adjustedSecond=adjustedSecond%60;

if(adjustedMinute>59) adjustedMinute=adjustedMinute%60;

if(adjustedHour>23) adjustedHour=adjustedHour%24;

if(adjustedDay>31) adjustedDay=adjustedDay%31;

if(adjustedMonth>12) adjustedMonth=adjustedMonth%12;

if(adjustedYear>100) adjustedYear=adjustedYear%100;

}

/中断处理函数/

void changing(void) interrupt 0 using 0 //需要修改时间和日期,或者停止修改

{

if(key_flag1)key_flag1=0;

else key_flag1=1;

}

void alarming(void) interrupt 3 using 0 //需要设置闹铃或者停止设置

{

if(key_flag2)key_flag2=0;

else key_flag2=1;

}

/主函数/

main()

{uint i;

uchar l;

uchar p1[]="D:",p2[]="T:";

SYSTEMTIME T;

EA=1;

EX0=1;

IT0=1;

EA=1;

EX1=1;

IT1=1;

init1602();

Initial_DS1302() ;

while(1)

{ write_com(0x80);

write_string(p1,2);

write_com(0xc0);

write_string(p2,2);

DS1302_GetTime(&T) ;

adjustedSecond=TSecond;

adjustedMinute=TMinute;

adjustedHour=THour;

adjustedWeek=TWeek;

adjustedDay=TDay;

adjustedMonth=TMonth;

adjustedYear=TYear;

for(i=0;i<9;i++)

{

adjustedDateString[i]=TDateString[i];

adjustedTimeString[i]=TTimeString[i];

}

adjust();

if(key_flag2)naoling();

if(according())alarm();

DateToStr(&adjusted);

TimeToStr(&adjusted);

write_com(0x82);

write_string(adjustedDateString,8);

write_com(0xc2);

write_string(adjustedTimeString,8);

delay(10);

}

(二)头文件1 显示模块 LCD1602H

#ifndef LCD_CHAR_1602_2009_5_9

#define LCD_CHAR_1602_2009_5_9

#define uchar unsigned char

#define uint unsigned int

sbit lcdrs = P2^0;

sbit lcdrw = P2^1;

sbit lcden = P2^2;

void delay(uint z) // 延时

{

uint x,y;

for(x=z;x>0;x--)

for(y=110;y>0;y--);

}

void write_com(uchar com) // 写入指令数据到 lcd

{

lcdrw=0;

lcdrs=0;

P0=com;

delay(5);

lcden=1;

delay(5);

lcden=0;

}

void write_data(uchar date) // 写入字符显示数据到 lcd

{

lcdrw=0;

lcdrs=1;

P0=date;

delay(5);

lcden=1;

delay(5);

lcden=0;

}

void init1602() // 初始化设定

{

lcdrw=0;

lcden=0;

write_com(0x3C);

write_com(0x0c);

write_com(0x06);

write_com(0x01);

write_com(0x80);

}

void write_string(uchar pp,uint n)

{

int i;

for(i=0;i<n;i++)

write_data(pp[i]);

}

#endif

(三)头文件2 时钟模块 DS1302H

#ifndef _REAL_TIMER_DS1302_2009_5_20_

#define _REAL_TIMER_DS1302_2003_5_20_

sbit DS1302_CLK = P2^6; //实时时钟时钟线引脚

sbit DS1302_IO = P2^7; //实时时钟数据线引脚

sbit DS1302_RST = P2^5; //实时时钟复位线引脚

sbit ACC0 = ACC^0;

sbit ACC7 = ACC^7;

typedef struct SYSTEM_TIME

{

unsigned char Second;

unsigned char Minute;

unsigned char Hour;

unsigned char Week;

unsigned char Day;

unsigned char Month;

unsigned char Year;

unsigned char DateString[9]; //用这两个字符串来放置读取的时间

unsigned char TimeString[9];

}SYSTEMTIME; //定义的时间类型

#define AM(X) X

#define PM(X) (X+12) // 转成24小时制

#define DS1302_SECOND 0x80

#define DS1302_MINUTE 0x82

#define DS1302_HOUR 0x84

#define DS1302_WEEK 0x8A

#define DS1302_DAY 0x86

#define DS1302_MONTH 0x88

#define DS1302_YEAR 0x8C

#define DS1302_RAM(X) (0xC0+(X)2) //用于计算 DS1302_RAM 地址的宏

/内部指令/

void DS1302InputByte(unsigned char d) //实时时钟写入一字节(内部函数)

{

unsigned char i;

ACC = d;

for(i=8; i>0; i--)

{

DS1302_IO = ACC0;

DS1302_CLK = 1;

DS1302_CLK = 0;

ACC = ACC >> 1; //因为在前面已经定义了ACC0 = ACC^0;以便再次利用DS1302_IO = ACC0;

}

}

unsigned char DS1302OutputByte(void) //实时时钟读取一字节(内部函数)

{

unsigned char i;

for(i=8; i>0; i--)

{

ACC = ACC >>1;

ACC7 = DS1302_IO;

DS1302_CLK = 1;

DS1302_CLK = 0;

}

return(ACC);

}

//

void Write1302(unsigned char ucAddr, unsigned char ucDa) //ucAddr: DS1302地址, ucData: 要写的数据

{

DS1302_RST = 0;

DS1302_CLK = 0;

DS1302_RST = 1;

DS1302InputByte(ucAddr); // 地址,命令

DS1302InputByte(ucDa); // 写1Byte数据

DS1302_CLK = 1;

DS1302_RST = 0;

}

unsigned char Read1302(unsigned char ucAddr) //读取DS1302某地址的数据

{

unsigned char ucData;

DS1302_RST = 0;

DS1302_CLK = 0;

DS1302_RST = 1;

DS1302InputByte(ucAddr|0x01); // 地址,命令

ucData = DS1302OutputByte(); // 读1Byte数据

DS1302_CLK = 1;

DS1302_RST = 0;

return(ucData);

}

void DS1302_SetProtect(bit flag) //是否写保护

{

if(flag)

Write1302(0x8E,0x10);

else

Write1302(0x8E,0x00);

}

void DS1302_SetTime(unsigned char Address, unsigned char Value) // 设置时间函数

{

DS1302_SetProtect(0);

Write1302(Address, ((Value/10)<<4 | (Value%10))); //将十进制数转换为BCD码

} //在DS1302中的与日历、时钟相关的寄存器存放的数据必须为BCD码形式

void DS1302_GetTime(SYSTEMTIME Time)

{

unsigned char ReadValue;

ReadValue = Read1302(DS1302_SECOND);

Time->Second = ((ReadValue&0x70)>>4)10 + (ReadValue&0x0F); //将BCD码转换为十进制数

ReadValue = Read1302(DS1302_MINUTE);

Time->Minute = ((ReadValue&0x70)>>4)10 + (ReadValue&0x0F);

ReadValue = Read1302(DS1302_HOUR);

Time->Hour = ((ReadValue&0x70)>>4)10 + (ReadValue&0x0F);

ReadValue = Read1302(DS1302_DAY);

Time->Day = ((ReadValue&0x70)>>4)10 + (ReadValue&0x0F);

ReadValue = Read1302(DS1302_WEEK);

Time->Week = ((ReadValue&0x70)>>4)10 + (ReadValue&0x0F);

ReadValue = Read1302(DS1302_MONTH);

Time->Month = ((ReadValue&0x70)>>4)10 + (ReadValue&0x0F);

ReadValue = Read1302(DS1302_YEAR);

Time->Year = ((ReadValue&0x70)>>4)10 + (ReadValue&0x0F);

}

unsigned char DataToBCD(SYSTEMTIME Time)

{

unsigned char D[8];

D[0]=Time->Second/10<<4+Time->Second%10;

D[1]=Time->Minute/10<<4+Time->Minute%10;

D[2]=Time->Hour/10<<4+Time->Hour%10;

D[3]=Time->Day/10<<4+Time->Day%10;

D[4]=Time->Month/10<<4+Time->Month%10;

D[5]=Time->Week/10<<4+Time->Week%10;

D[6]=Time->Year/10<<4+Time->Year%10;

return D;

}

void DateToStr(SYSTEMTIME Time)

{

//将十进制数转换为液晶显示的ASCII值

Time->DateString[0] = Time->Year/10 + '0';

Time->DateString[1] = Time->Year%10 + '0';

Time->DateString[2] = '-';

Time->DateString[3] = Time->Month/10 + '0';

Time->DateString[4] = Time->Month%10 + '0';

Time->DateString[5] = '-';

Time->DateString[6] = Time->Day/10 + '0';

Time->DateString[7] = Time->Day%10 + '0';

Time->DateString[8] = '\0';

}

void TimeToStr(SYSTEMTIME Time)

{

//将十进制数转换为液晶显示的ASCII值

Time->TimeString[0] = Time->Hour/10 + '0';

Time->TimeString[1] = Time->Hour%10 + '0';

Time->TimeString[2] = ':';

Time->TimeString[3] = Time->Minute/10 + '0';

Time->TimeString[4] = Time->Minute%10 + '0';

Time->TimeString[5] = ':';

Time->TimeString[6] = Time->Second/10 + '0';

Time->TimeString[7] = Time->Second%10 + '0';

Time->DateString[8] = '\0';

}

void Initial_DS1302(void)

{

unsigned char Second;

Second=Read1302(DS1302_SECOND);

if(Second&0x80) //初始化时间

DS1302_SetTime(DS1302_SECOND,0);

}

void DS1302_TimeStop(bit flag) // 是否将时钟停止

{

unsigned char Data;

Data=Read1302(DS1302_SECOND);

DS1302_SetProtect(0);

if(flag)

Write1302(DS1302_SECOND, Data|0x80);

else

Write1302(DS1302_SECOND, Data&0x7F);

}

#endif

这是12864的程序,这是调子程序的语句,看子程序的名是Disp_HZ(0x80,line1,1),应该是显示汉字的语句,调用时带有3个参数,第一个0x80,应该是显示行在第一行,第二个line1,应该是先定义的一个汉字的字符串,就是要显示的汉字,第三个数应该是表示左屏。有些12864屏是分左右屏显示的。具体的这3个参数是不是这些意义,要看具体的子程序就知道了。

我有51的程序,可供参考。

#include "lcd12864h"

#include "zikuh"

#include <stringh>

static void delay(uint j) //延时

{

uchar i;

for(; j!=0; j--)

for(i=0; i<100; i++);

}

void busy(void)

{

uchar i;

for(i=0;i<50;i++)

_nop_();

}

void wdata(uchar wdata)

{

busy(); //忙提示

LCD_RW=0;

LCD_DI=1;

P0=wdata;

LCD_EN=0;

LCD_EN=1;

LCD_EN=0;

}

void wcode(uchar wcode)

{

busy();

LCD_RW=0;

LCD_DI=0;

P0=wcode;

LCD_EN=0;

LCD_EN=1;

LCD_EN=0;

}

void subinit()

{

delay(10);

wcode(0xc0);//设置显示初始行

}

//设置显示位置

void setxy(uchar x,uchar y)

{

if ((y>=0)&(y<=63))

{

LCD_CSA=0;

LCD_CSB=1;

}

else //if (y<=127)

{

LCD_CSA=1;

LCD_CSB=0;

}

wcode(0x40|(y%64));

wcode(0xb8|x);

P0=0xff;

}

void wdram(uchar x,uchar y,uchar dd)

{

setxy(x,y);

wdata(dd);

P0=0xff;

LCD_CSA=1;

LCD_CSB=1;

}

//复位

void Lcd_RST(void)

{

//rst=0;

LCD_REST=0;

delay(50);

LCD_REST=1;

Lcd_Clear(0,7,0,128);

wcode(0x3f);//开显示

}

//LCD初始化

void Lcd_Init(void)

{

LCD_POR=0;

Lcd_RST();

LCD_CSA=0;

LCD_CSB=1;

wcode(0x3e);subinit();

LCD_CSA=1;

LCD_CSB=0;

wcode(0x3e);subinit();

Lcd_Clear(0,7,0,128);

LCD_CSA=0;

LCD_CSB=1;

wcode(0x3f);//开显示

LCD_CSA=1;

LCD_CSB=0;

wcode(0x3f);//开显示

}

void Lcd_On(void)

{

LCD_CSA=0;

LCD_CSB=1;

wcode(0x3f);//开显示

LCD_CSA=1;

LCD_CSB=0;

wcode(0x3f);//开显示

}

//LCD 清显示屏

void Lcd_Clear(uchar StartLine,uchar StopLine,uchar StartRow,uchar StopRow)

{

uchar x,y;

for(x=StartLine; x<StopLine+1; x++)

{

for(y=StartRow; y<StopRow; y++)

{

wdram(x,y,0);

}

}

}

//显示一个汉字

void Lcd_DispOneChar(uchar x,uchar y,uchar hz,uchar disp_mode,uchar Width)

{

uchar i;

for(i=0; i<Width; i++)

{

if(disp_mode==WHITE)

{

wdram(x,y+i,(hz+i));

wdram(x+1,y+i,(hz+Width+i));

}

else

{

wdram(x,y+i,0xff-(hz+i));

wdram(x+1,y+i,0xff-(hz+Width+i));

}

}

if(Width==12)

{

for(i=12; i<14; i++)

{

if(disp_mode==WHITE)

{

wdram(x,y+i,0);

wdram(x+1,y+i,0);

}

else

{

wdram(x,y+i,0xff);

wdram(x+1,y+i,0xff);

}

}

for(i=1; i<4; i++)

{

if(disp_mode==WHITE)

{

wdram(x,y-i,0);

wdram(x+1,y-i,0);

}

else

{

wdram(x,y-i,0xff);

wdram(x+1,y-i,0xff);

}

}

}

}

void Lcd_Disp_String(uchar x,uchar y,char pString,uchar disp_mode)

{

uchar i,j;

uchar LineDispCode[16];

//strlen(),为字符串长度测量。

memset(LineDispCode,0,16); //清零数组

strcpy(LineDispCode,pString); //字符串之间的相互复制。

for(i=0; i<strlen(pString); i++)

{

LineDispCode[i]=(pString+i);

}

i=0;

while(LineDispCode[i]!=0)

{

if(LineDispCode[i]>=0xA0)

{

//显示的是汉字

for(j=0; j<ZIMO_NUM; j++)

{

if(GB_12[j]Index[0]==LineDispCode[i] &&

GB_12[j]Index[1]==LineDispCode[i+1])

{

//显示的是汉字

Lcd_DispOneChar(x,y,GB_12[j]Msk,disp_mode,12);

y+=16;

break;

}

}

i+=2;

}

else

{

//显示的是ASCII编码

for(j=0; j<ASC_NUM; j++)

{

if(ASC_12[j]Index==LineDispCode[i])

{

//显示的是汉字

Lcd_DispOneChar(x,y,ASC_12[j]Msk,disp_mode,8);

y+=8;

break;

}

}

i++;

}

if(i>=16)

{

break;

}

}

}

//显示数字

void Lcd_Disp_OneNum(uchar x,uchar y,uchar num,uchar disp_mode)

{

switch(num)

{

case 0:{Lcd_Disp_String(x,y,"0",disp_mode);}break;

case 1:{Lcd_Disp_String(x,y,"1",disp_mode);}break;

case 2:{Lcd_Disp_String(x,y,"2",disp_mode);}break;

case 3:{Lcd_Disp_String(x,y,"3",disp_mode);}break;

case 4:{Lcd_Disp_String(x,y,"4",disp_mode);}break;

case 5:{Lcd_Disp_String(x,y,"5",disp_mode);}break;

case 6:{Lcd_Disp_String(x,y,"6",disp_mode);}break;

case 7:{Lcd_Disp_String(x,y,"7",disp_mode);}break;

case 8:{Lcd_Disp_String(x,y,"8",disp_mode);}break;

case 9:{Lcd_Disp_String(x,y,"9",disp_mode);}break;

default: break;

}

}

//显示二位数。

void Disp_2num(uchar x,uchar y,uchar num,uchar disp_mode)

{

uchar ch[2];

ch[0]=num%10;

ch[1]=num/10;

Lcd_Disp_OneNum(x,y,ch[1],disp_mode);

Lcd_Disp_OneNum(x,y+8,ch[0],disp_mode);

}

//

//显示三位数。

void Disp_3num(uchar x,uchar y,uint num,uchar disp_mode)

{

uchar ch[2];

ch[0]=num/100;

ch[1]=num%100;

if(ch[0])

Lcd_Disp_OneNum(x,y, ch[0],disp_mode);

else

Lcd_Disp_String(x,y," ",disp_mode);

Disp_2num(x,y+8, ch[1],disp_mode);

}

//

//显示四位数。

void Disp_4num(uchar x,uchar y,uint num,uchar disp_mode)

{

uchar ch[4],tmp;

tmp=num/100;

ch[0]=tmp/10;

ch[1]=tmp%10;

tmp=num%100;

ch[2]=tmp/10;

ch[3]=tmp%10;

Lcd_Disp_OneNum(x,y,ch[0],disp_mode);

Lcd_Disp_OneNum(x,y+8,ch[1],disp_mode);

Lcd_Disp_OneNum(x,y+16,ch[2],disp_mode);

Lcd_Disp_OneNum(x,y+24,ch[3],disp_mode);

}

void Lcd_DispIco2(uchar x,uchar y,uchar pIco)//显示老肯图标

{

uchar i,j;

for(i=0; i<4; i++)

{

for(j=0; j<32; j++)

{

wdram(x+i,y+j,pIco);

pIco++;

}

}

}

//

//显示多位数。 disp_mode&0x10==1时,进行即每位都显示,否则大于0的位置不显示。

void Disp_NumGB16(uchar x,uchar y,ulong Data,uchar num,uchar disp_mode)

{

uchar idata ch=0,i,tmp;

for(i=0;i<num;i++)

{

tmp=Data%10;

Data/=10;

if((disp_mode&0x10)||tmp>0||Data>0||num<=2)

Lcd_Disp_OneNum(x,y+(num-i-1)8,tmp,disp_mode%10);

else

Lcd_Disp_String(x,y+(num-i-1)8," ",disp_mode%10);

}

}

#include <reg52h>

#include <intrinsh>

#define uchar unsigned char

#define uint unsigned int

sbit CS=P2^5; //片选信号

sbit SID=P2^6; //数据信号

sbit SCLK=P2^7; //时钟信号

sbit RST=P2^2; //复位信号

sbit CH = P2^4; //并行、串行选择信号

/

名称 : delay()

功能 : 延时,延时时间为 100us t。这是通过软件延时,有一定误差。

输入 : t

输出 : 无

/

void delay(unsigned int t)

{

unsigned int i,j;

for(i=0; i<t; i++)

for(j=0; j<10; j++);

}

/

名称 : sendbyte()

功能 : 按照液晶的串口通信协议,发送数据

输入 : zdata

输出 : 无

/

void sendbyte(unsigned char zdata)

{

unsigned int i;

for(i=0; i<8; i++)

{

if((zdata << i) & 0x80)

{

SID = 1;

}

else

{

SID = 0;

}

SCLK = 0;

SCLK = 1;

}

}

/

名称 : write_com()

功能 : 写串口指令

输入 : cmdcode

输出 : 无

/

void write_com(unsigned char cmdcode)

{

CS = 1;

sendbyte(0xf8);

sendbyte(cmdcode & 0xf0);

sendbyte((cmdcode << 4) & 0xf0);

delay(2);

}

/

名称 : write_data()

功能 : 写串口指令

输入 : cmdcode

输出 : 无

/

void write_data(unsigned char Dispdata)

{

CS = 1;

sendbyte(0xfa);

sendbyte(Dispdata & 0xf0);

sendbyte((Dispdata << 4) & 0xf0);

delay(2);

}

/

名称 : lcdinit()

功能 : 初始化函数

输入 : cmdcode

输出 : 无

/

void lcdinit()

{

RST = 0;

delay(100);

RST = 1;

delay(20000);

write_com(0x30);

delay(50);

write_com(0x0c);

delay(50);

}

/

名称 : hzkdis()

功能 : 显示字符串

输入 : s

输出 : 无

/

void hzkdis(unsigned char code s)

{

while(s > 0)

{

write_data(s);

s++;

delay(50);

}

}

/

名称 : Test()

功能 : 显示子函数

输入 : 无

输出 : 无

/

void Test()

{

write_com(0x03);

delay(50);

write_com(0x81);

hzkdis(" HOT-51");

write_com(0x91);

hzkdis("单片机开发板");

write_com(0x89);

hzkdis(" ");

write_com(0x98);

hzkdis(" 东流电子");

}

/

名称 : Main()

功能 : 主函数

输入 : 无

输出 : 无

/

void Main()

{

CH = 0;

delay(1);

lcdinit();

delay(10);

while(1)

{

Test();

delay(5000);

}

}

#define uchar unsigned char

#define uint unsigned int

#define iDat 1 //数据标志

#define iCmd 0 //指令标志

#define LCDb_RS 0x20 //定义四个控制引脚

#define LCDb_RW 0x40

#define LCDb_E 0x80

#define LCDb_RST 0x04

#define LCDb_L1 0x80 //第一行的地址

#define LCDb_L2 0x90 //第二行的地址

#define LCDb_L3 0x88 //第三行的地址

#define LCDb_L4 0x98 //第四行的地址

#define LCDb_SET_RS P1OUT|=LCDb_RS //四个控制管脚的控制 *** 作

#define LCDb_SET_RW P1OUT|=LCDb_RW

#define LCDb_SET_E P1OUT|=LCDb_E

#define LCDb_SET_RST P8OUT|=LCDb_RST

#define LCDb_CLR_RS P1OUT&=~LCDb_RS

#define LCDb_CLR_RW P1OUT&=~LCDb_RW

#define LCDb_CLR_E P1OUT&=~LCDb_E

#define LCDb_CLR_RST P8OUT&=~LCDb_RST

#define LCDb_DO P4OUT //输出数据总线端口定义

#define LCDb_FUNCTION 0x38 // 液晶模式为8位,2行,58字符

#define LCDb_BASCMD 0x30 // 基本指令集

#define LCDb_CLS 0x01 // 清屏

#define LCDb_HOME 0x02 // 地址返回原点,不改变DDRAM内容

#define LCDb_ENTRY 0x06 // 设定输入模式,光标加,屏幕不移动

#define LCDb_C2L 0x10 // 光标左移

#define LCDb_C2R 0x14 // 光标右移

#define LCDb_D2L 0x18 // 屏幕左移

#define LCDb_D2R 0x1C // 屏幕又移

#define LCDb_ON 0x0C // 打开显示

#define LCDb_OFF 0x08 // 关闭显示

unsigned char RXData;

unsigned char Result[5]; //整数转化成字符串,给LCD显示

/

函数名称: Delayms

功 能: 延时指定毫秒(8M晶振)

参 数: MS--延时的毫秒数

返回值 : 无

/

void Delayms(uint MS)

{

uint i,j;

for( i=0;i<MS;i++)

for(j=0;j<1141;j++);

}

/

函数名称: Delayus

功 能: 延时指定微秒(8M晶振)

参 数: US--延时的微秒数(大约,不是很精确,MS越大越准确)

返回值 : 无

/

void Delayus(uint US)

{

uint i;

US=US5/4;

for( i=0;i<US;i++);

}

void LCD12864_portini()

{

P1DIR=0xFF;

P4DIR=0xFF;

P8DIR=0xFF; //Trig =P8^3输出;

P8OUT |=LCDb_RST;

// P1OUT=0xFF;

}

/

函数名称: LCD12864_sendbyte

功 能: 向12864液晶写入一个字节数据或者指令

参 数: DatCmd--为iDat时是数据,为iCmd时是指令

dByte--为写入12864的数据或者指令

返回值 : 无

/

void LCD12864_sendbyte(uchar DatCmd, uchar dByte)

{

if (DatCmd == iCmd) //指令 *** 作

LCDb_CLR_RS;

else

LCDb_SET_RS;

LCDb_CLR_RW; //写 *** 作

LCDb_SET_E;

LCDb_DO = dByte; //写入数据

//Delayus(500);

Delayms(1);

LCDb_CLR_E;

}

/

函数名称: LCD12864_sendstr

功 能: 向12864液晶写入一个字符串

参 数: ptString--字符串指针

返回值 : 无

/

void LCD12864_sendstr(uchar ptString)

{

while((ptString)!='\0') //字符串未结束一直写

{

LCD12864_sendbyte(iDat, ptString++);

}

}

/

函数名称: LCD12864_clear

功 能: 12864液晶清屏

参 数: 无

返回值 : 无

/

void LCD12864_clear(void)

{

LCD12864_sendbyte(iCmd,LCDb_CLS);

Delayms(2);// 清屏指令写入后,2ms 的延时是很必要的!!!

}

/

函数名称: LCD12864_gotoXY

功 能: 移动到指定位置

参 数: Row--指定的行

Col--指定的列

返回值 : 无

/

void LCD12864_gotoXY(uchar Row, uchar Col)

{

switch (Row) //选择行

{

case 2:

LCD12864_sendbyte(iCmd, LCDb_L2 + Col); break; //写入第2行的指定列

case 3:

LCD12864_sendbyte(iCmd, LCDb_L3 + Col); break; //写入第3行的指定列

case 4:

LCD12864_sendbyte(iCmd, LCDb_L4 + Col); break; //写入第4行的指定列

default:

LCD12864_sendbyte(iCmd, LCDb_L1 + Col); break; //写入第1行的指定列

}

}

/

函数名称: LCD12864_initial

功 能: 12864液晶初始化

参 数: 无

返回值 : 无

/

void LCD12864_initial(void)

{

Delayms(100); // 等待内部复位

LCD12864_portini(); //端口初始化

LCD12864_sendbyte(iCmd, LCDb_FUNCTION); //功能、模式设定

LCD12864_sendbyte(iCmd, LCDb_ON); //打开显示

LCD12864_clear(); //清屏

LCD12864_sendbyte(iCmd, LCDb_ENTRY); // 输入模式设定

}

void Int_char(int data)

{

if(data/1000)

{

Result[0]=data/1000+'0';

Result[1]=data/100%10+'0';

Result[2]=data/10%10+'0';

Result[3]=data%10+'0';

Result[4]=0;

}

else if(data/100)

{

Result[0]=data/100+'0';

Result[1]=data/10%10+'0';

Result[2]=data%10+'0';

Result[3]=0;

Result[4]=0;

}

else if(data/10)

{

Result[0]=data/10%10+'0';

Result[1]=data%10+'0';

Result[2]=0;

Result[3]=0;

Result[4]=0;

}

else

{

Result[0]=data%10+'0';

Result[1]=0;

Result[2]=0;

Result[3]=0;

Result[4]=0;

}

}

这使msp430单片机的程序,只要在主函数中调用函数,就是调用这个函数Int_char(tmp);每一次循环调用一次,这样可以实时显示这个变化温度数值

LCD12864_gotoXY(2,4);

LCD12864_sendstr(" ");

LCD12864_gotoXY(1,0); //第1行,第1列显示

LCD12864_sendstr("正在检测");

LCD12864_gotoXY(2,0); //第2行,第1列显示

LCD12864_sendstr("距离是:");

Int_char(tmp);

以上就是关于12864液晶不带字库的用C语言和51单片机编程全部的内容,包括:12864液晶不带字库的用C语言和51单片机编程、求51单片机12864和ds1307时钟程序、求一个12864画点简单程序,和一个画图的简单程序,不要教程 要亲测过可以才行。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9712501.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-01
下一篇 2023-05-01

发表评论

登录后才能评论

评论列表(0条)

保存