; export symbols XDEF Entry ; export 'Entry' symbol ABSENTRY Entry ; for assembly entry point

Similar documents
; export symbols ; export 'Entry' symbol. ; include derivative specific macros PORTA EQU $0000 PORTB EQU $0001 DDRA EQU $0002 DDRB EQU $0003

Lab 7: Asynchronous Serial I/O

Using the stack and the stack pointer

CMPEN 472 Sample EXAM II

Coe538 Final Study Guide 2016 (Questions & Answers)

Programming the Motorola MC68HC11 Microcontroller

538 Lecture Notes Week 5

538 Lecture Notes Week 5

Lecture 13 Serial Interfaces

Exam 2 E2-1 Fall Name: Exam 2

Quick Guide to Using Code Warrior

Cross Assembly and Program Development

Chapter 2: HCS12 Assembly Programming. EE383: Introduction to Embedded Systems University of Kentucky. Samir Rawashdeh

Lecture 9 Subroutines

Sample Problem Set #1

MC9S12 Assembler Directives A Summary of MC9S12 Instructions Disassembly of MC9S12 op codes. Summary of HCS12 addressing modes ADDRESSING MODES

Chapter 4: Advanced Assembly Programming. EE383: Introduction to Embedded Systems University of Kentucky. Samir Rawashdeh

Introduction to Programming the 9S12 in C Huang Sections 5.2 and 5.3. You will be able to use all of the Motorola data manuals on the exam.

538 Lecture Notes Week 3

Ryerson University Department of Electrical and Computer Engineering ELE 538 Microprocessor Systems Final Examination December 8, 2003

Table 1: Mnemonics Operations Dictionary. Add Accumulators Add B to Y. Add with carry to B. Add Memory to B. Add 16-bit to D And B with Memory

CodeWarrior. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

EE319K Final Fall 2005 Solution C. (3) Question 1. (3) Question 2. short function(const short in){ return in+5; } const

Exam 2 E2-1 Fall Name: Exam 2

MCO556 Practice Test 2

A B C D E F 0480 FE B F5 3B FC F3 E 1A 1D 2A 2D 3A 3D 4A 4D 5A 5D 6A 6D 7A 7D

ECE 367 -Experiment #1 Fall 2012

It translates (converts) assembly language to machine code.

Introduction to Programming the 9S12 in C Huang Sections 5.2 and 5.3

Exam 1 Feb. 23, 25, 27?

BRANCH IF REGISTER IS HIGHER/GREATHER/ THAN OPERAND e.g. CMPA #$D0

EE319 K Lecture 3. Introduction to the 9S12 Lab 1 Discussion Using the TExaS simulator. University of Texas ECE

Lecture #4 Microcontroller Instruction Set Embedded System Engineering Philip Koopman Monday, 25-Jan-2016

68HC11 Opera,ng Modes

The Motorola 68HC11 Instruc5on Set

ECE372 CodeWarrior Simulator Andreou/Michaelides

Outline. 2.8 Stack. 2.9 Subroutines

UNIVERSITY OF MANITOBA DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING. Term Test #2 Solution ECE 3610 MICROPROCESSING SYSTEMS

538 Lecture Notes Week 3

AN2153. A Serial Bootloader for Reprogramming the MC9S12DP256 FLASH Memory. Introduction. Semiconductor Products Sector Application Note

Comparison of C and Assembly How to compile a C program using CodeWarrior

0b) [2] Can you name 2 people form technical support services (stockroom)?

C SC 230 Computer Architecture and Assembly Language April 2000 Exam Sample Solutions

Review for Exam 3. Write 0x05 to ATD0CTL4 to set at fastest conversion speed and 10-bit conversions

LECTURE #21: G-CPU & Assembly Code EEL 3701: Digital Logic and Computer Systems Based on lecture notes by Dr. Eric M. Schwartz

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-470/570: Microprocessor-Based System Design Fall 2014.

Module 1-G. Marcos and Structured Programming

COSC345 Software Engineering. Basic Computer Architecture and The Stack

ME 6405 Introduction to Mechatronics

Timing Generation and Measurements

Linking Assembly Subroutine with a C Program

