1 / 39

How to Use HC08 Cross C Compiler

How to Use HC08 Cross C Compiler. Hiware C. Developed by Dennis Ritchie in Bell Lab for Unix on PDP-11 “The C Programming Language 2 nd Ed” (1988) Kernighan &Ritchie The ANSI C Standard Defined the Syntax and Semantics Standard Defined the Standard C library.

clem
Télécharger la présentation

How to Use HC08 Cross C Compiler

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. How to Use HC08 Cross C Compiler Hiware C

  2. Developed by Dennis Ritchie in Bell Lab for Unix on PDP-11 “The C Programming Language 2nd Ed” (1988) Kernighan &Ritchie The ANSI C Standard Defined the Syntax and Semantics Standard Defined the Standard C library “The C Programming Language” (1988)

  3. Hello World!

  4. C is originally from Unix (Linux gcc) Unix (Linux ) is written with C C and Unix

  5. Process management (Kernel, but not Real Time) Memory Management Files Management I/O Management What Unix (Linux) Does?

  6. Everything is Unix is to be seen as a file Any I/O is seen as a file: If you want to use an I/O, you have to: Mount the device (data flow or data block) Open the file ( Open for Read or Write) Memory buffer Access the file (R/W) Close the file Release the buffer How is the I/O in Unix ?

  7. I/O is not the part of ANSI C I/O can be part of OS Write Hardware Independent Part of an application only Because normally no file sys in an Embedded System, I/Os can be treated as tasks I/O in Cross C for Embedded System

  8. Cross C Compiler (1) • RAM & ROM are limited resource • need memory management & code/data optimization • memory map & system resources variousfor different MCUs • unique memory mapheader file & emulator personality file for every MCU • variables are stored in RAM, while codes & constant tables are stored in ROM

  9. Cross C Compiler(2) • system resources(variables, I/Os & functional modules) should beinitialized during startup • mostly include real time applications • executable codes are NOT relocatable • usually, functions cannot be re-entried

  10. C-compiler Architecture Compiler Linker Debugger Utilities Absolute Exe. Code Generator C-Level & ASM Trace Executable Code to S-19 Code Converter Directives Parser Assembler Code Generator Debugging Pre-processor Memory & Registers Monitor & Modify Absolute Listing Generator Assembler Code Optimizer H/W & S/W Breakpoints Object Code Libraries (system & user) Relocatable Obj. Code Generator Assembler(relocatable) Bus State Analyzer • Linker Command file • Integrated Environmentfor project edit, compile,link, debug, ... • In-line Assembler • Macro Definition • Compile Directives • Commands & macros • Activities log file

  11. Source Files for HC08 C Program MCU Memory Map Typ. Memory Usage MCU Memory Map Header File Variables(@<addr>) I/Os & Registers Variables(@tiny) .bsct seg(init. data) .ubsct seg(non-init. data) RAM(Page 0) Macro Definition Header File Variables(@near) .data seg(init. data) .bss seg(non-init. data) RAM(non-page 0) stack Function & Variable Declaration Header File Functions .text seg(code) Startup File (Reset entry, variable & stack initialization, program exit, …) ROM(internal) Constants .const seg(data) Program Files (+ Libraries) Main Pgm. File Variables(@near) .data seg(init. data) .bss seg(non-init. data) External RAM [optional] Fcn Module Files ISR Files Reset & Interrupt Vector Table(ROM) Constants[Pointers] .text seg(code) MCU Vector Table Header File

  12. Memory Memory Program Section Example Segment Type .text executable code ROM void main(); .bsct initialized data(page 0) RAM(page 0) @tiny char table_ptr = 0; .ubsct non-init. data(page 0) RAM(page 0) @tiny int I, j, k; .data initialized data RAM @near char tb_cnt = 5; .bss non-initialized data RAM @near float result; .const constant ROM @near const char step_table[5]= { 0, 10, 20, 30, 40 }; Section-to-Segment Mapping • Usually, the above mapping is assumed by the compiler, and cannot be overrided.

  13. C_start_up file: Initial Stack Pointer ;(Macro) Initial System Call main() Jump Exit() ;return to Monitor Simple than ANSI C No Command line parameters, No input output redirection No initial variable General Cross C compiler

  14. HC08 Demo Guide EDIT .C .h Compiler .O Link Assembler .abs Burn Simulator Dis assembler .S19 Down Load default.ini Working Path Project.env Windows Shell Project.prm Hardware Parameters for link Project.map Memory Location for Debug Debugging

  15. Function_a() { }; You got .o file, in which only one machine code of: RTS ; Start a Cross CStart from simplest Program (1)

  16. Main() { } You got more code than other functions Man() { printf (“\n Hello World!”) } /* in most case, it does not work!*/ Start from simplest Program (2)

  17. 68HC08 C Compiler How to insert ASM in C: #define HALT {__asm CLRA; __asm SWI ! {A}, {A+HX+SR};} #define HALTX(x) {__asm LDA x; __asm SWI ! {A}, {A+HX+SR};} #define HALT_AND_QUIT HALTX(#32) #define EnableInterrupts {__asm CLI;} #define DisableInterrupts {__asm SEI;} How to define hardwire address: In your .h file: #define Input_port_A (*(unsigned char *) 0x1800) In your .c program: Main() { Input_port_A = 5; }

  18. The Relationship between C and ASM Parameters transferred through Stack /* test.c */ main() { add(3,5); } int add(int a, int b) { return(a+b); }

  19. Decoding File: ‘ .o' 10: int add(int a, int b) 11: { 87 PSHA ;low byte of the b 89 PSHX ;high byte of the b 12: return(a+b); 9EE606 LDA 6,SP ;low byte of the a 9EEB02 ADD 2,SP ;low byte of the b 87 PSHA ;low of the result 9F TXA ;hi of the b 9EE906 ADC 6,SP ;hi of the a 97 TAX ;result hi in X 86 PULA ;result low in A A702 AIS #2 81 RTS 3: main() 4: { 5: 6: add(3,5); 7: 450003 LDHX #0x0003 89 PSHX 8B PSHH ;high byte of the 3 A605 LDA #0x05 5F CLRX ;high byte of the 5 CD0000 JSR add A702 AIS #2 8: } 81 RTS

  20. Parameters Transfer between C and ASM Data transferred with Stack Where is the first parameter? Where is the returned value? What is the order of of Parameters in the stack? C and ASM

  21. Demo C Program /* demo for the usage of a virtual Real Time Interrupt Timer */ #define TIMER_IC 0x80 #define TIMER_OC 0x40 #define TIMER_TO 0x20 #define TIMER_CONTROL (*((char*)0x12)) #define TIMER_STATUS (*((char*)0x13)) #define TIMER_CNT_MSB (*((char*)0x14)) #define TIMER_CNT_LSB (*((char*)0x15)) /** One may read the counter MSB first. Then LSB is stored in temporary place, and next read will reveal this value. **/ #define TIMER_CMP_MSB (*((char*)0x16)) #define TIMER_CMP_LSB (*((char*)0x17)) /** Compare value. Interrupt if ctr == cmp && TIMER_OC set **/

  22. typedef void (*Vector)(void); #define T_INT 16 #define T_VECTOR (*((Vector*)(0xFFFE - (T_INT << 1)))) /* #pragma DATA_SEG SHORT _DATA_ZEROPAGE */ int counter, ticks, time; #pragma TRAP_PROC void TimerInterrupt(void) { if (TIMER_STATUS & TIMER_OC) { /** also clears status reg **/ ticks++; } }

  23. void TimerInit(void) { TIMER_CMP_MSB = 1; TIMER_CMP_LSB = 0; TIMER_CONTROL |= TIMER_OC; T_VECTOR = TimerInterrupt; } void main(void) { int tick0; TimerInit (); counter = ticks = time = 0; asm CLI; for (;;) { if (counter == 5000) { time = ticks - tick0; counter = 0; tick0 = ticks; } counter++; } }

  24. Link File Towers.prm Let Compiler knows your Hardware LINK towers.abs NAMES towers.o start08.o ansi.lib END SECTIONS Z_RAM = READ_WRITE 0x0080 TO 0x00FF; MY_RAM = READ_WRITE 0x1000 TO 0x7FFF; MY_ROM = READ_ONLY 0xF000 TO 0xFEFF; PLACEMENT DEFAULT_ROM INTO MY_ROM; DEFAULT_RAM INTO MY_RAM; _DATA_ZEROPAGE INTO Z_RAM; END STACKSIZE 0x100 VECTOR 0 _Startup

  25. Generate Motorola S Code S00D0000746F776572732E616273EA S123F0009BCCF4190000F30E0000000011570001F01A0000F026F01EF02010000058000068 S109F020FFFF00000000E8 S105FFFEF419F0 S123F028A7FECE1054898ACE1055650000931F9EEF028B869EE7019F8B8848594859898A63 S123F04897D6100BC71055D6100AC71054654F8395E601FEA702818789A7FA9E6F049E6F2B …………………………………. …………………………………. …………………………………. S123F3A8F014F7205395F687EE018AE6019EE706F69EE705AD509EEE02878AE6019EE7044A S123F3C8F69EE703AD4095F795F687EE018AF68795E60387EE048A86F7956C0326026C028A S123F3E86C0126017C6D0526026A046A05E60487EE058A65000092D095F687EE018AE60153 S123F408FA26A2A70A819FAB029EE7048B86A90081C6F005A502260DC6F00CB7FEC6F00D0D S116F428B7FF55FE94CDF331CEF006898ACEF007FD20DEA8 S105F0260000E4 S903F0000C

  26. MC68HC08 C编译器 编程范例 • (实现简单的端口输出功能)

  27. 步骤一. 建立工程

  28. 步骤二. 编写源文件

  29. /************************************************ Demo files: The Simplest Program Of 08GP32 ************************************************/ #include <hidef.h> //C编译器提供的头文件 Byte PORTA @0x0000; //部分寄存器标号定义 Byte DDRA @0x0004; Byte CONFIG1 @0x001E; Byte CONFIG2 @0x001F; Byte PCTL @0x0036; Byte PBWC @0x0037; Byte PMSH @0x0038; Byte PMSL @0x0039; Byte PMRS @0x003A; #define b_PLLON 5 #define b_AUTO 7 #define b_BCS 4 #pragma CODE_SEG DEFAULT //标志代码段的开始

  30. void init_gp32(void) //初始化08GP32 { asm { sei LDA #0x01 //CONFIG设置 STA CONFIG1 LDA #0x3D STA CONFIG2 CLR PCTL //PLL锁相环的设置 MOV #0x01,PCTL MOV #0x04,PMSH MOV #0xB0,PMSL MOV #0xFF,PMRS BSET b_PLLON,PCTL BSET 3,PCTL BSET 2,PCTL BSET b_AUTO,PBWC BSET b_BCS,PCTL lda #0x05 //允许IRQ中断 sta 0x1d } }

  31. void main(void) { int i,j; init_gp32(); asm { cli //允许中断 } PORTA=0xFE; //初始化PORTA DDRA=255; while (TRUE) { for(i=0;i<200;i++) //延时 for (j=0;j<100;j++); PORTA=PORTA<<1; //移位,产生走马灯效果 PORTA++; if (PORTA==0xFF) PORTA=0xFE; } }

  32. void interrupt 2 Int_Event(void) //IRQ中断服务 { PORTA=0xFE; //PORTA复位 asm { lda #0x05 //清除中断标志 sta 0x1d } } void dummy(void) //其他无用中断的服务程序 { asm { rti } }

  33. 步骤三. 编译 (COMPILE)

  34. 步骤四. 链接 ( LINKER )

  35. ## fibo.prm文件 LINK fibo.abs NAMES fibo.o start08.o ansi.lib END SECTIONS MY_RAM = READ_WRITE 0x0040 TO 0x023F; MY_ROM = READ_ONLY 0x8000 TO 0xFFFF; PLACEMENT DEFAULT_ROM INTO MY_ROM; DEFAULT_RAM INTO MY_RAM; END STACKSIZE 0x100 VECTOR 0 _Startup VECTOR 1 dummy VECTOR 3 dummy …...

  36. MAKE (第三、四步的综合)

  37. ## ## fibo.mak文件 ## fibo.abs : fibo.prm fibo.o $(LINK) fibo.prm fibo.o : fibo.c $(COMP) $(FLAGS) fibo.c

  38. 步骤五. 调试 ( DEBUG )

  39. 步骤七. 写入芯片 ( BURNER )

More Related