#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);
}
}
}
|