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

📄 test_01.c

📁 不用多说
💻 C
字号:
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char 
#define uint unsigned int
#define DATABUS P0

sbit LCD_RS=P2^0;
sbit LCD_RW=P2^1;
sbit LCD_E=P2^2;
//#define Busy 0x80
#define fosc  11.0592
#define time0   50000
#define time1   5000
//void delay_ms(uint t); 
void delay5ms(void);
void delay400ms(void);
void display(uchar dd);
void LcdWriteCommand(uchar cmd);
void LcdWriteData(uchar dataW);
void delay(uint t);
void lcd_init();
void WaitForEnable( void ); 
void ePutstr(uchar x,uchar y, uchar  *ptr);
void Display_1(uchar posx,uchar posy, uchar *tab);
void LocateXY( uchar posx,uchar posy);
void DispOneChar(uchar x,uchar y,uchar Wdata); 
void delay(unsigned int t);
void Delay_us(uint value);
void main_int(void);
void changhextodec_mtime(void);

uchar code exampl[]="this is an example for LMB204BDCLCM.   \n";
uchar code temp1[]=
{0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,
0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,
0x51,0x52,0x53,0x53,0x54,0x55,0x56,0x57,0x58,0x59,
0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49};
uchar code temp2[]=
{'1','6','3','8','3','2','5','6','7','1',
'A','B','C','1','1','1','1','1','1','1',

'F','E','D','1','1','1','1','1','1','1',
'1','1','1','1','1','1','1','1','1','1'};

uchar code temp_m[]=
{
'M','T','P',' ','2','6','.','8',' ',' ','T','O','T','M',' ','1','2',':','3','1',
'S','H','M',' ','2','6','.','8',' ',' ','T','M',' ',' ',' ','0','2',':','3','1',

'S','T','T',' ','2','6','.','8',' ',' ','P','H','R',' ',' ','1',' ',' ',' ',' ',
'H','M','T',' ','2','6','.','8',' ',' ','V','T',' ','8',' ','P','T',' ','u','p',
};
uchar code temp_m1[]=
{
'S','T','P',' ','2','3','.','6',' ',' ','T','O','T','M','1','8','2',':','0','9',
'S','H','M',' ','2','1','.','2',' ',' ','T','M',' ',' ',' ','3','2',':','5','1',

'S','T','T',' ','2','5','.','9',' ',' ','W','D','G','T',' ','1','0','0','%',' ',
'H','M','T',' ','5','1','.','3',' ',' ','V','T',' ','7',' ','P','T',' ','m','d',
};

uchar idata disp_temp[80];
uchar count,mint_count,sec_count,hour_count;

uint time0_temp;
uint time1_temp;
uchar mtime_buf[5];

void main_int(void)
{
    

	TMOD=0X11;                   
    PT1=1;
	PT0=0;
    time0_temp=65536-time0*fosc/12;
	//TL0=(65536-50000)%256;            //50ms time
    //TH0=(65536-50000)/256;
    TL0=time0_temp%256;
    TH0=time0_temp/256;

	time1_temp=65536-time0*fosc/12;   	
    //TL1=(65536-5000)%256;             //5ms
	//TH1=(65536-5000)/256;
	TL1=time1_temp%256;
	TH1=time1_temp/256;

	ET1=1;     //PROMISE
	ET0=1;
	TR1=0;     //close time1    
	TR0=1;     //open time0
    EA=1;
	count=0;
	sec_count=0;
	mint_count=0;
	hour_count=0;
}





void main(void)
{
    uchar temp;
	uchar i;
    temp=0x80;
	main_int();
    lcd_init();
	LcdWriteCommand(temp);
   // Display_1(0,0,temp_m);
	delay5ms();
    //for(i=0;i<40;i++)
	  // {LcdWriteData(temp2[i]);}
	while(1);
  while(1)
	     {
            changhextodec_mtime();   
            for(i=0;i<80;i++)
	          {	
			      disp_temp[i]=temp_m[i];
                 changhextodec_mtime(); 
                 if(i==14)
				     {disp_temp[i]=mtime_buf[4];}
				 if(i==15)
				     {disp_temp[i]=mtime_buf[3];}
				 if(i==16)
				     {disp_temp[i]=mtime_buf[2];}
				 if(i==18)
				     {disp_temp[i]=mtime_buf[1];}
				 if(i==19)
				     {disp_temp[i]=mtime_buf[0];}
				 if(i==35)
				     {disp_temp[i]=mtime_buf[3];}
				 if(i==36)
				     {disp_temp[i]=mtime_buf[2];}
				 if(i==38)
				     {disp_temp[i]=mtime_buf[1];}
				 if(i==39)
				     {disp_temp[i]=mtime_buf[0];}
                 LcdWriteData(disp_temp[i]);
		         Delay_us(100);

	          }
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            LcdWriteCommand(0x01);
            delay5ms();
            delay5ms();
            delay5ms();
            delay5ms();

            for(i=0;i<80;i++)
	          {	
                 disp_temp[i]=temp_m1[i];
            changhextodec_mtime(); 
                 if(i==14)
				     {disp_temp[i]=mtime_buf[4];}
				 if(i==15)
				     {disp_temp[i]=mtime_buf[3];}
				 if(i==16)
				     {disp_temp[i]=mtime_buf[2];}
				 if(i==18)
				     {disp_temp[i]=mtime_buf[1];}
				 if(i==19)
				     {disp_temp[i]=mtime_buf[0];}
				 if(i==35)
				     {disp_temp[i]=mtime_buf[3];}
				 if(i==36)
				     {disp_temp[i]=mtime_buf[2];}
				 if(i==38)
				     {disp_temp[i]=mtime_buf[1];}
				 if(i==39)
				     {disp_temp[i]=mtime_buf[0];}
                 LcdWriteData(disp_temp[i]);
		         Delay_us(100);
	          }
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
            delay400ms();
   LcdWriteCommand(0x01);
         delay5ms();
delay5ms();
delay5ms();
delay5ms();
       }


}


