Transcript
Page 1: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

WHYP-- An Extensible Language

Chapter 4

Page 2: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

WHYP--An Extensible Language

• A Closer Look at WHYP• Defining New WHYP Words• Variables• Constants• EEPROM

Page 3: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

A Closer Look at WHYP

Serial Line

send address

PC Target 68HC12

Kernel: LOOP BSR INWDY JSR 0,Y BRA LOOP

892C

892C ----- ----- ----- ----- ----- RTS

Dictionary: --- --- --- --- --- --- --- --- display 892C --- --- --- ---

C++ Program

ScreenC:\>whyp12 ok display

Page 4: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

WHYP--An Extensible Language

• A Closer Look at WHYP• Defining New WHYP Words• Variables• Constants• EEPROM

Page 5: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Colon Definitions

: <name> --- --- --- --- ;

: squared ( n -- n2 ) DUP * ;

16 4104 JSR DUP16 4337 JSR *3D RTS

Page 6: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

C:\WHYP\WHYP12>whyp12Using WHYP12.HEDCommunicating with COM168HC12 WHYP12 - Version 4.6Press <Esc> or type BYE to exitok: squared DUP * ; okhex ok' squared u. 5000 ok5000 20 dump 0 1 2 3 4 5 6 7 8 9 A B C D E F5000 16 41 04 16 43 37 3D FF FF FF FF FF FF FF FB FF A C7=.........5010 FF FF FF FF FF FF DB FF FF EF FF FF FF FF FF FF ................okdecimal ok5 squared . 25 ok: cubed DUP squared * ; okhex ok' cubed u. 5007 ok5000 20 dump 0 1 2 3 4 5 6 7 8 9 A B C D E F5000 16 41 04 16 43 37 3D 16 41 04 16 50 00 16 43 37 A C7= A P C75010 3D FF FF FF FF FF DB FF FF EF FF FF FF FF FF FF =...............okdecimal ok5 cubed . 125 ok

Page 7: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

WHYP12.CFGWHYP12.HEDtdp 5000vdp 800TORG 4000HEDBASE 4000RAMBASE 0900INCHAR 32OUTPUT 3BTPUSH 44TPOP 4DINWDY 58INWDX 61STOREW 6ATBLKST 75SNDSUB 8B2EESTART 1000EESTOP 1FFFlast berts_code 31set_flags -1

Page 8: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

SEE and SHOWsee squaredsquared DUP * ;okshow squaredsquared 16 41 4 16 43 37 3Doksee cubedcubed DUP squared * ;okshow cubedcubed 16 41 4 16 50 0 16 43 37 3Dok

Page 9: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Single Steppingok5 step squaredsquared DUP * ;S:[1] 5R:[0] DUPS:[2] 5 5R:[0] *S:[1] 19R:[0]Exit single stepok. 25 ok

Page 10: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Single Steppingok5 step cubedcubed DUP squared * ;S:[1] 5R:[0] DUPS:[2] 5 5R:[0] squaredS:[2] 5 19R:[0] *S:[1] 7DR:[0]Exit single stepok. 125 ok

Page 11: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Loading WHYP words from a file

square.whp\ Colon definition examples

: squared ( n -- n**2 ) \ compute the square of n DUP * ; \ multiply top of stack by itself

: cubed ( n -- n**3 ) \ compute the cube of n DUP \ n n squared \ n n**2 * ; \ n**3

Page 12: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Loading WHYP words from a fileC:\WHYP\WHYP12>whyp12Using WHYP12.HEDCommunicating with COM168HC12 WHYP12 - Version 4.6Press <Esc> or type BYE to exitokload square.whp\ Colon definition examples

: squared ( n -- n**2 ) \ compute the square of n DUP * ; \ multiply top of stack by itself

: cubed ( n -- n**3 ) \ compute the cube of n DUP \ n n squared \ n n**2 * ; \ n**3

Current value of target dp is 5011ok

Page 13: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

CR and ."Box 4.1 Some WHYP I/O Words

CR ( -- ) ( "carriage return" ) Produces a "carriage return" and line feed on the screen.

