⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myc.c

📁 HX8346 lcd driver software which can port to every Platform with some modifying.
💻 C
字号:
//Myc.c
//OSC=12MHz
/*
;                         AT89C52
;              A0 P1.0  1|---=---|40 VCC
;              A1 P1.1  2|       |39 P0.0 DB0
;              A2 P1.2  3|       |38 P0.1 DB1
;              A3 P1.3  4|       |37 P0.2 DB2
;              A4 P1.4  5|       |36 P0.3 DB3
;              A5 P1.5  6|       |35 P0.4 DB4
;              A6 P1.6  7|       |34 P0.5 DB5
;              A7 P1.7  8|       |33 P0.6 DB6
;                  RST  9|       |32 P0.7 DB7
;        KEY (RXD)P3.0 10|       |31 EA/VPP
;        MRD (TXD)P3.1 11|       |30 ALE/PROG
; CLR STEP1 (INT0)P3.2 12|       |29 PSEN
; CLK STEP2 (INT1)P3.3 13|       |28 P2.7 DB15
;          RS (T0)P3.4 14|       |27 P2.6 DB14
;          WR (T1)P3.5 15|       |26 P2.5 DB13
;              RD P3.6 16|       |25 P2.4 DB12
;              CS P3.7 17|       |24 P2.3 DB11
;                XTAL2 18|       |23 P2.2 DB10
;                XTAL1 19|       |22 P2.1 DB9
;                  GND 20|-------|21 P2.0 DB8
*/
//=============================
#include <reg51.h>
#include <absacc.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

#define uchar unsigned char
#define uint unsigned int

sbit   KEY=P3^0;
sbit   SP1=P3^2;
sbit   SP2=P3^3;
sbit     E=P3^6;
sbit    RS=P3^4;
sbit    RW=P3^5;
sbit   CLR=P3^2;
sbit   CLK=P3^3;
sbit    CS=P3^7;
sbit   MRD=P3^1;
sbit    BY=P0^7;
sbit   BBY=P0^6;
//=================
sbit   SDA=P0^1;
sbit   SCL=P0^0;
//=================
uchar autorun0,autorun;
uchar AA7;  //由于column地址(A7)处于page地址中 (硬件)
//=========delay without key==========================================
void DelayX1ms(uchar count)
{
 uchar i,j,k;
 for(i=0;i<count;i++)
  for(j=0;j<40;j++)
   for(k=0;k<120;k++)
    {
     ;
    }
}
//=====================================================================
void DelayX10ms(uint count)
{
 uint i,j,k;
 for(i=0;i<count;i++)
  for(j=0;j<10;j++)
   for(k=0;k<120;k++)
    {
     ;
    }
}
//====================================================================
void Delay50us(uchar count)
{
 uchar i,j;
 for(j=0;j<count;j++)
  for(i=0;i<6;i++)
   {
    ;
   }
}
//==============KEY_WAIT================================================
void key_wait0(uint count)
{
 uchar i,j;
 for(j=0;j<count;j++)
  for(i=0;i<6;i++)
   {
    if(KEY==0)
    autorun0=1;
    ;
   }
}
//=======================================================================
void key_waitx(uint count)
{
 uint i,j,k;
 if(autorun==0)
  {
   for(i=0;i<count;i++)
   for(j=0;j<10;j++)
   for(k=0;k<120;k++)
    {
     if(KEY!=1)
      {
        autorun=1;
        goto next;
      }
     ;
    }
  }
 else
  {
   while(1)
    {
     if(KEY!=1)
      {
       for(i=0;i<100;i++)
       for(j=0;j<100;j++)
         {
            ;
         }
       goto next;
      }
    }
  }
 next:
 ;
}
//===============busy_test===============================================
void busy8080(void)
{
 RS=0;RW=1;E=1;
 P1=0xff;
 while(BY==1)
 {
 E=0;E=0;E=1;
 }
}
//-----------------------
void busy6800(void)
{
 RS=0;RW=1;RW=1;E=1;
 P1=0xff;
 while(BY==1)
 {
 E=0;E=0;E=1;
 }
 E=0;
}
//-------------------
void busy1335(void)
{
 RS=0;RW=1;RW=1;E=1;
 P1=0xff;
 while(BBY==1)
 {
 E=0;E=0;E=1;
 }
 E=0;
}
//==============read data============================================
uchar rd_data8080()
{
  RS=1;RW=1;E=1;P1=0xff;E=0;E=0;E=1;
  return (P1);
}
//--------------------------
uchar rd_data6800()
{
  RS=1;RW=1;E=0;P1=0xff;E=1;E=1;E=0;
  return (P1);
}
//===========EEPROM=SST28XF04===============
//---------------------------
uchar rd_rom()
{
  uchar m;
  MRD=1;;;P0=0xff;;;;;MRD=0;;;MRD=0;;;
  m=P0;
  m=P0;
  MRD=1;;;
  MRD=1;;;
  return (m);
}
//===========EEPROM===================
//========write instruction===========================================
void Set_NOKIA_8B_CMD(uchar x)
{
  RS=0;E=1;RW=1;RW=1;RW=1;P0=x;P0=x;P0=x;RW=0;RW=0;RW=0;RW=0;RW=1;RW=1;RW=1;
  //P0=0xff;
}

