Friendly
09.07.2013, 16:26
MK C8051F410 имеет повышенную тактовую частоту до 50 Мгц.
В сравнении с C051F320 имеет много отличий, требует более сложной конфигурации.
Программка, запускаемая в проекте Кейла для C8051F410 - поморгает светодиодом:
//************************************************** *********
#include <stdio.h>
#include <string.h>
#include <c8051f410.h>
#define uchar unsigned char
#define uint unsigned int
sbit LED = P0^4;
void delay_us(uint time);
void SYSCLK_Init (char speed);
//************************************************** ***
void main(void) {
int i;
PCA0MD &= ~0x40; // STARTUP.A51
SYSCLK_Init (12); // 12 Mhz
VDM0CN = 0x80; // enable the VDD monitor
for (i = 0; i < 80; i++); // wait for the monitor to stabilize
RSTSRC = 0x06; // enable missing clock detector and
// VDD monitor as reset sources
P0MDOUT = 0x00; // 0xFF: P0.n Output is push-pull.
P1MDOUT = 0x00; // 0xFF: P1.n Output is push-pull.
P2MDOUT = 0x00; // 0xFF: P2.n Output is push-pull.
P0MDIN = 0xFF; // 0xFF: P0.n pin configured digital.
P1MDIN = 0xFF; // 0xFF: P1.n pin configured digital.
P2MDIN = 0xFF; // 0xFF: P2.n pin configured digital.
P0SKIP = 0x00;
P1SKIP = 0x00;
P2SKIP = 0x00;
P0 = 0xFF;
P1 = 0xFF;
P2 = 0xFF;
XBR0 = 0x02; // Enable SPI
XBR1 = 0x40; // Enable crossbar and disable weak ups
while(1){
LED = ! LED;
for(i=0; i<50; i++) delay_us(20000);
} }
//**************************************************
void delay_us(uint time){
while(time--!=0);
}
//************************************************** *******************
// 1) char speed - desired speed in Mhz
// valid values are 3, 6, 12, 24, and 50
//************************************************** *******************
void SYSCLK_Init (char speed)
{
int i;
OSCICN = 0x87; // Init to default value
CLKSEL = 0x00;
CLKMUL = 0x00;
FLSCL = 0x00;
switch (speed)
{
case 3 : OSCICN = 0x84; break; // Div by 8
case 6 : OSCICN = 0x85; break; // Div by 4
case 12: OSCICN = 0x86; break; // Div by 2
case 24: OSCICN = 0x87; break; // Div by 1
case 50: OSCICN = 0x87; // 24.5 Mhz
CLKMUL = 0x00; // Disable; INTOSC/2 is CLKMUL src
// MULDIV = 1; so 24.5/2/1 * 4 = ~50Mhz
CLKMUL |= 0x80; // Enable
for (i = 0; i < 100; i++); // Delay
CLKMUL |= 0xC0; // Initialize
while ( (CLKMUL & 0x20) == 0){}; // Poll
FLSCL = 0x10; // If >25Mhz, enable FLRT
CLKSEL = 0x02; // Make multiplier the sysclk
break;
default: break; // Use default value from above
}
}
//************************************************** ************
В сравнении с C051F320 имеет много отличий, требует более сложной конфигурации.
Программка, запускаемая в проекте Кейла для C8051F410 - поморгает светодиодом:
//************************************************** *********
#include <stdio.h>
#include <string.h>
#include <c8051f410.h>
#define uchar unsigned char
#define uint unsigned int
sbit LED = P0^4;
void delay_us(uint time);
void SYSCLK_Init (char speed);
//************************************************** ***
void main(void) {
int i;
PCA0MD &= ~0x40; // STARTUP.A51
SYSCLK_Init (12); // 12 Mhz
VDM0CN = 0x80; // enable the VDD monitor
for (i = 0; i < 80; i++); // wait for the monitor to stabilize
RSTSRC = 0x06; // enable missing clock detector and
// VDD monitor as reset sources
P0MDOUT = 0x00; // 0xFF: P0.n Output is push-pull.
P1MDOUT = 0x00; // 0xFF: P1.n Output is push-pull.
P2MDOUT = 0x00; // 0xFF: P2.n Output is push-pull.
P0MDIN = 0xFF; // 0xFF: P0.n pin configured digital.
P1MDIN = 0xFF; // 0xFF: P1.n pin configured digital.
P2MDIN = 0xFF; // 0xFF: P2.n pin configured digital.
P0SKIP = 0x00;
P1SKIP = 0x00;
P2SKIP = 0x00;
P0 = 0xFF;
P1 = 0xFF;
P2 = 0xFF;
XBR0 = 0x02; // Enable SPI
XBR1 = 0x40; // Enable crossbar and disable weak ups
while(1){
LED = ! LED;
for(i=0; i<50; i++) delay_us(20000);
} }
//**************************************************
void delay_us(uint time){
while(time--!=0);
}
//************************************************** *******************
// 1) char speed - desired speed in Mhz
// valid values are 3, 6, 12, 24, and 50
//************************************************** *******************
void SYSCLK_Init (char speed)
{
int i;
OSCICN = 0x87; // Init to default value
CLKSEL = 0x00;
CLKMUL = 0x00;
FLSCL = 0x00;
switch (speed)
{
case 3 : OSCICN = 0x84; break; // Div by 8
case 6 : OSCICN = 0x85; break; // Div by 4
case 12: OSCICN = 0x86; break; // Div by 2
case 24: OSCICN = 0x87; break; // Div by 1
case 50: OSCICN = 0x87; // 24.5 Mhz
CLKMUL = 0x00; // Disable; INTOSC/2 is CLKMUL src
// MULDIV = 1; so 24.5/2/1 * 4 = ~50Mhz
CLKMUL |= 0x80; // Enable
for (i = 0; i < 100; i++); // Delay
CLKMUL |= 0xC0; // Initialize
while ( (CLKMUL & 0x20) == 0){}; // Poll
FLSCL = 0x10; // If >25Mhz, enable FLRT
CLKSEL = 0x02; // Make multiplier the sysclk
break;
default: break; // Use default value from above
}
}
//************************************************** ************