." ( -- ) ( "dot-quote" ) Prints a string consisting of characters to closing ".

: bar ( -- ) \ print a barCR ." ******" ;

: post ( -- ) \ print a postCR ." *"CR ." *"CR ." *" ;

Page 14: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

CR and ."Box 4.1 Some WHYP I/O Words

CR ( -- ) ( "carriage return" ) Produces a "carriage return" and line feed on the screen.

." ( -- ) ( "dot-quote" ) Prints a string consisting of characters to closing ".

: C ( -- ) \ print a Cbar post bar cr ;

: E ( -- ) \ print an Ebar postbar post bar cr;

Page 15: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

WHYP--An Extensible Language

• A Closer Look at WHYP• Defining New WHYP Words• Variables• Constants• EEPROM

Page 16: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

VariablesVARIABLE my.name

my.name . 800 ok

16 451E JSR (LIT)0800 08003D RTS

Stores the following code at tdp. my.name executes this code.

; (LIT) ( -- n ); Runtime routine for single literalsLIT

PULY ;Y -> numberLDD 0,Y ;Push numberSTD 2,-X ;on data stackINY ;jump over numberINYPSHYRTS

Page 17: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

VariablesC:\WHYP\WHYP12>whyp12Using WHYP12.HEDCommunicating with COM168HC12 WHYP12 - Version 4.6Press <Esc> or type BYE to exitokVARIABLE my.name okhex ok' my.name u. 5000 ok5000 20 dump 0 1 2 3 4 5 6 7 8 9 A B C D E F5000 16 45 1E 08 00 3D FF FF FF FF FF FF FF FF FB FF E =..........5010 FF FF FF FF FF FF DB FF FF EF FF FF FF FF FF FF ................okmy.name . 800 ok

Variables are stored in memory at address vdp.The value of vdp can be changed by pressing F8.VHERE puts the current value of vdp on the data stack.

Page 18: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Fetch and StoreBox 4.2 RAM Memory Access Words

! ( n addr -- ) ( "store" ) Stores the 16-bit value of n at address addr.

@ ( addr -- n ) ( "fetch" )Reads the value at address addr and puts it on the data stack.

C! ( c addr -- ) ("C-store")Stores the least significant byte (LSB) of the value on top of the stack at address addr.

C@ ( addr -- c ) ("C-fetch")Reads the byte at address addr and leaves it as the least significant byte (LSB)on top of the stack.

+! ( n addr -- ) ("plus-store")Add n to the value at address addr.

2! ( d addr -- ) ( "2-store" ) Stores the 32-bit value of d at address addr.

2@ ( addr -- d ) ( "2-fetch" )Reads the double number at address addr and puts it on the data stack.

Page 19: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Examples of @ and !C:\WHYP\WHYP12>whyp12Using WHYP12.HEDCommunicating with COM168HC12 WHYP12 - Version 4.6Press <Esc> or type BYE to exit

okVARIABLE my.name okhex okmy.name . 800 ok7 my.name ! ok800 10 dump