void wr_com8080_16(uchar x,uchar y)
{
  RS=0;E=1;RW=1;P0=y;P2=x;
  RW=0;
  RW=1;
  //P0=0xff;P2=0xff;
}
//-------------------------
void wr_com6800(uchar x)
{
  RS=0;E=0;RW=0;P1=x;E=1;E=1;E=0;
  P1=0xff;
}
//---------------------
void s_com(uchar x)
{
 uchar j;
 CS=0;
 RS=0;
 j=8;
 do
 {
  if(x&0x80)
    SDA=1;
  else
    SDA=0;
  ;
  SCL=0;
  ;
  SCL=1;
  --j;
  x<<=1;
 }while(j);
 CS=1;
}
//=========EEPROM===SST28XF04=======
//----------------------
void wr_col(uint x)
{
 P1=x;
 P1=x;
}
//----------------------
void wr_page(uint x)
{
 uint i;
 P1=0;
 P1=0;
 CLR=1;CLR=1;;
 CLR=0;CLR=0;;CLR=0;
 CLR=1;CLR=1;CLR=1;
 if(x>0)
 {
 for(i=0;i<x;i++)
  {
   CLK=1;CLK=1;;
   CLK=0;CLK=0;;CLK=0;
   CLK=1;CLK=1;CLK=1;
  }
 }
}
//---------------------
void wr_incpage()
{
 P1=0;
 P1=0;
 CLK=1;CLK=1;;
 CLK=0;CLK=0;;CLK=0;
 CLK=1;CLK=1;CLK=1;
}
//-----------------------------
//=============EEPROM==================
void wr_com1335(uchar x)
{
 RS=1;E=0;RW=0;P1=x;E=1;E=1;E=0;
}
//=====write display data==================================================
void Set_NOKIA_8B_PA(uchar x)
{
 RS=1;RW=1;RW=1;RW=1;E=1;P0=x;P0=x;P0=x; RW=0; RW=0; RW=0;RW=0;RW=1;RW=1;RW=1;
 //P0=0xff;
}
void wr_data8080_16(uchar x,uchar y)
{
 RS=1;RW=1;E=1;P0=y;P2=x;
 RW=0;
 RW=1;
 //P0=0xff;P2=0xff;
}
//---------------------------
void wr_data6800(uchar x)
{
  RS=1;E=0;RW=0;P1=x;E=1;E=1;E=0;
  P1=0xff;
}
//------------------------
void s_data(uchar x)
{
 uchar j;
 CS=0;
 RS=1;
 j=8;
 do
 {
  if(x&0x80)
    SDA=1;
  else
    SDA=0;
  ;
  SCL=0;
  ;
  SCL=1;
  --j;
  x<<=1;
 }while(j);
 CS=1;
}
//-------------------------
void wr_data1335(uchar x)
{
 RS=0;E=0;RW=0;P1=x;E=1;E=1;E=0;
}
//=============END===========================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -