Home
EDK3664F Tutorial Manual (US3664EDK1)
Contents
1. vector section DINTTBL as in previous tutorials A Address Add Address l l H D0000000 CECT The interrupt vector table must be located at this address to ensure Mod startup code is executed first on reset The startup code in file A Pr pr resetprg c does not change but the power on reset vector points to A PowerOn_Reset rather than the HDI m initialisation function Bene startup t C OSEC Up Down The vector table definition in vecttblt c does not contain any of the HDI m interrupts described in Section 2 3 3 instead these peripherals are available to the user Generate external symbol file Note also that in the menu item Options Linker Input there is NO inclusion of the HDI m library file F Use external subcommand file OF Cancel 2 4 2 LOW LEVEL INITIALISATION As we saw in the previous tutorials low level initialisation occurs before the user s code Is called in order to set up the bus protocol and essential peripherals Since we are running stand alone we cannot rely on HDI to initialise the EDK environment for us Therefore we must do it ourselves in Hardware_setup which is shown in the source below from Loner c void HardwareSetup void set_imask_ccr 0 Enable interrupts to CPU MSTCR1 BIT MSTIW 0 Enable TimerW module TMRW TMR BIT CTS 0 Timer off TMRW TIER BYTE amp 0x00 dissable all interrupts TMRW TSR BYTE amp
2. Create a new session on OK HS 300H Monitor 7 Exit Previous session file cn EW 3664 Tutonal4 3664 Tutornal Debug 3664 Browse 10 Jan 01 Issue 1 0 EDK3664F Tutorial Manual You should see the window below appear BS Hitachi Debugging interface H8S 2600 Monitor OF E File Edit View Run Memory Setup Window Help sara san Barr Mons wee APA fal gt ee ecsck ERREAL Linku O __ Note The status bar shows the message Link up to indicate successful connection to the HDI M monitor on the EDK If the EDK does not link up ensure the Baud rate is set to 19200 and that the correct PC serial port is selected 1 1 4 RUNNING TUTORIAL A The executable code for Tutorial A is provided in file C 3664 TutorialA debug 3664 TutorialA abs e To download the code to the EDK select the File Load Program menu option in HDI or click on the Load Program button in the Toolbar Menu Command Accelerator Toolbar Button File Load Program none E e Once the file has been specified click on the OK button to perform the download Downloading should appear in the HDI status bar If errors occur in downloading these will be displayed on the status bar too If errors occur this is an indication that the code programmed onto the chip is not the same as the code being downloaded onto HDI On completion of the download a status window should appear similar to the one below
3. Once this screen has been configured the EDK3664 must be placed in BOOT mode before a connection is made The EDK3664 is placed in BOOT mode using the switches S1 and S2 e Connect the supplied serial cable to your PC and the UART RS 232 port on the EDK and apply 5V to the EDK s power terminals The green power LED D5 should light indicating power is being supplied to the board Issue 1 0 Jan 01 9 EDK3664F Tutorial Manual e Press the ARM switch 2 The yellow ARMED LED D4 will light indicating the EDK can be placed in BOOT mode BOOT ARMED s2 P e Press the RESET BOOT switch S1 The red BOOT LED D3 will light indicating the EDK is now in BOOT mode If S1 is pressed again while the yellow ARMED LED is lit the EDK can be taken in and out of BOOT mode and the red BOOT LED D3 will turn st POWER on and off to indicate this RESET Once both the yellow ARMED LED D4 and the red BOOT LED D3 are lit FDT can connect BOOT to the EDK and program it with the desired s record e Press the Connect button in the FLASH Controller Window of FDT FDT will connect to the EDK and the FDT output window will indicate this e Once connected the Download file project_name mot to device button will be available Press this button and FDT will download the s record to the device and the FDT output window will indicate this Once downloading of the s record is complete the EDK can b
4. The final example simply takes the code from Tutorial E and makes it run on the EDK without HDI M The aim of this example is to show that an application can be created using these tools which will be capable of running stand alone The majority of the work has already been done the startup code was created in Tutorial C the peripheral register address header file was used in Tutorials B amp D and the interrupt vector table was explained in Tutorial E This example uses similar source files that were used in Tutorial E The main difference is that since HDI m will not be resident a real power on reset vector must be created and not one that calls HDI m initialisation function st art up Tutorial F is a version of Tutorial E Interrupt that will run from Flash without HDI m Also since HDI is no longer using the UART serial interface this is now available to our application we will use it to write a sign on banner and echo back characters from an external terminal in this case Hyperterminal 2 4 1 CREATION OF A VECTOR TABLE IN C WITHOUT HDI M e Generate a new tutorial project as done in previous tutorials but this time select 6 Loner Tutorial and call it 3664 TutorialF e f you now look at the linker section map in HEW menu item eame ee Options Linker Section you can see that the reset vector section DVECTTBL is placed at H 0 followed by the interrupt Input Output Optimize Section Verity Other
5. void INT_TRAP2 void void INT_TRAP3 void void UBCinte void Monitor address break interrupt void INT_SDT void void INT_IRQO void void INT _IRO1 void void INT_IRQ2 void void INT_IRQ3 void void INT _WKP5 void void INT_TMAOVF voi dummy void INT_TMW void void INT_TMV void sota SCiintg vota 51 Monitor serial port interrupt i JA i 5 5 7 5 Lo d an Used in tutorial E main function void INT_I2C void void INT_ADEND void 32 J an 01 Issue 1 0 EDK3664F Tutorial Manual 2 3 4 UNDERSTANDING THE INTERRUPTS TUTORIAL The file Interrupt c contains the source for the tutorial include lt machine h gt So that we can use language extensions for embedded systems include iodefine h Define constants for peripheral register vaules define TCR_CCLR Set TCNT cleared by TGRA match define TCR_CKEG Default clock edge define TCR_TPSC Clock source internal 256 define TCR_TOB Set pin ouput modes TIOB Function Prototypes void main void void HardwareSetup void pragma interrupt INT_TMW void main void unsigned short duty TMRW GRB duty 0x7fff Set duty of LED 50 by TGRB TMRW TMR BIT CTS 1 Start Channel 1 while 1 Loop forever void HardwareSetup void set_imask_ccr 0 Enable interrupts to CPU MSTCR1 BI
6. HDI Ed Module name CAHEW3664_Tutorial 43664_Tutorial Debug 3664_Tutorial abs Areas loaded 00000190 00001 990 000001 00 0000018F 00000000 00000049 00000044 OOO000CS 0000199 0000 SES This information shows that HDI m has loaded the file and summarises the memory regions used by the program Issue 1 0 Jan 01 11 EDK3664F Tutorial Manual To start executing the program you must set the Program Counter PC register to the address of the beginning of the main function e HDI provides a simple method to see and edit the CPU registers first open the Register window using one of the command entry options listed below Menu Command Accelerator Toolbar Button View Register Window Ctrl R The register window will appear Registers Sl Oy x Register Value OOOO0Z8O O0000z66 oooga OOOOO000 podoooo0 O0000000 OOC0FED DODOFEDO e Use the mouse to position the cursor over the PC register value field and double click on it A register edit window will appear which should be set as below Register PC Value Set As Whole Register ance The PC will now be set to the main function so you can perform a program step 12 Jan 01 Issue 1 0 EDK3664F Tutorial Manual e To verify this open a source code window and choose C 3664 TutorialA On_Off c from the file selection dialog Menu Command Accelerator Toolbar Button I View Program Window Ctrl K inti A
7. Timer off IT CCLR TCR_CCLR TCNT clear on GRA match TMRW TCR B TMRW TCR BIT CKS TER CKS Clock phi 8 TMRW TMR BIT PWMB TMR_PWMB PWM mode for channel B TMRW TCR BIT TOB TCR TOB initial output is 7 TMRW GRA Oxffff Set cycle period by GRA The function HardwareSetup sets up the control registers in the timer module In order for it to be called we must ensure the function is called at the start of resetprg c resetprg c then calls main in which the duty cycle register is set up and the timer started The program then goes into a loop setting the duty cycle this is so that we can easily modify the value 2 2 4 RUNNING TIMER Build the code generated from the project generator Now disconnect HDI from the EDK and Flash it with the file C 3664 TutorialD debug 3664 TutorialD mot as described in Tutorial A Disconnect FDT from the EDK and restart HDI and load C 3664 TutorialD debug 3664 TutorialD abs Open a code window with Timer c and set a breakpoint at the start of main Reset Go and the program should stop at the breakpoint Menu Command Accelerator Toolbar Button Run Reset Go Shift F5 e Step over the instruction to set the duty cycle e Step over the instruction to start the timer you should see the LED D2 start flashing with a duty cycle of 50 e Remove the breakpoint on main e Seta breakpoint in the while loop where the duty duty cycle is changed a
8. stacksct h _INITSCT vecth pe HardwareSetup Remove the comment when Proj you use Hardware Setup main while 1 sleep Cateh return from main Issue 1 0 Jan 01 21 EDK3664F Tutorial Manual The operations to be performed by the startup code are e Unmask all interrupts set_imask_ccr 0 IS library function used to clear the interrupt mask bit of the system control register CCR e Setthe stack pointer to a valid address The initialisation process can be viewed in the function PowerON_Reset In the project file resetprg c This function is declared as the entry point of the system using the entry pragma this tells the compiler to insert assembly code at the beginning of the function to set up the stack pointer using the section name S and the stack size stored in stacksck h For more details on setting the stack see the Hitachi H8S H8 300 Series C C Compiler User s Manual ADE 702 189 pragma entry PowerON_Reset e Setthe static variables with initial values to the correct values e Reset all other static variables to 0 According to the ANSI C language specification all uninitialised static data must be cleared to zero at startup Any global variable that has not been given initial value when it is declared can be classed as an uninitialised data variable and should be initialised to zero Similarly initialised static variables that have been given initial values when declared must be
9. 0x00 Clear any pending interrupts TMRW TCR BIT CCLR TCR CCLR TCNT clear on GRA match TMRW TCR BIT CKS TCR_CKS Clock phi 8 TMRW TMR BIT PWMB TMR_PWMB PWM mode for channel B TMRW TCR BIT TOB TCR_TOB initial output is 0 7 TMRW GRA Oxffff Set cycle period 1s by GRA TMRW TIER BIT OVIE 05 Disable the OVERFLOW interrupt TMRW TIER BIT IMIEB 1 Enable the GRB Match interrupt Serial Port 3 Setup IO PMR1 BIT TXD 1 Enable SC13 TX out InitSCI3 SCI_Init_Data initialise serial port Most of this file is identical to Tutorial E except for the initialisation of the serial port SCI3 This function is described in Section 2 4 4 Issue 1 0 J an 01 35 EDK3664F Tutorial Manual 2 4 3 THE MAIN FUNCTION The main function in is displayed below include lt machine h gt So that we can use language extensions for embedded systems include iodefine h include SCI3 h Define constants for peripheral register values define TCR_CCLR 1 Set TCNT cleared by TGRA match define TCR_CKS 3 Clock source internal 8 define TMR PWMB 1 PWM mode in channel B define TCR_TOB 0 output 0 on TIOB at start J SCI Tnitialisation data structure struct SCI_Init_Params SCI_Init_Data 1B9600 P_NONE 1 8 Function Prototypes void main void void HardwareSetup void pragma interrupt INT_TMW void main void volatil
10. The control and status registers of the peripheral modules are memory mapped each one having a unique address at the top of the address space Registers vary in type from byte wide to long word wide and from read write to read or write only To allow simple access to the registers the flexible casting feature of C may be used As we saw in Tutorials A and B a symbol can be defined which corresponds to the access inside the address of the given register This requires the address which is a constant integer value to be treated as an address reference i e a pointer and then pointer indirection to be used to access the contents of the address To further complicate matters the entire construct must be declared as volatile to stop the C compiler from optimising away accesses to the register This is because the registers may be modified by some operation other than one performed by the CPU and thus the compiler can have no visibility of this Optimising compilers often remove accesses to what appears to be redundant information this must be stopped in the case of peripheral control and status registers hence the use of the volatile keyword 26 Jan 01 Issue 1 0 EDK3664F Tutorial Manual If you remember in Tutorial A we defined the i o registers as below define IO volatile struct st_io OxFFDO IO Address and in Tutorial B we learned that to simplify the construction of user code the header file iodefine h has been cre
11. The information on how to Initialise the static areas must be stored in non volatile memory i e ROM so that the startup code knows what to do However the most desirable situation is one where the user can happily forget about the startup because initialisation information is automatically created and referenced using the compiler build tools This is the goal of tutorial C to demonstrate that this code has indeed worked A small example file statics c is created and then run under HDI M to verify the result e Create a new workspace as we did in Tutorial B but this time call the project 3664 TutorialC and select 3 Statics tutorial as the project to generate in the Project generator wizard 2 1 2 STARTUP CODE DETAIL e Setup the reset vector The vector table including the reset vector is defined in the file vecttbl src and its associated include file vect inc As HDI m Is being used the reset vector must pointto startup which is the HDI m startup function This is covered in Tutorial E interrupt tutorial Here is a list of the startup code for resetprg c ns include lt machine h gt J 3664 TutorialC W W include stacksct h E a i pragma entry PowerON_Reset po a i nnn I prg c extern void main void uu resetprg c extern void _INITSCT void sbrk c a E statics c pragma section ResetPRG bbe vectthl c E a Dependencies Er i i a iodefine h voi owerON_ Reset voi pu brk h 2 set_imask_ccr 0
12. The status bar indicates the cause of the break i e that we have reached the breakpoint Break Breakpoint The highlight bar shows the position in the code corresponding to the value of the program counter PC register and indicates what will be the next instruction to be executed if we Go or Step WARNING For EDK3664 the Breakpoints are controlled though the Address Break Controller The line of code where the breakpoint is placed is EXECUTED and the program stops on the next assembly line following the breakpoint e Opena disassembly window by using the local menu item GO Disassembly You will notice that the line where the breakpoint has been placed has been executed and the PC and highlighted line is on the next line of code in this case at address 0x118 rather than 0x114 Al Hitachi Debugging interface 3664_TutorialB H8 300H Monitor File Edit View Run Memory Setup Window Help flasher c Al E Address BP Labe Source n 00000100 unsigned short 11 0 00000102 IO PCR5 BYTE 0x80 Set PORT 5 BIT 7 for output all othe Q000011e hd le 1 00000106 00000108 i 17 30000 0000010e PDR5 BIT B7 0 turn on LED f 0000011a PDRS BIT B7 1 turn off LED Address e Labe 00000110 7 ROH 00000112 40F2 H 0106 8 00000114 7928EA60 H EA60 E0 else if 11 6000 7FD8 7070 BSET H FFFFDS IO PDR5 BIT B7 BRA H 0106 8 whi 40E6 e 1 5E00019A _sbrk JSR sp_regsv 3 char sbrk unsig
13. This hardware contains devices that are sensitive to electrostatic discharge Ensure appropriate precautions are observed during handling and accessing connections Failure to do so could result in damage to the equipment 3 Electromagnetic Compatibility Itis advised that suitable EMC precautions be observed Cautions 1 This document may be wholly or partially subject to change without notice 2 All rights reserved No one is permitted to reproduce or duplicate in any form a part or this entire document without Hitachi Micro Systems Europe Limited s written permission Trademarks 1 General All brand or product names used in this manual are trademarks or registered trademarks of their respective companies or organisations 2 Specific Microsoft MS and MS DOS are registered trademarks and Windows and Windows NT are trademarks of Microsoft Corporation IBM is a registered trademark of International Business Machines Corporation ProComm Is a registered trademark of Datastorm Technologies Document Information ProductCode D002770_11 Version 1 0 January 2001 Copyright O Hitachi Micro Systems Europe Ltd 2001 All rights reserved 2 Jan 01 Issue 1 0 EDK3664F Tutorial Manual CONTENTS CONTENTS nata iS 3 Le EDK USAGE TUTORIALS aaa 5 A A E 6 1 1 1 SOU CI st RI E A RIONI 7 1 1 2 Programming the flash on 3664 Using FDT iii 9 1 1 3 Connecting Hitachi Debugging Interface Monitor ii 10 1
14. 1 4 RUNN TUTO occhioni 11 1 2 TUTORES LAS HE asada 14 Lz VIA SIA 14 12 2 DELE TT E lle 14 1 2 3 Building the FEASHER Phro el cricca 15 1 2 4 Flashing Tutorial B onto the EDK ii 15 12 5 petine and VIEWING break poins A A A A A E a la 16 1 2 6 Running the program and halting execution iii 17 1 27 VIEW LINC GV IGLOS inalienabile 18 1 2 8 Usine HDI M to modify a variable il 19 2 EMBEDDED CODE TUTORIALS coccion coins 20 2 TOTORA C STATIC PRE E PE O TEA EA A 21 S Need JOR ING Sarap dellla 21 2 12 UREA AAA A A A 21 2 13 VIEWS IMEI TOS everett Coit Oa seats o eae attest 23 2 1 4 AAA o AE 24 215 Memory map for EDK3664F With HDI M rreren onin en EON EEEE 25 20 POTORMGDE TIMER aaa 26 2 2 1 Setting the LED D2 to the correct port ri 26 ADA Accessing the control and Status registers iii 26 229 TONE TIME PrO OM A A iaia 27 224 III PIRRO RESI COTTE TINA ARA 28 DA VOOR RIE OR AI REA PISA 29 2 3 TUTOR AEE INTERR OP aia 31 2 3 1 Interrupts on the HS 00HTINY 3004F oS id ase Bech Renan RS 31 2 3 2 Crearon OF GN TSR IICA SA AA 31 23 39 epiche 32 2 3 4 Understanding the Interrupts Tutorial iii 33 2 500 Viewing and Running the application iii 34 2 3 6 VAPO ONS aa 34 ZA TUG RIAL FONE Serom incinn aoaaa e OE 35 2 4 1 Creation of a vector table in C without HDI M iii 35 2 4 2 Lowlevel Imas T Oia tics 35 2 4 3 ThE MAN lait 36 2 4 4 hesiak VO TNE ONS
15. 3 5 VIEWING AND RUNNING THE APPLICATION e Select the project 3664 TutorialE and execute a build to create the debug absolute load file and an S record to download to flash using FDT e Now disconnect HDI from the EDK and Flash it with the file C 3664 TutorialE debug 3664 TutorialE mot as described in Tutorial A Disconnect FDT from the EDK and restart HDI and load C 3664 Tutoriale debug 3664 TutorialE abs e Open a code window with the file interrupt c and set a breakpoint at the following line in the ISR INT_TMW TMRW GRB 0x400 Decrement duty value by 1000 e Open an I O register window It is H83664 io located in the HDI directory Install it using menu item Setup Configure Platform Menu Command Accelerator__________BToolbar Button View l OArea Ctri l It This window lists all of the on chip peripheral modules you can expand the module name to show its registers by double clicking on the module name Expand the W_16 Bit Free Running Timer module You can see the duty cycle value in the GRB register 170 Registers HME ES e Reset Go and the program should stop at the 116 Bit Free Running Timer n breakpoint OOOOFFSO H 48 DOOOFFS1 HTOO You should see the GRB updated with the initial duty GOUNE RNA HTU value H 7fff and the LED start flashing with a duty cycle ment ans 500 0000FF94 H 0O 0 DODOFFES HES DOOOFFS6 H FF e Run to the breakpoint again DOOOFFES H FFFF DODOFFEA H FFFF DODOFFEC H FFFF O0O0U0FF
16. Files window will open showing the code above i E dbsct c pine 3 intpra c on_olf c File Component Details El resetpra c The include iodefine h include at the start of the file sets up a data CR pe structure that allows us to access the data direction register of the port and also individual E a ni bits of a byte of data in this case the data register of the port See H8 300H TINY 3664F iodefine h Series Hardware Manual for details on how the data direction register is used to set El sbrk h individual bits of ports for input or output ara The def i ne statement in iodefine h assigns the data structure to an absolute address in Proj the H8 3664 memory space by using a pointer declaration define IO volatile struct st lo OxFFDO TO Address Setting the structure to start at this address allows the structure elements to map onto the corresponding Port 5 peripheral control registers in the device s address space By taking the time to set up this structure the actual code in the main function can be created very simply First we set bit 7 in the data direction register which controls whether a particular bit of the port is for input or output to one to set the corresponding bit in the port as an output By default all data direction bits are set to zero making all the port bits inputs IO PCR5 BYTE 0x80 Set PORT 5 BIT 7 for output all others inputs The bit 7 pin of the port Itself
17. Find in Files A Version Control You will see a warning from the linker 1210 CANNOT FIND SECTION C this is not a major problem in this case Section C is used to store constant data and an entry has been put in the linker section options list for this section The linker is complaining that it cannot find any data for that section because as this code has no Constants no constant data Is generated This will be explained further in Tutorial C Section 2 1 3 1 2 4 FLASHING TUTORIAL B ONTO THE EDK The HDI monitor library has been built with the user code for this project into an s record which has the same name as the project The s record is 3664_TutorialB debug 3664_TutorialB mot Until this file is flashed onto the microcontroller no debug can be performed with HDI Ensure that no programs are using the serial port i e the last session of HDI must be closed and flash the 3664_TutorialB mot file onto the EDK using the same method described in Tutorial A Section 1 1 2 Once programmed ensure that FDT is disconnected from the EDK and proceed to the next section on debugging the code Issue 1 0 Jan 01 15 EDK3664F Tutorial Manual 1 2 5 SETTING AND VIEWING BREAKPOINTS Now launch the debugger again and this time load the file that we have just built C 3664 TutorialB debug 3664 TutorialB abs the same way as you did in Tutorial A Open the program window as before this time with the file C 3664 TutorialB Flasher c e T
18. and thus the LED D1 can then be controlled just by setting the individual value of bit 7 in the port s data register to a 1 LED off or a zero LED on We can do this very simply using the structure expression IO PDR5 BIT B7 IO PDR5 BIT B7 O turn on LED Le turn GLE LED 7 These two statements are contained inside a while 1 loop and so will alternate between setting the LED D1 on and off forever until we stop the program Next we will try running the program e Click the Build project icon or press lt F7 gt This will build the first tutorial and create an s record for downloading onto the 3664 Flash 8 J an 01 Issue 1 0 EDK3664F Tutorial Manual 1 1 2 PROGRAMMING THE FLASH ON 3664 USING FDT Because the EDK3664 has limited RAM and is a single chip microcontroller the HDI monitor code is built with the user s code To debug the user code both user code and the monitor code must be programmed into flash whenever the user code is built The HDI monitor library has been built and linked with the user code for this project into an s record which has the same name as the project The s record is 3664_TutorialA debug 3664_TutorialA mot Until this file is flashed onto the microcontroller no debug can be performed with HDI To flash the EDK3664 first ensure that FDT and the 3664 Flash Kernels Patch have been installed from the EDK3664 CD see user manual for installation instructions Run FDT using the start men
19. normal mode with on chip ROM Flash enabled The processor can access 64Kbytes of memory space see H8 300HTINY 3664F Hardware Manual CPU Section HDI M sets up system registers in order to communicate with the user code these peripheral registers should not be changed once HDI M is running The Peripherals used by HDI M are 1 SCI3 for serial communications 2 Address Break controller for stepping and breakpoint control 3 NMI control for Flash Programming EDK H8 3664F TINY Memory Map with HDI m H 0000 Vector area H 0034 HDI Monitor code Relocatable 6Kbytes H 17F6 Free FLASH For User Code 26Kbytes H 7FFF Unpopulated H F780 Flash work Area And User RAM 1Kbytes H FB80 Internal RAM For User code 778Bytes H FE8A Internal RAM For Monitor Work Area Relocatable 245Bytes H FF 80 Internal Registers H F FFF Issue 1 0 Jan 01 25 EDK3664F Tutorial Manual 2 2 TUTORIAL D TIMER 2 2 1 SETTING THE LED D2 TO THE CORRECT PORT The EDK is equipped with a TWO RED LEDs that may be controlled by a program LED D1 is connected to the 3664F port 5 bit 7 pin 30 on X3 underside of board X4 topside of board LED D2 can be connected to port 5 bit 6 Board pin 31 on X3 X4 or port 8 bit 2 pin 19 on X3 X4 by setting jumper J 10 Below is a description of jumper LED and pin positions A table of LED to port bit and board pin is also below For a more detailed description of the pin out of the EDK refer
20. user startup code this CANNOT be changed 40 J an 01 Issue 1 0 EDK3664F Tutorial Manual 3 2 2 INCLUDED FILES AND COMPILER SETUP This Project contains many of the same files seen previously The main difference is the vecttbl c and vect h files The reset vector tables now contain a conditional preprocessor command shown below xi pragma section VECTTBL EEE void RESET Vectors 0 Power On Reset aniihi ifdef DEBUG Monitor Reset capture El Igy StandAlone else a C source file void PowerON_Reset User standalone Reset Sn B dbect c pasa cn Intpra c i z S main c If the symbol DEBUG is defined then the HDI m Library initialisation function p Pa startup is the reset function otherwise PowerON_Reset is the ale funci an B wecttbl c reset Tuncton Sie Dependencies iodefine h For the interrupt vector table the same method is employed to include the HDI m E sbrk h interrupt vectors E stackscth E veck h ifdef DEBUG I void NMIcapture Monitor NMI capture rrrrr else void INT NMI User NMI for standalone build configuration endif 1fdef DEBUG void UBCint Monitor address break interrupt else void INT_UBC User address break interrupt for standalone configuration endif ifdef DEBUG void SCIint Serial port interrupt else void ENT SCE User Serial port interrupt for standalone confi
21. window appears showing the C source code with the first line corresponding to the PC value highlighted Al Hitachi Debuaana interface 3664_TutorialA H8 300H Monitor File Edit View Run Memory Setup Window Help ETE oeny P RRB FADO EE as 3664_TutorialA c pal x E Registers OME x Register Value 00000280 00000266 00000148 IO PCR5 BYTE 0x80 00000000 00000000 0000014 while 1 00000000 00000000 0000014 IO PDR5 BIT B OOOOFBDO 00000152 IO PDR5 BIT B OOOOFBDO 000144 00000158 D N gt 5 For Help press F1 m li e To make the screen layout more readable you might like to dock the register window To do this click on the dock button in the window s title bar The window will automatically dock to the right hand side of the HDI main window To dock to another side just drag the window by its title bar a dotted outline will appear which will snap to the sides of the main window When it snaps where you want the window release the mouse button and the window will dock To undock a window just click the dock button again e To execute the first line of the program select the Step Over command using one of the methods listed below Menu Command Accelerator Toolbar Button Run Step Over F7 1P e Repeat the step over process for the next line and you will see the LED D1 on the board turn on Step again and the LED D1 turns off Stepping repeatedly will cycle around the while
22. 0 B SAB S8B ABS16B R SABS8R ABS16R S OFB80 o c hew 3664_TutorialF 3664_TutorialF Release 3664 TutorialF abs c hew 3664_TutorialF 3664_TutorialF Release dbsct obj hew 3664_TutorialF 3664_TutorialF Release sbrk obj hew 3664_ TutorialF 3664_ TutorialF Release vecttbl obj hew 3664_TutorialF 3664_ TutorialF Release resetprg obj hew 3664_ TutorialF 3664_ TutorialF Release Loner obj hew 3664_TutorialF 3664_ TutorialF Release intprg obj i c hew 3664_TutorialF 3664_TutorialF Release SCI3 0bj lib c hew tools hitachi h8 3_0a_0 lib c38hn lib lib c hew tools hitachi h8 3_0a_0 lib ec2hn lib H H H H H H 000000 EXI Another difference in linking compared with Tutorial E concerns the H85 H8 300 OptLinker options Release output format of the absolute load module Input Output Optimize Section Verify Other Since we wish to program the absolute file into the Flash memory mn rather than debugging it with HDI m we want an S Record format Type of load module Absolute El output file rather than a SYSROF debug file the build process Debug infomation Nore El includes a final build phase that creates a mot s record file from the ROM to RAM mapped sections abs file Also debug information is of no use to us by default the rr output format for the Release build configuration is to not include D A e debug information in the output file Remove e You can inspect these opti
23. 6 whileill Name Value loc 00000048 sleepi 0000004 count A o0000 string hello world Now both count and string have been initialised but the local loc has not its value is in fact blank This is because local variables only have a valid scope inside their functions i e local to them e Letthe program continue with the Go command it will stop at the breakpoint in main You can see that Loc now has a value because the PC is now in the scope of the local variable i e in its function Watch Window HME Local variables are stored on the stack and the values that they have are Name Value indeterminate being whatever happens to be at that location on the stack Therefore 10 HT e400 they need to be initialised manually in the code as the compiler does not initialise SoU 02 them on the stack alternatively the STATIC keyword could be used to ensure that the local variable is stored ata memory location string hello world int loc 0 or static int loc Now test the execution of the main code by setting a break after the main function call in PowerOn_Reset line 0x46 and running to this break The string variable string will now contain the sequence abcdefghijkl rather than Hello World 24 Jan 01 Issue 1 0 EDK3664F Tutorial Manual 2 1 5 MEMORY MAP FOR EDK3664F WITH HDI M The processor on the EDK is in single chip mode and cannot be changed This means the chip is in
24. AA A ese cal cle wesc 36 24 59 Linking for stand alone Cod rc Ai A AAA AA AAA IA A AIDA 37 2 4 6 RUANO NECE setae a teen tetera mua AAA o 38 2 4 7 VOTLO LONS A EE REI ET IR 38 3 NORMAE PROTEGE binaria lai iaia 39 3 1 NORMAL PROJECT shell 40 3 1 1 Creating AN E NOME billo 40 S212 HEW Bulad COM CUIOMONS esaea E A eae 40 32 DEBUG CONFIGURATION FOR OPERATION WITH HDI M 0000 40 3 2 1 Emker Senp and SCCHOM MID EA SAA Se 40 3 2 2 Included files and Compiler Setup iii 4 3 3 RELEASE CONFIGURATION FOR STANDALONE OPERATION 000 00 42 3 3 1 ARTI ERRORI 42 Issue 1 0 J an 01 3 EDK3664F Tutorial Manual APPEND a aa cds 43 4 1 BOARDOVERVIEW ilaele 43 4 2 LEDIPINOUT sila aerea 44 4 3 PNOUTFOR XL AIAI ZE Llano 45 4 4 Ho o0 MEMORY MAP nie 46 4 Jan 01 Issue 1 0 EDK3664F Tutorial Manual 1 EDK USAGE TUTORIALS This manual answers in tutorial form the most common questions asked about using this evaluation board e How do compile link download and run a simple program e How does building an embedded application differ from application programming e How do use Hitachi s tools Files referred to in this manual are installed using the project generator as you work through the tutorials The tutorial examples in this manual assume that installation procedures described in the EDK User manual have been completed Source code listings in thi
25. DIMLIB lib Use of this library is described in the next tutorials and specifically in Section 3 2 14 Jan 01 Issue 1 0 EDK3664F Tutorial Manual 1 2 3 BUILDING THE FLASHER PROJECT This next section will outline how to build a project to run with HDI M First start Hitachi Embedded Workshop from its icon or the Windows Start Menu the previous workspace will automatically be loaded e Create a new workspace as in Tutorial A but this time call the project 3664 TutorialB and select 2 Flasher tutorial as the project to generate in the Project generator wizard Z x I 3664_TutorialB E aa Project Files i 5 dbscto 5 Hasher c intprg c i dl resetprg c sbrk c i E vecttbl c gt a Dependencies iodefine h Z sbrk h stacksct h di vect h 7 l Proj e Click the Build project icon hid or press lt F 7 gt If itis not already open the output window will open and the progress of the build will be displayed 2 Building 3664_T utorialB Debug F Phase H85 H8300 C C Compiler starting CNHEWS664 Tutornalb 3664 Tutorial 3664 7 utorialB c H SERIES Evaluation Software Evaluation period Sun Mar 11 09 00 00 2001 Phase H85 H8300 C C Compiler finished Phase H9S HS 300 IM OptLinker starting 1210 CANNOT FIND SECTION C Phase H9S HS 300 IM OptLinker finished Phase H Series Stype Converter starting Phase H Series Stype Converter finished Build Finished O Errors 1 Warning Ade Build
26. EBUG CONFIGURATION FOR OPERATION WITH HDI M This configuration will generate a standard s record for downloading to the EDK for operation with HDI e Ensure the Configuration is set to Debug 3 2 1 LINKER SETUP AND SECTION MAP e Select the menu item Options Linker Sections and inspect the linker section map shown above The Linker section map for the Debug Configuration contains 5 extra section names for HDI m HDI m Code 6010 bytes HDI m Constants 72 bytes HDI m Uninitialised Data 111 bytes MONSTACK HDI m Stack pointer 132 bytes S TOP User initial stack pointer RAM see stacksct h Address When these section are linked with the code care must be taken that they are all in valid memory locations Check the link map file 3664 STANDALONE map to ensure this is the case and check with Section 4 4 H8 3664 Memory Map e Select the menu item Options Linker Input and inspect the libraries built with Debug configuration Ensure that 3664HDIMLIB lib HDI m Library file is included WARNING S_ TOP is set by the user code but it must be placed after the user stack section S in the linker sections window This Section name is used by HDl m Library to set the reset stack S for the user code Power_ONReset must always be the name of the users startup function and it must always be where the user stack is set using pragma entry PowerON_Reset HDI m Library uses the Power _ONReset function name in referencing
27. EDK3664F Tutorial Manual EDK3664F Low Cost Evaluation Board Tutorial Manual for Hitachi H8S H8 300 Series C C Compiler For H8 300H Tiny 3664 On chip FLASH Microcontroller Issue 1 0 J an 01 1 EDK3664F Tutorial Manual PREFACE Product Warranty The warranty periods against defects in materials and workmanship are as set out in the accompanying Customer Information sheet Limitation of Warranty The foregoing warranty does not cover damage caused by fair wear and tear abnormal storage conditions incorrect use accidental misuse abuse neglect corruption misapplication addition or modification or by the use with other hardware or software as the case may be with which the product is incompatible No warranty of fitness for a particular purpose is offered The user assumes the entire risk of using the product Any liability of Hitachi Micro Systems Europe Limited is limited exclusively to the replacement of defective materials or workmanship Restrictions Hitachi Micro Systems Europe Limited s products are not authorised for use in medical applications without prior written consent Such use includes but is not limited to life support systems Hardware Considerations 1 Earthing This hardware is designed for use with equipment that is fully earthed Ensure that all equipment used is appropriately earthed Failure to do so could lead to danger for the operator or damage to equipment 2 Electrostatic Discharge Precautions
28. K and restart HDI and load C 3664 TutorialC debug 3664 TutorialC abs e Open a program window for Statics c and place a breakpoint at the first line of code in main Place a watch on the three variables loc string and count using the same method used in Tutorial B The watch window should show something similar to the picture lt can be seen from aria SOSIA this that before initialisation Loc has no value as it is a stack based local variable o count and the character string string have random values los count H ESPE string Cx00ffe40e e Now reset the processor and then Step once Menu Command Accelerator Toolbar Button Run Reset Bij A source code window will open showing the resetprg c file with the PC highlight bar in the PowerON_Reset function This first step will have executed the assembly code that sets up the stack pointer you can check in the disassembly window if you want to verify this e Step again to set the interrupt mask the highlight will now be on the call to the iste A Line Address BP Label Source _INITSCT function 00000034 _PowerON void PowerON Resetivold e If you Step Over this call while inspecting ECT i Lui en 1 1 sE 11043 a E F the Watch Window you will see that the HAGE INITSCT variables string and count have now been initialised with our initial data and zero respectively 00000042 main Hardwaresetup i El Watch Window gt OP x 0000004
29. P_NONE P_EVEN P_ODD unsigned char Stops Number of stop bits 1 2 unsigned char Length Length of byte transmitted 7 8 struct SCI_Init_Params SCI_Init_Data 1B9600 P_NONE 1 8 The baud rate can be either B9600 for 9600 baud or B19200 for 19200 baud 36 J an 01 Issue 1 0 EDK3664F Tutorial Manual 2 4 5 LINKING FOR STAND ALONE CODE For an application to exist successfully in a stand alone environment like the EDK it must be able to stand the removal of power from the system and initialise itself from a subsequent Power On reset condition To achieve this the parts of the application which setup the system including all of the code and constant sections must be placed non volatile memory such as Flash In order to be able to store and modify variables and data structures these must exist in RAM To allow the system to start correctly the stack will be placed in the on chip Below is the linker map file for Tutorial F in C 3664 TutorialF debug 3664 TutorialF H8L this file lists information about how the linker has built the application and where it has located the program sections according to the addresses defined in the HEW linker options You can see that the data sections have been placed in on chip RAM ent _PowerON_ Reset ro D R p c hew 3664_TutorialF 3664_TutorialF Release 3664_TutorialF map nooptimize st DVECTTBL DINTTBL 00 PIntPRG PResetPRG 034 P C D ABS8D SABS16D CSDSEC C BSEC 010
30. RAM Input Output Optimize Section Very Other this can be seen in the Ouput tab of the Options Linker Output menu Format of load module ERIE Item Type of load module Absolute If the user adds their own section names using the pragma section Psbusinfemation In output load module zi statement 4 new sections could be created for example ROM to RAM mapped sections Add pragma section ResetPRG i T If there is code following this section definition the code will be stored in a section named PResetPRG CResetPRG DResetPRG and BResetPRG depending on the data types shown in the table above I Generate map file Load module directory DResetPRG and BResetPRG must be added to dbsctc and e Shewdemo evb2623 tutorials D_Timer Debug Modify RResetPRG must be defined in the section definitions under menu item Options Linker Sections DResetPRG and RResetPRG must also be lee added to the ROM to RAM mapping Custom sections are described in more detail in Section STANDALONE 3 2 NOTE If a section is defined in the link map Options Linker Sections menu item but no data is assigned to it the linker will issue a warning 1210 Cannot Find Section name Issue 1 0 Jan 01 23 EDK3664F Tutorial Manual 2 1 4 RUNNING THE CODE e Now disconnect HDI from the EDK and Flash it with the file C 3664 TutorialC debug 3664 TutorialC mot as described in Tutorial A Disconnect FDT from the ED
31. SE H FFFF You should see the GRB value decrement by H 400 continue running and stopping at the breakpoint You can see the duty value change and the corresponding flash period of the LED also change Note that when the program Is stopped the duty value does not change even though the LED continues to flash and compare match occurs Although this does in fact cause an interrupt request HDI masks interrupts while the program Is stopped e Remove the breakpoint and Go You cannot see the TGR1B value decrement while the program is running however you can see the duty value of the LED flash change WARNING To use this I O window HDI m must read a mode bit at address H FFF1 This is the address for the SYSCR2 register which controls the subactive clock frequency A 1 must be written to this register in order for the I O window to be used and so the subactive clock cannot be 8 2 3 6 VARIATIONS Once interrupts have been mastered programming for real time applications becomes much simpler In addition the removal of polled loops enables many tasks to be performed seemingly at the same time In tutorial E_Interrupt the main program does nothing as it just sits in a while loop you could try performing some useful operation in this loop Alternatively you could try using some of the other on chip modules See the H8S hardware users manual for more information on them 34 J an 01 Issue 1 0 EDK3664F Tutorial Manual 2 4 TUTORIAL F LONER
32. T MSTIW 0 Enable TimerW module TMRW TMR BIT CTS 0 Timer off TMRW TIER BYTE amp 0x00 dissable all interrupts TMRW TSR BYTE amp 0x00 Clear any pending interrupts TMRW TCR BIT CCLR TCR_CCLR TCNT clear on GRA match TMRW TCR BIT CKS TCR CKS Clock phi 8 TMRW TMR BIT PWMB TMR_PWMB PWM mode for channel B TMRW TCR BIT TOB TCR_TOB Initial output is 0 TMRW GRA Oxffff Set cycle period by GRA TMRW TIER BIT OVIE 0 Disable the OVERFLOW interrupt TMRW TIER BIT IMIEB 1 Enable the GRB Match interrupt void INT_TMW void TMRW TSR BIT IMFB amp 0 clear B compare match bit TMRW GRB 0x400 Decrement duty value by 400 The main function is very similar to the main function from Tutorial D Because the ISR changes the duty value we do not need to do this in the main and so It just sits in a while loop The INT_TMW void function Is the interrupt service routine This corresponds to the symbol entry in the vector table definition in vecttbl c The first line clears the timer s compare match interrupt bit if the interrupt is not cleared another interrupt will immediately be generated on return from the ISR The second line in the ISR decrements the duty value in the TGRB register to shorten the off time of the LED when itis decremented past 0 the value in the register will underflow and start again at a high value i e with a sh
33. al project generation wizard are common to both build configurations HEW allows you to define different configurations for building executable modules from the same set of source files in a project Each different configuration may have different compiler assembler and linker options and may exclude files from the build When you create the Normal project two configurations Debug and Release are created automatically You can select the current H85 H6 300 OptLinker options D ebug GE S 3664_Standalone Hitachi Embedded Workshop CCAHEWA3664_5Sta Input Output Optimize section Vey Other l 3 A I File Edit Project Options Build Tools Window Help Relocatable section start address WE be E Section LITI Ed ee a i Modify Ae 3564 Standalone a Pe EE CGA H n A TREE E 3664_Standalone Fo 12 Dvare configuration from the standard tool bar Hemo ay If you use the EDK project generator wizard to create a new project the Debug configuration will set up the linker to place the HDI m Library file and its associated setup in the code so that HDI m can ads download your application to the board 5_TOP E88 Emon E Up Down Generate external symbol file _F In the Release configuration the sections are defined to create an absolute module that you can program into the Flash ROM of the Use external subcommand file OK Cancel device for standalone operation i e without HDI m 3 2 D
34. ate a new project in HEW several files defining the vector table and ISRs are created vecttbl c actually defines the vector table itself and the vector entries vect h declares the ISR function names as external symbols intprg c a default ISR function for all interrupts not used by HDI m or the User s Code a catch all An added complication when using HDI M is that the vector table is located from address H 0 which is in the Flash ROM area used by HDI m and the user s code To allow us to develop with interrupts the HDI monitor must be built with the user code and the power on reset vector must point to HDI m code HDI m also uses the serial and address break interrupts so these cannot be used if HDI m is built with the user code Issue 1 0 J an 01 31 EDK3664F Tutorial Manual 2 3 3 INTERRUPTS AND HDI M e Generate a new tutorial project as done in previous tutorials but this time select 5 Interrupt Tutorial and call it 3664 TutorialE The following workspace view should be seen Vecttbl c actually defines the vector table itself and creates a section named DVECTTBL xl which contains the power on reset function vector and also a section named DINTTBL which contains the vector entries for all interrupts available on the H8 3664F As this project has been built for use with HDI m the Reset vector in DVECTTBL points to the power on reset 3664_TutorialE da Project Files vector for HDI m E L n E i
35. ated which contains all of the on chip peripheral registers for the H8 300HTINY 3664F The file iodefine h follows the naming scheme used in the hardware manual The name of the structure corresponds to that of the peripheral module and the structure elements to the control registers and even individual bits in those registers Note The addresses used in the header file are those defined in the hardware manual for the device operating in 64kbyte mode if an address greater than 64K Bytes is offered to the CPU the most significant bits are ignored Thus there is no need to re write the file for use in 64KByte systems 2 2 3 THE TIMER PROGRAM The Tutorial project 4 Timer Tutorial contains the source files for this tutorial the main module Timer c is listed below The application flashes the LED D2 using one of the on chip 16 bit timer modules Timer W instead of by software We will use the timer to output a PWM square wave signal on timer output TIOB which is multiplexed with Port 8 Bit 2 of the device to which the LED D2 is connected via J 10 2 3 on the EDK Port 8 and the timer output TIOB both share this pin but cannot use it at the same time The cycle period for the waveform is set by the value in the timer s TGRA register and the duty cycle is set by the value in the TGRB register When the timer is enabled it will start counting up When the value in the TCNT register matches the value in the TGRB register the output of the pin wi
36. e taken out of BOOT mode and FDT disconnected from the board e Press the RESET BOOT switch S1 The red BOOT LED D3 will turn off indicating the EDK is notin BOOT mode e Press the ARM switch S2 The yellow ARMED LED D4 will turn off and the EDK cannot be put into BOOT mode e Press the Disconnect button in the FLASH Controller Window of FDT FDT will disconnect from the EDK Now the RESET BOOT switch S1 can be used only as a RESET source to the H8 3664 Before trying to connect HDI to the EDK ensure the connection with FDT is no longer operational if it is HDI will not be able to acquire the serial port from the Windows operating system e Ensure the code is running on the EDK by pressing reset button 1 again 1 1 3 CONNECTING HITACHI DEBUGGING INTERFACE MONITOR Installed with HEW is the modular Hitachi Debugging Interface HDI an embedded monitor kernel programmed onto the EDK HDI m with the user code allows you to debug the user code running on it using HDI For more information about the HDI debugging monitor HDI m on the EDK see the EDK3664 User Manual HDI Section e Connect the supplied serial cable to your PC and the UART RS 232 port on the EDK and apply 5V to the power terminals e Run HDI by clicking on the Launch Debugger icon on the HEW toolbar a Launch Debugger A Select Session dialog should appear as below e select a new session on H8 300H Monitor Select Session
37. e unsigned short duty TMRW GRB duty 0x7FFF Bet duty cycle at 50 in GRB TMRW TMR BIT CTS 1 Start the timer PutStr unsigned char r nEDK3664F Demo serial output r n while 1 PutChar GetChar void INT_TMW void TMRW TSR BIT IMFB amp 0 Clear the interrupt TMRW GRB 0x400 Decrement duty cycle by 0x400 This function is much like Tutorial E s main function Three serial functions have been added one to print out a text string and the others to echo any characters received by the serial port input in the while statement The timer interrupt also remains unchanged 2 4 4 THE SERIAL I O FUNCTIONS CI3 c and SC13 h are the files containing the four serial functions shown in the table below trici Initialises serial port using data InitSCI3 unsigned char in structure and returns error SCI Init Params flags Z x 3664_TutorialF Bey Project Files i E dbsctc i E intpra c i E onere Gechar e a character received by api E sbrk pad Transmits a character a Sido Transmits a string of characters El vecttblo x 5 lodefine h E sbrk h This is example code for control of the SCI3 port The initialisation function takes a structure El i containing four variables setin SCI_Init_ Data E stackscth struct SCI Init Params unsigned char Baud baud rate register value BRR unsigned char Parity Parity
38. ed in target user hardware Throughout code listings are given where appropriate in the text 20 Jan 01 Issue 1 0 EDK3664F Tutorial Manual 2 1 TUTORIAL C STATICS The source files for this tutorial are generated in the project 3 Statics tutorial 2 1 1 NEED FOR THE STARTUP CODE Most C applications will have a certain number of variables which are of either global or module scope These variables are referred to as static as they require statically allocated i e at build time space Static variables may be of any valid type and may or may not be given an initial value In an embedded system the code is resident in some form of non volatile memory ROM Flash and the application must boot from an uninitialised state at power on In such systems the static data must be set to its initial values before the user s application code is called i e before main executes In addition it IS common for the application s data area to be located in some form of memory which requires the system hardware to be initialised before it can be accessed e g RAM These systems require startup code to perform the initialisation from reset and then to pass execution to the user code If the user s code should ever return from main not really a good idea in an embedded system then some valid operation should be performed rather than randomly executing code which happens to exist past the call to main in the startup code
39. ee that the next test is satisfied we can see in the Watch window that ii does equal 60000 and so the LED is turned off Issue 1 0 Jan 01 19 EDK3664F Tutorial Manual EDK3664F Tutorial Manual 2 EMBEDDED CODE TUTORIALS Up to now all of our examples have assumed that we are writing code within the friendly environment provided by HDI M and that only the basic features of the H8 300HTINY 3664F are being used This second set of tutorials provides an example set of applications to allow you to write code which is intended for execution without HDI M being present i e code for a final application The tutorials address the following issues Using the Hitachi Embedded Workshop HEW to build a project Using an example startup code file which allows the static data sections to be initialised provision is also made for stack pointer initialisation hardware setup and exit code The use of the on chip timer module is examined This highlights the use of the on chip control registers and in particular the interrupt mechanism within the EDK standard environment This includes creation of the interrupt vector table and the use of in line hardware control functions to control the CPU from C The final tutorial allows the HDI M monitor in flash to be replaced with a user s application code this will then operate without the overheads but also the protection of HDI M and represents the final version of an application which would be us
40. g is useful if the variable is more complex e g a pointer array or structure e Selectthe Add Watch option and the main Watch window will open showing the count variable 18 Jan 01 Issue 1 0 EDK3664F Tutorial Manual Note that the default display for the variable shows its value in hexadecimal H However our code test values are decimal so it would be more useful to be able to view the value of the watched variable in decimal e Tochange the radix of the watchpoint display click on the variable name in the Watch window and pop up the local menu select Radix Decimal The value in the watch window will then be displayed in decimal The Watch window will display the current value of il whenever the program has stopped 1 2 8 USING HDI M TO MODIFY A VARIABLE e To see this working seta breakpoint on the line of code where ii is incremented 1 i1 and Go to this point e n the watch window place the cursor on the ii variable and press the right mouse button to show the Watch window s local menu again Select Edit Value to display the dialog below Current Value 0 Cancel New Value i e Now change the value of ii to 59999 and run to the next instruction you should see that the value of ii has been incremented to 60000 Step to the test if 11 30000 e Step again and you will see that the program steps past to the next i test as this test is not satisfied e Step again and you will s
41. guration endif The DEBUG defined symbol is added to the project via the compiler options in the following manor e Open the Compiler options dialog Options MA RUE Fic ES Compiler Source dialog and select the 123 ua AL Source Object List Optimize Other CPU Defines option from the Show entries for epa Show entries for drop down list e Click on the Add button a symbol entry Defines Add DEBUG dialog appears Insert e Enter the symbol DEBUG for the defined Remove macro name Move up e The symbol DEBUG is now defined y Macio besua Move down Replacement a This results in the application vector table containing HDI m interrupt and power on vectors if the Debug configuration is built As stated before Power _ONReset must have the user stack initialised by declaring pragma entry Power _ONReset in resetprg c the user hardware initialisation code can then be placed in The user application code can then be written in the main function in Main c Remember that some of the memory is used by HDI M library code as described in Section 3 2 1 Issue 1 0 J an 01 41 EDK3664F Tutorial Manual 3 3 RELEASE CONFIGURATION FOR STANDALONE OPERATION This configuration will generate a standard s record for downloading to the EDK for operation without any debugger This is the same as Tutorial F but without any functionality i e blank mai
42. initialised at startup with these values For your C program to be able to manipulate the resultant initialised data it must reside in RAM However the initial values for the data must be stored in non volatile memory to survive a power on reset and copied to RAM at startup thus initialising the data Static variable initialisation is done by a library function __INITSCT which is called from resetprg c Sections to be initialised are defined in dbsct c If the user creates a data section with a different name from the standard sections then they must be added to dbsct c Memory Sections are described in the 2 1 3 e Call the hardware initialisation code If the comments are removed hardware initialisation function HardwareSetup is called It is up to you to define this function and include it in your project if you need to Initialise your hardware A good example of low level initialisation is SDRAM setup Most of Hitachi s microcontrollers have direct interfaces to many different types of memory but some of these interfaces have to be setup before the memory can be accessed The interface should be setup in HardwareSetup before static initialisation so that any static variables within this memory can be initialised later in the startup code For H8 3664 there is no external bus to interface so the Hardware setup file could be used to Initialise the microcontroller s on chip peripherals This is covered in Tutorial D Timer e Callthe users
43. ll go to 1 turning the LED D2 off and the counter will continue to increment When the value in the TCNT register matches the value in the TGRA register the TCNT register will be reset to zero causing the cycle to reset and the output of the pin to be cleared turning the LED D2 on TCNT value Counter cleared by Pd TGRA compare match e Generate a new tutorial project as done in previous tutorials but this time select 4 Timer Tutorial and call it 3664 TutorialD The following workspace view should be seen xl a Ty 3664_TutorialD Et ra Project Files TE B dbsct c Z intprg c aa resetprg c Z sbrk c i dl B timer c i E vectibl c 5 2 Dependencies a iodefine h E sbrk h Z stacksct h A weet z l Proj e View the file Timer c by double clicking on it in the workspace window Issue 1 0 Jan 01 27 EDK3664F Tutorial Manual tinclude iodefine h Define constants for peripheral register vaules define TCR_CCLR Set TCNT cleared by TGRA match define TCR_CKS f Clock source internal s define TMR_PWMB PWM mode in channel B define TCR_TOB output 0 on TIOB at start OrRWEH void main void volatile unsigned short duty TMRW GRB duty 0x7fff Set duty of LED 50 by GRB TMRW TMR BIT CTS 1 Start Timer W while 1 TMRW GRB duty Change duty cycle void HardwareSetup void MSTCR1 BIT MSTTW 0 Enable TimerW module TMRW TMR BIT CTS 0
44. loop turning the LED D1 on and off e We would like to turn the LED D1 on and off without having to keep stepping in the debugger you can use the Go command to do this try it Menu Command Accelerator Toolbar Button Run Go F5 B e Youcan stop the program running using the Halt command Menu Command Accelerator Toolbar Button Run Halt ESC a Did you see what you expected Did the LED D1 flash on and off or did it instead just glow dimly The LED D1 is actually flashing on and off but the micro controller is doing it so fast you cannot actually see it instead it looks dim This is because the processor operates much faster than we can step manually In order to see it flash at a rate visible to humans we need to slow it down using a delay We will do this in the next tutorial Issue 1 0 Jan 01 13 EDK3664F Tutorial Manual 1 2 TUTORIAL B FLASHER This tutorial shows how to build a program that automatically flashes the EDK s red LED D1 and how to use HDI m to download run and modify this program In the process you will see how to e Use header files for declaring data structures e Use a delay loop to set human visible delays e Use HDI m for examining and debugging a program 1 2 1 SOURCE FILES Here is a listing of the source file for Tutorial B include iodefine h register definition header file void main void unsigned short ii 0 TO PCR5 BYTE 0x80 Set PORT 5 BIT 7 fot output all o
45. ls each being capable of generating at least one CPU interrupt In addition the CPU may be signalled from external devices using the NMI or one of the IRQ interrupt signals In this tutorial we will use the TGRB compare match interrupt of the PWM Timer W to vary the duty cycle of the flashing LED D2 The H8 300H TINY architecture provides direct hardware support for interrupts via the interrupt controller Each interrupt source is allocated a special vector address The vector address is used to store the address of the interrupt service routine ISR which is to be executed when the relevant interrupt is accepted The interrupt controller tests the priority level of an incoming interrupt against the priority level that the CPU will currently accept If the incoming interrupt is higher than the current CPU interrupt mask level Stored in the condition code register then interrupt processing begins The program counter PC and the condition code register CCR are stacked and the PC set to the value contained in the relevant vector address Execution then continues from the new PC value The ISR should be terminated with a return from exception RTE instruction to ensure that the PC and CCR are correctly restored on exit In this H8 300H Tiny we can only use interrupt mode 0 This means that the bit in the CCR Is the interrupt mask bit If is set to 0 interrupts will be enabled i e not masked See the H8 3664F Hardware Manual Interrupt Section for
46. main routine main is called e If the users code returns call the exit routine Finally the PowerON_Reset function ends with a sleep intrinsic function call to put the microcontroller into a Safe state WARNING When using HDI m the PowerON_Reset function must always be used This is explained in STANDALONE Section 3 2 22 Jan 01 Issue 1 0 EDK3664F Tutorial Manual 2 1 3 VIEWING THE STATICS The example C file Statics c is shown below unsigned char string hello world Global variables int count void main void int volatile loc for count 0 count lt 12 count overwrite the characters in string string count a unsigned char count LACA This file has been built to run with HDI m There are three variables in this code two global and one local The character string string has an initial value integer count does not and neither does the local int Loc By default the sections have the following names Hitachi ANSI C Section Compiler Linker section name Program Initialised Data Uninitialised Data Constants The uninitialised integer count is in section B RAM and is initialised to zero by _INITSCT The local integer loc is uninitialised in accordance with the ANSI C specification and has an undetermined initial value The code in _INITSCT copies the initial value of string inROM to EXE El ES RAM The initial value is in section D ROM and is copied to R
47. more information on interrupt control 2 3 2 CREATION OF ANISR INC It is often desirable to write all your application code in C where possible The Hitachi tools support extensions to the ANSI C language to allow interrupt service routines ISR to be written As mentioned above an ISR is distinguished from a normal function by the fact that it is terminated using a RTE instruction However this is not the only difference ISRs are by nature asynchronous and thus you cannot rely on the state of the registers on entry to the function In addition the ISR must preserve the state of all registers as there is no way of telling which registers were currently in use by the CPU when the exception occurred You also need to create an entry in the vector table that gives the address of the ISR for the given interrupt Each vector is located at a fixed address so care must be taken to place it correctly To define a function as an ISR simply precede it by the following form of statement pragma interrupt INT_TMW This instructs the compiler to treat the function INT_TMWw when it is defined in the source code as an ISR and hence to preserve the register values and to terminate with a RTE instruction When the interrupt occurs the corresponding ISR function address is fetched from the vector table and the program will jump to that address Therefore the address of the INT_TMW ISR needs to be stored in the correct place in the vector table When you cre
48. mp 19 from X2 depend on jumpers J5 J6 for function Rev B boards only Issue 1 0 Jan 01 QFP 64 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 DIP 42S 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 PIN DESCRIPTION PB5 AN5 PB4 AN4 P17 IRQ3 TRGV P16 IRQ2 P15 IRQ1 P14 IRQO NC NC NC NC P22 TXD P21 RXD P20 SCK3 P87 P86 P85 P84 FTIOD P83 FTIOC P82 FTIOB P81 FTIOA P80 FTCI NMI NC NC NC NC P76 TMOV P75 TMCIV P74 TMRIV P57 SCL P56 SDA P12 45 EVB 2623F Tutorial Manual 4 4 46 H 0000 H 0034 H 17F6 H 7FFF H F 780 H FB80 H FE8A H FF 80 H FFFF H8 3664 MEMORY MAP HDI m Example Memory Map Vector area HDI Monitor code Relocatable 6K bytes Free FLASH For User Code 26K bytes Unpopulated Flash work Area And 1Kbyte User Ram Internal RAM For User code 778Bytes Internal RAM For Monitor Work Area Relocatable 245Bytes Internal R egisters Jan 01 H813664F Memory Map Vector area Free FLASH 32Kbytes Unpopulated Flash work Area And 1Kbyte User RAM Internal RAM For User code 1Kbytes Internal Registers Issue 1 0
49. n and HardwareSetup functions e Ensure the Configuration is set to Release 3 3 1 LINKER SETUP e Select the menu item Options Linker Sections and inspect the linker section map check that there are no HDI m sections defined e Selectthe menu item Options Linker Input and select the Defines option from the Show entries for drop down list Check to see that the symbol DEBUG Is NOT defined All the same files are used in this configuration but all H8 3664 hardware is available because HDI m is not built with this code 42 J an 01 Issue 1 0 EVB 2623F Tutorial Manual 4 APPENDIX 4 1 Issue 1 0 BOARD OVERVIEW JI DIP a Pin Out e hi e an oa gt o og A i i E 9751 do D ng el a 3 me gd En Mi coo E TA 3664F DIP 425 13 xd oO av ass pilo 54 odi 053 24052 05390 51 o al D odd o nas od mide 46 ara 45 D n dd 0390 43 ada de 0330 41 ases 40 0310539 oala 39 goede a oca 36 cra 37 o Oo 34 T 533 Do as o om 3 pe60 30 oca 23 mein ca 0230 27 qlla co Doo QFP 64 Pin Out Jan 01 SERIAL I O si J10 SDA SCL BOOT ARMED Da Ear st POWER D3 RESET IBOOT ara i 0 4 Green LED D5 Power Red LED D2 Port 5 Bit 6 Port 8 Bit 2 Red LED D1 Port 5 Bit 7 Red LED D3 Boot Mode Activated Yellow LED D4 EDK Armed for Boot Mode 43 EVB 2623F Tut
50. nd Go to the breakpoint Remember to check if the instruction will break the process e Open a local watch window you can see the value of the variable duty Menu Command Accelerator Toolbar Button View Locals Ctrl Shift W A 28 Jan 01 Issue 1 0 EDK3664F Tutorial Manual Now you can modify the duty value in the Local watch window by double clicking on the value field in the window try a new value of H 1fff ae er Go again to write the value into the TGRB register and you will EA gt e Go again to write the value into the register and you will see Ty the duty cycle of the LED flash has changed on EDK Try different SF a duty cycle values and see what effect it has on the LED s flashing Curent o _ Cancel New Value Hpi 2 2 5 VARIATIONS You could try changing the period value in the TGRA register to change the cycle time for the LED D2 flashing or modify the program to vary the duty cycle and create different PWM patterns Issue 1 0 Jan 01 29 EDK3664F Tutorial Manual 2 3 TUTORIAL E INTERRUPT 2 3 1 INTERRUPTS ON THE H8 300HTINY 3664F In most user applications the rapid response of the system to external stimuli is essential in such systems the CPU must be informed of the change in the system status immediately To rely on polled tests of the various peripheral control registers represents a large CPU overhead The H8 300H TINY series of microcontrollers all support a wide range of on chip periphera
51. ned long s 0F84 MOV L ERO ER4 nz Breakpoints Enable File Line Symbo Address Type flasher c 29 00000114 PC breakpoint For Help press F1 NUM Ui Issue 1 0 J an 01 17 EDK3664F Tutorial Manual If you look at the LED D1 on the EDK it should be on e Go again and you should see the LED D1 stay on and the program stop at the breakpoint again If you keep issuing the Go command you will see the LED D1 flash once the program is executed to the breakpoint about 60000 times Now we would like to run the code at full speed and see the delay loops making the flash of the LED D1 visible We can temporarily disable a breakpoint by selecting it in the Breakpoint window and choosing Disable from the right mouse button local menu If you do this you will see the black dot disappear from the Enable column in the Breakpoint window and also the corresponding dot disappear from the BP column in the Program window Alternatively you can double click on the dot in the Breakpoint window Enable column to toggle the enabled disabled state for the breakpoint Note even though the breakpoint is disabled it is still valid and so no more breakpoints may be added e Make sure the breakpoint Is disabled and start the program running with the Go command You should now see the LED D1 flashing visibly on the EDK and the message on the status bar should read User Program is Running So now our program is running at full speed but ho
52. ntpra c If HDI m is to be used this power on reset vector must always be used E resetprac Power on reset vector when using HDI m is startup Me Li 0 3 Dependencies Within the interrupt table DINTTBL there are 3 interrupts that cannot be changed if operation i E iodefine h with HDI m is desired These vectors are E an H El stacksct NMI interrupt NMI capture for flash programming control SCI3 interrupt SCIint for communications between the PC and the EDK UBC interrupt UBCint for breakpoint control If any of these interrupt functions are omitted from the interrupt table HDI m will not operate correctly All other interrupts in this table are serviced by catch all functions defined in intprg c All the functions are blank except one the timer interrupt INT_TMW is commented out This is the interrupt routing for the timer used in this tutorial The ISR INT_TMW can be found in Interrupt c If you want to add your own interrupt functions it is advisable to keep the same names already in the tables and simply comment out the catch all function in intprg c and write another elsewhere Always remember to use the following compiler syntax when writing an interrupt routine pragma interrupt interruptname Here is the code listing for intprg c pragma section IntPRG void Dummy void void NMIcapture void Monitor NMI capture void INT_TRAPO void void INT_TRAP1 void
53. o a oO og 4 l RESET BOOT EDK3664 Board layout The numbers next to X2 and X3 are for DIP 425 package The numbers next to X1 and X4 are for QFP 64 package For example Pin 3 on X1 and X2 is connected to Pin 59 on QFP 64 and Pin 1 on DIP 425 LED X3 X4Pin QFP 64Pin DIP 42S Pin Pin Function Port 5 Bit7 SCL This first tutorial example shows how to turn the LED D1 on and off In the process you will also learn e How to access on board H8 300HTiny 3664F peripheral control registers e How to setup an H8 300HTINY 3664F 1 0 port for output e How to toggle a biton an H8 300HTINY 3664F 1 0 port e How to download and run a simple program using the HDI debugger 6 J an 01 Issue 1 0 EDK3664F Tutorial Manual 1 1 1 SOURCE FILE Here is a listing of the source file On_Off c include iodefine h 3664 Onchip peripheral registers void main void Finction prototype void main void IO PCR5 BYTE 0x80 Set PORT 5 BIT 7 for output while 1 IO PDR5 BIT B7 0 turn on LED IO PDR5 BIT B7 1 Tarn off LED To look atthe program start Hitachi Embedded Workshop from the Windows Start Menu or from its icon iy Hitachi Embedded Workshop HE File Edit Project Options Build Tools 7 New Ctrl M e Open a new tutorial workspace from the File New Workspace menu or E E Open i select Create a new project workspace if you are presented with the no c
54. o setthe PC register to the start of the program click on the _ main label in the Label column of the Program Window to position the cursor right click to pop up the local menu and select Set PC Here The line should then be highlighted to show that It is at the current PC address 3664_TutorialB c Line Address BP Label Source 0000012 unsigned short ii 0 Copy EE O0000ize i 0x80 Set PORT 5 BIT 7 for ar Find F3 Set Address 0000014 Set Line 00000132 Go To Cursor 00000134 Set PC Here 30000 Instant Watch 0000013a Add Watch BIT B 0 turn on LED 00000140 PASTOS ii 60000 00000146 BIT B 1 turn off LED EWA To check that the program does what we expect we will first set breakpoints to stop at the line in the code where the port bit controlling the LED D1 is toggled e To seta breakpoint open the breakpoint control window using the commands shown below Menu Command Accelerator Toolbar Button View Breakpoints Ctrl B EJ e Right click in the breakpoint window to pop up the local menu select the Add item and enter the address shown below Breakpoint address re Once entered the break window will show the new breakpoint and Y Enable _ Comcel also the code window will have a black dot next to the line of code in the BP column 114 else if ili 60000 Al Hitachi Debugamna interface 3664_TutorialB H8 300H Monitor File Edit Vie
55. ons in the Ouput tab of the Options Linker dialog in HEW 4 Generate map file Load module directory g The s record final build phase setup can be viewed in Options E Shewdemo evb2523f tutorials F_Loner Fieleas Modify S Type Converter dialog in HEW Use external subcommand file OF Cancel e Loading the built file into the Flash device using Hitachi s Flash Development Toolkit FDT as discussed in the Tutorial A Section 1 1 2 Issue 1 0 J an 01 37 EDK3664F Tutorial Manual 2 4 6 RUNNING THE CODE e Ensure that FDT is disconnected from the EDK and jumper J 10 is fitted with a Jo D1 block connecting Pins 2 3 Press the reset button S1 on the EDK SDA SCL This will reinitialise the H8 300HTINY 3664F into normal execution mode An RS 232 BOOT ARMED cable may then be connected to the UART port of the EDK3664F The LED should start 5 Da ARM to flash with a decreasing duty To verify that the character echo code is functioning as previously described in this st POWER tutorial RESET IBOOT e Starta terminal emulation program such as Hyperterminal e Connect to the EDK with the correct protocol settings set in Loner c the structure struct SCI_Init_Params SCI_Init_Data B9600 P_NONE 1 8 In this case 9600 baud 8 bit no parity 1 stop e On pressing reset button 1 the RED LED D2 should start to flash with the varying duty cycle indicating correct operation of the in
56. orial Manual 4 2 LED Pin OuT 10 Block X3 X4 QFP 64Pin DIP 425 Pin Pin Function BE Pin Port 5 Bit7 SCL Port 5 Bit 6 SDA Port 8 Bit 2 FTIOB J umper 10 with NO Block Fitted Illegal setting rey J10 J umper 10 with Block Fitted 1 2 LED D2 connected to Port 5 Bit 6 sol Li J umper 10 with Block Fitted 2 3 LED D2 connected to Port 8 Bit 2 rey J10P 44 Jan 01 3664F DIP 425 o 3de T 07330 4 axes J10 0310 3 103007320 e E 4 3 s A SCL o 0230 37 Ves 0280 36 027e 35 BOOT ARMED s2 ARN Issue 1 0 EVB 2623F Tutorial Manual 4 3 X1 X2 0 NODO VI DS WN Co 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 21 28 29 30 31 32 NOTES PIN OUT FOR X1 X2 X3 amp X4 QFP 64 DIP42S PIN DESCRIPTION 57 PB6 AN8 58 PB7 AN7 59 1 PB3 AN3 60 2 PB2 AN2 61 3 PB1 AN1 62 4 PBO ANO 63 NC 64 NC 1 NC 2 NC 3 5 Avcc 4 6 X2 note 1 5 7 X1 note 1 6 8 VCL 7 9 RES 8 10 TEST 9 11 Vss 10 12 OSC2 note 2 11 13 OSC1 note 2 12 14 Vcc 13 15 P50 WKPO 14 16 P51 WKP1 15 NC 16 NC 17 NC 18 NC 19 17 P52 WKP2 20 18 P53 WKP3 21 19 P54 WKP4 22 20 P55 WKP5 23 21 P10 TMOV 24 P11 X3 X4 0 N O OM DS ON 1 pins 12 4 13 from X1 are always connected to the H8 3664 pins 13 amp 13 from X2 depend on jumpers J2 J3 for function Rev B boards only 2 pins 18 amp 19 from X1 are always connected to the H8 3664 pins 18 a
57. ort pulse on the LED Note we decrement the value rather than increment it because if we incremented then very shortly after returning from the interrupt we would get a compare match on this larger value as the timer is still counting rather than waiting until another complete cycle period has been completed The startup function HardwareSetup has been increased to include an additional line of code to enable the Timer module channel B compare match interrupt TMRW TIER BIT IMIEB 1 Enable the GRB Match interrupt This causes an interrupt to occur whenever the value in the TCNT register matches that in the TGRB register The special function set_imask_ccr 0 is added this is an in line function to insert an instruction to change the CCR values and unmask Issue 1 0 J an 01 33 EDK3664F Tutorial Manual the interrupts in order to use this special function we have to include the header file machine h This contains a number of functions definitions to allow access to CPU operations like accessing the condition code register CCR and using specific instructions e g trapa sleep movfpe eepmov mac rotlw dsub nop These functions may be used in an application to gain access to the CPU they should be used with care as they directly control the underlying hardware and are not subject to checking by the compiler For more information on these function see the Hitachi H8S H8 300 Series C C Compiler User s Manual ADE 702 189 2
58. s manual are for explanation purposes only Due to software revisions the listings may not be identical to the listings on the disk Note These tutorials are designed to show you how to use the EDK and are not intended as a comprehensive introduction to HDI M Hitachi Embedded Workshop HEW or the compiler toolchains please consult the relevant manuals for more in depth information Issue 1 0 Jan 01 5 EDK3664F Tutorial Manual 1 1 TUTORIAL A ON OFF The EDK is equipped with a TWO RED LEDs that may be controlled by a program LED D1 is connected to the 3664F port 5 bit 7 pin 30 on X3 underside of board X4 topside of board LED D2 can be connected to port 5 bit 6 Board pin 31 on X3 X4 or port 8 bit 2 pin 19 on X3 X4 by setting jumper 10 see Section 2 2 1 For this tutorial we will be using LED D1 Below Is a picture of the EDK3664F showing the LEDs n Xx1 X2 X3 X4 Jana 5 rase SERIAL I O Cd sso D o 055 5901 a pilo 54 glo a cdo 53 D5 blade m40e 52 bfoada 03905 51 630 a o 30 bdo ao o odd 1 o o ads ce a D 47 3050 0220 46 dodge mire 45 507 0 o3 no dd asa 3664F 0350 43 Fede DIP 425 wide de 5 010 0 ai 0330 41 gt oe 20 W108 O 10 ni a 031039 ele 0200 39 SDA SCL 42 Did y Dedo 37 130150 0280 36 14 lb e cra 37 150 a o o34 Ise o E BOOT ARMED larm 17 o Q ae co 19 017 o peso 30 200180 0250 29 220206 LE o o a a Pais etere E POWER gd
59. terrupt code and you should see the sign on banner dumb HyperTerminal File Edit View Call Transfer Help EDK3664F Demo serial output Type in some text to confirm Connected 00 01 31 ANSI 9600 8 N 1 CAPS NUM Capture Print echo e Characters typed on the keyboard should be echoed back in the terminal window 2 4 7 VARIATIONS Now that successful programming of the on chip FLASH has been completed it is possible to program the H8 300HTINY 3664F with any application 38 J an 01 Issue 1 0 EDK3664F Tutorial Manual 3 NORMAL PROJECT The EDK3664 Project generator comes with a Normal project generater as well as the Tutorial and Completed project generator This section of the tutorial manual explains this function of the Normal Project and the 2 build configurations One build configuration is Debug which provides an empty project which is already linked to HDI m Library code enabling the user code to run with HDI through the serial port SC13 The other configuration is Release which provides an empty project without HDI m code for standalone operation on the EDK much like Tutorial F Issue 1 0 Jan 01 39 EDK3664F Tutorial Manual 3 1 NORMAL PROJ ECT 3 1 1 CREATING THE NORMAL PROJECT e Generate a new Workspace as done in previous tutorials but this time select Normal Project and call it 3664 Standalone 3 1 2 HEW BUILD CONFIGURATIONS All the files generated by the Norm
60. thers inputs while 1 1144 if ii 30000 IO PDR5 BIT B7 0 turn on LED else if ii 60000 IO PDR5 BIT B7 1 turn off LED The structure definition and assignment that we did in Tutorial A to make it easy for us to access the on chip peripheral control registers has already been done for all the device s peripheral registers and the code for this is in a header file called iodefine h This file is created when you generate a new project in HEW So for this tutorial example all we have to do is include the file in our C file include iodefine h register definition header file With this file included we can then use any structures or assignments declared in it in our C program Note that each separate C file that uses any of these definitions must include the header file in it In the main function the local variable ii is incremented in an endless while loop and adds delay to the setting and resetting of the LED D1 bit of port 5 When ii is equal to 30000 the LED D1 is switched on when ii is equal to 60000 the LED D1 is switched off The unsigned short ii hasa range of 0 to 65535 so on reaching 65535 it increments back to 0 thus keeping both if andelse if statements valid 1 2 2 HDI M LIBRARY FILE INCLUSION By looking at the menu item Options Linker Input you can see that the monitor library has been included in this build The library is in the project directory and is 3664H
61. to the EDK3664F User manual For this tutorial we will be using LED D2 connected to port 8 bit 2 X3 X4 PIN 19 which is also a timer output pin e Ensure 10 is connected with a jumper block across 2 3 as shown below i r X3 X4 Jumper 10 with NO Block Fitted EA SERIAL I O Illegal setting Mi 590 o o 055 pilo 54 odio 53 d4l 52 D5 0390 5l o 6570 q odi o Das ads J umper 10 with Block Fitted 1 2 0320 46 i 3 0 45 LED D2 connected to Port 5 Bit 6 3664 236044 DIP 425 0240 ds A p no e LU E mama SDA SCL J umper 10 with Block Fitted 2 3 a 034 BOOT ARMED s2 hee LED D2 connected to Port 8 Bit 2 E o 03 4 0250 29 Fa prde 28 AA Ce J1 0 lazzo 26 st POWER Le 75 4 i RESET IBOOT EDK3664 Board layout LED J10Block X3 X4 QFP 64 DIP 425 Pin Function Position Pin Pin Pin Port 5 Bit 6 SDA Port 8 Bit 2 FTIOB 2 2 2 ACCESSING THE CONTROL AND STATUS REGISTERS The H8 300HTINY 3664F microcontroller contains a lot more than simply a CPU A whole host of peripherals are available to you for use in a target application Each peripheral module has a set of control and status registers which act as the interface to the CPU many peripherals also have pins associated with them which act as the interface to the outside world Each peripheral can signal a change in its status by setting bits in one of its registers or by sending an interrupt to the CPU prompting immediate action
62. u item or the icon WARNING Do not create an FDT workspace we will be using the Quick Programming method e Once the Welcome screen for FDT is displayed press CANCEL DO NOT create a workspace FDT should now be running with no open workspace or file Now load the s record created when the project was built e Load the s record 3664_TutorialA mot by Selecting the menu item File Open or the icon gt Once the s record has been loaded into FDT it should be visible in the work area Open the FLASH Controller window FLASH Development Toolkit 3664 TutorialA mot e Select the menu item Image Download Image or the download image icon sH Setup the FLASH Controller window e Select H8 3664 as the Target device select BOOT mode and ensure that the Select E Interface is set to Direct Connection Ensure correct COM Port is selected for the PC being used 00000000 C0000008 FLASH Controller 3664_T utorial mot Device Selection Target device des dele H8 3564F El RAM Size 1 75K Connection BOOT Mode C USER Program Mode Select Interface Direct Connection T I Kemel already resident User settings IY Use default settings COM Port COM z Commands Connect Blank check Erase FLASH blocks Download fle 3664 Tutorials not to device Baud rate 19200 H Controller 3664 TutorialA mo lal Not Connected E
63. ura oy Welcome dialog Hew Workspace Open Workspace Save Workspace Close Workspace o Enter a name and path for example 3664 TutorialA and C 3664 TutorialA select Hitachi H8S H8 300 Standard Tool chain and Project type EDK3664F Click OK to start the EDK3664F Project Generator wizard New Project Workspace E x e Select Tutorial Projects as the type of project to generate Hame and then click Next 3664_Tutorial sl Cancel Directory Cancel e Choose 1 On Off Tutorial as the project to generate c edk 3864 3664 Tutorial Browse CPU Family Click Finish to create the project Has He 48 300 Tool chain The project generator wizard will create the project OnOff and Hitachi H85 H8 300 Standard insert the necessary files Project type iy Application E Assembly Application Demonstration PFE DK3664F Empty Application del Library Issue 1 0 J an 01 7 EDK3664F Tutorial Manual e Ifthe Workspace window is not visible show it now by clicking the Workspace window icon on the 2 toolbar Alternatively you can select the Window Workspace menu item or press Alt K on the keyboard You will see a tree display showing all the files in this project gt gt gt El Uy 3664_Tutorial e To view the file On Off c double click on the file in the Workspace window A new al a Project
64. w Bun Memory Setup Window Help garal aay ar DI OA Wee P OP 16 Address B 00000100 00000102 0000011e 00000106 00000108 0000010e 00000114 e 00000lla unsigned short 11 0 IO PCRS BYTE 0x80 Set PORT 5 BIT 7 for oL ri 1 11 if 11 30000 IO PDR5 BIT B7 0 turn on LED else if 11 60000 IO PDR5 BIT B7 1 turn off LED Address Type 00000114 PC breakpoint For Help press F1 Num Z Jan 01 Issue 1 0 EDK3664F Tutorial Manual If the line you wish to break on is visible in the code window a quicker way to set breakpoints is to double click in the BP column on the same line as the code You should see the black dot appear and an entry for that breakpoint appear in the breakpoint window If you double click again you can remove the breakpoint you should see the black dot in the program window and the entry in the breakpoint window disappear e Ensure a breakpoint is set on address 0x114 WARNING The EDK3664 will only allow ONE breakpoint to be assigned at any one time If a breakpoint is set then the command Go to Cursor will not work as this command uses a temporary breakpoint 1 2 6 RUNNING THE PROGRAM AND HALTING EXECUTION e Torun to the breakpoint select the Go command Menu Command Accelerator Toolbar Button Run Go F5 E The program stops and the yellow highlight bar will now be placed on the breakpoint in the main function in the code window
65. w do we stop it To halt program execution Menu Command Accelerator Toolbar Button Run Halt ESC STOP The program will stop with the highlight bar in the Program window showing the current location and the User Break message on the status bar Break User Break WARNING Be very careful when placing breakpoints always use the Disassembly window and be aware of instruction prefetches after branch instructions A breakpoint set on a branch will break on the line of code that the instruction branches to A breakpoint set on a line of code after a branch may never be triggered because the line of code may always be prefetched Try putting a breakpoint at address 0x11a this will never be triggered because the compare and branch instructions before the code cause the code at 0x11a to always be prefetched 1 2 7 VIEWING VARIABLES We would like to view the value of the ii variable e Place the cursor in the code window over ii after a short delay a tool tip style information box will pop up showing the value of ii This gives you a quick way of viewing a variable s value e Alternatively click to locate the cursor on the variable then use the right mouse button to pop up the local menu Copy Etrie Find Fa Set Address Set Line Go To Cursor Set PC Here Instant Watch Add Watch Go to Disassembly e Selectthe Instant Watch option a dialog will open showing you that i i is equal to 0 This dialo
Download Pdf Manuals
Related Search
Related Contents
CollectionConnection User Manual Version 2.0 Jontec 300 j-flex Altec Lansing inMotion IM310 Copyright © All rights reserved.
Failed to retrieve file