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

📄 lcd.c

📁 ad准确采集
💻 C
字号:
//#include <C8051F020.H>
#include <lcd.H>
#include <intrins.h>
#include <main.h>

void SYSCLK_Init_LCD(void)
{
   
    WDTCN = 0xde;                       // disable watchdog timer
    WDTCN = 0xad;
    //OSCICN |= 0x01;                      //Use internal oscillator as SYSCLK:4MHz

    //while (!(OSCICN & 0x10)) ;          // Wait for crystal osc. to settle
    SFRPAGE =0x0F;
    OSCICN = 0x85;                      // Use internal oscillator as SYSCLK:4MHz

}          

/********************************************************
1. ???:void LCD_Prepare(void)
2. ??:T6963???
3. ??:?
4. ???:?
5. ????:
6. ??????:
7. ????:
8. ????:T6963????
9. ???:???
10.????:2004.11.1
11.?????:Ver 0.1
12.?????:???
13.??????:2004.12.12
14.????:
15.??????:
********************************************************/
void LCD_Prepare(void)
{   
    /* Initialise the controller */
 	LCD_Initialise();
    /* Clear Graphic RAM */
    LCD_Clear_Graphics();
    /* Clear Text RAM */
    LCD_Clear_Text();
    /* Set Text Mode and Graphics Mode On */
    LCD_Write_Command(LCD_DISPLAY_MODES_GRAPHICS_ON|LCD_DISPLAY_MODES_TEXT_ON);

    /* Set Address Pointer To GRAPHIC Home */
    LCD_Write_Data(LCD_GRAPHICS_HOME); /* LSB */
    LCD_Write_Data(LCD_GRAPHICS_HOME >> 8); /* MSB */
    LCD_Write_Command(LCD_ADDRESS_POINTER_SET);
}
/********************************************
 * Function name: initialise                *
 * Description:   Initialise PIC and LCD    *
 *******************************************/
void LCD_Initialise(void)
{
        SFRPAGE=0x0F;
    XBR2 = 0x40;

	P0MDOUT |= 0x20;    //Control the direction of 1# 245. From A to B.
    P0 |= 0x20;

    /* Set Control Lines to outputs and High */
    P4MDOUT |=0xC0;
	P4 |=0xC0;
    P1MDOUT |=0xC1;
	P1 |=0xC1;
    
    /*??LCD*/
	P1MDOUT |=0x40;
	P1 &=0xBF;

	/*??LCD*/
	P1MDOUT |=0x80;
    P1 &=0x7F;
    
	//delay_ms(2000);
    /* Hold Reset Line for 5 SYSTEM CLOCK */            //ADD NEW
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    /*????*/
    P1 |=0x80;
    /* Set Char Gen Up */
    LCD_Write_Command(LCD_CG_ROM_MODE_OR);
   
    /* Set Graphic Home Address */
    LCD_Write_Data(LCD_GRAPHICS_HOME);
    LCD_Write_Data(LCD_GRAPHICS_HOME >> 8);
    LCD_Write_Command(LCD_GRAPHIC_HOME_ADDRESS_SET);

    /* Set Graphic Area */
    LCD_Write_Data(LCD_GRAPHICS_AREA); /* Width of 32 Chars */
    LCD_Write_Data(0x00);
    LCD_Write_Command(LCD_GRAPHIC_AREA_SET);

    /* Set Text Home Address */
    LCD_Write_Data(LCD_TEXT_HOME);
    LCD_Write_Data(LCD_TEXT_HOME >> 8);
    LCD_Write_Command(LCD_TEXT_HOME_ADDRESS_SET);

    /* Set Text Area */
    LCD_Write_Data(LCD_TEXT_AREA); /* Width of 32 Chars */
    LCD_Write_Data(0x00);
    LCD_Write_Command(LCD_TEXT_AREA_SET);
}

/********************************************
 * Function name: LCD_Write_Data            *
 * Description:   Write Data to LCD         *
 *******************************************/
