+ All Categories
Home > Documents > Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and...

Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and...

Date post: 28-Sep-2020
Category:
Upload: others
View: 4 times
Download: 0 times
Share this document with a friend
40
myCSoC Programming the 8032 MCU Core ©2000 by XESS Corp. 72 2 Programming the 8032 MCU Core Objectives Become familiar with the 8032 microcontroller core on the Triscend CSoC. Learn how to instantiate and use 8032 I/O ports. Learn how to use some of the dedicated peripherals of the 8032. Learn how to use the Keil software development environment to write C programs. Learn how to create interrupt-driven programs. Learn how the Triscend CSoC handles code and data memory spaces. Microcontroller Resources in the CSoC Your introduction to the Triscend CSoC continues with an exploration of the built-in 8032 microcontroller core. The areas of the CSoC you will use are: the 8032 microcontroller unit (MCU) with its dedicated peripherals, the byte-wide system SRAM, the memory interface unit (MIU), the address mappers, the JTAG interface, the hardware breakpoint unit. These areas are highlighted in Figure 11.
Transcript
Page 1: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 72

2222Programming the 8032 MCU Core

Objectives

Become familiar with the 8032 microcontroller core on the Triscend CSoC.

Learn how to instantiate and use 8032 I/O ports.

Learn how to use some of the dedicated peripherals of the 8032.

Learn how to use the Keil software development environment to write C programs.

Learn how to create interrupt-driven programs.

Learn how the Triscend CSoC handles code and data memory spaces.

Microcontroller Resources in the CSoC

Your introduction to the Triscend CSoC continues with an exploration of the built-in8032 microcontroller core. The areas of the CSoC you will use are:

the 8032 microcontroller unit (MCU) with its dedicated peripherals,

the byte-wide system SRAM,

the memory interface unit (MIU),

the address mappers,

the JTAG interface,

the hardware breakpoint unit.

These areas are highlighted in Figure 11.

Page 2: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 73

ClockControl

ConfigurableSystem Logic

(CSL)Matrix

Selector

SelectorSelectorSelectorSelectorSelector

PIO

PIOPIOPIOPIOPIOPIOPIO

Power-OnReset

PowerMgmt.

Address Bus

Data BusBus

Arbiter

Two-ChannelDMA Controller

JTAGInterface

AddressMappers

HardwareBreakpoint Unit

Byte-wideSystem RAM

MemoryInterface Unit

8032 MCUCPU

UART

Timer0Timer1Timer2

WatchdogTimer

256x8RAM

InterruptUnit

Data Address

Configurable SystemInterconnect Bus

Figure 11: Areas of the Triscend CSoC used in the designs in this chapter.

The 8032 Microcontroller Unit

The Triscend CSoC contains an enhanced version of the industry-standard 8051 MCUarchitecture. The 8051 architecture has been described in hundreds of books over thepast twenty years, so I won't try to replicate that body of work here. I will list thefeatures of the enhanced 8032 MCU in the CSoC:

Turbo CPU: The standard 8051 uses twelve clock cycles per instruction cycle, but the8032 MCU in the CSoC uses only four clock cycles. The 8032 MCU also hastwo data-pointer registers versus the single data-pointer in the original 8051.

SRAM: The 8032 MCU contains 256-bytes of SRAM for use as scratch-pad storage andto hold the program stack.

UART: A universal asynchronous receiver/transmitter (UART) is built into the MCU forserial data communications. The 8032 UART offers automatic addressrecognition and frame error detection in addition to the standard features ofthe original 8051 UART.

Timers: The 8032 MCU has three programmable timers which are used to generatepulse-trains, periodically interrupt the MCU, and set the bit rate of the UART.

Page 3: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 74

Watchdog timer: The watchdog timer resets the 8032 MCU to a known state unlessthe MCU regularly clears the watchdog. If the program running in the 8032MCU goes astray and the watchdog is no longer being cleared, then thewatchdog will restart the program.

Interrupt unit: The 8032 MCU responds to interrupts from twelve different sources thatare organized into three levels of priority.

