C and Assembler Subroutines: Using the LCD. Outline Basic structure of CW-created C programs for the HC12 How to incorporate assembly code How to use.

Slides:



Advertisements
Similar presentations
OutLine of Tutorial 3 Memory Allocation Const string New string(byte array) Read memory in simulator Function invocation How Import library files Modify.
Advertisements

Chapter 7 Introduction to LC-3 Assembly Language Assembly Language Assembly Process Using the Editor & Simulator for Assembly Language Programming.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Programming III SPRING 2015 School of Computer and Information Sciences Francisco R. Ortega, Ph.D. McKnight Fellow and GAANN Fellow LECTURE #3 Control.
Program Development Tools The GNU (GNU’s Not Unix) Toolchain The GNU toolchain has played a vital role in the development of the Linux kernel, BSD, and.
SYSTEM PROGRAMMING & SYSTEM ADMINISTRATION
Characteristics of Realtime and Embedded Systems Chapter 1 6/10/20151.
C Language Programming. C has gradually replaced assembly language in many embedded applications. Data types –C has five basic data types: void, char,
CSS 372 Lecture 1 Course Overview: CSS 372 Web page Syllabus Lab Ettiquette Lab Report Format Review of CSS 371: Simple Computer Architecture Traps Interrupts.
Chapter 12: High-Level Language Interface. Chapter Overview Introduction Inline Assembly Code C calls assembly procedures Assembly calls C procedures.
Programming the HC12 in C. Some Key Differences – Note that in C, the starting location of the program is defined when you compile the program, not in.
AVR Programming CS-212 Dick Steflik. ATmega328P I/O for our labs To get data into and out of our Arduino its a little trickier than using printf and.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Linking Separately Assembled “Relocatable” Assembly Files Up to this point in the course, we have been working with “Absolute Assembly” programs where.
1 Introduction to Programming Environment Using MetroWerks CodeWarrior and Palm Emulator.
Software Development and Software Loading in Embedded Systems.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Introduction Purpose Objectives Content Learning Time
Lecture 6 Assembler Directives. 2  Code generation flow  Assembler directives—Introduction  Segment control  Generic segment (SEGMENT, RSEG)  Absolute.
University of Washington CSE 351 : The Hardware/Software Interface Section 5 Structs as parameters, buffer overflows, and lab 3.
Operating System Program 5 I/O System DMA Device Driver.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Purpose  This training course describes how to configure the the C/C++ compiler options.
Introduction to Subroutines. All the combinations in which a subroutine can be written 1. The subroutine may be: a. Internal or b. External 2. The type.
MIPS coding. SPIM Some links can be found such as:
chap13 Chapter 13 Programming in the Large.
PMS /134/182 HEX 0886B6 PMS /39/80 HEX 5E2750 PMS /168/180 HEX 00A8B4 PMS /190/40 HEX 66CC33 By Adrian Gardener Date 9 July 2012.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
The miniDragon+ Board and CodeWarrior Lecture L2.1.
1 Homework / Exam Finish up K&R Chapters 3 & 4 Starting K&R Chapter 5 Next Class HW4 due next class Go over HW3 solutions.
Introduction Purpose This training course covers debugging an application on an SH target in the Renesas HEW (High-performance Embedded Workshop) development.
UniMAP 1 Interfacing Peripherals. UniMAP 2 Interfacing devices on Embedded Linux In general, to interface to a device connected to an embedded Linux platform.
Objective At the conclusion of this chapter you will be able to:
9-1 EE 319K Introduction to Microcontrollers Lecture 9:I/O Synchronization; LCD Interfacing; Implementing Local Variables using a Stack Frame; Parameter.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 3 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Assembly Language for x86 Processors 7th Edition Chapter 13: High-Level Language Interface (c) Pearson Education, All rights reserved. You may modify.
Blackfin Array Handling Part 1 Making an array of Zeros void MakeZeroASM(int foo[ ], int N);
ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.
1 Stacks, Subroutines, I/O Routines Today: First Hour: Stacks, Subroutines –Section 3.9,3.10 of Huang’s Textbook –In-class Activity #1 Second Hour: I/O.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Configuring CodeWarrior V5.1 for the HCS12.
An overview of C Language. Overview of C C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Introduction Purpose  This training course demonstrates the Project Generator function.
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Preocedures A closer look at procedures. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Introduction 8051 Programming language options: Assembler or High Level Language(HLL). Among HLLs, ‘C’ is the choice. ‘C’ for 8051 is more than just ‘C’
1 Subroutines Advanced Programming. 2 Top-Down approach to problem solving Algorithm step by step description of how to solve a problem Divide and Conquer.
Hello world !!! ASCII representation of hello.c.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 – Loaders.
Vishwakarma government engineering college Prepare by. Hardik Jolapara( ) LCD Interfacing with ATmega16.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 3 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Lecture 3 Translation.
Mixing C and ASM Programs
Introduction to Operating Systems
LCD Interfacing using Atmega 32
System Programming and administration
Assembler Directives Code generation flow
High-Level Language Interface
An Embedded Software Primer
L7 – Assembler Directives
Lecture 6 Assembler Directives.
Introduction to Operating Systems
Interrupts in C Programs
Register Variables Declaring a variable as a "register" variable is an advisory to the compiler to keep the normal location of the variable in a register,
ECE 3567 Microcontrollers Dr. Gregg J Chapman
Example 7 Liquid Crystal Display
8051 ASSEMBLY LANGUAGE PROGRAMMING
C Programming Language
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
Presentation transcript:

C and Assembler Subroutines: Using the LCD

Outline Basic structure of CW-created C programs for the HC12 How to incorporate assembly code How to use subroutines –With no pass variables –With pass variables

Compiler selection Check both C and assembler to use both varieties of code when using the project wizard

The Project Folder The project folder looks a lot like it did before with some new folders Lets open some and see what’s inside Most likely we will only need the prm and the sources folders New

The Bin Folder These are created after you compile. There are corresponding files created for the simulator and the monitor board. At this point these files are created after compiling for the simulator only Parameters created during compilation inclusing RAM, ROM start/end addresses, all the variables used, program statistics The raw machine code that will be pushed out to the board

The S19 and S32 Source Files Here is the S19 file created by CW. This is the binary data (in hex) that will get pushed to the board. Many applications are available only in this form without the source code This code can be pushed with the simple debug program shipped by Technological Arts. We use CW.

The PRM folder Simulator and Monitor Linkers /* This is a linker parameter file for the MC9S12C32 */ NAMES END /* CodeWarrior will pass all the needed files to the linker by command line. But here you may add your own files too. */ SEGMENTS /* here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */ RAM = READ_WRITE 0x3800 TO 0x3FFF; /* unbanked FLASH ROM */ ROM_4000 = READ_ONLY 0x4000 TO 0x7FFF; ROM_C000 = READ_ONLY 0xC000 TO 0xF77F; END PLACEMENT /* here all predefined and user segments are placed into the SEGMENTS defined above. */ _PRESTART, /* Used in HIWARE format: jump to _Startup at the code start */ STARTUP, /* startup data structures */ ROM_VAR, /* constant variables */ STRINGS, /* string literals */ VIRTUAL_TABLE_SEGMENT, /* C++ virtual table segment */ //.stackstart, /* eventually used for OSEK kernel awareness: Main-Stack Start */ SSTACK, /* allocate stack first to avoid overwriting variables on overflow */ //.stackend, /* eventually used for OSEK kernel awareness: Main-Stack End */ END STACKSIZE 0x100 VECTOR 0 _Startup /* reset vector: this is the default entry point for a C/C++ application. */ //VECTOR 0 Entry /* reset vector: this is the default entry point for an Assembly application. */ //INIT Entry /* for assembly applications: that this is as well the initialization entry point */

The PRM file No ORG statements are required in C. Absolute memory references are in the prm file Stack size (100 in this case) can be modified to be larger The VECTOR statement can be used to identify the location of interrupt service routines