void LCD_Write_Data(unsigned char lwd_data)
{
    
    STA_RST();
    SFRPAGE=0x0F;

	/* Clear C/D#   Set bit /RD */
	P1MDOUT |=0x01;
	P1 &=0xFE;    
	P4MDOUT |=0x40;
	P4 |=0x40;
	/* Set Data Lines to Output */ 
    LCD_DATA_BUS = lwd_data;
    
	XBR2 = 0x40;
	P0MDOUT |= 0x20;    //Control the direction of 1# 245. From A to B.
 	P0 |= 0x20;
    LCD_DATA_BUS_TRIS |= ALL_OUTPUTS;
    
   
    
	/* Clear CE and WR */
	P1MDOUT |=0x40;
	P1 &=0xBF;
	P4MDOUT |=0x80;
	P4 &=0x7F;
    _nop_();
    _nop_();
	_nop_();    
  
    /* Set CE and WR and C/D*/
	P1MDOUT |=0x40;
	P1 |=0x40;
	P4MDOUT |=0x80;
	P4 |=0x80;	
	P1MDOUT |=0x01;
	P1 |=0x01;

	/* Set Data Lines to Input */
//    P0MDOUT &= 0xDF;    //Control the direction of 1# 245. From B to A.
// 	P0 &= 0xDF;
//    P0MDOUT |= 0x20;    //Control the direction of 1# 245. From B to A.
// 	P0 &= 0xDF;
//    LCD_DATA_BUS_TRIS &= ALL_INPUTS;
}

/********************************************
 * Function name: LCD_Write_Command         *
 * Description:   Write Command to LCD      *
 *******************************************/
void LCD_Write_Command(unsigned char lwc_data)
{
    //unsigned char status;

    STA_RST();

    SFRPAGE=0x0F;
    /* Set C/D,/RD */
	P1MDOUT |=0x01;
	P1 |=0x01;
	P4MDOUT |=0x40;
	P4 |=0x40;

	/* Set Data Lines to Output */
    LCD_DATA_BUS = lwc_data;

    XBR2 = 0x40;
	P0MDOUT |= 0x20;    //Control the direction of 1# 245. From A to B.
 	P0 |= 0x20;
    LCD_DATA_BUS_TRIS |= ALL_OUTPUTS;
    /* Clear CE and WR*/
    P1MDOUT |=0x40;
	P1 &=0xBF;
	P4MDOUT |=0x80;
	P4 &=0x7F;
    _nop_();
    _nop_();

	/* Set CE and WR */
	P1MDOUT |=0x40;
	P1 |=0x40;
	P4MDOUT |=0x80;
	P4 |=0x80;
	P1MDOUT |=0x01;
	P1 |=0x01;

	/* Set Data Lines to Input */
//    P0MDOUT &= 0xDF;    //Control the direction of 1# 245. From B to A.
// 	P0 &= 0xDF;
//    LCD_DATA_BUS_TRIS &= ALL_INPUTS;
}



/********************************************
 * Function name: lcd_clear_graphics        *
 * Description:   Wipe Graphics RAM         *
 *******************************************/
void LCD_Clear_Graphics(void)
{
    unsigned char address_l, address_h;
    unsigned int address, address_limit;
    /* Set Address Pointer */
    address = LCD_GRAPHICS_HOME;
    address_l = address & 0xff;
    address_h = address >> 8;
    LCD_Write_Data(address_l);
    LCD_Write_Data(address_h);
    LCD_Write_Command(LCD_ADDRESS_POINTER_SET);

    address_limit = (LCD_GRAPHICS_HOME + LCD_GRAPHICS_SIZE);

    while (address < address_limit)
    {
        
		LCD_Write_Command(LCD_DATA_WRITE_AUTO_INCREMENT);//MODIFY: REPLACE THE sequence.
		LCD_Write_Data(0x00);
        //LCD_Write_Command(LCD_DATA_WRITE_AUTO_INCREMENT);
        address = address + 1;
    }

}
/********************************************
 * Function name: lcd_clear_text            *
 * Description:   Wipe Text RAM             *
 *******************************************/
void LCD_Clear_Text(void)
{
    unsigned char address_l, address_h;
    unsigned int address, address_limit;
    /* Set Address Pointer */
    address = LCD_TEXT_HOME;
    address_l = address & 0xff;
    address_h = address >> 8;
    LCD_Write_Data(address_l);
    LCD_Write_Data(address_h);
    LCD_Write_Command(LCD_ADDRESS_POINTER_SET);
        address_limit =  (LCD_TEXT_HOME + LCD_TEXT_SIZE);
        while (address < address_limit)
    {
        LCD_Write_Command(LCD_DATA_WRITE_AUTO_INCREMENT);   //MODIFY: REPLACE THE sequence. 
		LCD_Write_Data(0x00);
        
        address = address + 1;
    }
}