The Byte-wide System SRAM

The TE505 on your CSoC Board contains 16 KBytes of fast static SRAM (SRAM). ThisSRAM can store data or programs for the 8032 MCU.

The Memory Interface Unit

The MIU controls the access of the CSoC to external memory or other devices. Theset-up and hold timing for external devices can be programmed into the MIU.

The Address Mappers

The 8032 MCU uses 16-bit addresses to fetch instructions and data from internal orexternal memory. The address mappers expand these addresses to 32-bits and sendthem to the CSI address bus. At this point, the translated address will determinewhether the internal SRAM, external SRAM, or CSL is accessed. The address mappersare programmable, so you can select which 8032 address ranges will activate aninternal or external memory access.

The JTAG Interface

You use a PC host system to program and debug a Triscend CSoC through a JTAGinterface consisting of four wires:

TCK: This clock input to the CSoC synchronizes the signals on the other JTAG wires.

TMS: The logic value on this input to the CSoC is used to steer the internal statemachine of the CSoC into various states for configuring the CSoC, debuggingits operations, etc.

TDI: This wire carries configuration data or other instructions to the CSoC.

TDO: This wire carries data from the CSoC back to the host system.

Page 4: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 75

The Hardware Breakpoint Unit

The 8032 MCU on your CSoC Board runs at up to 25 MHz. The four-wire JTAGinterface is too narrow to monitor the program and data accesses at this speed. Youcan program the hardware breakpoint unit to monitor the 32-bit CSI address bus, thebyte-wide data bus, the control signals, and the type of memory access (instructionfetch or data read/write). When a trigger event is detected, the hardware breakpointunit halts the CSoC and alerts the host system through the JTAG interface. Then youcan examine the state of the CSoC.

You will use the 8032 MCU, MIU, internal and external SRAM, and the addressmappers in the design examples that follow. You will not be directly involved with theJTAG interface and hardware breakpoint unit, but these will be used by the softwaretools as you do the examples.

Design 2.1 - 8032 MCU I/O Ports

Your first MCU-based CSoC design will read the settings of the DIP switch and displaythe lower seven-bits on the seven-segment LED digit of the CSoC Board (Figure 12).The MCU will continuously poll the DIP switch settings and then write the settings into aregister that drives the LED digit.

SEGASEGB

SEGFSEGESEGDSEGC

SEGG

8032MCU

P0.0P0.1

P0.6P0.5P0.4P0.3P0.2

P0.7

A

GF

E

D

C

B1

23

45

67

8

LED.0LED.1

LED.5LED.4LED.3LED.2

LED.6

Figure 12: Block diagram of an MCU-based system that reads DIP switch settingsand displays them on an LED digit.

This design example requires you to design some hardware to read the DIP switch anddrive the LED digit, and then you have to write some software for the 8032 MCU thatpasses the value from the DIP switch circuitry to the LED driver. You will create thehardware in the next section and then go on to write the software.

Instantiating the Hardware

To begin this design, start FastChip and create a project called Chap21. Then open thelibrary of soft modules and select Peripherals⇒Ports⇒8032 PIO Port from the menu anddrop it into the Programmable I/O Pins area. This places a standard 8032 I/O port into yourdesign that you can use to read the DIP switch settings.

Page 5: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 76

Next, select I/O⇒Output and drop an output port into the same area. You will use thisoutput port to drive the LED. This output has to be driven with a value written by the8032 MCU, so select Peripherals⇒Control⇒Command Register from the library and place it inthe Configurable System Logic area. This instantiates a register that the MCU can write withthe value to be displayed on the LED.

Why not use another 8032 port to drive the LED digit rather than the combination of acommand register and an output? Because the standard 8032 port cannot sourceenough current to illuminate the LED segments (it is limited to sourcing less than 100µA). But the Output module is capable of sourcing up to 12 mA per pin, which is plenty.

After instantiating these soft modules, your project design window will appears asfollows.

Page 6: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 77

Now you need to modify the modules to suit the design. Click on the Port_A module tomake the following window appear.

