www.pudn.com > lcd_dispaly-eeprom.rar > main.c, change:2013-06-18,size:4092b


/*************************************************************************** 
檔名		: MAIN.C 
目的		:  test EEPROM 24C02 
程式設計者	:  
日期		: 
版本		:  
****************************************************************************/ 
 
#include "reg51.h" 
 
// LCD Used 
 
int xdata delaytime=100; 
 
void Delay_100ms(void); 
void delay_time(unsigned int k); 
 
void LCD_Data_In(char  LCD_WORD); 
void  LCD_COMMAND(char temp); 
void check_BF(void); 
void  LCD_Clear(void);  
void  LCD_Home(void);  
void  LCD_ADDRESS(char row, char column); 
void LCD_Display_String(char  *s1); 
void init_lcd(void); 
 
 
// EEPROM USed 
void delay_1ms(void); 
void EEI2C_START(void); 
void EEI2C_STOP(void); 
void EEI2C_ACK(void); 
 
// For 24c04以上版本 
void eewrite(unsigned char rom_addressHigh,unsigned char rom_addressLow,	unsigned char write_data); 
unsigned char eeread(unsigned char rom_addressHigh,unsigned char rom_addressLow); 
 
// For 24C00, 24C01, 24C02 版本 
//void eewrite(unsigned char rom_address,	unsigned char write_data); 
//unsigned char eeread(unsigned char read_address); 
 
void write_8bit(wData); 
unsigned char read_8bit(void); 
 
void UART1_SendOneByte(unsigned char Send_Data); 
 
// IO Polarity 
sfr P1M0      = 0x91; 
sfr P1M1      = 0x92; 
 
void main(void){ 
 
unsigned char xdata TEST1[]="Computer !"; 
unsigned char xdata TEST2[]="Science :)"; 
	 
unsigned char  	xdata String1[]="      NTUE     \0"; 
unsigned char  	xdata String2[]="www.ntue.edu.tw ";   // 16 bytes 
 
 
unsigned char xdata ReadBuff[16]; 
unsigned char xdata buffer=0x00;   // 設定一個暫存區 
unsigned char xdata showtext[]="Hi! Computer \r\n\0"; 
unsigned int i,j; 
 
   	  TMOD=0x21;   // 設定Timer0為Mode1,設定Timer1為Mode2 
      SCON=0x50;   // UART Mode1,REN=1 
      TH1=0xFD;    // 設定baud rate=9600, 
      TL1 = 0xFD; 
	    TR1=1;       // 啟動Timer1 
      TI = 0; 
	    RI = 0; 
	 
			for (buffer=0;buffer<50;buffer++){ 
				if (showtext[buffer]=='\0'){ 
					break; 
				} else { 
						UART1_SendOneByte(showtext[buffer]); 
				} 
			} 
	 
	  init_lcd(); 
	 
		   LCD_Display_String(String1);  //顯示String1[]字串 
         
       LCD_ADDRESS(2,1);     //設定LCD游標位址再第二列第一行 
       for (i=0;i<16;i++) {    
           LCD_Data_In(String2[i]);  //顯示一個字元 
           for (j=0;j<50;j++)   
             delay_time(50);            //延遲一段時間 
       } 
			  
			 P1M0 = 0x00; 
			 P1M1 = 0xFF; 
			 while(1){ 
			  
         eewrite(0,0x55,0xAA); 
				  
					 for (i=0;i<500;i++){ 
							delay_time(50); 
							delay_time(50); 
							delay_time(50); 
					 }	 
 
					 UART1_SendOneByte(eeread(0,0x55)); 
					  
					 for (i=0;i<200;i++){ 
							delay_time(50); 
							delay_time(50); 
							delay_time(50); 
					 }	 
				  
			} 
 
//  檢查當 按鍵 A 壓下放開 
     for (i=0;i<10;i++){ 
        eewrite(0,i,TEST1[i]); 
     } 
     for (i=0;i<100;i++){ 
        delay_1ms(); 
        delay_1ms(); 
        delay_1ms(); 
     } 
     for (i=0;i<10;i++){ 
        ReadBuff[i]=eeread(0,i); 
     } 
      
// LCD Display ReadBuff[0]~ReadBuff[9] 
    LCD_Clear();                 //清除LCD顯示RAM 
    LCD_Home();                  //LCD游標歸位		  
		 ReadBuff[10] = '\0'; 
		 LCD_Display_String(ReadBuff); 
		  
  Delay_100ms(); 
  Delay_100ms(); 
  Delay_100ms(); 
  Delay_100ms(); 
  Delay_100ms(); 
  Delay_100ms(); 
  Delay_100ms(); 
		  
//  檢查當 按鍵 B 壓下放開 
     for (i=0;i<10;i++){ 
        eewrite(0,i,TEST2[i]); 
     } 
      
     for (i=0;i<100;i++){ 
        delay_1ms(); 
        delay_1ms(); 
        delay_1ms(); 
     } 
     for (i=0;i<10;i++){ 
        ReadBuff[i]=eeread(0,i); 
     } 
  // LCD Display ReadBuff[0]~ReadBuff[9] 
       LCD_ADDRESS(2,1);     //設定LCD游標位址再第二列第一行 
       for (i=0;i<10;i++) {    
           LCD_Data_In(ReadBuff[i]);  //顯示一個字元 
           for (j=0;j<50;j++)   
             delay_time(5000);            //延遲一段時間 
       }        
         
     
		 while(1); 
		  
 
 
 
} 
 
 
void UART1_SendOneByte(unsigned char Send_Data) 
{ 
 
	SBUF=Send_Data; 
    while(TI == 0); 
	TI=0; 
}