#include "reg52.h"
#include "I2C.h"
#define EEPROM_ADDR_Write 0xa0
#define EEPROM_ADDR_Read 0xa1
#define PCF_ADDR_Write 0x90
#define PCF_ADDE_Read 0x91
#define uchar unsigned char
#define uint unsigned int
uchar music[100];
uchar ack, i;
void EEPROM_Read(uchar address);
void main(){
SDA = SCL = 1;
//读取EEPROM
EEPROM_Read(0x00);
//串口验证
TMOD = 0x20;//定时器1设定为工作模式2
TR1 = 1;//打开定时器1,这时有了一个波特率,但不是我们设置的波特率,单片机会检测到数据,却不是我们所发的数据
TH1 = 0xfd, TL1 = 0xfd;//波特率9600
REN = 1;//串口允许接收
SM0 = 0, SM1 = 1;//串口工作方式为模式一,收到停止位才会RI = 1,没有这一步,RI会不停自动置1
i=0;
while(1){
SBUF = music[ i];
while(!TI);
TI = 0;
if(music[ i] == 0x00)
break;
i++;
}
}
void EEPROM_Read(uchar address){
uchar i;
I2C_Start();
I2C_SendByte(EEPROM_ADDR_Write);
I2C_WaitAck();
I2C_SendByte(address);
I2C_WaitAck();
I2C_Start();
for(i=0; i<100; i++){
music[ i] = I2C_RcvByte();
if(music[ i] == 0x00){
I2C_Ack(0);
I2C_Stop();
break;
}
else{
I2C_Ack(1);
}
}
}
|