AN1745. Interfacing the HC705C8A to an LCD Module By Mark Glenewinkel Consumer Systems Group Austin, Texas. Introduction

Introduction to Microcontrollers

EE319 K Lecture 7. Address mode review Assembler, Debugging Psuedo ops 16 bit timer finite state machines. University of Texas ECE

Programming Book for 6809 Microprocessor Kit

Freescale Semiconductor, I

CHAPTER 8. Solutions for Exercises

538 Lecture Notes Week 2

COE538 Lecture Notes Week 3 (Week of Sept 17, 2012)

MC68705P3 Bootstrap ROM

EE 308 Spring A software delay. To enter a software delay, put in a nested loop, just like in assembly.

1. Memory Mapped Systems 2. Adding Unsigned Numbers

ECE 3610 MICROPROCESSING SYSTEMS AN ENCRYPTED ASCII CODE DECODER

2) [ 2 marks] Both of the following statements cause the value $0300 to be stored in location $1000, but at different times. Explain the difference.

Comparison of C and Assembly How to compile a C program using CodeWarrior

EE 308 Spring A software delay

An ability to program a microcontroller to perform various tasks

AN1742. Programming the 68HC705J1A In-Circuit By Chris Falk CSG Product Engineering Austin, Texas. Introduction. Overview

ECE331 Handout 3- ASM Instructions, Address Modes and Directives

Module 3.F. Serial Communications Interface (SCI) Tim Rogers 2017

Exam I Review February 2017

AN-HK-32. In-Circuit Programming of FLASH Memory in the MC68HC908GP32. nc... Freescale Semiconductor, I. PART 1 Introduction

ME4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume LECTURE 7

Go Gators! Relax! May the Schwartz be with you!

Microcontrollers. 2IN60: Real-time Architectures (for automotive systems) Mike Holenderski,

Introduction to the 9S12 Microcontroller

EE 5340/7340 Motorola 68HC11 Microcontroler Lecture 1. Carlos E. Davila, Electrical Engineering Dept. Southern Methodist University

Lab 2 Part 3 Assembly Language Programming and 9S12 Ports

Lecture 7 Assembly Programming: Shift & Logical

Introduction to Mechatronics. Fall Instructor: Professor Charles Ume. Interrupts and Resets

COSC 243. Instruction Sets And Addressing Modes. Lecture 7&8 Instruction Sets and Addressing Modes. COSC 243 (Computer Architecture)

ECE3120: Computer Systems Hardware & Software Development Tools

Decimal, Hexadecimal and Binary Numbers Writing an assembly language program

Program Development. Chapter 5

NAM M6800 DISK-BUG DS VER 3.5 OPT PAG

CET335 Microprocessor Interfacing Lab 5: LCD Interface (Bus Attached Peripheral)

ME 4447 / ME 6405: Introduction to Mechatronics

ECET Chapter 2, Part 3 of 3

Reading Assignment. 68HC12 Instruction Set. M68HC12 Instruction Set Categories. Some Tips. Endianness (Byte Order) Load and Store Instructions

EE 3170 Microcontroller Applications

Using and Installing: HCS12C128 Board, USB-to-Serial port driver, and HyperTerminal

Module 1-D. Control Structure Applications. Tim Rogers 2017 [1.D]-1

Introduction to Microcontrollers III

ECE 3120: Computer Systems Chapter 8: ECE-3120-A Musical

Freescale Semiconductor, I

Asynchronous Data Transfer

MC9S12 Address Space

EE 308 Spring The HCS12 has 6 addressing modes

Lecture 36 April 25, 2012 Review for Exam 3. Linking Assembly Subroutine with a C Program. A/D Converter

Dallas Semiconductor DS1307 Real Time Clock. The DS 1307 is a real-time clock with 56 bytes of NV (nonvolatile)

Transcription:

