This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

The CP1 of C8051F020 can't set CP1RIF

I use UART0,UART1 and CP1. P0^4 is work well when CP1E is set in XBR1.But when CP1E is reset, the ISR of CP1 doesn't send out 0x88.The program is following.
#include
#include
void SYSCLK_INIT()
{
int i;
WDTCN = 0x07;
WDTCN = 0xDE;
WDTCN = 0xAD;
OSCXCN = 0x67;
for (i=0; i < 256; i++) ;
while (!(OSCXCN & 0x80)) ;
OSCICN = 0x08;
}
void config (void) {
int x = 0;
WDTCN = 0x07;
WDTCN = 0xDE;
WDTCN = 0xAD;
XBR0 = 0x04; // XBAR0: Initial Reset Value
XBR1 = 0x00; // XBAR1: Initial Reset Value
XBR2 = 0x44; // XBAR2: Initial Reset Value
EMI0CF = 0x34;
CPT0CN = 0x00;
CPT1CN = 0x8c; // Comparator 1 Control Register
for(x = 0; x < 10; x++);
CPT1CN &= ~0x33; //clear interrupt pending flags


REF0CN = 0x03;
AMX0CF = 0x60; // AMUX Configuration Register
AMX0SL = 0x00; // AMUX Channel Select Register
ADC0CF = 0x50; // ADC Configuration Register
ADC0CN = 0xc0; // ADC Control Register

ADC0LTH = 0x00; ADC0LTL = 0x00;
ADC0GTH = 0xFF; ADC0GTL = 0xFF; AMX1SL = 0x00; // AMUX1 Channel Select Register
ADC1CF = 0xF8; // ADC1 Configuration Register
ADC1CN = 0x00; // ADC1 Control Register
DAC0CN = 0x80; // DAC0 Control Register
DAC0L = 0x55; // DAC0 Low Byte Register
DAC0H = 0x10; // DAC0 High Byte Register
DAC1CN = 0x00; // DAC1 Control Register
DAC1L = 0x00; // DAC1 Low Byte Register
DAC1H = 0x00; // DAC1 High Byte Register
SPI0CN = 0x00; // SPI Control Register
SPI0CFG = 0x00; // SPI Configuration Register
SPI0CKR = 0x00; // SPI Clock Rate Register
SCON0 = 0x50; // Serial Port Control Register
SCON0 &= 0xFC; //clear interrupt pending flags
SADEN0 = 0x00; // Serial 0 Slave Address Enable
SADDR0 = 0x00; // Serial 0 Slave Address Register

PCON = 0x00; // Power Control Register

SCON1 = 0x50; // Serial Port 1 Control Register
SCON1 &= 0xFC; //clear interrupt pending flags
SADEN1 = 0x00; // Serial 1 Slave Address Enable
SADDR1 = 0x00; // Serial 1 Slave Address Register

CKCON = 0x00; // Clock Control Register
TH0 = 0x00; // Timer 0 High Byte
TL0 = 0x00; // Timer 0 Low Byte
TH1 = 0x00; // Timer 1 High Byte
TL1 = 0x00; // Timer 1 Low Byte
TMOD = 0x00; // Timer Mode Register
TCON = 0x00; // Timer Control Register

RCAP2H = 0xFF; // Timer 2 Capture Register High Byte
RCAP2L = 0xFD; // Timer 2 Capture Register Low Byte
TH2 = 0x00; // Timer 2 High Byte
TL2 = 0x00; // Timer 2 Low Byte
T2CON = 0x34; // Timer 2 Control Register

TMR3RLL = 0x00; // Timer 3 Reload Register Low Byte
TMR3RLH = 0x00; // Timer 3 Reload Register High Byte
TMR3H = 0x00; // Timer 3 High Byte
TMR3L = 0x00; // Timer 3 Low Byte
TMR3CN = 0x00; // Timer 3 Control Register

RCAP4H = 0xFF; // Timer 4 Capture Register High Byte
RCAP4L = 0xDC; // Timer 4 Capture Register Low Byte
TH4 = 0x00; // Timer 4 High Byte
TL4 = 0x00; // Timer 4 Low Byte
T4CON = 0x34; // Timer 4 Control Register


IE = 0x90; //Interrupt Enable
IP = 0x10; //Interrupt Priority
EIE1 = 0x80; //Extended Interrupt Enable 1 COMP1
EIE2 = 0x40; //Extended Interrupt Enable 2 UART1
EIP1 = 0x00; //Extended Interrupt Priority 1
EIP2 = 0x00; //Extended Interrupt Priority 2


// other initialization code here...

}


unsigned char TI1(unsigned char j)
{
switch (j)
{
case 0: SCON1 &= 0XFD; break;
case 1: SCON1 |= 0X02; break;
default: break;
}
if (SCON1 & 0X02) return(1);
else return(0);
}
unsigned char RI1(unsigned char k)
{
switch (k)
{
case 0: SCON1 &= 0XFE; break;
case 1: SCON1 |= 0X01; break;
default: break;
}
if (SCON1 & 0X01) return(1);
else return(0);
}
void ES1(unsigned char l)
{
switch (l)
{
case 0: EIE2 &= 0XBF; break;
case 1: EIE2 |= 0X40; break;
default: break;
}
}
void Main(void)
{
unsigned int x,y;
unsigned char Channel;
SYSCLK_INIT();
config();
PRLED = 1;
Channel = 0;
while(1)
{
REMOTE = 0;
DIRECT = 1;
AMX0SL = Channel;
Channel ++;
if (Channel == 9) Channel = 0;
AD0BUSY = 1;
while(!AD0INT);
AD0INT = 0;
SBUF0 = ADC0;
while(!TI0);
TI0 = 0;
SBUF0 = ADC0>>8;
while(!TI0);
TI0 = 0;
for (x = 0 ; x < 1000 ; x ++)
for (y = 0; y < 1000 ; y ++);
PRLED = !PRLED;
DAC0 = 0X0100;
CPT1CN = 0x8c;
}
}
void Comp1(void) interrupt 13 using 3
{
CPT1CN = 0x8c;
while(1)
{
SBUF0 = 0X88;
while(!TI0);
TI0 = 0;
POWERON3 = 0;
POWERON2 = 0;
POWERON1 = 0;
}
}