Within the window, select P0 in the 8032 PIO Port Type area. Then type P0 into theComponent Names box to reflect the function of this port. You will use this port to read theDIP switch settings, so the output drive strength is irrelevant. Also, since the DIP switchcircuitry on your CSoC Board already has external pullups, you can enable or disablethe P0 pullups without affecting the operation of your design. Then click on OK to closethe window.

Next, click on the CmdReg_A module. When the Module window opens, change theregister width to seven bits (since there are seven LED segments) and change thename of the register outputs to led. The 8032 MCU will write values into this registerthat will appear on the led outputs, so the MCU needs a way to reference the register.In the Symbolic Address box, type the name by which you will reference this register(ledPort) in the program code for the 8032. You can select whether the MCUaccesses this register as if it were in the external data memory space (Xdata) or as if itwere a special function register (SFR). For external data accesses, the 8032 uses adata pointer that is initialized to the register address. This takes a bit more code and abit more time than would be the case if the register was accessed as an SFR. SFRshave addresses in the range [0x80,0xFF] so there are not very many of them. ( A lot ofthem are already used by the MCU's dedicated peripherals like the UART and timers.)In this example, code size and execution time are not critical and there is plenty of

Page 7: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 78

space in the SFR address region, so you can select either method. (I chose to makethe register an SFR.) The click on OK to finalize your modifications.

Click on the Output_B module to bring up the window that will configure the LED digitdrivers. Change the name of the module to LED so its function is easily discernable.Adjust the output width to seven bits and connect the outputs to the CommandRegister module by typing led into the <output> field. Change the drive strength to 12mA so the LED segments will be brightly lit. Then click on OK to set the changes.

Now that the modules have been instantiated and their connectivity has been specified,you can assign the inputs of the P0 port and the outputs of the LED port to the pins ofthe CSoC using the I/O Editor. As shown below, the LED port consists of outputs only(signified by red, unidirectional arrows) while the P0 port is capable of input and output

Page 8: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 79

functions (represented by blue, bi-directional arrows). Click and drag the LED and P0I/Os to the pins listed in Table 6.

Page 9: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 80

Table 6: Pin assignments and functions for the 8032 MCU I/O port design.

Signal Pin CSoC Board Resource

P0.0 53 DIP switch position #1

P0.1 54 DIP switch position #2

P0.2 55 DIP switch position #3

P0.3 58 DIP switch position #4

P0.4 59 DIP switch position #5

P0.5 60 DIP switch position #6

P0.6 62 DIP switch position #7

P0.7 63 DIP switch position #8

LED.0 35 LED digit segment A

LED.1 39 LED digit segment B

LED.2 43 LED digit segment C

LED.3 41 LED digit segment D

LED.4 40 LED digit segment E

LED.5 34 LED digit segment F

LED.6 36 LED digit segment G

You need to specify a clock to sequence the operations of the MCU. To do this, click onthe Clocks icon in the Dedicated Resources area of the project window. The Clock Controlwindow that appears lets you select one of several sources for the BusClock signal.Click the button for the second option: Clock input to XTAL/BCLK. This selects thededicated clock input to the Triscend CSoC as the driver for BusClock. An externalprogrammable oscillator is connected to this input on the CSoC Board. If you haveconfigured your CSoC Board as described in Appendix B, then the external oscillatorwill output a stable 25 MHz clock frequency. Type 25.00 into the Frequency field to letthe FastChip software know this is the frequency of the external clock source. Thentype 5 into the Clock Settling Time field. (This value is used by the Triscend CSoC to keepthe chip in a reset state until the main clock is stabilized after power-up. This parameterisn't very important in your current environment since the CSoC Board is already

Page 10: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 81

powered before the chip is ever configured with your timer circuit.) Then click on OK toclose the window.

Page 11: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 82

Finally, you need to set-up the memory interface unit because the instructions for yourMCU program will be stored in external memory. Click on the MIU icon in the DedicatedResources area of the project window and the following window will appear. This windowlets you select how many address bits will be used by the MIU to access externalmemory. There are only 128 KBytes of external SRAM on your CSoC Board, so selectthe smallest address range in the drop-down list (256 KBytes). This wastes oneaddress bit and the SRAM contents will be replicated twice within the 256 KByteaddress range, but this won't cause any problems. Click on OK and move to the nextstep.

Generating the Hardware/Software Interface

At this point you have defined the hardware for your design. Now you have to generatea header file that links the hardware to the software you will write for the 8032 MCU.Among other items, this header file will contain the addresses of the P0 and ledPortregisters you built into your hardware. Your application code will use these addressesto read the DIP switch settings and write the data to the register that drives the LEDdigit.

Page 12: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 83

You start the creation of the header file by clicking on the Generate toolbar icon. Thefollowing window will appear.

You can generate a header file for use with either 8032 assembly or C code by clickingon the Assembly or C button in the Generated Language area of the window. I used to write8052 assembly code in the early 80's and I have no desire to revisit those times. Now Iwrite as much of my application software in C as possible. You are free to use eitherlanguage, but I will not present any examples of assembly language coding in this text.Click on the C radio button to generate the C header file.

By default, the header file will be created in your FastChip project folder with the samename as your project. You can use the Browse button to choose another folder, but I amusually happy with the default. Once you select the language for your header file, theFile Name box in the Generated Source File area will change the suffix of the header file to.inc or .h depending upon whether you chose to use assembly or C language,respectively.

Clicking on OK generates the actual header file. If you checked the View Generated Codebox, then a window appears with the contents of the header file (Listing 1). Theinteresting part of the header file is found on lines 31–35. The ledPort register isplaced in the SFR address space of the 8032 (as you specified previously when youcustomized the CmdReg_A module) at address 0x9a. And port P0 is placed at address0x80 in the SFR which is the standard address for this port in the 8051 MCUarchitecture.

Listing 1: Top of the header file generated by the FastChip software for the8032MCU I/O port design.

// Generated 3/5/00 11:39 AM By FastChip Version 1999 Build 1512

///////////////////////////////////////////////////////////////3// ----------------------------------4

Page 13: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 84

// ------ GENERATED CODE --------5// ----------------------------------6// The code in this header file was generated automatically for your7// project by Triscend FastChip. Please DO NOT EDIT this header file.8// It will be overwritten the next time FastChip generates code for9// your project.10//11///////////////////////////////////////////////////////////////12

13//======== Required symbol and macro definitions ========14

15#ifdef PROTOTYPE_ONLY16# define CHAR_XDATA(name,location) extern volatile unsigned char xdata name;17# define CHAR_ARRAY_XDATA(name,location,size) extern volatile unsigned char18xdata name[size];19#else20# define CHAR_XDATA(name,location) volatile unsigned char xdata name _at_21location;22# define CHAR_ARRAY_XDATA(name,location,size) volatile unsigned char xdata23name[size] _at_ location;24#endif25

26//========= BEGIN SOFT MODULE REGISTER DECLARATIONS ======27

28//-------------------------------- Module CmdReg_A29 sfr ledPort = 0x9a;30

31//-------------------------------- Module P032 sfr P0 = 0x80;33

34//========== END SOFT MODULE REGISTER DECLARATIONS =======35

The header file contains a bunch of other address definitions for the standard SFRs ofthe 8051 as well as some additional SFRs and extended data memory locations thatcontrol functions found only in the Triscend 8032 MCU. These are followed by a seriesof definitions for subroutines that initialize the peripherals of the 8032 such as the timersand the UART. At the very bottom of the header file is a master initialization subroutine(Chap21_INIT()) that calls all the other initialization subroutines (Listing 2).

Listing 2: Bottom of the header file generated by the FastChip software for the8032 MCU I/O port design.

//========= PROJECT INITIALIZATION FUNCTION ======12

#ifdef PROTOTYPE_ONLY34

extern void Chap21_INIT();56

#else78

void Chap21_INIT () {9

Page 14: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 85

Timer_0_INIT();10 Timer_1_INIT();11 Timer_2_INIT();12 UART_INIT();13 Interrupt_INIT();14 Watchdog_INIT();15 DMA_0_INIT();16 DMA_1_INIT();17 Power_INIT();18}19

20#endif21

Creating the 8032 MCU Application Code

Now that you have the hardware designed and the header file that specifies theaddresses of the registers in the hardware, you can begin to create the application codethat will run in the 8032 MCU. To do this, you will have to leave the FastChipenvironment and use software development tools for the 8051 architecture. In this text Iwill use the Keil 8051 software tools, but you can use any 8051 compiler (although thesteps in creating and compiling the code will probably be different from what I showhere).

To begin, you should create a folder where you will store your application code. Iusually create a folder called keil within the FastChip project folder as shown below.

Page 15: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 86

Once the folder is created, click on the icon to start up the Keil integrateddevelopment environment (IDE). In the µµµµVision/51 window that appears, click on theFile⇒New menu item to open a subwindow.

Page 16: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 87

In the <Untitled 1> window, type the source code for the application. Start with aninclude statement that brings in all the definitions from the Chap21.h header file.(Recall that the header file was generated in the FastChip project folder directly abovethe keil folder.) Then create a main() routine whose first action is to call theChap21_INIT() subroutine that initializes all the 8032 peripherals. Finally, place aninfinite while-loop that continually reads the P0 port and writes the value into theledPort register. The header file will inform the compiler of the addresses for theseregisters in the SFR space. That's all there is to the application code for this example!

Click on File⇒Save As… to bring up the following window. Store your source code in thechap21.c file in the keil folder.

Page 17: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 88

Once your code is saved in the keil folder, you can create a project within the Keil IDE.The project file will store all the settings and source files that are needed to generate the8032 object code from the C source code. Click on the Project⇒New Project… menu itemas shown below.

In the Create New Project window that appears, save your project in the chap21.prj file inthe keil folder.

Page 18: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 89

Click on the OK button and the Project window will appear. You will use this window tospecify the source files that are compiled to create the project object code. This isdone by clicking on the Add button.

Clicking the Add button brings up the Add File to Project window. The C files in the keilfolder are shown in the left-hand side of the window. There is only one file in thisexample, so click on chap21.c to select it and then click on Add.

Page 19: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 90

The Add File to Project window will disappear and the Project window will show thatthe chap21.c file has been added to your Keil project. This is the only C file needed tocreate the object code, so click on Save to store the list of source files in the chap21.prjfile.

Now you need to tell the Keil compiler and linker tools about the particular features thatexist in the Triscend 8032 core. That lets the compiler take advantage of any specialfeatures in the hardware and it lets the linker know the organization of the memoryspaces. To set-up the compiler, click on the Options⇒C51 Compiler… menu item.

Page 20: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 91

Click on the Chip tab of the C51 Compiler Options window in order to specify thenumber of data pointers in the Triscend 8032 MCU. This MCU is not included in the list,but the Dallas version of the 8051 architecture has two data pointers just like theTriscend 8032 MCU so select that one.

Next, click on the Memory Model tab. Select the Large limit on the code size so programscan use as much as 64 KBytes of memory (even though you won't need that much).Also select the Small memory model which stores program variables in the internal 256-byte scratchpad memory of the 8032 MCU.

Page 21: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 92

Finally, click on the Object tab and check the folloing boxes to include extra debugginginformation in the compiled object file. This extra information makes it easier to debugC language programs using the Keil debugging tools. Click on OK to finalize your C51compiler option settings.

Now set-up the linker by clicking on the Options⇒BL51 Code Banking Linker… menu item.

Page 22: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 93

Click on the Size/Location tab in the BL51 Code Banking Linker window that appears.The 8032 MCU in the CSoC has 256 bytes of scratchpad RAM for storing variables, soenter 256 into the Ram Size box.

Finally, click on the Linking tab and check all the boxes for including debugginginformation into the object code. Then click on OK to close this window.

Page 23: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 94

Now that the source files and compiler/linker options are set for your project, click on theProject⇒Make: Build Project menu item. This will compile the chap21.c file and then link itinto a HEX file that can be loaded into the Triscend CSoC.

If there are no errors during the compilation or linking processes, you will see a ProjectStatus window reporting that the make operation was successful. Otherwise you willget a window listing any errors and their locations in the source code. Click on OK toremove the Project Status window.

Binding and Downloading the Hardware and Application Code

Once the application code has been compiled and linked, you can re-enter the FastChipproject window and click on the Bind toolbar icon. This will map your hardware into the

Page 24: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 95

CSL while making sure that the P0 and ledPort registers are assigned the sameaddresses that are listed in the chap21.h header file.

After the binding operation is complete, click on the Download toolbar icon. In theDownload window, click on the Browse button in the Application Object Code area. Enter thekeil folder using the Triscend FastChip File Browse window that appears. You will seethe chap21.hex file that was generated by the Keil linker in the previous section. Selectthe chap21.hex file and click on the Open button.

At this point, you will see the chap21.hex file is listed in the Intel HEX File Name box in theFastChip Download window. This 8032 object code file will be combined with theconfiguration file for the CSoC circuitry and the result will be loaded into the CSoC.

Now you have to decide where to load the 8032 object code. You could use the internal16 KByte SRAM of the TE505 CSoC that exists in the 8032 address range of[0x0000,0x3FFF]. But the linker in the evaluation version of the Keil software tools willonly place the 8032 object code at address 0x4000 or higher, so you can't use theinternal SRAM to hold the program.

Page 25: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 96

Your CSoC Board also has Flash RAM and SRAM (each stores 128 KBytes) that canhold the object code. The Flash RAM will retain the object code even if the power toyour CSoC Board is interrupted. But you are just doing some quick tests on this codeand you don't need to store it for a long time. Programming the code into the FlashRAM also takes a minute or so. For these reasons, you should choose External SRAM inthe Memory Device area of the Download window as shown below.

Once you select the external SRAM as the location for your 8032 object code, you haveto make a few more decisions. First, you can store the object code and configurationfor the CSoC into a HEX file that will be loaded into the CSoC Board SRAM at a latertime, or you can elect to download the object code and configuration directly into theCSoC Board through the parallel port download cable. In this example, select the DirectProgram option.

Second, you have to give the FastChip some information on the type of external SRAMchip you are using. FastChip knows the characteristics of a small set of SRAM devices,but the SRAM chip on your CSoC Board isn't one of them so you need to use the SpecifyAdditional Part area to list its size and access time. The SRAM chip has 128 KBytes, butthe smallest size listed is 256 KBytes so choose that. This will replicate the contents ofthe SRAM twice within the 256 KByte address range, but that won't cause a problem.The access time for the CSoC Board SRAM chip is 15 ns so type that in as well.

Now click on OK in the Download window and the 8032 object code and the CSoCconfiguration will download into your CSoC Board through the parallel port. As always, .make sure your CSoC Board is attached to the 9V DC power supply and it is connectedto the parallel port of your PC with the downloading cable. You should also set theshunts on jumpers J8 and J9 of the CSoC Board so that the SRAM chip-enable input isconnected to the CSoC MIU chip-enable output (see Appendix A2).

Page 26: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 97

Testing Your Application Code

Now the CSoC Board is loaded with your circuit and application code. You will use theKeil dScope debugging tool to test the code. In the Keil IDE, click on the Run⇒dScopeDebugger… menu item to start the debugger.

Page 27: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 98

The dScope window will appear with several subwindows that display MCU registervalues and object code as well as those which allow you to reset the MCU and enterother commands.

The first thing you need to do is inform the debugger of the type of MCU you areworking with. In the drop-down list near the top of the dScope window, select the 8032-te5.dll entry. This installs a library of routines that interface the dScope debugger to theTE505 8032 MCU and hardware breakpoint unit through the JTAG port.

Page 28: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 99

Once you select the MCU interface, the dScope debugger will initiate a connection withthe CSoC Board. Just click on OK in the TCP/IP Configuration window that appears.

After the connection is established, you should reset the 8032 MCU in the CSoC byclicking on the Reset button in the Toolbox window. (If the Toolbox window is notvisible, click on the button in the dScope window.)

Once the MCU is reset, you should select File⇒Load object file… to load the debugginginformation for your application into dScope. (This does not initiate another download tothe CSoC Board.)

Page 29: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 100

A window will appear that you will use to select the file with the debugging information.Go into the keil folder within your FastChip project folder and select the chap21 OMF file(this file does not actually have any suffix). Click on OK and the debugging informationis loaded into dScope.

With the debugging information now available in dScope, you have the choice ofviewing your application software as assembly language, C high-level language, or amixed mode which shows each line of C code and its associated assembly languageinstructions. Tracing through the your code's assembly language as it executes givesyou the most detailed view of what it is doing, but this level of detail is overkill for thisapplication. Instead, select the hll option from the drop-down list in the Module windowso you can view your code as C language statements.

Page 30: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 101

Now your Module window looks like the one below. Where is the C code? The Modulewindow shows code starting at the beginning of memory, but your C code starts ataddress 0x4000 so it isn't visible.

There are two ways to get to the beginning of your C code. The first way is to click onthe slider bar on the right side of the Module window and slide it upwards until you seeAddress = C:4000H at the bottom of the window. Release the slider and you may see yourC code displayed in the window. I say "may" because sometines this works for me, andother times it doesn't.

Page 31: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 102

The second way to get to the start of your C code is more reliable, but takes a few moresteps. It involves setting a breakpoint at the start of the main() routine and then lettingthe application program execute until it hits that breakpoint. This causes the program tostop execution at the beginning of main() and the C code at that point will appear inthe Module window. To set the breakpoint, click on Setup⇒Breakpoints… in the menu barof the dScope window.

Page 32: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 103

The Breakpoints window will appear. It has an area which shows the current set ofbreakpoints defined for your program (which should be empty at this time). Below thatis an Expression box where you can enter an expression that defines an address withinyour program. This address is loaded into the hardware breakpoint unit of your CSoC.The 8032 MCU will be halted when the breakpoint unit sees a combination of readand/or write accesses to that address which equals the number entered into the Countfield in the Breakpoints window.

Page 33: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 104

But how do you write an expression for the beginning address of the main() routine?It turns out you don't have to. Just click on the Show symbols… button in the Breakpointswindow. This brings up the Symbols window where you can see all the variable andsubroutine names for your program. Click on the Locals radio button and a list of thesubroutines will appear. Click on the MAIN() line in the Symbols window and drag it intothe Expression box in the Breakpoints window.

After you drop the MAIN() symbol into the Breakpoints window, it will appear in theExpression box.

Page 34: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 105

Next, click on the Define button and the symbolic address in the Expression box will beconverted to a breakpoint that appears in the current Breakpoints area.

Page 35: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 106

At this point you have a single breakpoint, but you can have more than one in the list. Ifyou want to examine or change a breakpoint, just select it in the list as shown below.You can enable or disable the checkpoint using the Enabled checkbox. Or you candelete the breakpoint completely by clicking on the Kill selected button. You can alsoincrease or decrease the number of times the address is accessed before thebreakpoint becomes active by changing the value in the Count box. Or you can use theCommand box to enter a command in a C-like syntax that will be executed when thebreakpoint occurs. But you don't need to change anything about this breakpoint rightnow. Just click on Close to accept the current breakpoint and remove the window.

Now the application code is loaded into the 8032 MCU and the debugger, the MCU isreset, and the breakpoint at the start of main() is defined. You can start the MCUprogram running by clicking on Go! or the button in the Module window. The 8032will start to run, but it will immediately stop as soon as it gets to the beginning of themain() routine.

Page 36: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 107

The Module window now shows the C code for your program. The next C statementthat will be executed is highlighted in red. This is a call to the subroutine that initializesthe various 8032 peripherals.

Now you can execute the C code statement-by-statement and see how the programworks. The StepOver! command or the button is used to execute a single Cstatement. In this case the next statement is a subroutine call, so activating StepOver!will enter the subroutine, execute all the statements in the subroutine, and then return tothe next statement in the calling routine and halt.

If you want to see the statements within the Chap21_INIT() subroutine as they areexecuted, use the StepInto! command or the button to drop down into the subroutine.Then use the StepOver! command to trace the execution of statements at that level, ormove deeper into the nested subroutines by using the StepInto! command. When youtrace to the end of a subroutine, you will automatically return to the next statementfollowing the subroutine call in the calling routine. If you have seen all you need to inthe current subroutine, you can issue the StepOut! command or press the button andthe rest of the statements in the subroutine will be executed, control will return to thecalling routine, and program execution will stop.

Page 37: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 108

After the Chap21_INIT() subroutine completes, the program enters the while loop.The next statement that will be executed will read a value from the P0 port and transferit to the ledPort register. At this point, you should change some of the DIP switchsettings so you can see if the pattern on the LED digit changes.

Page 38: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 109

Clicking the StepOver! command or the button now moves the execution to the end ofthe while loop. You should see the LED digit change to reflect the DIP switch settingas shown in the examples in Figure 13.

1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 81 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8

Figure 13: The LED digit activation for several DIP switch settings.

At this point, you have to click the button twice before the LED digit segmentschange to reflect the DIP switch settings. If you want your program to run at full speedwithout interruption, just press the Go! command or the button. The program will notreturn to the start of the main() routine so it will never hit the breakpoint and halt.Once the program starts running, any changes to the DIP switches will appearinstantaneously on the LED digit. To halt the program, just click on the Stop! or button.

Changing Your Application Code

What if you discover an error and want to correct your application code? For example,suppose you want the LED segments to light up when their associated DIP switch is in

Page 39: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 110

the up position instead of the down position. This is easy to handle in the C sourcecode: just add an inversion operator (~) before the P0 variable. This makes thestatement read the DIP switch settings from port P0, do a bitwise inversion of the value,and then store the altered value into the ledPort register.

Now you have to recompile your program to reflect this change. Select Project⇒Make:Update Project or click on the button in the µµµµVision/51 window. The C source code isrecompiled and linked to create a new chap21.hex file.

With the updated HEX file in hand, the next step is to load it into your CSoC Board. Youcould use the downloading features of the FastChip software, but the dScope debuggeralso has this capability. First, you should halt any program that is running in the 8032MCU by pressing the Stop! command in the Module window. Then in the dScopewindow, click on the Triscend⇒Download Hex… menu item as shown below.

Page 40: Programming the 8032 MCU Core - XESS Corp.The MCU will continuously poll the DIP switch settings and then write the settings into a register that drives the LED digit. SEGA SEGB SEGF

myCSoC Programming the 8032 MCU Core

©2000 by XESS Corp. 111

This brings up a Download HEX file window where you can specify the name orbrowse to the location of the updated HEX file. Click on Download to reload the CSoCwith the updated application code.

After the CSoC has been updated, you still need to load the debugging info for the newsource program into dScope. Do this by clicking on the File⇒Load Object File… menu itemand select the chap21 OMF file.

Once the updated debugging information is loaded, click on the Reset button in theToolbox window and then click on Go! in the Module window. With the programrunning, you should see that the DIP switch buttons have the opposite effect on theactivation of the LED digit segments.

After verifying the operation of your modified program, click Stop! to halt the program.Then select File⇒Exit in the dScope window to close the debugger. You can also exitfrom the Keil IDE and the FastChip program.

Design 2.2 - UART Loopback

Your next MCU-based CSoC design will use the UART in the 8032 to transmit andreceive bytes of test data (Figure 14). The MCU will continuously load the UARTtransmitter and poll the receiver to see if the received byte is identical to the transmittedbyte. An AND gate will be placed in the loopback path so the transmitted byte can beblocked or passed through based on the setting of DIP switch 1. The MCU will displayan 0 on the LED digit as long as the loopback path is not broken (gate = 1). When thepath is broken (gate = 0), the transmitted and received bytes will no longer match andthe MCU will display an E.


Recommended