THE DESIGN CYCLE
DOES IT REALLY WORK?
I sincerely hope that there was absolutely no doubt
in your mind. The Configuration Wizard 2 application can
do many wonderful things. However, it can’t write your
core application code for you. We went to a bunch of
trouble to configure our C8051F120 hardware to spit
some ASCII characters out of the UART0 transmit pin. So,
I’ve put together a very simple application that sends a
message via the UART0 transmit pin and toggles an LED
every time the message is sent. Here’s the application code
behind my madness:
C statement. I rest my case with Figure 7.
WHERE’S THE HARDWARE?
*********************************************************
void main()
{
unsigned int x,y; // declare local variables
Init_Device(); // init the microcontroller
SFRPAGE = UART0_PAGE; // enable UART0 access
while(1){
x = 0xFFFF;
y = 0x007F;
do{ // kill some time
while(—x);
}while(—y);
// init the kill-time values
LED = ~LED; // toggled the LED on P1.6
printf(“\r\nNUTS AND VOLTS READERS ROCK!\r\n”);
}
}
*********************************************************
Again, no rocket science here. After declaring a
couple of integers for use by a kill-time routine, my little
C8051F120 application calls the Init_Device function.
Recall that the Init_Device function does everything
necessary to prepare the C8051F120 peripherals and
general-purpose I/O pins for pumping stuff out of UART0
and bit twiddling the LED, which
is attached to general-purpose I/O
pin P1.6. I selected the kill-time
delay values to toggle the LED and
send a message once every couple
of seconds.
Sending a message using UART0
involves writing to the UART0 buffer
register SBUF0. We must load the
SFRPAGE register with the SBUF0
SFR page so we can address the
SBUF0 register within the SBUB0
SFR page. The kill-time routine is
a simple do-while loop that
decrements the x variable from
0xFFFF to zero as long as the
y variable has not decremented
to zero itself. When all of the
integer variables expire to zero,
the LED is toggled and a message
is emitted from UART0. This is all
contained within the braces of an
endless loop created by the while(1)
(Yes, I was tempted to headline this section as
“Where’s the Beef?”) If you’ve ever taken pilot training,
you know that more time is spent on the ground in
training than in the air when you begin the process.
With that thought, you’ve done enough ground
training with the C8051F120, and in the next installment
of Design Cycle, we’ll jump into the cockpit of a
C8051F120 microcontroller. In addition to examining
the C8051F120 hardware, we’ll finish off writing some
code for the rest of the C8051F120 peripherals. In
the meantime, I’ll post the C source code and
the Configuration Wizard 2 configuration file
(nuts_and_volts.cwg) we discussed here on the Nuts &
Volts website for you.
For those of you that want to get your hands dirty
right now, you’ll need to get a demo or registered copy
of the Keil C51 C Compiler and a Silicon Laboratories
USB Debug Adapter to run the code I’ve presented in
this Design Cycle entry. The easy way to do this is to
get yourself a Silicon Laboratories C8051F120
Development Kit, which contains a nifty C8051F120-
equipped development board, a demo version of the
Keil C51 C Compiler, and a Silicon Laboratories USB
Debug Adapter. I’ll show you how to integrate and
use the Keil and Silicon Laboratories tools as we put
the C8051F120 hardware through its paces next time
around. NV
CONTACTING THE AUTHOR
■ Peter Bestcanbereachedviaemailatpeter@nerdvilla.com.
The Standard for checking
Capacitors in-circuit
Good enough to be the
choice of Panasonic,
Pioneer, NBC, ABC, Ford,
JVC, NASA and thousands
of independent service
technicians.
Locate shorted or leaky
components or conditions
to the exact spot in-circuit
Still cutting up the pcb,
and unsoldering every
part trying to guess at
where the short is?
$209
Your DVM shows the same shorted reading all
along the pcb trace. LeakSeeker 82B has the
resolution to find the defective component.
And with a 60 day trial period, satisfaction Touch pads along the trace, and LeakSeeker
guaranteed or money-back policy, the only beeps highest in pitch at the defect’s pad. Now
thing you can lose is all the time you’re you can locate a shorted part only a quarter of
currently spending on trying to repair all an inch away from a good part. Short can be
those dogs you’ve given up on. from 0 to 150 ohms
CapAnalyzer 88A LeakSeeker 82B
Available at your distributor, or call 561-487-6103
Electronic Design Specialists www.eds-inc.com
Inexpensive enough to pay for itself in just
one day’s repairs. At $209, it’s affordable.
May 2007 85