C8051F34x-DK
4
Rev. 0.2
5. Example Source Code
Example source code and register definition files are provided in the “
SiLabs\MCU\Examples\C8051F34x
”
directory during IDE installation. These files may be used as a template for code development. Example
applications include a blinking LED example which configures the green LED on the target board to blink at a fixed
rate. A Universal Serial Bus (USB) application example is also included with the C8051F34x development kit.
5.1. Register Definition Files
Register definition files
C8051F340.inc and C8051F340.h
define all SFR registers and bit-addressable control/
status bits. They are installed into the “
SiLabs\MCU\Examples\C8051F34x
” directory during IDE installation. The
register and bit names are identical to those used in the C8051F34x datasheet. Both register definition files are
also installed in the default search path used by the Keil Software 8051 tools. Therefore, when using the Keil 8051
tools included with the development kit (A51, C51), it is not necessary to copy a register definition file to each
project’s file directory.
5.2. Blinking LED Example
The example source files
blink.asm
and
blinky.c
show examples of several basic C8051F34x functions. These
include; disabling the watchdog timer (WDT), configuring the Port I/O crossbar, configuring a timer for an interrupt
routine, initializing the system clock, and configuring a GPIO port. When compiled/assembled and linked this
program flashes the green LED on the C8051F340 target board about five times a second using the interrupt
handler with a timer.
5.3. Universal Serial Bus (USB) Application Example
The included USB application example requires Windows 98SE/2000/XP operating system. This example consists
of three parts: firmware running on the C8051F340 device, a USB device driver running on the host PC, and a host
application. The host application communicates with the C8051F340 via USB, allowing the user to view and to
change the state of several I/O peripherals on the C8051F340 target board. The example files can be found in the
“
SiLabs\MCU\Examples\C8051F34x\C\USB_INT
” directory. Located in this directory is the project file for the
firmware, the USB driver files, and the host application executable. In addition, three subdirectories are provided
that contain the source code for each part of the example application; Host Application Source, Driver Source, and
Firmware. Use the following instructions to set up the example USB firmware, install the USB driver, and then run
the example host application.
After the target board is connected to the host computer via USB, the example application enumerates and sends
data between the target and the host application using Endpoint 0, 1, and 2. The Endpoint 0 packets are control
packets as defined in Chapter 9 of the Universal Serial Bus Specification, version 2.0. Endpoints 1 and 2 are used
for data IN and OUT, respectively. These data packets consist of 8 bytes used to denote the current status of the
buttons, LEDs, Potentiometer, and logic levels of various port pins on the target board. Accessing the USB core
(i.e., accessing the USB registers and moving data to and from the Endpoint FIFOs on the target board) is
documented in Silicon Laboratories’ C8051F34x datasheet.
electronic components distributor