找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1543|回复: 1
打印 上一主题 下一主题
收起左侧

12864程序

[复制链接]
跳转到指定楼层
楼主
ID:385513 发表于 2018-8-12 16:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include"main.h"
#include"12864.h"
#include<intrins.h>
#include<stdlib.h>

#define BASIC_SET 0x30
#define EXTEND_SET 0x34
#define DRAW_ON 0x36
#define DRAW_OFF  0x34






//=======================================================================
//        函数名称: void delaypic(uint k)
//        函数功能: 延时函数
//        作者:
//        日期:2017.8.4
//        备注:
//=======================================================================
void delaypic(uint k)
{
uint i;
uchar j;
for(i = 0; i < k ;i ++)
for(j = 0; j < 10 ;j ++);
}

//=======================================================================
//        函数名称:  delay(uint16 time)
//        函数功能:延时函数
//        作者:
//        日期:2017.8.4
//        备注:
//=======================================================================
      delay(uint16 time)               
{
  uint16  i,j;            
  for(i=0;i<time;i++)   
     for(j=0;j<100;j++);
}






//=======================================================================
//        函数名称:  checkbusy()
//        函数功能:查忙
//        作者:
//        日期:2017.8.4
//        备注:
//=======================================================================
checkbusy()           
{
   RS=0;                    
   RW=1;                  
   E=1;                  
   while((P0&0x80)==0x80);
   E=0;                  
}






//=======================================================================
//        函数名称:wcode(uint8 cmdcode)
//        函数功能:写入命令
//        作者:
//        日期:2017.8.4
//        备注:
//=======================================================================

wcode(uint8 cmdcode)
{
   checkbusy();            
   RS=0;                  
   RW=0;                  
   E=1;                  
   P0 = cmdcode;            
   delay(10);            
   E=0;                  
}






//=======================================================================
//        函数名称: wdata(uint8 dispdata)
//        函数功能:写入数据
//        作者:
//        日期:2017.8.4
//        备注:
//=======================================================================
wdata(uint8 dispdata)
{
   checkbusy();           
   RS=1;                  
   RW=0;                  
   E=1;                    
   P0 = dispdata;            
   delay(10);            
   E=0;                  
}









/*******************************************************
* 函 数 名:unsigned char rd_dat( void )
* 功能描述:读数据
* 函数说明:从12864b读数据
* 输入参数:无
* 返 回 值:unsigned char byReturnValue
*******************************************************/
unsigned char rd_dat( void )  
{
    unsigned char byReturnValue ;
    P0 = 0xff ;
        checkbusy();
        RS=1;
        RW=1;
        E=0;
        E=1;
  byReturnValue = P0 ;
        E=0;
  return byReturnValue ;   
}


//=======================================================================
//        函数名称: InitLCD()
//        函数功能:LCD初始化
//        作者:
//        日期:2017.8.4
//        备注:
//=======================================================================
InitLCD()
   {
   PSB=1;            
   RES=0;            
   delay(10);        
   RES=1;            
   wcode(0x30);      
   wcode(0x0c);      
   wcode(0x01);      
   wcode(0x06);      
   }






//=======================================================================
//        函数名称: void dis(uint8 x,uint8 y,uint8 code *s)
//        函数功能:坐标位置写入数据
//        作者:
//        日期:2017.8.4
//        备注:X为横行,Y为纵行
//=======================================================================
void dis(uint8 x,uint8 y,uint8  *s)   
{                                    
switch(y)                                   
     {
          case 0: wcode(0x80+x);break;   
          case 1: wcode(0x90+x);break;   
          case 2: wcode(0x88+x);break;   
          case 3: wcode(0x98+x);break;   
      default:break;
         }
   while(*s>0)                       
     {  
      wdata(*s);                     
      delay(10);                    
      s++;                           
     }
}






