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

📄 hx8303.c

📁 C8051F单片机应用和液晶显示器编程的例子
💻 C
📖 第 1 页 / 共 2 页
字号:
//-----------------------------------------------------------------------------
// Copyright (C) 2004 Silicon Laboratories, Inc.
//
// AUTH: JS
// DATE: 03 JUL 02
//
// This program flashes the green LED on the C8051F31x target board about 
// five times a second using the interrupt handler for Timer2.
//
// Target: C8051F31x
//
// Tool chain: KEIL Eval 'c'
//

//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
//OSC=24.5MHz
/* 
;                                C8051F310
;            KEY5    P0.1       1|---=---|32 P0.2 XTAL1
;            KEY6    P0.0       2|       |31 P0.3 XTAL2
;            GND                3|       |30 P0.4 KEY1
;            VDD                4|       |29 P0.5 KEY2
;            /RST/C2ACK         5|       |28 P0.6 CNVSTR KEY3
;            KEY7    P3.0(C2D)  6|       |27 P0.7 KEY4
;            CS2     P3.1       7|       |26 P1.0 D0
;            CS1     P3.2       8|       |25 P1.1 D1
;            RD      P3.3       9|       |24 P1.2 D2
;            WR      P3.4      10|       |23 P1.3 D3
;            RS      P2.7      11|       |22 P1.4 D4
;            MR_B    P2.6      12|       |21 P1.5 D5
;            MWE     P2.5      13|       |20 P1.6 D6
;            MRE     P2.4      14|       |19 P1.7 D7
;            MALE    P2.3      15|       |18 P2.0 LP
;            MCLE    P2.2      16|-------|17 P2.1 MCE
;              
*/
//=============================
#include <c8051f310.h>

//=============================

