SOURCES
■ Keil — An ARM Company ( www.keil.com) — Keil C51 C
Compiler.
■ Silicon Laboratories ( www.silabs.com) — C8051F120;
C8051F120 Development Kit; USB Debug Adapter.
*********************************************************
void Timer_Init()
{
*********************************************************
void Port_IO_Init()
{
SFRPAGE = CONFIG_PAGE;
P0MDOUT = 0x03;
P1MDOUT = 0x40;
XBR0 = 0x04;
XBR2 = 0x40;
// enable access to
// port config regs
// push-pull on P0.0
// and P0.1
// push-pull on P1.6
// enable UART0
// Digital Crossbar
// enabled
}
*********************************************************
SFRPAGE = TIMER01_PAGE;
TCON = 0x40;
TMOD = 0x22;
CKCON = 0x10;
TH1 = 0xE5;
// enable access to the
// Timer1 register set
// enable Timer1
// Timer1 to Mode 2
// 8-bit Counter/Timer
// with Auto-Reload
// Timer1 uses system
// clock
// Timer1 reload value
// for 115200 baud
Of course, the UART0 bits were twiddled in the fray:
*********************************************************
void UART0_Init (void)
{
SFRPAGE = UART0_PAGE;
SCON0 = 0x40;
}
*********************************************************
If you’re wondering where the “Mode 2” wording
came from in the Timer_Init function, it is the name that the
C8051F120 datasheet uses to describe the eight-bit
Counter/Timer with Auto-Reload mode of operation. I’m
not going to insult your intelligence as everything you need
to know about the Timer_Init function can be found in the
function’s comments. I already checked the Configuration
Wizard 2 application’s work and the bits generated by
the Configuration Wizard 2 application in the Timer_Init
function match the C8051F120 datasheet declarations.
Bringing up UART0 also required an addition to our
Port_IO_Init function code. Recall that the UART0 transmit and
receive pins needed to be configured for push-pull operation.
Here’s the new code that the Configuration Wizard 2 application
generated and pushed into the existing Port_IO_Init function:
SSTA0 = 0x10;
TI0 = 1;
// enable access to
// UART0 registers
// UART0 serial port
// mode = 8-bit Timer/
// Counter Auto-Reload
// disable baud rate
// divide by 2
// Indicate TX0 ready
}
*********************************************************
The UART0_Init function is pretty simple. UART0 is forced
into Eight-bit Timer/Counter Auto-Reload mode, its baud rate
divisor is disabled, and the UART0 transmit-ready bit is set.
The final operation performed by the Configuration
Wizard 2 application is to update the Init_Device function.
Here’s what the updated Init_Device function looks like now:
*********************************************************
void Init_Device(void)
{
Reset_Sources_Init();
Oscillator_Init();
Timer_Init();
■ FIGURE 6. To my amazement, the Configuration Wizard 2
application correctly calculated the reload value. The ultimate
test will be to
see if we can
issue a printf
statement and
get something
we can read in
the Tera Term
Pro window.
Port_IO_Init();
UART0_Init();
// disable the watchdog
// set SYSCLK to 49 MHz
// set 8-bit Timer/Counter
// Auto-Reload mode
// set UART0 TX and RX pins
// for push-pull
// enable UART0 and set UART
// mode to match Timer 1
}
*********************************************************
■ FIGURE 7. This is the result of all of our hard work. I’ll
show you the hardware behind this in the next installment
of Design Cycle.
84
May 2007