DOC PREVIEW
UNCC ECGR 4101 - C Start-Up and Simple Digital IO

This preview shows page 1-2-23-24 out of 24 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

C Start-Up Module and Simple Digital I/OIn these notes . . .C Start-Up Module – Why?C Start-Up Module Functions – ncrt0.a30sect30.incSetting Stack Size in Sect30.incAllocating Sections to RAM or ROMDirectives for Arranging SectionsMacros to Initialize Memory Sections – sect30.incInitialize Memory Sections – ncrt30.a30Define Fixed Interrupt Vector Table - sect30.incStart the main() function – ncrt0.a30Digital Input/Output (I/O) PortsProgrammable I/O PortDigital I/O Port as InputDigital I/O Port as OutputPull-Up Resistors for InputsExample: P6 Echoes Nibble DataDo I really have to write assembly code?What about..Example in C: P6 Echoes Nibble DataC Definitions for our Two Nibble PortsSample Code from DemoSlide 247-1Embedded SystemsC Start-Up Module and Simple Digital I/O Lecture 7Embedded Systems 7-2In these notes . . . C Start-Up Module–Why is it needed?–How is it done?–MCPM, section 2.2Simple Digital I/O–Port•Data Direction•Data•Drive Capacity–Use•Initialization•Reading•Writing–Example•Echo LEDsEmbedded Systems 7-3C Start-Up Module – Why?MCU must be configured to run in correct mode–Are memory wait states needed?Program sections must be allocated to specific parts of memory–Code, data, interrupt vectorsSome C constructs must be initialized before the program starts running–Where does the stack start?–What about initialized static variables?Other C constructs are created or managed “on the fly”–Building a stack frame (activation record) to call a subroutine–Dynamically allocating blocks of memory–Don’t have to do anything about theseMain() function must be calledEmbedded Systems 7-4C Start-Up Module Functions – ncrt0.a30Include sect30.inc – provides supporting informationInitialize stack pointer to top of stack areaConfigure MCU to use external clock without frequency divisionLoad pointer for relocatable (variable) interrupt vector tableZero out bss section–use a macro to write zeroesInitialize data section–use a macro to copy dataInitialize heap, if it existsCall main as a subroutineExecute infinite loop if main ends and control returns hereEmbedded Systems 7-5sect30.incDefine sizes and macros–heap size–user stack size (if RTOS used)–interrupt stack size–interrupt vector address–define macros for •zeroing data (N_BZERO) •copying data (N_BCOPY)•initializing heap control variables (HEAPINIT)•special page interrupt vectorsArrange memory (sub)sections–SBDATA (static base data)•data_SE, bss_SE•data_SO, bss_SO–Near RAM•data_NE, bss_NE•data_NO,bss_NO•stack•interrupt stack•heap–Near ROM•rom_NE, rom_NO–Far ROM•rom_FE, rom_FO•data_SEI, data_SOI, data_NEI, data_NOI, data_FEI, data_FOI•switch tableDefine interrupt vectors–variable vectors–fixed vectorsEmbedded Systems 7-6Setting Stack Size in Sect30.incSTACKSIZE .equ 0hISTACKSIZE .equ 80hStack is used for calling subroutines, handling interrupts, and temporary local storageTwo stacks pointers available: USP and ISP–Which pointer is active depends upon the stack pointer select bit (“U”) in the flag register. See M16C Software Manual, p. 5–U is cleared on reset, so ISP is selected initially–USP is used if an RTOS (real-time operating system) is present–We will use ISP onlyHow big of a stack do we need? Coming up later…–Too small and the program will crash as stack overwrites static variables, and static variables overwrite stack frame–Too large and we waste RAMEmbedded Systems 7-7Allocating Sections to RAM or ROMdata and bss sections are subdivided for efficiency at run-time–Addressable from static base register? (within 64K of SB?)•yes, put in S subsection•no, if address in range 0-0FFFFh put in N subsection (near)•no, else put in F subsection (far)–Even data size? (can ensure all accesses are aligned with bus)•yes, put in E subsection•no, put in O subsectionAlso have I subsection (in ROM) for initial data valuesdata_SEbss_SEdata_SObss_SOdata_NEbss_NEdata_NObss_NOstackistackheapAEmbedded Systems 7-8Directives for Arranging Sectionssect30.inc defines where each section goes in memorySection directive has two formats–Allocate section to a memory area – this version is used here•.section name, area_type [CODE|ROMDATA|DATA], [ALIGN]–Place the following code in a certain section•.section name; Near RAM data area; SBDATA area.section data_SE,DATA.org 400Hdata_SE_top:.section bss_SE,DATA,ALIGNbss_SE_top:.section data_SO,DATAdata_SO_top:.section bss_SO,DATAbss_SO_top:; near RAM area.section data_NE,DATA,ALIGNdata_NE_top:.section bss_NE,DATA,ALIGN. . . .blkb STACKSIZEstack_top:.blkb ISTACKSIZEistack_top:.section heap,DATAheap_top:.blkb HEAPSIZE.section rom_FE,ROMDATA.org 0A0000Hrom_FE_top:.section rom_FO,ROMDATArom_FO_top:Embedded Systems 7-9Macros to Initialize Memory Sections – sect30.incDefine two assembly-language macrosN_BZERO – zero out bytes –Two arguments•TOP_: start address of memory section•SECT_: name of memory section –Uses instruction sstr.b (string store - byte) to store R0L at addressses A1 to A1+R3–sizeof is assembler directiveN_BCOPY–Three arguments•FROM_: start address of source data•TO_: start address of destination•SECT_: name of memory section–Uses instruction smovf.b (string move forward - byte) to copy R3 bytes of data from address A0 to address A1N_BZERO .macro TOP_ ,SECT_mov.b #00H, R0Lmov.w #(TOP_ & 0FFFFH), A1mov.w #sizeof SECT_ , R3sstr.b.endmN_BCOPY .macro FROM_,TO_,SECT_mov.w #(FROM_ & 0FFFFH),A0mov.b #(FROM_ >>16),R1Hmov.w #TO_ ,A1mov.w #sizeof SECT_ , R3smovf.b.endmEmbedded Systems 7-10Initialize Memory Sections – ncrt30.a30ncrt0.a30 calls macros defined in sect30.incFill bss sections with zeros–N_BZERO Copy initialized data from ROM–N_BCOPY==========================================; Variable area initialize. This code uses ; the macros in "sect30.inc“ for initializing ; C variables. Clears global variables, sets ; initialized variables, etc.;==========================================; NEAR area initialize.;------------------------------------------------; bss zero clear;------------------------------------------------N_BZERO bss_SE_top,bss_SEN_BZERO bss_SO_top,bss_SON_BZERO bss_NE_top,bss_NEN_BZERO bss_NO_top,bss_NO;------------------------------------------------; initialize data section;------------------------------------------------N_BCOPY data_SEI_top,data_SE_top,data_SEN_BCOPY data_SOI_top,data_SO_top,data_SON_BCOPY


View Full Document

UNCC ECGR 4101 - C Start-Up and Simple Digital IO

Documents in this Course
Load more
Download C Start-Up and Simple Digital IO
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view C Start-Up and Simple Digital IO and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view C Start-Up and Simple Digital IO 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?