#define uchar unsigned char
#define uint unsigned int
//=============================
uchar xdata buffer[513];     //开辟页缓存数组
uchar *pointer;              //建立数组指针
uchar raddrl; uchar raddrh;  //页寻址的高、低位
uchar mydata;                //数据
//=============================
sbit         KEY3  =P0^6;    //fr
sbit         KEY4  =P0^7;    //-
sbit         KEY2  =P0^5;    //+
sbit         KEY7  =P3^0;    //no step
sbit         KEY1  =P0^4;    //step
sbit           RD  =P3^3;
sbit           RS  =P2^7;
sbit           WR  =P3^4;
sbit          MR_B =P2^6;
sbit          MWE  =P2^5;
sbit          MRE  =P2^4;
sbit          MALE =P2^3;
sbit          MCLE =P2^2;
sbit          MCE  =P2^1; 
sbit		  CS1  =P3^2; 
sbit          LP   =P2^0;
//================
sbit    LED  =P0^0;
//=================
uchar autorun0,data_out;
uint ii,jj,kk,wait_value,aa,bb,cc;
int otp_value;
//========write instruction===========================================
void wr_com8080(uchar x)
{
  RS=0;RD=1;WR=1;WR=1;WR=1;P1=x;P1=x;P1=x;WR=0;WR=0;WR=0;WR=0;WR=1;WR=1;WR=1;
  P1=0xff;
}
void wr_com8080_16(uchar XH,XL)
{
  RS=0;
  RD=1;
  LP=1;
  WR=1;WR=1;WR=1;
  P1=XH;P1=XH;
  LP=0;
  LP=0;
  P1=XL;P1=XL;
  WR=0;WR=0;WR=0;WR=0;
  WR=1;WR=1;WR=1;
  P1=0xff;
}
//=====write display data==================================================
void wr_data8080(uchar x)
{
 RS=1;WR=1;WR=1;WR=1;RD=1;P1=x;P1=x;P1=x; WR=0; WR=0; WR=0;WR=0;WR=1;WR=1;WR=1;
 P1=0xff;
}
void wr_data8080_16(uchar XH,XL)
{
 RS=1;
 RD=1;
 LP=1;
 WR=1;WR=1;WR=1;
 P1=XH;P1=XH;
 LP=0;
 LP=0;
 P1=XL;P1=XL;
 WR=0; WR=0; WR=0;WR=0;
 WR=1;WR=1;WR=1;
 P1=0xff;
}
//=========================================================
void coordinate(uchar col,page)
{
     //RAM Address Set (R21h)
     wr_com8080_16(0x00,0x21);
     wr_data8080_16(page,col);
}
//=========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++)
   {
    ;
    }
}
//=======================================================================
void key_wait(uint count)
{
 uint i,j,k;
 if(autorun0==0)
  {
   for(i=0;i<count;i++)
   for(j=0;j<10;j++)
   for(k=0;k<20;k++)
    {
     if(KEY1!=1)
      {
        autorun0=1;
        goto next;
      }
     //==========================
     if(KEY7==0)
     {
      while(KEY7==0)
	  {
	   ;
	  }
      kk=1000;
	  while(KEY7==0)
	  {
	   ;
	  }
      goto next; 
	 }
    //==========================
	if(KEY3==0)
     {
	  while(KEY3==0)
	  {
	  ;
	  }
	  DelayX10ms(25);
	  while(KEY3==0)
	  {
	  ;
	  }
	  if(wait_value==40)
	   wait_value=70;
      else if(wait_value==70)
	   wait_value=110;
      else if(wait_value==110)
	   wait_value=180;
      else 
	   wait_value=40;
     goto next;  
     }
    }
  }
 else
  {
   while(1)
    {
     if(KEY1!=1)
      {
       for(i=0;i<100;i++)
       for(j=0;j<100;j++)
         {
            ;
         }
       goto next;
       }
     //==============================
     if(KEY7!=1)
     {
      while(KEY7!=1)
	  {
	   ;
	  }
      kk=1000;
      goto next; 
	 }
    //==========================
	DelayX10ms(25);
     if(KEY2==0)
     {
      while(KEY2==0)
	  {
	  ;
	  }
	  /*wr_com8080(0x2a);
      otp_value=otp_value+1;
      if(otp_value==256)
        otp_value=0xff;
      wr_com8080(otp_value);*/
     }
    //==========================
    if(KEY4==0)
     {
      while(KEY4==0)
	  {
	  ;
	  }
	  /*wr_com8080(0x2a);
      otp_value=otp_value-1;
      if(otp_value==-1)
        otp_value=0x00;
      wr_com8080(otp_value);*/
     }
   }
  }
 next:
 //==========================
 RS=1;
 //==========================
}
//=======================================================================
void pic_wait(uint count)
{
 uint i,j,k;
 if(autorun0==0)
  {
   for(i=0;i<count;i++)
   for(j=0;j<10;j++)
   for(k=0;k<120;k++)
    {
     if(KEY1!=1)
      {
        autorun0=1;
        goto next;
      }
     //==========================
     if(KEY7!=1)
     {
      while(KEY7!=1)
	  {
	   ;
	  }
      kk=1000;
      goto next; 
	 }
    }
  }
 else
  {
   while(1)
    {
     if(KEY1!=1)
      {
       for(i=0;i<100;i++)
       for(j=0;j<100;j++)
         {
          ;
         }
      while(KEY1==0)
	   {
		 ;
	   }
       goto next;
      }
     //==========================
     if(KEY7!=1)
     {
      while(KEY7!=1)
	  {
	   ;
	  }
      kk=1000;
      goto next; 
	 }
     //==========================
	 DelayX10ms(25);
     if(KEY2==0)
     {
      while(KEY2==0)
	  {
	  ;
	  }
	  /*wr_com8080(0x2a);
      otp_value=otp_value+1;
      if(otp_value==256)
        otp_value=0xff;
      wr_com8080(otp_value);*/
     }
    //==========================
    if(KEY4==0)
     {
      while(KEY4==0)
	  {

⌨️ 快捷键说明

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