原创 51 LCD12864实验 实验(十九)

2008-5-12 11:36 3484 5 6 分类: MCU/ 嵌入式

rarrarrar


这个实验是基于LCD12864的基本显示实验,熟悉LCD12864的使用.详情见附件.


平台:FDR-1开发板


主程序代码:


#include <reg52.h>
#include"delay.h"    //包含延时函数的头文件
/**************************************************************
               iO口宏定义区
***************************************************************/
sbit CS =P1^0;
sbit SID="P1"^1;//r/w
sbit SCK="P1"^2;//e
sbit psb="P1"^3;//串行并行数据选择端
sbit rst="P1"^5;//复位 
/*******************************************************************
              常量声明区
********************************************************************/
unsigned char code time[]={"0123456789"} ;     
unsigned char code AC_TABLE[]={               //坐标编码
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,
};
/****************************************************************
 声明:建议读者先查阅我们提供的12864word文档资料,理解12864定坐标的
 方式。              
              发送一个字节
*****************************************************************/
void SendByte(unsigned char Dbyte)
{
 unsigned char i;
 for(i=0;i<8;i++)
 {
  SCK = 0;
  Dbyte=Dbyte<<1;
  SID = CY;
  SCK = 1;
  SCK = 0;
 }
}
/**********************************************************
              接收一个字节
***********************************************************/


unsigned char ReceiveByte(void)
{
 unsigned char i,temp1,temp2;
 temp1=temp2=0;
 for(i=0;i<8;i++)
 {
  temp1=temp1<<1;
  SCK = 0;
  SCK = 1;               
  SCK = 0;
  if(SID) temp1++;
 }
 for(i=0;i<8;i++)
 {
  temp2=temp2<<1;
  SCK = 0;
  SCK = 1;
  SCK = 0;
  if(SID) temp2++;
 }
 return ((0xf0&temp1)+(0x0f&temp2));
}
/****************************************************************
                      检查忙状态
******************************************************************/
void CheckBusy( void )
{
 do SendByte(0xfc);     //11111,RW(1),RS(0),0
 while(0x80&ReceiveByte());
}


/******************************************************************
           写一个字节的指令
*******************************************************************/
void WriteCommand( unsigned char Cbyte )
{
 CS = 1;
 CheckBusy();
 SendByte(0xf8);          //11111,RW(0),RS(0),0
 SendByte(0xf0&Cbyte);
 SendByte(0xf0&Cbyte<<4);
 CS = 0;
}
/*************************************************************
                 写一个字节的数据
**************************************************************/
void WriteData( unsigned char Dbyte )
{
 CS = 1;
 CheckBusy();
 SendByte(0xfa);          //11111,RW(0),RS(1),0
 SendByte(0xf0&Dbyte);
 SendByte(0xf0&Dbyte<<4);
 CS = 0;
}


/******************************************************************
                         lcd初始化函数
*******************************************************************/
void LcmInit( void )
{
     rst="1";
  psb="0";    //串行接法
     WriteCommand(0x30);
     WriteCommand(0x03);
     WriteCommand(0x0c);
     WriteCommand(0x01);
     WriteCommand(0x06);
}


/*******************************************************************************************************
                                 设定光标函数
********************************************************************************************************/
void Location_xy_12864(unsigned char x,unsigned char y)
{
 switch(x)
 {
  case 0:
   x=0x80;break;
  case 1:
   x=0x90;break;
  case 2:
   x=0x88;break;
  case 3:
   x=0x98;break;
  default:
   x=0x80;
 }
 y=y&0x07;
 WriteCommand(0x30);
 WriteCommand(y+x);
 WriteCommand(y+x);


}
/***********************************************************************************
                  清除文本
************************************************************************************/
void LcmClearTXT( void )
{
 unsigned char i;
 WriteCommand(0x30);
 WriteCommand(0x80);
 for(i=0;i<64;i++)
 WriteData(0x20);
 Location_xy_12864(0,0);    
}
/**************************************************************************************
                   清除图片
*****************************************************************************************/
void LcmClearBMP( void )
{
 unsigned char i,j;
 WriteCommand(0x34);
 WriteCommand(0x36);
 for(i=0;i<32;i++)
 {
  WriteCommand(0x80|i);
  WriteCommand(0x80);
  for(j=0;j<32;j++)
  WriteData(0);
 }
}
/****************************************************************************************
                      显示字符串
*****************************************************************************************/
void PutStr(unsigned char row,unsigned char col,unsigned char *puts)
{   
 WriteCommand(0x30);
 WriteCommand(AC_TABLE[8*row+col]);
 while(*puts != '\0')
 {
  if(col==8)
  {
   col=0;
   row++;
  }
  if(row==4) row="0";
  WriteCommand(AC_TABLE[8*row+col]);
  WriteData(*puts);
  puts++;
  if(*puts != '\0')
  {
   WriteData(*puts);
   puts++;
   col++;
  } 
 }
}


