Home

LMP2 – Introduction to the Metrowerks CodeWarrior and the Hi

image

Contents

1. Project Stationery Board Support 9s 2badge cml 2s dp25b Dragon flat evbd 2dp25b HCS12 T Board W HOST Stationery Figure LMP2 6 Selecting the Dragon12 flat stationery CodeWarrior now makes a copy of the Dragon12 flat stationery project and saves it as myHello If everything worked so far you should be presented with a fully functional 6 Microcontroller Programming LMP2 Metrowerks CodeWarrior IDE project with a small main program Figure LMP2 7 all project groups have been expanded Metrowerks CodeWarrior File Edit View Search Project Debug Processor Expert Window Help Beebo rte xR BRBARME SHEE HE n mM Simulator B y aA 5 gt Files Link Order Targets g Ey Start o D Statlac EA burner bb AB _MC9S12D 256_FLA 3 Libraries EA me9s12dp256 h Aa Wi ii uu ai uu uu uu us 2 s w w D me3s12dp256 c ansis lib B63 Debugger Config File E Simulator ini ooo oc fo ood Oo oo co ce eee see o o Ee og iE Monitor ini Debugger Command Files AD sermon_startup cmd AD sermon_postload cmd E sermon_preload cmd AD sermon_reset cmd ff sim_startup cmd AD sim_postload cmd E sim_preload cmd Loare 7 IE E E 7_ Bsa GOSE ASEDIO es E cpoam E sedboar Mime mev E nerone I FAO GGEMNSSO 15m Figure LMP2 7 The CodeWarrior project stationery Dragon12 flat The left hand side of Figure LMP2 7 shows th
2. 2 0005 Reserved Write Al D oy 2 0006 Reserved Write Al D oy 2 0007 er Reserved Write Read ooog i i Bit 7 PORIE Write 0009 pore NOP Bit Write P Read 000A FEAR Write NOACC l Read 000B MODE Write MODOC Bit 2 PIPOE NECLK LSTRE RDWE MODA MIS mi MODB EMK EME SIR aa D 000F Reserved m am Al 000C PUCR ioe PUPKE PUPEE PUPBE PUPAE Read 0000 RDRIV Write RDPK DPB ROPA Read 0 0 po Oo E C wite AAA Figure LMP2 13 Detailed memory map special function register block 11 Microcontroller Programming LMP2 Metrowerks CodeWarrior IDE Step over the first two instructions Figure LMP2 14 The colour of all 8 LEDs changes from grey to green This indicates that the associated microcontroller pin has been set as output LED active The reset state of the port P data register is zero corresponding to a LOW state green of all LEDs Notice that you can manually activate deactivate individual LEDs with left hand mouse clicks onto the corresponding icon However while this changes the state of the associated data direction register DDR the port register is not affected True Time Simulator amp Real Time Debugger C Documents and Settings fwornle My Documents frank Microcontroller 9S12DP256B _work myHello Simulator ini 18 x File View Run Simulator Component Led C Documents and Settings fwornle My Docu
3. IIC FC bus interface 5 CAN bus interfaces an Enhanced Capture Timer ECT 256 kByte Flash EEPROM 4 kByte EEPROM 12 kByte RAM etc The bus speed can go up to 50 MHz with operations being clocked at up to 50 MHz Figure LMP2 2 presents a more detailed overview of the internal structure of the MC9S12DP256B C 4K Byte EEPROM PADAO VODR PAD V5SR PAD VREGEN Voltage Regulator D0 PADIS ODA PAD VSS1 2 PADS PKA KADDRIS PK2 XADDRIG ISingle wire Background i Debug Module CPU XFC VODPLL Clock and PK3 i A RA VSSPLL PLL ee in Stacia EXTAL Module COP Watchdog i XTAL s PEO PE PE ess System Enhanced Capture a Integration Timer PE Module nee SIM PEGE PET ae NOACC RELA TEST eee ECTS FEE EEE SE mi ri Multiplexed Address Data Bus YA T eee ECTS FEEEEE SE 5 DDRA DDRE tl PTA PTB z tL eee R2222 ee ot oe E tdgddddgd PREPRESS A DnA i op fH D a at i ty amp r E EEEE E E E EEEE E O 0 O Q O G G Eh Ch Cdi Ci Cd Cd od Ls O O G O O O O O O O O O O O O m dlll Cigigidgd 3 ARE tha KA ne o a oo Multiplexed zz zzz T Wide Bus SEEREEREE i jad ddd 5 bhenn ew ewe eee eee ee ee ee I ae e a Multiplexed 2222 2 m Narrow Buse 444448 Internal Logic 2 54 iO Driver 54 bee Ea VODX fe 5 51 aa WEZA a A D Converter V amp PLL 2 54 Voltage Regulator Reference VODPLL qw VODA VSSPLL ale VESA Voltage Regulator 5V amp VO YODR jee VSSR L Figure LMP2 2 Intern
4. Record file Switch back to the Simulator target and open the source file main c Example program for the Wytec Dragon 12 MC9S12DP256C include lt mc9s12dp256 h gt derivative information include pll h defines _BUSCLOCK sets bus frequency to _BUSCLOCK MHz void main void set system clock frequency to _BUSCLOCK MHz 24 or 4 PLL Init set port B as output LEDs DDRB Off Port B is output PORTB 0x55 switch on every other LED forever Lorry 1 This small program first boosts the system bus clock from half the value of the crystal oscillator 0 5 x 4 MHz 2 MHz to the maximum clock frequency of 24 MHz PLL_Init It then defines the pins of port B as outputs DDRB OxFF setting a bit in the Data Direction Register of port B activates the corresponding output driver circuit 8 Microcontroller Programming LMP2 Metrowerks CodeWarrior IDE On the Dragon12 development board port B is connected to an array of LEDs The 3 line of main finally sets every other bit of port B to 1 0x55 0101 0101 This displays an on off pattern on the LEDs To simulate this program within the CodeWarrior debugger simulator Hi Wave click on the small green Debug button Figure LMP2 9 Metrowerks CodeWarrior File Edit View Search Project Debug Processor Expert Window Help Bese Borex RR OFawWe SR eb zia ea aa B O A Example program for the Wytec Dragon 12 MC9S1
5. 2DP256C include lt mc9s12dp256 h gt derivative information Files Link Order Targets include pll h defines _BUSCLOCK sets bus frequency t void main void set system clock frequency to _BUSCLOCK MHz 24 or 4 x PEE Init set port B as output LEDs DDRB Oxff 22 Port BD 1S output PORTE 0556 switch on every other LED oococccccfo e S a og forever for m E W Am Debugger Command Files AD sermon_startup cmd AD sermon_postload cmd ED sermon_preload cmd AD sermon_reset cmd NB sim_startup cmd hy OM e B ol of Line 21 Col 19 AD sim postload cmd E sim preload cmd AB sim reset cmd AB sim setepu cmd str G 3 ASEDIO Makeup L cpoum E Bacos M m2 mer E metrowe N PAO REEANS O 14m Figure LMP2 9 Launching the debugger simulator Hi Wave CodeWarrior works out the dependencies of the current target Simulator and if required rebuilds the code A small red check symbol in the leftmost column of the target browser window marks files that have been modified and need to be re compiled see Figure LMP2 7 Once the target has been brought up to date the simulator is started and the target code is loaded A breakpoint has been placed at the beginning of main and the controller specific start up code has been run Hi Wave allows you to simulate a variety of input and output units such as anal
6. FS SFFF2 SFFFS Unimplemented instruction trap XIRG SFFFO FFF1 SFFEE FFEF FFEG FFED SFFEB FFEO SFFE1 SFFDE SFFLF Figure LMP2 16 Real time interrupt Enhanced capture timer channel 0 Enhanced capture timer channel 1 Enhanced capture timer channel 2 Enhanced capture timer channel 3 Enhanced capture timer channel 4 Enhanced capture timer channel 5 Enhanced capture timer channel 6 Enhanced capture timer channel 7 Enhanced capture timer overflow MC9S12DP256B C interrupt vector table extract 13 Microcontroller Programming LMP2 Metrowerks CodeWarrior IDE Quit the simulator File Exit and return to the CodeWarrior environment Change the target from Simulator to Monitor The Monitor target has been configured for communication with the on chip monitor program Flash EEPROM area OxF800 OxFFFF of the Dragon12 development board Figure LMP2 17 This will allow you to perform source level debugging on the actual hardware La ua AAA Stepper Mot Driv D T BEA ms Figure LMP2 17 The Dragon12 development board The Dragon12 board features a large number of peripheral units such as an on board LCD display 7 segment displays LEDs switches a potentiometer a buzzer and an infrared IR transceiver unit The microcontroller sits in the centre of an array of connectors which give access to all of its pins A small circuit board has been designed to protect the controller from accidental o
7. LMP2 4 First 1024 bytes of the memory map Special function registers Launch the CodeWarrior IDE from the Windows Start menu entry Programs gt Metrowerks CodeWarrior CW 12 V3 0 CodeWarrior You should be presented with an empty screen From the File menu select New to create a new HCS72 Stationery project Enter a project name e g myHello and click on Set Location This allows you to save your project in a folder of your choice Figure LMP2 5 Microcontroller Programming LMP2 Metrowerks CodeWarrior IDE 18 x File Edit view Search Project Debug Processor Expert Window Help Bee Bovx haan G amp i HE i HC S 12 New Project Wizard HCS12 Stationery Location C Documents and Settings fwo Set a ERNO aa Create New Project _ 19 Flash Template G myRTI mySIG_through myScl_AD_DA mySIG_through2 Metrowerks_DP2568 G mySCIDataLoager mySIG_through3 mysiG_FIR127 myte G mySIG_IIR myTor myBlinky_orig ymySIG_IIR_web myToF_RAM ee Save as type Project Files mcp Cancel IV Create Folder P Dsn GESER ASEDIO sn Qepoam Fesviso Mme mer E metrowe HO MANBSABROO 12037m Figure LMP2 5 Creating a new project using an HCS12 Stationery A small requester appears allowing you to choose the type of stationery to be used Figure LMP2 6 Expand the list of supported boards and select Dragon12 fat New Project ES Select project stationery
8. Microcontroller Programming LMP2 Metrowerks CodeWarrior IDE Laboratory LMP2 Example based introduction Metrowerks CodeWarrior IDE Objectives To learn how to generate a small Metrowerks CodeWarrior project To debug an application using the simulator of CodeWarrior To debug an application using CodeWarrior s source level debugger Hi Wave Introduction The Motorola MC9S12DP256B C e www motorola com is a member of Motorola s HC12 series of 16 bit microcontrollers With its large number of peripheral units 5 independent CAN interfaces this controller is widely used for industrial automation automotive applications and consumer electronics Figure LMP2 1 gives an overview of all hardware units of the Motorola MC9S12DP256B C microcontroller a ii i rt ie us Nig ae ene PO ee ee on PS el bh all reer j roy rm rT ir a Cc oF a M E g RA i ioe dhil e uo L l A U S A L L uu ES NEC a SOTA NCC Figure LMP2 1 The MC9S12DP256B C microcontroller In addition to a substantial number of general purpose digital I O lines the controller features 8 pulse width modulation PWM channels two 8 channel A D converters 10 1 Microcontroller Programming LMP2 Metrowerks CodeWarrior IDE bit 2 asynchronous serial communication interfaces SCI 3 synchronous serial peripheral interfaces SPI an Inter IC
9. al structure of the MC9S12DP256B C Microcontroller Programming LMP2 Metrowerks CodeWarrior IDE Notice that some pins are used for multiple purposes For example the general purpose digital 1 0 port PAD shares its pins with the A D converter This is to say that there are two or more internal circuits connected to these pins The sample and hold amplifier of the A D converter unit is connected in parallel to the output driver s of port PAD configured as output as well as the corresponding input buffer amplifiers PAD configured as input This practice of sharing the limited number of pins between several hardware units is common to most microcontrollers It has to be taken into account when considering the suitability of a particular controller for a specific task A number of programming environments are available for the MC9S12DP256B C both commercial as well as free software GNU www gnu m68hc11 org In this exercise we will use Metrowerks CodeWarrior an Integrated Development Environment IDE which includes many useful features to assist us with the software development process A 12 kByte code size limited evaluation version can be obtained free of charge from www metrowerks com MW download default asp Creating a new project using a project stationery template In this section we are going to experiment with a small project which simply outputs a bit pattern on the LEDs connected to one of the digital I O ports of the micro
10. are in parallel with switch SW7 t WA Hg pa v g i P d A J ON i Yaa j aka 4 SHU WED i alii ll ha tata a NOD PRBR i Fe LS 06000000 2 w T m S ANE A AA RIRU IPI eselye te as act ba ox 1 i f rizie NOUS WHY ai e i n Se a gt 5 3 z a y i Aa af amp kd i pa _ g tale T Led les N dj g Motorola Dragonic MC9S12DP256 De leso Jan 2005 9 E FOr aaa 0 3Vv power aaa as oe Figure LMP2 21 The protective circuit board 16 Microcontroller Programming LMP2 Metrowerks CodeWarrior IDE Make sure the Dragon12 board is powered up and connected to the serial port of the host computer Switch SW 7 controls the operational mode of the board The red on board LED labelled EVB should be lit right hand side of the Dragon12 board This indicates that the board is in debugger mode Start the debugger by clicking on the green Debug button of the CodeWarrior IDE Several things should happen The Monitor target is brought up to date might involve compilation linking etc and the debugger is launched The non secure area of the Flash EEPROM is erased and the target application is downloaded Finally a breakpoint is defined at main and a software reset is triggered This causes the microcontroller on the Dragon12 board to fetch the reset vector OxFFFE OxFFFF and divert
11. code execution to the initialisation routine _ Startup Once the breakpoint is hit the debugger halts code execution and displays the current register set Single step through the program as you step over the second line of main the red on board LEDs on the Dragoni2 board should display the expected pattern 0x55 0101 0101 Reset the board by clicking onto the reset button of the debugger The LEDs switch off and the debugger returns at the beginning of _Startup Click on Start Continue green arrow Code execution resumes until the breakpoint is hit beginning of main Step through the program as before The LED pattern is displayed as expected Perform a hardware reset of the board by operating the on board RESET button SW6 Note that this has the same effect as resetting the board through the debugger This concludes our short introduction to CodeWarrior and the simulator debugger Hi Wave In the following sections we will write a few small programs which will teach us how to read analogue voltages send clear text messages to a terminal and set up interrupt driven timers Eventually all of these techniques will be combined to implement a complete digital control loop including A D conversion ADC on chip data processing and the interfacing to an external D A converter DAC A digital FIR filter will serve as test application Concluding remark The programming of microcontrollers requires frequent access to on line manua
12. controller To keep things simple we are going to develop our programs based on a predefined project template stationery CodeWarrior assists software designers by providing them with templates for projects stationery which define the most commonly used settings and compiler options For this set of laboratory exercises the stationery Dragon12_ small has been created This template defines an empty project with three targets Simulation Monitor and Release A target can be seen as a recipe of how to compile a number of source files for a particular target platform environment A project which is targeted at a simulator might be different from a project which runs on a development board such as the Dragon 12 and the final release version usually differs from the corresponding debug version For example the release version may be programmed into a secure area of Flash EEPROM to prevent unauthorised and or accidental modifications of the code The stationery Dragon12_ flat has been put together for laboratory exercises using the Wytec Dragon 12 development board It is configured to build applications with a flat memory model This implies a linear 16 bit address space ranging from O to OxFFFF Figure LMP2 3 shows the memory map of this memory model The free evaluation version of the CodeWarrior compiler can produce executable files with a maximum code size of up 12 kByte All our programs will therefore be compiled for the Flash EEPROM section f
13. e fully expanded project tree for target Simulator There are a number of target groups symbolised by a small folder icon containing a variety of files e g source files header files configuration files and special command files Start12 c is a module which runs before your main program most hardware dependent initialisations are carried out by a function called _Startup defined in Start12 c Group prm includes parameter files such as burner bbl describes the making of Flash programmable S Record files and the memory map definition file MC9S12DP256 FLAT prm The library group includes statically linked libraries as well as special function register definition files Finally the debugger groups configure the built in simulator and debugger Hi Wave Fortunately you can ignore most of these groups and files they have been included to make your life easier The only target group you will have to deal with is Sources This group contains the main program file main c a pre defined interrupt vector table isr_vectors c and two support files pll c and pll h Inspect the target column red bulls eye with black arrow cf Figure LMP2 7 This column specifies if a project file belongs to the chosen target currently Simulator Observe that the debugger configuration file Simulator ini is part of this target whereas the file Monitor ini is not Similarly the debugger command files sermon_ name cmd are not part of target Simulation no dot i
14. imulator Component Source Window Help DSa Baie r gt Be P ae amp C Documents and Settings fwornle My Documents frank Microcontroller 95 12D P256B_work main c 0x4065 255 0x03 set port B as output LEDs DDRB Orff ff Port B is output PORTB 0x55 switch on every other LED forever SE A E CPU Cycles 89 55FF 407D 4063 SP 13FD PC 4063 PPAGE 0 Startup PORT 55 DDR FF a uuuuuuu uuuuuuuu uuuuuu 0 uu 55 uu FF 08 uu uu uu uu uu uu uu 110 uu uu uu uu uu uu uu uu 000018 uu uu uu uu uu uu 8 uu uu uu uu uu uu uu uu 30 uu uu uu 05 00 uu 8 uu 80 D1 uu uu uu uu O uu uu uu uu uu uu uu uu 8 uu uu uu uu uu uu uu uu uu uu uu uu uu uu uu uu 000058 uu uu uu uu uu uu uu uu 0060 uu uu uu uu uu uu uu uu 1 3113 3999 193 uuuuuuuu u uu u u uuu uU uuuuuuuu uuuuuuuu uuuuuuuu uuuuuuuu uuuuuuuu 11111 main c Auto Symb Global H _DDRAB lt 2 gt volatile DDRABSTR fH PORTAB lt 2 gt volatile PORTABSTR Auto Symb Local 2 000000 MHz 89 HCS12 CORE STEPPED PS makeu Q C DPo Blackb R LM2_ EB Metro True 3 FAO Ete 24tNS oO 19m Reset the target Hsar F OSLO RMAGERIO Figure LMP2 15 Testing the state of digital 1 0 port B Vector Address SFFFG SFFFD Clock monitor fail reset COP failure reset SFFFS SFFFS FFF6 SFFFY SFFF4 SFF
15. inue to step through the program As you execute the next line PORTB 0x55 the state of every other LED changes from LOW to HIGH The IO LED visualisation tool uses the colour red to display a HIGH level of the corresponding pin Figure LMP2 15 Reset the target by clicking on the reset button small red circle with black arrow see Figure LMP2 15 This should take you through a simulated reset cycle The microcontroller fetches the address stored in the reset vector OxFFFE OxFFFF see Figure LMP2 16 for an extract of the interrupt vector table of the MC9S12DP256C and diverts code execution to wherever this vector points to Right hand mouse click into the memory window and select Address from the appearing pop up menu Set the address to OxFFFE The memory window should now display the reset vector which in our case points to address 04029 This is the beginning of the microcontroller initialisation routine _ Startup You could single step through this system sub routine until you reach main Alternatively you can simply 12 Microcontroller Programming LMP2 Metrowerks CodeWarrior IDE start code execution green arrow This will take you through to the beginning of main where our previously placed breakpoint is hit and code execution stops lt True Time Simulator amp Real Time Debugger C Documents and Settings fwornle My Documents frank Microcontroller 9S12DP256B _work myHello Simulatorini File View Run S
16. ls and or the register definition header files CodeWarrior assists the programmer in finding and opening header files containing macro definitions such as DDRB or PORTB A right hand mouse click onto such a macro makes appear a small pop up menu from which the entry Go to macro declaration of lt NAME gt can be selected This finds and opens the appropriate header file at the page of the macro declaration While not as informative as the on line manuals the header file can sometimes be used as quick reference to find out the purpose and structure of any of these macros Looking up the macro definition of PORTB for example tells us that this is the special function register B at address 0x0001 for all this is worth PORTB Port B Register 0x00000001 17
17. ments frank Microcontroller 95 12D P256B_work main c Line 7 main voimain void M l TSR 0x4065 LDAB 255 set system clock frequency to _BUSCLOCK MHz 24 or 4 STAB 0x03 J PLL_Init i STAA 0x01 set port B as outp BRA 0 abs 4063 DDRB Oxtt Port B is output PORTB 0x55 switch on every other LED HC12 CPU Cycles 74 D DIFF A pl B Fr Ix 407D IY 0 IP 405F pc 40sF ppace 0 13FD Startup x SSSSSeSe PORT 00 DDR FF 000000 uu 00 uu FF u Uu 00008 uu uu uu uu uu uu uu uuuuuuu 010 uu uu uu uu uu uu uu uu uuuuuuuu 000018 uu uu uu uu uu uu uuuuuu O28 uu uu uu uu uu uu uu uu uuuuuuuu main c Auto Symb 000030 uu uu uu 05 00 uu u uu u s m 000038 uu 80 D1 uu uu uu uu u uuu u DDRAB lt 2 gt volatile DDRABSTR RAE i 000040 uu uu uu uu uu uu uu uu uuuuuuuu _PORTAB lt 2 gt volatile PORTABSTR z 100048 uu uu uu uu uu uu uu uu uuuuuuuu 000050 uu uu uu uu uu uu uu uu uuuuuuuu 000058 uu uu uu uu uu uu uu uu uuuuuuuu 000060 uu uu uu uu uu uu uu uu uuuuuuuu 3317 1711 1111 111 I Auto Symb Local Postload command file correctly executed Breakpoint STARTED STEPPING OVER Execute one source instruction 2 000000 MHz 74 IHCS12 CORE STEPPED OVER 7 amp sar F OSES MMASE MIO aa Q ciwo Asad Mua rero hte B FAMA ANSO v7 Figure LMP2 14 Programming DDRB as output Cont
18. n the target column Change the target from Simulator to Monitor This can be done by selecting Monitor from the pull down menu in the target browser toolbar Figure LMP2 8 7 Microcontroller Programming LMP2 Metrowerks CodeWarrior IDE Metrowerks CodeWarrior File Edit View Search Project Debug Processor Expert Window Help Beene xR BBARMU CHEB BB smr Heyyy f Cli Y EE Sources AR maine ooococccccSo BS ooo a v O E Simulator ini EA Monitor ini Debugger Command Files a J a O w Ow E sermon_preload cmd E sermon_reset cmd ED sim_startup cmd ED sim_postload cmd ED sim_preload cmd AB sim_reset cmd iE sim_setcpu cmd BS oo BEB aa ka ba ka ha ha ka ha ha ha ha Ma ba aa ha ha ha Da Da Da Da Ya Ma Ma NNNNN AN aaaAAaAaAaAaAaAaAaAaAEE AI start e 8a AGZGERAO PS makeups E cpoam 5lackboar RI m2 metr BB Metrowe EN PAV HBSEANSSO 137m Figure LMP2 8 Changing targets Notice that the Monitor target includes a different subset of files e g the monitor command files sermon_ name cmd instead of sim_ name cmd Change the target to Release The release target produces a Motorola S Record file which can be downloaded burnt to the microcontrollers Flash EEPROM Release includes the burner configuration file burner bb This is a format specification of the downloadable S
19. n12 with the protective circuit board rrrrrrrr 7 gt e f v 2 gt SOO OO wt et View ZANA op Aa y GEETEY EY BEJA m E j ay th OTe eee Rete TE e jele ie gt A PD DDI D DA DE TS is SE Ties aa da oo le ele a OOO ANI IAE U gN wu A gt 4 gt gt LI amp Y we T Y gt oa ese g Nr gt i amp gt ee s t Ga reret hg Ww AJIO F e T o p y Y 0 a ni 7 Ba E b efs Sla YA Be gt s HELU AA WAA Figure LMP2 20 The Dragon 12 with fitted protective circuit board 15 Microcontroller Programming LMP2 Metrowerks CodeWarrior IDE Figure LMP2 21 is a close up of the protective circuit board The connectors on the far left are the digital inputs of port P T and H respectively The connectors on the left hand side of the two potentiometers give access to the corresponding digital outputs The ADC input channels can be found on the far right of the board whereas the two DAC output channels are located near the top Note that the channels of the A D converters have been labelled ADO2 to AD15 This might not have been the most fortunate choice as this is not consistent with the Freescale manuals Pins ANO2 ANO7 correspond to channels 2 7 of ADC unit O ATDO Pins ANO amp AN15 correspond to channels 0 7 of ADC unit 1 ATD1 Note that channel O and 1 of ATDO have not been connected as they
20. og input voltage stimuli output LED arrays LCD displays virtual keyboards etc From the Component menu open the IO LED array Figure LMP2 10 This 8 fold array of LEDs can be hooked up to any output port of the microcontroller thereby simplifying the testing of simple digital output drivers Figure LMP2 11 Microcontroller Programming LMP2 Metrowerks CodeWarrior IDE Open Window Component List Details Assembly Command Commaster ty 1 Data Fort Ag T OF lo ports True Time Simulator amp Real Time Debugger C Documents and Settings fwornle My Documents frank Microcontroller 9S12DP256B _work myHello Simulator im File View Run Simulator Component Led Window Help Daj ee 2 azel voimain vcid M set system clock frequency to _BUSCLOCK MHz 24 or 4 PLL Init set port B as output LEDs DDRB Oxff Port B is output PORTB 0x55 switch on every other LED o 13FD CCR SXHINZVC ain Startup PN IO Led BOOQOOOo Auo PORT 00 DDR 00 00000 uu 00 wu 00 u u 4 uu uu UU uu uu uu uu uuuuuuu 0 uu uu uu uu uu uu uu uu uuuuuuuu 00018 uu uu uu uu uu uu uuuuuu pa p QO ee eer ee Data 1 O x lol xi WA AA ci main c Auto Symb Global 000030 uu uu uu uu uu uu u uuuu u DDRAB lt 2 gt volatile DDRABSTR ee A eee Cee _PORTAB lt 2 gt volatile PORTABSTR SAA oe eee ee ee eee uu uu uu
21. rom Ox4000 to Ox 7FFF Variables can be allocated statically or dynamically within the 12 kByte of on chip RAM 0x1000 to Ox3FFF The 4 kByte EEPROM 0x0000 to OxOFFF will not be used Microcontroller Programming LMP2 Metrowerks CodeWarrior IDE 0x0000 0x1000 RAM 12 kByte lt Program variables will be allocated here 0x4000 Program code will be stored here 0x8000 OxC000 OxF 800 OxFFFF Figure LMP2 3 Memory map of the flat memory model Notice that the special function registers Figure LMP2 4 are mapped into an area overlapping with the EEPROM The lowest 1024 bytes of the 4k EEPROM will be masked by these registers and cannot be used unless special steps are being taken the starting address of the EEPROM can be redefined Also notice that a small monitor program resides in the upper 2k of the available memory space This program will allow us to communicate with the target through the serial communication interface SCIO during the debugging phase The monitor program is in a secure area of the chip it can therefore not be erased by accident Microcontroller Programming LMP2 Metrowerks CodeWarrior IDE Address Module Ports A E E i ice TD register PARTID S0029 0027 16 bit 8 channels ADA 008 ATU 10 0it 8 channels LATO PMI 8 bit 8 channels ASH control raqister A control register reserves AIL 10 bit 8 channels ATL 7 7 7 7 EEEL a reservar Figure
22. uu uu uu uu uu uuuuuuuu 0 uu uu uu uu uu uu uu uu uuuuuuuu uu uu uu uu uu uu uu uu uuuuuuuu 0 uu uu uu uu uu uu uu uu uuuuuuuu Boas AaAaAeA oix main Auto Symb Local RUNNING done cmd sim_postload cmd Postload command file correctly executed Breakpoint For Help press F1 00000 maz a2 Heroe Breakpoint S Wa G S RBR ASEDIO Kymerer Q cipo ado Mm vero tue N FATMA ANSO 147m Figure LMP2 11 The Hi Wave debugger simulator LED array Right hand mouse click inside the LED window to get a small pop up menu Select Setup to open another pop up menu which will allow you to attach the LEDs to a particular I O port of the microcontroller Figure LMP2 12 10 Microcontroller Programming LMP2 Metrowerks CodeWarrior IDE x Configure Addresses POAT fi tits DDR pooo Set Target Target Targeo bject h Figure LMP2 12 Configuring the LED output module Port B of the MC9S12DP256B C is memory mapped at address Ox0001 with the associated data direction register DDR at 0x0003 see the extract of the user manual chapter 1 6 Figure LMP2 13 Connect the LED array to port Ox0001 and set DDR to 0x0003 0000 000F MEBI map 1 of 3 Core User Guide Address Name Bit 5 Bit 2 Bit 1 Read 0000 PORTA Bit ar Read 0001 Bit 7 ORE write EAEE Read 0002 Bit 7 s DONA write ELA Read 0003 Bit 7 eee wite 0004 Reserved Al D oy 2 Write Al D oy
23. ver voltages and short circuits Digital inputs can be protected using a series resistor and a 5 1 V Zener diode Figure LMP2 18 Such a circuit can be used to shield a microcontroller from excessive positive and or negative input voltages I P Figure LMP2 18 Protecting digital inputs Digital outputs can be protected against accidental shorts or too large loads using small operational amplifiers which act as buffer between the output connector and the 14 Microcontroller Programming LMP2 Metrowerks CodeWarrior IDE microcontroller As before accidentally applied voltages can be limited using a Zener diode and a small series resistance 100 Q The voltage drop across this series resistance is usually very small On the protective board used in the laboratory every output is connected to a small surface mount LED This will make it easier to test and debug programs Figure LMP2 19 Figure LMP2 19 Protecting digital outputs against accidental shorts The protective circuit board also gives access to most of the channels of both A D converter units of the microcontroller all but ADO and AD1 A pair of 10 kQ potentiometers has been connected between the supply rail and ground the centre pin of these potentiometers can therefore be adjusted to any voltage between 0 and 5 V In addition the board carries two serially loaded D A converters DAC which can be used to generate analogue output voltages Figure LMP2 20 shows the Drago

Download Pdf Manuals

image

Related Search

Related Contents

地震探査システム用観測車取扱説明書  La sicurezza antincendio negli alberghi italiani  Virtual Machine Mobility Planning Guide  Alecto DC-12USB  TDSHーBA 東芝電球シャ ンデリア取扱説明書  Excellence 60 - Dru site for the trade  INSTALLATION AND SERVICE MANUAL    User Manual - Sicher Systems & Technology Pte Ltd    

Copyright © All rights reserved.
Failed to retrieve file