/********************************************
 * Function name: LCD_Write_Text            *
 * Description:   Write Character to X, Y   *
 *                0 <= X <= LCD Text Width  *
 *                0 <= Y <= LCD Text Height *
 *******************************************/
void LCD_Write_Text(unsigned char character, unsigned char x, unsigned char y)   //Will modify. Address is not correct!!!!!!!!
{
    unsigned int address;

    address = (y * LCD_TEXT_AREA) + x + LCD_TEXT_HOME;                   //Will modify. Address is not correct!!!!!!!!
  
    character = character - 0x20;   /* Adjust standard ASCII to T6963 ASCII */

    LCD_Write_Data(address & 0xff);
    LCD_Write_Data(address >> 0x08);
    LCD_Write_Command(LCD_ADDRESS_POINTER_SET);
    LCD_Write_Data(character);
    LCD_Write_Command(LCD_DATA_WRITE_AUTO_INCREMENT);
}


void New_Write_Under_Picture(unsigned char  o_x,unsigned char o_y,char cch[2],int reverse)  //reverse=1???
{                        //???????????????????????????
  unsigned int data add;
  unsigned char data dat1,dat2,i,j,k=0;
   
  add=(unsigned int)(o_y*0x01E0+o_x*2)+0x01E0;
  for(k=0;k<size;k++) 
     {                                                             
       if((HANZIKU[k].ch[0]==cch[0])&&(HANZIKU[k].ch[1]==cch[1]))   //????????
       break;//???????
     }
  if(k>=(sizeof(HANZIKU)/sizeof(HANZIKU[0])))
     return;
  for(i=16,j=0;i>0;i--,j+=2)
   {
     dat1=(unsigned char)add&0xff;
     dat2=(unsigned char)((add>>8)&0xff);
     
     LCD_Write_Data(dat1);
     LCD_Write_Data(dat2);         
     LCD_Write_Command(LCD_ADDRESS_POINTER_SET); 
	 
	 if(reverse==0) 
        LCD_Write_Data(HANZIKU[k].dat[j]);
     else if(reverse==1)
	    LCD_Write_Data(~HANZIKU[k].dat[j]);
	 LCD_Write_Command(LCD_DATA_WRITE_AUTO_INCREMENT);

	 if(reverse==0) 
        LCD_Write_Data(HANZIKU[k].dat[j+1]);
     else if(reverse==1)
	    LCD_Write_Data(~HANZIKU[k].dat[j+1]);
	 LCD_Write_Command(LCD_DATA_WRITE_AUTO_INCREMENT);
	 add+=30;
   }
    
}   
  
void STA_RST(void)
{    	
     unsigned char x;
     //set_bit(LCD_CONTROL, LCD_CD_BIT);
     x = LCD_DATA_BUS;
     
//     LCD_CONTROL |= 0x08;  // setbit LCD_CD_BIT;
	 
	 SFRPAGE=0x0F;
	  /*????*/
     P1MDOUT |=0x01;
	 P1 |=0x01;

	 XBR2 = 0x40;	
	 P0MDOUT |= 0x20;    //Control the direction of 1# 245. From A to B.
 	 P0 |= 0x20;
     LCD_DATA_BUS_TRIS |= ALL_OUTPUTS;
	 
     LCD_DATA_BUS |= 0x8B; /*?????*/
     _nop_();
     _nop_();
     _nop_();
	 
     /* While BUSY1 and BUSY2 are not 1 */
//   	 while ( (LCD_Read_Status() & (LCD_STATUS_BUSY1 | LCD_STATUS_BUSY2 | LCD_STATUS_DAWRDY)) != (LCD_STATUS_BUSY1 | LCD_STATUS_BUSY2 | LCD_STATUS_DAWRDY));  //MODIFIED!
     LCD_DATA_BUS = x;

//	 P0MDOUT &= 0xDF;    //Control the direction of 1# 245. From B to A.
// 	 P0 &= 0xDF;
//     LCD_DATA_BUS_TRIS &= ALL_INPUTS;
}

⌨️ 快捷键说明

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