想利用C8051内部的SmaRTClock的闹钟事件,但不知道驱动那里写的不对!还请大家帮我看一下!!
void SysInit( void )
{
FLSCL = 0x40;
OSCICN = 0x8F;
CLKSEL = 0x00;
PCA0MD &= ~0x40; // disable WDT
XBR2 = 0x40; // enable crossbar
}
unsigned char SmaRTClockRead( unsigned char add )
{
RTC0ADR = (0x90 | add);
NOP();
NOP();
NOP();
return RTC0DAT;
}
void SmaRTClockWrite( unsigned char add,unsigned char val )
{
RTC0ADR = (0x10 | add);
RTC0DAT = val;
}
void SmaRTClockWriteAlarm( unsigned long val )
{
unsigned char temp;
RTC0ADR = (0x10 | RTC0CN);
RTC0DAT &= ~RTC0AEN; //SamRTClock alarm disable
NOP();
//Write the value to the alarm registers
RTC0ADR = (0x10 | ALARM0);
RTC0DAT = val;
NOP();
RTC0DAT = (val>>8);
NOP();
RTC0DAT = (val>>16);
NOP();
RTC0DAT = (val>>24);
NOP();
temp = SmaRTClockRead(RTC0CN);
RTC0ADR = (0x10 | RTC0CN);
RTC0DAT = (temp | RTC0AEN | RTC0TR); // SamRTClock alarm enable
}
void SmaRTClockInit( void )
{
// If the interface is locked
if(RTC0KEY == 0x00)
{
RTC0KEY = 0xA5; // Unlock the smaRTClock interface
RTC0KEY = 0xF1;
}
#ifdef CRYSTALMODE
#endif
#ifdef SELFOSC
SmaRTClockWrite(RTC0PIN, 0xE7); // Short XTAL3 and XTAL4 together
SmaRTClockWrite(RTC0XCN, 0x00); // Configure smaRTClock in
SmaRTClockWrite(RTC0XCF, 0x80); // enable Automatic Load Capacitiance
SmaRTClockWrite(RTC0CN, 0x80); // Enable smaRTClock oscillator
SmaRTClockWrite(RTC0CN, 0xC0);
}
void main( void )
{
unsigned char temp;
SysInit();
SmaRTClockInit();
//SmaRTClockWriteAlarm(0x30d40);
SmaRTClockWriteAlarm(0x4E20);
while(1)
{
temp = SmaRTClockRead(RTC0CN);
if( temp & 0x04 )
{
P2_0 = !P2_0;
temp = SmaRTClockRead(RTC0CN);
temp &= ~0x08; // clear alarm interrupt flag
SmaRTClockWrite(RTC0CN,temp);
temp = SmaRTClockRead(RTC0CN);
temp |= 0x08; // clear alarm interrupt flag
SmaRTClockWrite(RTC0CN,temp);
}
}
}
|