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

📄 main.c

📁 lcm display,it use i2c 8576,and it can be used motor etc
💻 C
字号:
#include <reg52.h>
//#include <absacc.h>
#include <math.h>
//#include <bios.h>
//#include <AN223.c> 
//#include "Gptbios1.c"
#define DATAPORT P0
#define CNTLPORT P3
#define Uchar   unsigned char
#define SLAVE_ADDR	0x70		//slave address = 0111 0000
void Delay( int t)
{
  	unsigned int i;
  	for(;t>0;t--);
  	 for(i=0;i<1000;i++);
}
void Delay1( int t)
{
  	//unsigned int i;
  	for(;t>0;t--);
}


void I2C_Start(void)
{
	CNTLPORT=0x01;    // SCL = 1
	DATAPORT=0x01;    // SDA = 1
	DATAPORT=0x00;    // SDA = 0
}

void I2C_Stop(void)
{
	CNTLPORT=0x01;    // SCL = 1
	DATAPORT=0x00;    // SDA = 0
	DATAPORT=0x01;    // SDA = 1
}

void ackchk(void)        
{  
   CNTLPORT=0x00;    // SCL = 0
   DATAPORT=0x01;    // SDA = 1
   CNTLPORT=0x01;    // SCL = 1
   CNTLPORT=0x00;    // SCL = 0
}
  
void I2C_Write(Uchar bydata)     //function:write one byte
{
   Uchar i=8;
   while(i--)
   {
      CNTLPORT=0x00;  //SCL=0
	   if(bydata&0x80) DATAPORT=0x01;   //SDA=bit
	   else DATAPORT=0x00;
	   CNTLPORT=0x01;
	   CNTLPORT=0x00;
	   bydata<<=1;
   }               
   ackchk();
}
void add_set(unsigned char address)
{ 	I2C_Start();
   I2C_Write(SLAVE_ADDR);      // 0111 0000
	I2C_Write(0xe0); 
	I2C_Write(address*2);
}

void Initial(void)
{
   I2C_Start();
	I2C_Write(SLAVE_ADDR);  // 0111 0000
	I2C_Write(0xc8);        // MODE SET
	I2C_Write(0xe0);        // DEVICE SELECT
	I2C_Write(0xf8);        // BANK SELECT
	I2C_Write(0xf0);        // BLINK
	I2C_Write(0x00);        // 0000 0000   ;data pointer address
	I2C_Stop();
}

void write_clear(void)
{
   unsigned char i;
   Initial();
   add_set(0x00);
   for(i=0;i<10;i++)
   {
      I2C_Write(0x00);
   }
   I2C_Stop();
}
void write_all(void)
{
   unsigned char i;
   Initial();
   add_set(0x00);
   for(i=0;i<10;i++)
   {
      I2C_Write(0x00);
   }
   I2C_Stop();
}

void write_checkerboard_a(void)
{
   unsigned char i;
   Initial();
   add_set(0x00);
   for(i=0;i<5;i++)
   {
     I2C_Write(0xaa);
     I2C_Write(0x55);
   }
   I2C_Stop();
}

void write_checkerboard_b(void)
{
   unsigned char i;
   Initial();
   add_set(0x00);
   for(i=0;i<5;i++) 
   {
     I2C_Write(0x55);
     I2C_Write(0xaa);      
   }
   I2C_Stop();
}

void character1(void)
{
   unsigned char i;
   unsigned char datacode[]={0xf5,0x05,0xd3};//0 1 2
   Initial();
   add_set(0x00);
   for(i=0;i<3;i++) 
   {
     I2C_Write(datacode[i]);      
   }
   I2C_Stop();
}

void character2(void)
{
   unsigned char i;
   unsigned char datacode[]={0x97,0x27,0xb6};  //3 4 5

   Initial();
   add_set(0x00);
   for(i=0;i<3;i++) 
   {
     I2C_Write(datacode[i]);      
   }
   I2C_Stop();
}

void onebyone(void)
{
   int i;
   unsigned char data1[7]={0x10,0x11,0x15,0x95,0xd5,0xf5,0xf7};
   Initial();
   for( i=0;i<7;i++) 
      { add_set(0);
        I2C_Write(data1[i]);
        I2C_Stop();
        Delay(20000); Delay(20000);

      }
  for( i=0;i<7;i++) 
      { add_set(1);
        I2C_Write(data1[i]);
        I2C_Stop();
        Delay(20000); Delay(20000);

      }
    for( i=0;i<7;i++) 
      { add_set(2);
        I2C_Write(data1[i]);
        I2C_Stop();
        Delay(20000); Delay(20000);

      }
    add_set(2);
    I2C_Write(0xff);
    I2C_Stop();
    Delay(20000); Delay(20000);

  
  
}

unsigned char checkkey(void)
{
unsigned char mm;
mm=P1 ;
if((mm&0X80)==0x80) return 0;

do{

mm=P1 ;
}while((mm&0X80)==0x00);
return 1;

}
//void ShutDown(void);
//void Beep(void);
//void ModifyVlcd(void);
//data int iVlcdSet=500;
//char step=0,step1=9;
//int CC,iVdd,iIdd,iVlcd,iIlcd;//,iVled,iIled;
void main( void )
{ char  step=0,i;
  bit KEY=0;                       			
  while( 1 )
  { 
    CNTLPORT=0x00;
    DATAPORT=0X00;
    Delay(200);
    Initial();
    for( step=0;step<7;step++)
    {
       switch( step )
       {
         case 0:	write_all  ();	 				break;
         case 1:   write_clear();  				break;
         case 2:	character1  (); 				break;
         case 3:	character2  (); 				break;
         case 4:   write_checkerboard_a();    break;
         case 5:   write_checkerboard_b();    break;							
         case 6:   write_clear(); onebyone   ();   	break;										
       }
       KEY=0;
       for(i=0;(i<30)||KEY;i++){Delay(2000);if(checkkey())KEY=!KEY; if(i>=30)i=30;}
       //Delay(20000);     
    }  
    // Delay(20000); Delay(20000);Delay(20000);
    //Delay(20000); Delay(20000); 
    //Delay(20000); 
    //Delay(20000); 
    //Delay(20000); 
    //Delay(20000); 
    //Delay(20000); 
    // checkkey(); 
    // Delay(20000); 
 }         
}                  




⌨️ 快捷键说明

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