0 1 2 3 4 5 6 7 8 9 A B C D E F0800 00 07 86 80 52 00 80 02 09 00 28 18 90 00 83 00 ..R . ( . .

okmy.name @ . 7 ok12 my.name c! ok34 my.name 1+ c! ok800 10 dump

0 1 2 3 4 5 6 7 8 9 A B C D E F0800 12 34 86 80 52 00 80 02 09 00 28 18 90 00 83 00 4..R . ( . .

okmy.name c@ . 12 okmy.name 1+ c@ . 34 ok

Page 20: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

68HC12 code for !, @, C!, and C@; ! ( w a -- )STORE

LDY 2,X+ ;Y=a, pop data stack in YMOVW 2,X+,0,Y ;store w at aRTS

; @ ( a -- w )AT

LDY 0,X ;Y = aMOVW 0,Y,0,X ;w = @YRTS

; C! ( c b -- )CSTOR

LDY 2,X+ ;Y=bLDD 2,X+ ;D = cSTAB 0,Y ;store c at bRTS

; C@ ( b -- c )CAT

LDY 0,X ;Y=bCLRA LDAB 0,YSTD 0,XRTS

Page 21: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Plus-store1 my.name +!

; +! ( n addr -- ) add n to @addrPSTORE

LDY 2,X+ ;Y = addrLDD 0,Y ;D = @addrADDD 2,X+ ;add n to @addrSTD 0,YRTS

Page 22: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

68HC12 code for 2!, and 2@

; 2! ( d a -- ) store double wordLDY 2,X+ ;Y = aMOVW 2,X+,2,Y+ ;store dHMOVW 2,X+,0,Y ;store dLRTS

; 2@ ( a -- d ) fetch double wordLDY 2,X+ ;Y = aMOVW 2,Y,2,-X ;push dL on data stackMOVW 0,Y,2,-X ;push dH on data stackRTS

Page 23: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

System Variables: SP0, RP0

STACK EQU RAMBASE+$100 ;initial system stack pointerDATSTK EQU RAMBASE+$80 ;initial data stack pointer****** WHYP System Variables ******SP0 EQU RAMBASE ;initial data stack pointerRP0 EQU RAMBASE+$02 ;initial return stack pointer

; DEPTH ( -- n ) return #items on stackDEPTH

STX 2,-X ;save data stack ptrLDD SP0SUBD 0,X ;#bytes = SP0 - XASRARORB ;D = #stack itemsSTD 0,X ; if neg, underflowRTS

Page 24: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

ArraysVARIABLE my.array 8 VALLOT

my.array my.array[0]my.array + 2 my.array[1]my.array + 4 my.array[2]my.array + 6 my.array[3]my.array + 8 my.array[4]

vdp -->

my.array 3 2* + @ .

will print the value of my.array[3]

Page 25: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

ArraysVARIABLE my.array 8 VALLOT

my.array 3 2* + @ .

will print the value of my.array[3]

: A@ ( ix addr -- n ) SWAP 2* + @ ;

3 my.array A@ .

Chap 13: 3 my.array @ . 1234 3 my.array !

Page 26: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

WHYP--An Extensible Language

• A Closer Look at WHYP• Defining New WHYP Words• Variables• Constants• EEPROM

Page 27: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Constants25 CONSTANT quarter

16 451E JSR (LIT)0019 00193D RTS

Stores the following code at tdp. quarter executes this code.

quarter .

will print the value 25 on the screen.

Page 28: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Examples of using CONSTANTsHEX0024 CONSTANT PORTH0025 CONSTANT DDRH0028 CONSTANT PORTJ0029 CONSTANT DDRJ

FF DDRH C!00 DDRJ C!3A PORTH C!PORTJ C@ .

Page 29: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

TablesCREATE table

CFA JSR DOVAR <---- tablePFA <---- tdp

; DOVAR ( -- a ) (leave pfa on data stack);Run time code for CREATE

DOVARPULY ;get return addr (pfa)STY 2,-X ;push on data stackRTS ;return one level up

Page 30: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Box 4.3 WHYP Words to Insert Data into Target Memory

, ( n -- ) ( "comma" )Store the value n at the location pointed to by the target dictionary pointer, tdp,and increment tdp by 2. Will comma data into EEPROM.

C, ( c -- ) ( "C-comma" )Store the byte c at the location pointed to by the target dictionary pointer, tdp,and increment tdp by 1. Will C-comma data into EEPROM.

HEXCREATE table5 , 8 , 23 ,

CFA JSR DOVAR <---- tablePFA $5 0

$8 1$23 2

: @table ( ix -- n ) 2* table \ 2*ix pfa + @ ; \ @(pfa + 2*ix)

Page 31: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

C:\WHYP\WHYP12>whyp12Using WHYP12.HEDCommunicating with COM168HC12 WHYP12 - Version 4.6Press <Esc> or type BYE to exitokCREATE table okhex ok' table u. 5000 ok5000 10 dump 0 1 2 3 4 5 6 7 8 9 A B C D E F5000 16 46 AA FF FF FF FF FF FF FF FF FF FF FF FF FF F..............ok' dovar u. 46aa okhere u. 5003 oktable u. 5003 ok5 , 8 , 23 , ok5000 10 dump 0 1 2 3 4 5 6 7 8 9 A B C D E F5000 16 46 AA 00 05 00 08 00 23 FF FF FF FF FF FF FF F. #.......okhere u. 5009 ok ok: @table 2* table + @ ; ok2 @table . 23 ok

Example of creating a table

Page 32: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Box 4.3 WHYP Words to Insert Data into Target Memory

, ( n -- ) ( "comma" )Store the value n at the location pointed to by the target dictionary pointer, tdp,and increment tdp by 2. Will comma data into EEPROM.

C, ( c -- ) ( "C-comma" )Store the byte c at the location pointed to by the target dictionary pointer, tdp,and increment tdp by 1. Will C-comma data into EEPROM.

HEXCREATE table5 C, 8 C, 23 C,

CFA JSR DOVAR <---- tablePFA $5 0

$8 1$23 2

: C@table ( ix -- c ) table + C@ ;

Page 33: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

EEPROM

• MC68HC812A4– 4 Kbytes of EEPROM– $1000 - 1FFF

• MC68HC912B32– 768 bytes of EEPROM– $0D00 - $0FFF

Page 34: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

EEPROM Initial Position Register

7 6 5 4 3 2 1 0$0012 EE15 EE14 EE13 EE12 0 0 0 EEON INITEE

EE[15:12]: Internal EEPROM map positionUpper four bits of 16-bit EEPROM address.

EEON: Internal EEPROM On (Enable)0 – Disable EEPROM1 – Enable EEPROM (Default on reset)

Page 35: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

MC68HC812A4 EEPROMBlock Protect Register

7 6 5 4 3 2 1 0$00F1 1 BPROT6 BPROT5 BPROT4 BPROT3 BPROT2 BPROT1 BPROT0 EEPROT

BPROT[6:0]: EEPROM Block Protection0 – Associated EEPROM block can be programmed and erased.1 – Associated EEPROM block can not be programmed and erased.

Table 4.1 4-Kbyte EEPROM Block ProtectionBit Name Block Protected Block SizeBPROT6 $1000 to $17FF 2048 BytesBPROT5 $1800 to $1BFF 1024 BytesBPROT4 $1C00 to $1DFF 512 BytesBPROT3 $1E00 to $1EFF 256 BytesBPROT2 $1F00 to $1F7F 128 BytesBPROT1 $1F80 to $1FBF 64 BytesBPROT0 $1FC0 to $1FFF 64 Bytes

Page 36: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

MC68HC912B32 EEPROMBlock Protect Register

7 6 5 4 3 2 1 0$00F1 1 1 1 BPROT4 BPROT3 BPROT2 BPROT1 BPROT0 EEPROT

BPROT[4:0]: EEPROM Block Protection0 – Associated EEPROM block can be programmed and erased.1 – Associated EEPROM block can not be programmed and erased.

Table 4.2 768-Byte EEPROM Block ProtectionBit Name Block Protected Block SizeBPROT4 $0D00 to $0DFF 256 BytesBPROT3 $0E00 to $0EFF 256 BytesBPROT2 $0F00 to $0F7F 128 BytesBPROT1 $0F80 to $0FBF 64 BytesBPROT0 $0FC0 to $0FFF 64 Bytes

In WHYP12: CLR EEPROT

Page 37: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

The EEPROM Control Register7 6 5 4 3 2 1 0

$00F3 BULKP 0 0 BYTE ROW ERASE EELAT EEPGM EEPROG

BULKP: Bulk Erase Protection0 – EEPROM can be bulk erased .1 – EEPROM is protected from being bulk or row erased. (Default on reset)

BYTE: Byte and Aligned Word Erase0 – Bulk or row erase is enabled1 – One byte or one aligned word erase only.Has no effect when ERASE = 0.

ROW: Row or Bulk Erase (when BYTE = 0)0 – Erase entire EEPROM array.1 – Erase only one 32-byte row.Has no effect when ERASE = 0.

ERASE: Erase Control0 – EEPROM configured for programming.1 – EEPROM configured for erasure.

EELAT: EEPROM Latch Control0 – EEPROM set up for normal reads.1 – EEPROM address and data bus latches set up for programming orerasing. Can only write to if EEPGM = 0.

EEPGM: Program and Erase Enable0 – Disables program/erase voltage to EEPROM1 – Applies program/erase voltage to EEPROM

Page 38: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Erasing an EEPROM Byte7 6 5 4 3 2 1 0

$00F3 BULKP 0 0 BYTE ROW ERASE EELAT EEPGM EEPROG

; ERASE BYTE AT ADDRESS YBYTEE

LDAB #$16STAB EEPROG ;set to byte erase modeSTAB 0,Y ;write any data to addr to eraseLDAB #$17STAB EEPROG ;turn on high voltageJSR DLY10 ;10 msec delayLDAB #$16STAB EEPROG ;turn off hi voltageCLR EEPROG ;clear EELAT bitRTS

Page 39: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Delay 10 Milliseconds

; 10MS.DELAY ( -- ) ; 8 MHz clockDLY10 ; 4*N + 12 = 80000

PSHX ; 2 cyclesLDX #19997 ; 2 " N = 19997

DL1 DEX ; 1 "BNE DL1 ; 3 "PULX ; 3 "RTS ; 5 "

Page 40: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Erase Entire EEPROM7 6 5 4 3 2 1 0

$00F3 BULKP 0 0 BYTE ROW ERASE EELAT EEPGM EEPROG

; ERASE.BULK ( -- )BULKE

LDAB #$06STAB EEPROG ;set to bulk erase modeSTAB EESTART ;write any data to EEPROMLDAB #$07STAB EEPROG ;turn on high voltageBSR DLY10 ;10 msec delayLDAB #$06STAB EEPROG ;turn off high voltageLDAB #$00STAB EEPROG ;clear EELAT bitRTS

Page 41: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Program an EEPROM Byte7 6 5 4 3 2 1 0

$00F3 BULKP 0 0 BYTE ROW ERASE EELAT EEPGM EEPROG

; EEPROM PROGRAMMING ROUTINES; STORE BYTE A AT ADDRESS YEESTA

PSHA ;save byteLDAA 0,Y ;if @addr != FFCMPA #$FFBEQ EEB1BSR BYTEE ;erase byte

EEB1 PULA ;get byteLDAB #$02STAB EEPROG ;set EELAT bitSTAA 0,Y ;store data to EEPROM addrLDAB #$03STAB EEPROG ;set EEPGM bit (EELAT=1)JSR DLY10 ;10 msec delayLDAB #$02STAB EEPROG ;turn off hi voltageCLR EEPROG ;clear EELAT bitRTS

; STORE WORD D AT ADDRESS Y AND Y+1EESTD

PSHBBSR EESTAINYPULABSR EESTARTS

Page 42: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Box 4.4 EEPROM Memory Access Words

EEC! ( c addr -- ) ("E-E-C-store")Stores the least significant byte (LSB) of the value on top of the stack atthe EEPROM address addr.

EE! ( n addr -- ) ( "E-E-store" ) Stores the 16-bit value of n at the EEPROM address addr.

ERASE.BULK ( -- )Erases the entire EEPROM by storing $FF in all EEPROM addresses.

; EEC! ( c addr -- )EECST

LDY 2,X+LDD 2,X+TBAJSR EESTARTS

; EE! ( n addr -- )EEST

LDY 2,X+LDD 2,X+JSR EESTDRTS

Page 43: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Examples of using EEPROMmemory access words

C:\WHYP\WHYP12>whyp12Using WHYP12.HEDCommunicating with COM168HC12 WHYP12 - Version 4.6Press <Esc> or type BYE to exitokhex ok1000 10 dump 0 1 2 3 4 5 6 7 8 9 A B C D E F1000 11 12 34 FF FF FF FF FF FF FF FF FF FF FF FF FF4.............okerase.bulk ok1000 10 dump 0 1 2 3 4 5 6 7 8 9 A B C D E F1000 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF................ok55 1000 eec! ok1000 10 dump 0 1 2 3 4 5 6 7 8 9 A B C D E F1000 55 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FFU...............ok6789 1001 ee! ok1000 10 dump 0 1 2 3 4 5 6 7 8 9 A B C D E F1000 55 67 89 FF FF FF FF FF FF FF FF FF FF FF FF FFUg..............ok

Page 44: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

C:\WHYP\WHYP12>whyp12Using WHYP12.HEDCommunicating with COM168HC12 WHYP12 - Version 4.6Press <Esc> or type BYE to exitokerase.bulk okhex ok1000 20 dump 0 1 2 3 4 5 6 7 8 9 A B C D E F1000 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF................1010 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF................ok <press function key F9>Current value of target dp is 5000Enter a new hex value for tdp (5000): 1000Value of tdp is 1000load square.whp\ Colon definition examples

: squared ( n -- n**2 ) \ compute the square of n DUP * ; \ multiply top of stack by itself

: cubed ( n -- n**3 ) \ compute the cube of n DUP \ n n squared \ n n**2 * ; \ n**3

Current value of target dp is 1011ok1000 20 dump 0 1 2 3 4 5 6 7 8 9 A B C D E F1000 16 41 08 16 43 3B 3D 16 41 08 16 10 00 16 43 3B A C;= AC;1010 3D FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF=...............okdecimal ok5 squared . 25 ok5 cubed . 125 oksave.headersEnter a filename for header names: square.hedok

Page 45: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

square.hedcubed 1007squared 1000calc.output 48d0firerules 48b6fill.weights 48a2SNDSUB 4895DUMP 487bCMOVE> 47beCMOVE 47aaMOVE 4796----- ----

Page 46: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

whyp12.cfgSQUARE.HEDtdp 5000vdp 800TORG 4000HEDBASE 0000RAMBASE 0900INCHAR 35OUTPUT 3ETPUSH 47TPOP 50INWDY 5BINWDX 64STOREW 6DTBLKST 78SNDSUB 88fEESTART 1000EESTOP 1FFFlast berts_code 34set_flags -1

Page 47: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

Box 4.5 Other WHYP Words Introduced in Chapter 4

: ( -- ) ( "colon" )Used to define a new WHYP word using the following format:: <name> --- --- --- ;

; ( -- ) ( "semi-colon" )Used to end a colon definition.

' ( -- cfa ) ( "tick" -- a single quote )The statement ' <name> will leave the CFA of <name> on the data stack.

ALLOT ( n -- )Allocates n bytes of memory by incrementing tdp by n.

DUMP ( addr len -- )Display a block of memory of length len starting at address addr. The value of len isthe number of bytes to display; however, DUMP always displays multiples of 16 bytes.

Page 48: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

SEE ( -- )SEE <name> will decompile the WHYP definition of <name>.

SHOW ( -- )SHOW <name> will display the machine code of <name>.

STEP ( <name_stack> -- )STEP <name> will single-step through the WHYP words making up <name>.The data stack must contain the values expected by <name> before STEP is called.Pressing the space bar single-steps the next instruction. Pressing q quits STEP.

LOAD ( -- )LOAD <filename> will load the file <filename> containing colon definitions.

VARIABLE ( -- )VARIABLE <name> will define <name> to be a variable.

DEPTH ( -- n )Returns the number of items on the data stack.

VALLOT ( n -- )Allocates n bytes of RAM memory by incrementing vdp by n.

Page 49: WHYP -- An Extensible Language

Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell

CONSTANT ( n -- )n CONSTANT <name> will define <name> to be a constant with value n.

CREATE ( -- )CREATE <name> will add <name> to the dictionary and compile a JSR DOVARat its CFA. Executing <name> will put its PFA on the data stack.

HERE ( -- n )Puts the current value of the target dictionary pointer, tdp, on the data stack.

VHERE ( -- n )Puts the current value of the variable dictionary pointer, vdp, on the data stack.

10MS.DELAY ( -- )Produces a 10 millisecond delay.

\ ( -- n ) ("backslash")All characters following \ to the end of the line are treated as a comment.

( ( -- n ) ("paren")All characters between ( and a closing ) are treated as a comment.


Recommended