/*******************************************************
* 函 数 名:void DrawPoint( unsigned char X, unsigned char Y, unsigned char Color )
* 功能描述:画点
* 函数说明:在制定位置画一个像素的点
* 输入参数:unsigned char X, unsigned char Y, unsigned char Color
*          X为列,Y为行,COLOR为不显示、显示或者翻转(0、1、2)
* 返 回 值:无
*******************************************************/
void DrawPoint( unsigned char X, unsigned char Y, unsigned char Color )
{
    unsigned char Row , Tier , Tier_bit    ;
    unsigned char ReadOldH, ReadOldL ;
          Tier = X >> 4 ;   
    Tier_bit = X & 0x0f ;
    if( Y < 32 )
    {
        Row = Y ;
    }
    else
    {
        Row = Y - 32 ;
        Tier += 8 ;
    }
        wcode(Row + 0x80);                //写入行坐标
        wcode(Tier + 0x80);        //写入列坐标
        rd_dat();
    ReadOldH = rd_dat() ;         //读出原始数据
    ReadOldL = rd_dat() ;
        wcode(Row + 0x80);
        wcode(Tier + 0x80);
    if( Tier_bit < 8 )
    {
        switch( Color)
        {
            case 0 : ReadOldH &=( ~( 0x01 << ( 7 - Tier_bit ))) ; break ;        //不显示
            case 1 : ReadOldH |= ( 0x01 << ( 7 - Tier_bit )) ; break ;                //显示
            case 2 : ReadOldH ^= ( 0x01 << ( 7 - Tier_bit ))    ; break ;   //翻转
            default : break ;   
        }
                wdata(ReadOldH);  //写入新数据
                wdata(ReadOldL);
    }
    else
    {
        switch(Color)
        {
            case 0 : ReadOldL &= (~( 0x01 << ( 15 - Tier_bit ))) ; break ;
            case 1 : ReadOldL |= ( 0x01 << ( 15 - Tier_bit ))    ; break ;
            case 2 : ReadOldL ^= ( 0x01 << ( 15 - Tier_bit )) ; break ;
            default : break ;
        }
                wdata(ReadOldH);
                wdata(ReadOldL);
    }
}






/*------------------------------------------------
                 设置到绘图模式
------------------------------------------------*/
void SetGraphicMode()
{
    wcode(0x36);       //选择8bit数据流 图形模式
   delaypic(50);

}


/*------------------------------------------------
                   显示图片
------------------------------------------------*/
void LCD_PutGraphic(unsigned char code *img)
{
int i,j;
//显示上半屏内容设置
   for(i=0;i<32;i++)            
    {
      wcode(0x80 + i); //SET  垂直地址 VERTICAL ADD
      wcode(0x80);     //SET  水平地址 HORIZONTAL ADD
      for(j=0;j<16;j++)
       {
         wdata(*img);
         img++;
       }
    }
//显示下半屏内容设置
   for(i=0;i<32;i++)            
    {
      wcode(0x80 + i); //SET  垂直地址 VERTICAL ADD
      wcode(0x88);     //SET  水平地址 HORIZONTAL ADD
      for(j=0;j<16;j++)
       {
        wdata(*img);
         img++;
       }
    }  

}


/*------------------------------------------------
                      清屏
------------------------------------------------*/
void ClrScreen()
{
   wcode(0x01);
   delaypic(40);
}
//***************************************************************************以下为GDRAM绘图部分************************************************************************//
//*********************绘图显示的清屏函数(因清屏指令在画图时不能用)------------------------------------------------------------------------------注意!!!!!!!
void gui_clear()
{
uchar i , j , k;
wcode(EXTEND_SET);//扩展指令集,8位数据传输
wcode(DRAW_OFF);  //绘图显示关闭
for(i = 0; i < 2; i ++)//分上下两屏写
{
for(j = 0; j < 32; j ++)
{
wcode(0x80 + j);//写y坐标
delaypic(1);
if(i == 0) //写x坐标
{
wcode(0x80);
delaypic(1);
}
else //写下半屏
{
wcode(0x88);
delaypic(1);
}
for(k = 0; k < 16; k ++)//写一整行数据
{
wdata(0x00);//写高字节
wdata(0x00);//写低字节
delaypic(1);
}
}

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:1 发表于 2018-8-14 00:52 | 只看该作者
需要补全原理图与头文件后才可获得积分  不然这帖无意义的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表