The Source Folder / Assembler subroutines Main.c Main_asm.h #include /* common defines and macros */ #include /* derivative information */ #pragma LINK_INFO DERIVATIVE "mc9s12c32" #include "main_asm.h" /* interface to the assembly module */ void main(void) { /* put your own code here */ EnableInterrupts; asm_main(); /* call the assembly function */ Delay_100us(); DELAY_1MS(); for(;;) {} /* wait forever */ /* please make sure that you never leave this function */ } #ifndef _MAIN_ASM_H #define _MAIN_ASM_H #ifdef __cplusplus extern "C" { /* our assembly functions have C calling convention */ #endif void asm_main(void); /* interface to my assembly main function */ void Delay_10us(void); void Delay_100us(void); void DELAY_1ms(void); void DELAY_10ms(void); #ifdef __cplusplus } #endif #endif /* _MAIN_ASM_H */ Declare routines

Main.asm ; code section MyCode: SECTION ; assembly routine called by the C/C++ application asm_main: MOVB #1,temp_byte ; demonstration code rts ; ; ; ; Subroutine DELAY: delays 10 uS ; ; DELAY_10us: Delay_10us: DELAY_10US: PSHA LDAA #55 ; for 10 uS delay To execute assembly language routines simply use them as normal C functions, assembly file PLUS use XDEF in the assembly file to connect the two: ;******************************************* ;*This is like the "old" utillib.asm file * ;******************************************* ; export symbols XDEF asm_main XDEF Delay_10us XDEF DELAY_100us xdef DELAY_1ms xdef DELAY_10ms ; we use export 'Entry' as symbol. This allows us to ; reference 'Entry' either in the linker.prm file ; or from C/C++ later on ; include derivative specific macros INCLUDE 'mc9s12c32.inc' ; variable/data section MY_EXTENDED_RAM: SECTION ; Insert here your data definition. demonstration, temp_byte. temp_byte: DS.B 1

How about passing parameters between C and ASM We have routines that pass data through a CPU register –The LCD routine uses B to pass charaters and commands CW uses the following registers to pass data If data is passed back the return values are stored in …

More on passing Most of the routines we used, LCD_out, LCD_cmd used the register B, so we’re in good shape to use these again The Read_ATD subroutine that read the A2D and returned a value in D is also in good shape

Passing Variables Main_asm.h #ifndef _MAIN_ASM_H #define _MAIN_ASM_H #ifdef __cplusplus extern "C" { /* our assembly functions have C calling convention */ #endif void asm_main(void); /* interface to my assembly main function */ void Delay_10us(void); void Delay_100us(void); void DELAY_1MS(void); void DELAY_10ms(void); char LCD_Out(char); #ifdef __cplusplus } #endif #include /* common defines and macros */ #include /* derivative information */ #pragma LINK_INFO DERIVATIVE "mc9s12c32" #include "main_asm.h" /* interface to the assembly module */ extern char LCD_Out(char); void main(void) { /* put your own code here */ EnableInterrupts; asm_main(); /* call the assembly function */ Delay_100us(); DELAY_1MS(); LCD_Out(0x34); for(;;) {} /* wait forever */ /* please make sure that you never leave this function */ } Main.c

Main.asm ; export symbols XDEF asm_main XDEF Delay_10us. xdef DELAY_10MS xdef LCD_Out. ;===================================================================== ; The 3 major 'low level' LCD routines: ; Init_LCD = no parameters, initializes the LCD (cursor and display on ; clears and homes display, 2 line) ; LCD_CMD = takes value in reg. B and sends it as a command. ; LCD_Out = takes value in reg. B and sends it as data (ASCII codes) ;===================================================================== LCD_Data: LCD_Out: PSHB BCLR LCDCtrlPort, #RW_Bit ;it's data BSET LCDCtrlPort, #E_Bit+RS_Bit STAB LCDDataPort BCLR LCDCtrlPort,#E_Bit PULB RTS

Global Variables If you want to share data between the two languages, one approach is to use global variables AND the extern keyword (on the C side) plus the XDEF directive (on the assembly side):

LCD We will need to use the LCD as an indicator of what we are doing while the HC12 is running. We can’t always rely on the simulator We have three routines in our old utillib.asm file –LCD_init –LCD_out –LCD_cmd In C we want to create more, with more flexibility

Routines we want for the LCD LCD_clear –Clears LCD and brings cursor home LCD_location(2,10) –Moves cursor to row 2, position 10 without clearing the screen LCD_writeline(buffer) –Clears the screen –Prints the array of characters in buffer[]