/***********************LCD1602地址相關(guān)******************************/
#define LINE1_HEAD 0x80 // 第一行DDRAM起始地址
#define LINE2_HEAD 0xc0 // 第二行DDRAM起始地址
#define LINE1 0 //第一行
#define LINE2 1 //第二行
#define LINE_LENGTH 16 //每行的最大字符長度
#define LINE2_HEAD 0xc0 // 第二行DDRAM起始地址
#define LINE1 0 //第一行
#define LINE2 1 //第二行
#define LINE_LENGTH 16 //每行的最大字符長度
/***********************LCD1602接線引腳定義**************************
**********************可根據(jù)實(shí)際電路改變*******************************/
**********************可根據(jù)實(shí)際電路改變*******************************/
#define LCDIO P2 //定義P2口與LCD1602的數(shù)據(jù)口相接
sbit LCD_RS=P1^4;
sbit LCD_RW=P1^3;
sbit LCD_EN=P1^2;
sbit LCD_BUSY=LCDIO^7;
/**********************另外相關(guān)的定義*********************************/
#define HIGH 1
#define LOW 0
#define TURE 1
#define FALSE 0
#define uchar unsigned char
#define uint unsigned int
#define NUM 10
/*************************以下是函數(shù)的申明部分*************************/
void LCD_init(void); //LCD1602初始化
void LCD_send_command(uchar command); //
void LCD_send_data(uchar dat);
void LCD_write_char(uchar x,uchar y,uchar dat);
void LCD_write_string(uchar x,uchar y,char *Data);
void delay_ms(uint n);
void LCD_check_busy(void);
sbit LCD_RS=P1^4;
sbit LCD_RW=P1^3;
sbit LCD_EN=P1^2;
sbit LCD_BUSY=LCDIO^7;
/**********************另外相關(guān)的定義*********************************/
#define HIGH 1
#define LOW 0
#define TURE 1
#define FALSE 0
#define uchar unsigned char
#define uint unsigned int
#define NUM 10
/*************************以下是函數(shù)的申明部分*************************/
void LCD_init(void); //LCD1602初始化
void LCD_send_command(uchar command); //
void LCD_send_data(uchar dat);
void LCD_write_char(uchar x,uchar y,uchar dat);
void LCD_write_string(uchar x,uchar y,char *Data);
void delay_ms(uint n);
void LCD_check_busy(void);
/*********************結(jié)束***********************************************/
//at24c02 part
#define WRITE24C02 0xA0
#define READ24C02 0xA1
//I2C part
#define Wait1us _nop_();
#define Wait2us {_nop_();_nop_();}
#define Wait4us {Wait2us;Wait2us;}
#define Wait8us {Wait4us;Wait4us;}
#define Wait10us {Wait8us;Wait2us;}
sbit SDA=P2^7; //AT24C02 serial data pin 5
sbit SCL=P2^6; //AT24C02 serial clock pin 6
/********************************************************************/
void I2C_start(void);//I2C start function
void I2C_stop(void);//I2C stop function
//void I2C_send_ack(void);//I2C send responsion function
void I2C_send_noack(void);
void I2C_write_byte(unsigned char IIC_data);//I2C bus write byte function
unsigned char I2C_read_byte(void);//I2C bus read byte function
/********************************************************************/
void AT24C02_write(unsigned char address,unsigned char *buf,unsigned char n);//write 24c02 information function
void AT24C02_read(unsigned char address,unsigned char *buf,unsigned char n);//read 24c02 information function
/********************************************************************/
void Mcu_init(void);//system initize funcition
void I2C_init(void);
unsigned char count[2];
unsigned char sharebuf[NUM];
/********************************************************************/
void main()
{
unsigned char temp;
Mcu_init();
while(1)
{
sharebuf[0]=count[1];
sharebuf[1]=count[0];
AT24C02_write(0x00,sharebuf,2);
AT24C02_read(0x00,sharebuf,2);
temp=sharebuf[0];
LCD_write_string(0x00,LINE1,"AT24C02 TEST");
LCD_write_char(0x0e,LINE1,(temp/10) 0x30);
LCD_write_char(0x0f,LINE1,(temp%10) 0x30);
LCD_write_string(0x00,LINE2,"TIMER0 JISHU");
LCD_write_char(0x0e,1,(count[1]/10) 0x30);
LCD_write_char(0x0f,1,(count[1]%10) 0x30);
}
}
/***********************************************************************/
void timer0(void) interrupt 1 using 1
{
TH0=-(12000/256);
TL0=-(12000%256);
count[0]=count[0]+1;
if(count[0]==100)
{
count[0]=0;
count[1]=count[1]+1;
if(count[1]==99)
count[1]=0;
}
}
/***********************************************************************/
void Mcu_init(void)
{
TMOD=0x01;
TH0=-(12000/256);
TL0=-(12000%256);
EA=HIGH;
ET0=HIGH;
TR0=HIGH;
LCD_init();
}
/***********************************************************************/
//at24c02 part
#define WRITE24C02 0xA0
#define READ24C02 0xA1
//I2C part
#define Wait1us _nop_();
#define Wait2us {_nop_();_nop_();}
#define Wait4us {Wait2us;Wait2us;}
#define Wait8us {Wait4us;Wait4us;}
#define Wait10us {Wait8us;Wait2us;}
sbit SDA=P2^7; //AT24C02 serial data pin 5
sbit SCL=P2^6; //AT24C02 serial clock pin 6
/********************************************************************/
void I2C_start(void);//I2C start function
void I2C_stop(void);//I2C stop function
//void I2C_send_ack(void);//I2C send responsion function
void I2C_send_noack(void);
void I2C_write_byte(unsigned char IIC_data);//I2C bus write byte function
unsigned char I2C_read_byte(void);//I2C bus read byte function
/********************************************************************/
void AT24C02_write(unsigned char address,unsigned char *buf,unsigned char n);//write 24c02 information function
void AT24C02_read(unsigned char address,unsigned char *buf,unsigned char n);//read 24c02 information function
/********************************************************************/
void Mcu_init(void);//system initize funcition
void I2C_init(void);
unsigned char count[2];
unsigned char sharebuf[NUM];
/********************************************************************/
void main()
{
unsigned char temp;
Mcu_init();
while(1)
{
sharebuf[0]=count[1];
sharebuf[1]=count[0];
AT24C02_write(0x00,sharebuf,2);
AT24C02_read(0x00,sharebuf,2);
temp=sharebuf[0];
LCD_write_string(0x00,LINE1,"AT24C02 TEST");
LCD_write_char(0x0e,LINE1,(temp/10) 0x30);
LCD_write_char(0x0f,LINE1,(temp%10) 0x30);
LCD_write_string(0x00,LINE2,"TIMER0 JISHU");
LCD_write_char(0x0e,1,(count[1]/10) 0x30);
LCD_write_char(0x0f,1,(count[1]%10) 0x30);
}
}
/***********************************************************************/
void timer0(void) interrupt 1 using 1
{
TH0=-(12000/256);
TL0=-(12000%256);
count[0]=count[0]+1;
if(count[0]==100)
{
count[0]=0;
count[1]=count[1]+1;
if(count[1]==99)
count[1]=0;
}
}
/***********************************************************************/
void Mcu_init(void)
{
TMOD=0x01;
TH0=-(12000/256);
TL0=-(12000%256);
EA=HIGH;
ET0=HIGH;
TR0=HIGH;
LCD_init();
}
/***********************************************************************/





