*********************************************************
void Port_IO_Init()
{
//P1.0 - Unassigned, Open-Drain, Digital
//P1.1 - Unassigned, Open-Drain, Digital
//P1.2 - Unassigned, Open-Drain, Digital
//P1.3 - Unassigned, Open-Drain, Digital
//P1.4 - Unassigned, Open-Drain, Digital
//P1.5 - Unassigned, Open-Drain, Digital
//P1.6 - Unassigned, Push-Pull, Digital<---
// our change
//P1.7 - Unassigned, Open-Drain, Digital
SFRPAGE = CONFIG_PAGE;
P1MDOUT = 0x40;
XBR2 = 0x40;
}
*********************************************************
It’s rather obvious in the Port_IO_Init function code
that not only did the Configuration Wizard 2 application
create the Port_IO_Init function, it populated the
Port_IO_Init function structure with the code that is
necessary to activate the Digital Crossbar and configure
general-purpose I/O pin P1.6 as a push-pull digital output.
The generation of C8051F120 source code doesn’t stop
here. Not only did the Configuration Wizard 2 application
generate a new general-purpose I/O function, it entered a
call to the newly generated Port_IO_Init function in the
Init_Device function that we will eventually call from our
main application. I’ve pulled the newly altered Init_Device
function out from the main code body for you to see in the
Init_Device function code snippet that follows:
*********************************************************
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
Port_IO_Init();
}
*********************************************************
■ FIGURE 1. Wizards are usually good things. In this case, the
Configuration Wizard 2 application has opened up the entire
C8051F120 peripheral and general-purpose I/O collection to us
to do with what we please.
USING CONFIGURATION WIZARD 2
TO CONFIGURE THE C8051F120
OSCILLATOR
The C8051F120 has its own internal oscillator. However,
the C8051F120 can also be clocked by an external crystal. It
seems that no code is generated if the C8051F120 internal
oscillator is configured for its most basic operational mode.
We want some action. So, I configured the C8051F120 to use
an external 22.1184 MHz crystal to supply the C8051F120’s
SYSCLK. There’s not a lot of pretty interactive screen play as
we kinda saw with the general-purpose I/O configuration.
However, the results generated by the Configuration Wizard 2
application are indeed impressive. If you want to check the
Configuration Wizard 2 application’s work, you’ll find that the
OSCXCN value in the Oscillator_Init function below breaks
down as follows. The upper nibble (0x6_) puts the
C8051F120 into crystal oscillator mode. The lower nibble of
OSCXCN (0x_ 7) is set up for a crystal frequency that is greater
than 10 MHz and lower than 30 MHz. The most significant bit
of OSCXCN is set when the crystal oscillator is stable.
*********************************************************
void Oscillator_Init()
{
int i = 0;
SFRPAGE = CONFIG_PAGE;
OSCXCN = 0x67;
for (i = 0; i < 3000; i++); // Wait 1ms for
// initialization
while ((OSCXCN & 0x80) == 0);
CLKSEL = 0x01;
}
*********************************************************
The least significant bit of the CLKSEL register is set to
■ FIGURE 2. Look closely along the Push-Pull/Open Drain
line at the bottom of this shot to see the configuration change
I made to the P1.6 general-purpose I/O pin. Also, notice I
enabled the Digital Crossbar.
May 2007 81