**************************************************************** * This program for CMPEN 472, Flash Memory Writing * * By Kyusun Choi, ID=0000 * * Date: 11/15/2017 * * Freescale CodeWarrior, for the HCS12C128 Program * * Target: Axiom's CSMBC128 Board, ASCII Monitor Mode * **************************************************************** parameter declearation section export symbols XDEF Entry export 'Entry' symbol ABSENTRY Entry for assembly entry point include derivative specific macros PORTA EQU $0000 PORTB EQU $0001 DDRA EQU $0002 DDRB EQU $0003 PPAGE EQU $0030 Flash page register FCLKDIV EQU $0100 Flash clock divider register EQU $0105 Flash status register FCMD EQU $0106 Flash command register SCIBDH EQU $00c8 Serial port (SCI) Baud Rate Register H SCIBDL EQU $00c9 Serial port (SCI) BAUD Rate Register L SCICR1 EQU $00ca Serial port (SCI) Control Register 1 SCICR2 EQU $00cb Serial port (SCI) Control Register 2 SCISR1 EQU $00cc Serial port (SCI) Status Register 1 SCIDRL EQU $00cf Serial port (SCI) Data Register CR equ $0d carriage return, ASCII 'Return' key LF equ $0a line feed, ASCII 'next line' character ******************************************************* variable/data section ORG $3000 RAMStart defined as $3000 flash data block flashd: DC.B $30,$30,$30,$30,$CF,$31,$00,$CE DC.B $70,$00,$A6,$30,$07,$13,$A6,$30 for HCS12C128 board DC.B $07,$0F,$A6,$30,$07,$0B,$A6,$30 DC.B $07,$07,$A7,$A7,$A7,$A7,$A7,$20 DC.B $F9,$4F,$CC,$80,$FC,$5A,$CF,$3D flashc DC.B $28 data byte count in hex, $28 = 40 bytes dly1s_r1 DC.W $0400 dly1s_r2 DC.W $0400 counter1 DS.B 1 msg1 DC.B 'Well', $00 msg2 DC.B 'Flash memory writing, 40 bytes at $7000', $00 msg3 DC.B 'Done. Reset and type go 7004 to check', $00 for HCS12C128 board

******************************************************* code section ORG $3100 Entry LDS #Entry initialize the stack pointer ldx #msg1 print the first message, 'Well' printmsg nextline ldx #msg2 print the second message printmsg nextline #$3E for HCS12C128 board staa PPAGE needed if $8000, not needed for $7000 fclkset set flash memory clock dly1s ferase erase 1024 byte sector from $7000 dly1s fwr40b write 40 bytes to flash, starting at $7000 ldx #msg3 print the third message printmsg nextline jmp $7004 looop bra looop ******************************************************* subroutine section ***********fclkset************************************* fclkset: flash memory clock setting subroutine >>>>> Must use OSCCLK and NOT BUSCLK <<<<< oscillator clock (OSCCLK) = 4MHz for HCS12C128 board bus clock (BUSCLK) = 24MHz prescale by 8: yes, 4MHz/8 = 500KHz for HCS12C128 board divider n: $03, 500KHz/3 = 166.6KHz for HCS12C128 board the fclock will run at 166.6KHz for HCS12C128 board fclock must be: 150KHz < fclock < 200KHz fclkset: fclksetend: FCLKDIV anda #%10000000 bne fclksetend #$43 for HCS12C128 board staa FCLKDIV ***********end of fclkset******************************

***********ferase************************************** ferase: flash memory sector erase subroutine assume FCLKDIV register is properly set Sector size is 1024 byte ferase: ferase_p2: anda #%01000000 check for CCIF bit, is it finished? beq ferase_p2 wait until flash sector clear done ***********end of ferase*******************************

***********fwr40b*********************************** fwr40b: flash memory word write subroutine assume FCLKDIV register is properly set Sector size of 1024 byte is already erased fwr40b: anda #%10000000 check for CBEIF bit beq fwr40b wait until set, registers empty to load anda #%00110000 check for ACCERR and PVIOL beq fwr40b_p1 clear if set #%00110000 staa fwr40b_p1: fwr40b_p2: fwr40b_p3: ldx #$7000 set flash memory address pointer ldy #flashd set data pointer flashc load data byte counter lsra change it to word counter staa counter1 set flash word counter ldd 2,Y+ load flash data word to write std 2,X+ set flash memory write word address #$20 set command as WRITE(Program), $20 staa FCMD #%10000000 clear CBEIF, by writing 1 staa start flash word write (program) operation anda #%10000000 check for CBEIF bit, is it ready for next command? beq fwr40b_p3 wait until flash command ready dec bne counter1 fwr40b_p2 fwr40b_p4: anda #%01000000 check for CCIF bit, is it finished? beq fwr40b_p4 wait until flash WRITE all done ***********end of fwr40b***************************

