| ??? 11/19/03 22:45 Read: times |
#59066 - Writing to EEPROM (P89LPC932) |
Hi can any one tell me why this program does not write to EEPROM. After setting IE0, the program jumps to its respective ISR but it does not write to EEPROM. It reads from, but it does not write to memory. I am using the emulator.
Thank you #include <Reg932.h> #include <stdio.h> void init(void); void brkrst_init(void); sbit Pulse = P1^3; //port to recieve pulses #define ADDR 0x05 //Low byte #define ADDR1 0x06 //high byte void EEPROMwrite(unsigned int adr,unsigned char dat); unsigned char EEPROMread(unsigned int adr); unsigned int pus = 0, glass = 0; unsigned int Ldata, P_Counter; unsigned char Low, High; void Main(void) { P0 = 0x00; P1 = 0x00; // turn off all P1 Pins. All pins unused P2 = 0x00; // turn off all P2 Pins. All pins unused P3 = 0x00; // turn off all P3 Pins. All pins unused init(); // configure ports as inputs or outputs // P0 Output and inputs, P1 Output and inputs // P2 all pins are outputs brkrst_init(); P_Counter = 0; P1 = 0x38; IT0 = 1; EX0 = 1; IT1 = 1; EX1 = 1; EA = 1; High= EEPROMread(ADDR1); Low = EEPROMread(ADDR); Ldata = High; Ldata <<= (0x08); Ldata |= Low; if (Ldata == 0xFFFF) { Ldata = 0; } glass = Ldata; P2 = glass; while(1) { PCONA = 0xEF; PCON = 0x11; // Stay on Idle mode } } void init(void) { P0M1 = 0x00; P0M2 = 0xCD; P1M1 = 0x00; // Push-pull clk, reset, TX P1M2 = 0x3F; P2M1 = 0x00; // push pull output, for display only P2M2 = 0xFF; P1M1 |= 0x1A; // make INT0 and INT1 input pins P1M2 &= 0xED; ES = 1; // enable UART interrupt //EA = 1; } void brkrst_init(void) // This function allows ISP entry through the UART break detect { SCON = 0x50; // select the BRG as UART baud rate source, pg. 60 SSTAT = 0x00; //Timer1 BRGR0 = 0xF0; // 9600 BAUD at @ 7.373MHz internal RC oscillator BRGR1 = 0x02; //timer increments every .0271 microsec. BRGCON = 0x03; // enable BRG, pg. 59 AUXR1 |= 0x80; // Clock Low Power Select } void UART(void) interrupt 4 //Interrupt number for serial port { RI = 0; // clear receive interrupt flag } void Interrupt_Pulses (void) interrupt 0 { P_Counter++; // increment pulse counter if (P_Counter == 1) { P_Counter = 0; glass--; P2 = glass; pus = glass; EEPROMwrite(ADDR, pus); // write new value back to EEPROM pus >>= (0x08); // write high byte EEPROMwrite(ADDR1, pus); } } /*********************************Write to Memory***************************************/ void EEPROMwrite(unsigned int adr, unsigned char dat) { EA=0; // disable Interrupts during write DEECON=(unsigned int)((adr>>8)&0x01); // mode: write byte, set address DEEDAT=dat; // set write data DEEADR=(unsigned char) adr; // start write EA=1; while((DEECON&0x80)==0); // wait until write is complete } /**************************************************************************************/ /*********************************Read from Memory*************************************/ unsigned char EEPROMread(unsigned int adr) { DEECON=(unsigned char)((adr>>8)&0x01); // mode: read byte, set adress DEEADR=(unsigned char) adr; // start read, contains 0x05 while((DEECON&0x80)==0); // wait until read is complete DEECON &= ~0x8E; return (DEEDAT); // return data } /**************************************************************************************/ |
| Topic | Author | Date |
| Writing to EEPROM (P89LPC932) | 01/01/70 00:00 | |
RE: Writing to EEPROM (P89LPC932) | 01/01/70 00:00 |