/**************************************************************************
                      显示全屏图片
***************************************************************************/
void PutBMP(unsigned char *puts)
{         
 unsigned int x="0",y=0;
 unsigned char i,j;
 WriteCommand(0x34);
 WriteCommand(0x36);
 for(i=0;i<32;i++) 
 {
  WriteCommand(0x80|i);
  WriteCommand(0x80); 
  for(j=0;j<16;j++)   
  {                    
   WriteData(puts[x]);
   x++;
  }
  y=x-16;
  for(j=0;j<16;j++)   
  {                   
   WriteData(puts[y+512]); 
   y++;
  }
 } 
}
/**************************************************************************
                                    图片数据存放区
**************************************************************************/
unsigned char code bmp7[]={ 0x10};
unsigned char code bmp8[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x04,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x0F,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF8,0x00,0x7F,0xC0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0x07,0xFF,0xF0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x1F,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,
0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,
0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,
0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,
0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xC0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,
0xFF,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,
0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,
0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,
0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xF0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xF0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xE0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFC,0x01,0xFF,0xC0,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xF8,0x00,0x3F,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,0x0E,0x70,0x30,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x11,0x08,0x48,0x88,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x11,0x08,0x84,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x11,0x08,0x84,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x11,0x08,0xFC,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x11,0x08,0x84,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x11,0x08,0x84,0x88,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,
0x08,0x84,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
/******************************main 函数开始*****************************/  
void main()

 LcmInit();
 delayms(100);
 PutStr(1,2,"loading...");
 delayms(10000);
 LcmClearTXT();
 LcmClearBMP();
 PutBMP(bmp8) ;
 delayms(10000);
 LcmClearBMP();
 PutStr(0,1,"FDR 工作室");
 PutStr(1,1,"QQ群:");
 PutStr(2,3,"49865954");
 while(1);
}

PARTNER CONTENT

文章评论1条评论)

登录后参与讨论

用户833911 2010-11-7 10:39

好东东
相关推荐阅读
正点原子 2013-05-17 23:47
【连载】【ALIENTEK 战舰STM32开发板】STM32开发指南--第六十一章 战舰STM32开发板综合实验(标准例程终结篇)
   第六十一章 战舰STM32开发板综合实验        前面已经给大家讲了55个实例了,本章将设计一个综合实例,作为本指南的最后一个实验 ,该实验向大家展示了STM...
正点原子 2013-05-03 23:02
【连载】【ALIENTEK 战舰STM32开发板】STM32开发指南--第六十章 UCOSII实验3-消息队列、信号量集和软件定时器
   第六十章 UCOSII实验3-消息队列、信号量集和软件定时器   上一章,我们学习了UCOSII的信号量和邮箱的使用,本章,我们将学习消息队列、信号量集和软件定时器...
正点原子 2013-05-03 20:42
【连载】【ALIENTEK 战舰STM32开发板】STM32开发指南--第五十七章 ENC28J60网络实验
第五十七章 ENC28J60网络实验   本章,我们将向大家介绍ALIENTEK ENC28J60网络模块及其使用。本章,我们将使用ALIENTEK ENC28J60网络模块...
正点原子 2013-05-01 23:00
【连载】【ALIENTEK 战舰STM32开发板】STM32开发指南--第五十九章 UCOSII实验2-信号量和邮箱
第五十九章 UCOSII实验2-信号量和邮箱      上一章,我们学习了如何使用UCOSII,学习了UCOSII的任务调度,但是并没有用到任务间的同步与通信,本章我们将学习两个最基本的...
正点原子 2013-04-30 10:55
【连载】【ALIENTEK 战舰STM32开发板】STM32开发指南--第五十八章 UCOSII实验1-任务调度
  第五十八章 UCOSII实验1-任务调度      前面我们所有的例程都是跑的裸机程序(裸奔),从本章开始,我们将分3个章节向大家介绍UCOSII(实时多任务操作系...
正点原子 2013-04-26 23:16
【连载】【ALIENTEK 战舰STM32开发板】STM32开发指南--第五十七章 ENC28J60网络实验
 第五十七章 ENC28J60网络实验  本章,我们将向大家介绍ALIENTEK ENC28J60网络模块及其使用。本章,我们将使用ALIENTEK ENC28J60网络模块和uIP 1...
EE直播间
更多
我要评论
1
5
关闭 站长推荐上一条 /3 下一条