Databuff[4]=ReadEEPROM(0x05);
Databuff[5]=ReadEEPROM(0x06);
Databuff[6]=ReadEEPROM(0x07);
Databuff[7]=ReadEEPROM(0x08);
for(;;) {
//__RESET_WATCHDOG(); /* feeds the dog */
for(i=0;i<8;i++) {
PTAD=Databuff[i];
outputdelay();
outputdelay();
}
} /* loop forever */
/* please make sure that you never leave main */
}
void IICdelay(void) {
unsigned int i=200;
while(i--) {
}
}
void outputdelay(void) {
unsigned int j=0;
for(j=0;j<0x6000;j++){
}
}
void writeEEPROM(unsigned char caddr_data,unsigned char data) {
IICC1_TXAK=0;
IICC1|=0x30;
IICD=0xA0;
while(!IICS_IICIF);
IICS_IICIF=1;
while(IICS_RXAK);
IICD=caddr_data;
while(!IICS_IICIF);
IICS_IICIF=1;
while(IICS_RXAK);
IICD=data;
while(!IICS_IICIF);
IICS_IICIF=1;
while(IICS_RXAK);
IICS_IICIF=1;
IICC1_MST=0;
}
unsigned char ReadEEPROM(unsigned char caddr) {
unsigned char cdata;
IICC1_TXAK=0;
IICC1|=0x30;
IICD=0xA0;
while(!IICS_IICIF);
IICS_IICIF=1;
while(IICS_RXAK);
IICD=caddr;
while(!IICS_IICIF);
IICS_IICIF=1;
while(IICS_RXAK);
IICC1_RSTA=0;
IICD=0xA1;
while(!IICS_IICIF);
IICS_IICIF=1;
while(IICS_RXAK);
IICC1_TX=0;
IICC1_TXAK=1;
cdata=IICD;
while(!IICS_IICIF);
IICS_IICIF=1;
IICC1_MST=0;
cdata=IICD;
return cdata;
}
void MCG_Init(void) {
// if (ExtClkFlg == 1) { /* If using a 4 MHz crystal */
if (SRS_LOC == 0) { /* If no loss of clock has occurred, enter PEE to generate 16 MHz bus */
/* FEI -> FBE Mode */
MCGC2 = 0x36; /* BDIV by 1, xtal freq RANGE high, High GAIN, EREFS set */
MCGC1 = 0xB8; /* RDIV by 128 down to 31.25 kHz for FLL, Switch to ext. ref */
while (MCGSC_IREFST); /* Check internal ref. no longer on */
MCGC3 = 0xA0; /* LOL interrupt, LOC reset (CME) enabled (ONLY after IREFS = 0) */
while (!MCGSC_OSCINIT); /* Wait until crystal initializes */
while (MCGSC_CLKST != 0b10);/* Check external ref. switched */
/* FBE -> PBE */
MCGC3 = 0xE2; /* Set PLLS bit with VDIV mult by 32 */
MCGC1 = 0x90; /* RDIV by 4 (4 MHz/4 = 1 MHz for PLL) */
while (!MCGSC_PLLST);
while (!MCGSC_LOCK);