***********printmsg*************************** * Program: Output character string to SCI port, print message * Input: Register X points to ASCII characters in memory * Output: message printed on the terminal connected to SCI port * C * Registers modified: CCR * Algorithm: Pick up 1 byte from memory where X register is pointing Send it out to SCI port Update X register to point to the next byte Repeat until the byte data $00 is encountered (String is terminated with NULL=$00) ********************************************** NULL equ $00 printmsg psha Save registers pshx printmsgloop pick up an ASCII character from string pointed by X register then update the X register to point to the next byte cmpa #NULL beq printmsgdone end of strint yet? putchar if not, print character and do next bra printmsgloop printmsgdone pulx pula ***********end of printmsg******************** ***************putchar************************ * Program: Send one character to SCI port, terminal * Input: Accumulator A contains an ASCII character, 8bit * Output: Send one character to SCI port, terminal * Registers modified: CCR * Algorithm: Wait for transmit buffer become empty Transmit buffer empty is indicated by TDRE bit TDRE = 1 : empty - Transmit Data Register Empty, ready to transmit TDRE = 0 : not empty, transmission in progress ********************************************** putchar brclr SCISR1,#%10000000,putchar wait for transmit buffer empty staa SCIDRL send a character ***************end of putchar***************** ****************getcharw********************** * Program: Input one character from SCI port, terminal/keyboard * Input: none * Output: Accumulator A containing the received ASCII character * Registers modified: CCR * Algorithm: Wait for receive buffer become full Receive buffer full is indicated by RDRF bit RDRF = 1 : full - Receive Data Register Full, 1 byte received RDRF = 0 : not full, 0 byte received ********************************************** getcharw brclr SCISR1,#%00100000,getcharw SCIDRL ****************end of getchar**************** ****************nextline********************** nextline #CR move the cursor to beginning of the line putchar Cariage Return/Enter key #LF move the cursor to next line, Line Feed putchar ****************end of nextline***************

************************************************************** delay1sec subroutine dly1s LDY dly1s_r2 long delay by dly1s_p1 JSR dlyms Y * dlyms DEY BNE dly1s_p1 RTS ************************************************************** dlyms subroutine This subroutine cause few msec. delay Input: a 16bit count number in 'dly1s_r1' Output: time delay, cpu cycle waisted Registers in use: X register, as counter Memory locations in use: a 16bit input number in 'dly1s_r1' Comments: one can add more NOP instructions to lengthen the delay time. dlyms LDX dly1s_r1 short delay dlyms_p1 NOP X * NOP DEX BNE dlyms_p1 RTS

***********Flash ROM printmsg*************************** * Program: Output character string to SCI port, print 4 byte message * Input: 4 ascii bytes at $7000. * Register X points to ASCII characters in memory * Output: message printed on the terminal connected to SCI port * C * Registers modified: X, A, CCR * Algorithm: Pick up 1 byte from memory where X register is pointing Send it out to SCI port Update X register to point to the next byte Repeat until the 4 byte data is finished. * this is NOT a subroutine, it is infinite loop * this code will be programmed into Flash ROM starting at $7004 ********************************************** hw11code fprintmsgloop LDS #$3100 initialize the stack pointer ldx #$7000 for HCS12C128 board bra fprintmsgloop brclr SCISR1,#%10000000, wait for transmit buffer empty staa SCIDRL send a character * the machine code for the above program is as follows: * the first 4 byte is the data to print (student's id, last 4 digits in ascii) DC.B $30,$30,$30,$30,$CF,$31,$00,$CE DC.B $70,$00,$A6,$30,$07,$13,$A6,$30 for HCS12C128 board DC.B $07,$0F,$A6,$30,$07,$0B,$A6,$30 DC.B $07,$07,$A7,$A7,$A7,$A7,$A7,$20 DC.B $F9,$4F,$CC,$80,$FC,$5A,$CF,$3D * after flash programming, when the program at $7004 is ran, * it will print 0000 on the SCI port terminal. END this is end of assembly source file lines below are ignored - not assembled/compiled