void delay5ms(void)
{
    uint i=5552;
    while(i--);
}
void delay400ms(void)
{
    uchar i=5;
    uint j;
    while(i--)
       { 
           j=7269;
           while(j--);
       };
}




          
           

void LcdWriteCommand(uchar cmd)
{

   delay5ms();
   //delay5ms();
   //delay5ms();
    LCD_RW=0;
    LCD_RS=0;
    //delay(5);
	LCD_E=1;
   DATABUS=cmd;
    //delay(5);
    LCD_E=0;
    //delay(5);

}

void LcdWriteData(uchar dataW)
{
	delay5ms();
	//delay5ms();
	//delay5ms();
	//delay5ms();
    LCD_RW=0;
    LCD_RS=1;
    //delay(5);
	LCD_E=1;
   DATABUS=dataW;
    //delay(5);
    LCD_E=0;
    //delay(5);
}
/*void display(uchar dd)
{
    uchar i;
    for(i=0;i<20;i++)
        {
             DispOneChar(i,1,dd++);
             dd&=0x7f;
             if(dd<32)dd=32;
        }
}*/

void lcd_init()
{
//
     LCD_E=0;
     delay5ms();
     delay5ms();
     delay5ms();
     delay5ms();
            delay5ms();
     delay5ms();
     delay5ms();
     delay5ms(); 
     delay5ms();
     delay5ms();
     delay5ms();

     LcdWriteCommand(0x38);
         Delay_us(100);

     LcdWriteCommand(0x38);
	 delay5ms();
         Delay_us(100);          
    LcdWriteCommand(0x0e);
         Delay_us(100);

   LcdWriteCommand(0x01);
         delay5ms();


    LcdWriteCommand(0x06);
         Delay_us(100);

}

  
    
    
/*=======================================================
 显示字符串
=======================================================*/
void ePutstr(uchar x,uchar y, uchar  *ptr) 
{
    uchar i,l=0;
        //LcdWriteCommand(0x01,1);
    //Delay_us(1520);
	while (ptr[l] >31)
	    {
		    l++;
		};
	for (i=0;i<l;i++) 
	    {
		    DispOneChar(x++,y,ptr[i]);
			 
		    if ( x == 20 )
		         {
			         x = 0; 
			         if(y<3)
			            y=y+1;  
			         else
			            y=0;
		         }
	    }
}

/*=======================================================
 演示一行连续字符串,配合上位程序演示移动字串
=======================================================*/
void Display_1(uchar posx,uchar posy, uchar *tab) 
{

    uchar i;   	
	for (i=0;i<20;i++) 
	 {
		DispOneChar(posx++,posy,tab[i]);

	 		tab[i] &= 0x7f;
		    if (tab[i]<32) tab[i]=32;
	 }
}


/*=======================================================
 显示光标定位
=======================================================*/
 void LocateXY( uchar posx,uchar posy) 
 {

     uchar temp=0;

	if(posy==0)
	     {temp=posx ;}//& 0x13;
     //	posy &= 0x03;
	
	if(posy==1)
	    {temp=posx+0x40;}
	if(posy==2)
	    {temp=posx+0x14;}
	if(posy==3) 
	    {temp=posx+0x54;}

	 temp|= 0x80;
	 //LcdWriteCommand(temp&0xf0,0);
     LcdWriteCommand(temp);
           Delay_us(37);
	 //LcdWriteCommand((temp&0x0f)<<4,0);


}

/*=======================================================
 按指定位置显示数出一个字符
=======================================================*/
void DispOneChar(uchar x,uchar y,uchar Wdata) 
{

	LocateXY( x, y );
    LcdWriteData(Wdata);
	delay5ms();

}
    
    
void delay(unsigned int t)
  {
     unsigned int i;
     for(i=0;i<t;i++); 
  }
void Delay_us(uint value)
{
	for(value=value/4+1 ; value ; value--);
}

    

void time0_int(void) interrupt 1 using 1
{
    //TF2=0;
    time0_temp=65536-time0*fosc/12;
	//TL0=(65536-50000)%256;            //50ms time
    //TH0=(65536-50000)/256;
    TL0=time0_temp%256;
    TH0=time0_temp/256;
    
    count++;
    if(count==20)
        {
            count=0;             //1s            
            if(disp_temp[17]!=0x20)
			    {disp_temp[17]=0x20;}
			else
			    {disp_temp[17]=':';}
			if(disp_temp[37]!=0x20)
			    {disp_temp[37]=0x20;}
			else
			    {disp_temp[37]=':';}
            sec_count++;
            if(sec_count==60)
                {
                    sec_count=0;
                    mint_count++;
                    if(mint_count==60)
                        {
                            mint_count=0;
                            hour_count++;
                        }
                }
           	//dian_buf=0x3a;     //: display per second
			//delay_ms(40);
			//dian_buf=0x20;

        }
}


void changhextodec_mtime(void)
{
    uchar i;
    mtime_buf[0]=mint_count%10+0x30;
	mtime_buf[1]=mint_count/10+0x30;
	mtime_buf[4]=hour_count/100+0x30;
	i=hour_count%100;
	mtime_buf[2]=i%10+0x30;
	mtime_buf[3]=i/10+0x30;
}



















⌨️ 快捷键说明

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