附代码:
#include <c8051f330.h>
unsigned int CEX0_Compare_Value; // Holds current PCA compare value
void main (void)
{
PCA0MD = 0;
// 系统时钟
OSCICN = 0x83;
CLKSEL = 0x00;
XBR0 = 0x00;
XBR1 = 0x01;
P0MDIN = 0x10;
P0MDOUT = 0x00;
P0SKIP = 0xFF;
P1MDIN = 0xFF;
P1MDOUT = 0xFF;
P1SKIP = 0xFE;
P0 = 0x00;
P1 = 0x00;
XBR1 |= 0x40;
// PCA0 INIT
PCA0CN = 0x00;
PCA0MD = 0x08;
PCA0CPM0 = 0xCB;
CEX0_Compare_Value = 65536 - (65536 * 0.5);
PCA0L = (CEX0_Compare_Value & 0x00FF);
PCA0H = (CEX0_Compare_Value & 0xFF00)>>8;
CEX0_Compare_Value = CEX0_Compare_Value - (CEX0_Compare_Value * 0.08);
PCA0CPL0 = (CEX0_Compare_Value & 0x00FF);
PCA0CPH0 = (CEX0_Compare_Value & 0xFF00)>>8;
EIE1 |= 0x10;
CR = 1;
EA = 1;
while(1)
{
;
}
}
void PCA0_ISR (void) interrupt 11
{
CCF0 = 0; // Clear module 0 interrupt flag.
CEX0_Compare_Value = 65536 - (65536 * 0.5);
PCA0L = (CEX0_Compare_Value & 0x00FF);
PCA0H = (CEX0_Compare_Value & 0xFF00)>>8;
P1 ^= 0x80;
} |