Motorola 68HC08 Hello World
I have a MC68HC908JB8 that I know exactly diddly about. This is an attempt to piece together a simple "Hello World" program in assembly. I want to be able to hook the chip up to a USB port and read the device name. I'm working primarily from the code from the usb-ir-boy project. This code is heavily commented in hopes that I can gain a clue.
I spent several hours trying to understand the SCI interface before noticing that my microcontroller doesn't have one.
SCC1 = $0013
This is a variable definition. This is the address of the Serial Communication Interface (SCI) Control Register #1. From the documentation, this register is:
$0013 | Read: |
LOOPS |
ENSCI |
TXINV |
M |
WAKE |
ILTY |
PEN |
PTY |
Write: |
SCC2 = $0014
SCI Control Register #2:
$0014 | Read: |
SCTIE |
TCIE |
SCRIE |
ILIE |
TE |
RE |
RWU |
SBK |
Write: |
SCC3 = $0015
SCI Control Register #3:
$0015 | Read: |
R8 |
T8 |
R |
R |
ORIE |
NEIE |
FEIE |
PEIE |
Write: | |
SCS1 = $0016
SCI Status Register #1:
$0016 | Read: |
SCTE |
TC |
SCRF |
IDLE |
OR |
NF |
FE |
PE |
Write: |
R |
R |
R |
R |
R |
R |
R |
R |
SCS2 = $0017
SCI Status Register #2:
$0017 | Read: |
0 | 0 | 0 | 0 | 0 | 0 |
BKF |
RPF |
Write: |
R |
R |
R |
R |
R |
R |
R |
R |
SCDR = $0018
SCI Data Register: Read and write data from the SCI
SCBR = $0019
SCI Baud Rate Register:
$0019 | Read: | 0 | 0 |
SCP1 |
SCP0 |
|
SCR2 |
SCR1 |
SCR0 |
Write: | | |
PPG = $001E
PLL Programming Register (PPG):
$001E | Read: |
MUL7 |
MUL6 |
MUL5 |
MUL4 |
VRS7 |
VRS6 |
VRS5 |
VRS4 |
Write: |
MOR = $001F
Mask Option Register (MOR):
$001F | Read: | 0 |
ROMSEC |
LVIRSTD |
LVIPWRD |
SSREC |
COPL |
STOP |
COPD |
Write: |
R |
R |
R |
R |
R |
R |
R |
UCR0 = $003B
UCR1 = $003C
USB Control Register 1:
$003C | Read: |
T1SEQ |
STALL1 |
TX1E |
FRESUM |
TP1SIZ3 |
TP1SIZ2 |
TP1SIZ1 |
TP1SIZ0 |
Write: |
UCR2 = $0019
USB Control Register 2:
$0019 | Read: |
T2SEQ |
STALL2 |
TX2E |
RX2E |
TP2SIZ3 |
TP2SIZ2 |
TP2SIZ1 |
TP2SIZ0 |
Write: |
UCR3 = $001A
USB Control Register 3:
$001A | Read: |
TX1ST |
0 |
OSTALL0 |
ISTALL1 |
0 |
PULLEN |
ENABLE2 |
ENABLE1 |
Write: | |
TX1STR |
|
UCR4 = $001B
USB Control Register 4:
$001B | Read: |
0 | 0 | 0 | 0 | 0 |
FUSBO |
FDP |
FDM |
Write: | | | | | |
USR0 = $003D
USB Status Register 0:
$003D | Read: |
R0SEQ |
SETUP |
0 |
0 |
RP0SIZ3 |
RP0SIZ2 |
RP0SIZ1 |
RP0SIZ0 |
Write: |
| | | |
| | | |
USR1 = $003E
USB Status Register 1:
$003E | Read: |
R2SEQ |
TXACK |
TXNAK |
TXSTL |
RP2SIZ3 |
RP2SIZ2 |
RP2SIZ1 |
RP2SIZ0 |
Write: |
| | | |
| | | |
UE0D0 = $0020
USB Endpoint 0 Data Register 0: First of eight read/write data registers (UE0D7
= $0027
)
UE1D0 = $0028
USB Endpoint 1 Data Register 0: First of eight write only data registers (UE1D7
= $002F
)
UE2D0 = $0030
USB Endpoint 2 Data Register 0: First of eight read/write data registers (UE2D7
= $0037
)
UIR0 = $0039
USB Interrupt Register 0:
$0039 | Read: |
EOPIE |
SUSPND |
TXD2IE |
RXD2IE |
TXD1IE |
0 |
TXD0IE |
RXD0IE |
Write: | |
UIR1 = $003A
USB Interrupt Register 1:
$003A | Read: |
EOPF |
RSTF |
TXD2F |
RXD2F |
TXD1F |
RESUMF |
TXD0F |
RXD0F |
Write: |
| | | |
| | | |
UIR2 = $0018
USB Interrupt Register 1:
$0018 | Read: |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Write: |
EOPFR |
RSTFR |
TXD2FR |
RXD2FR |
TDX1FR |
RESUMFR |
TXD0FR |
RXD0FR |
UADDR = $0038
USB Interrupt Register 1:
$0018 | Read: |
USBEN |
UADD6 |
UADD5 |
UADD4 |
UADD3 |
UADD2 |
UADD1 |
UADD0 |
Write: |
FLASH = $8000
I don't really get this. According to the docs, this is in the $0A00
- $ADFF
range that is "Unimplemented"
VECTORS = $FFFE
This is the address of the Reset Vector
.area GSINIT0
Don't know what this means, just copied it from the sdcc generated assembly
entry::
I'm pretty sure double colons specify an exported entry point
ldhx #$0140
Load H:X from M
H:X is the 2-byte "Index Register"
txs
Transfer H:X to SP
So the previous $0140
becomes the value of the Stack Pointer. This is the end of RAM which goes from $0040
- $013F
. This makes sense because the stack pointer decrements during pushes and increments during pulls.
mov #$80, UADDR
Sets the USBEN
bit, enabling the USB module
mov #$3B, UIR0
Enable all Tx/Rx interrupts (TXD2IE | RXD2IE | TXD1IE | TXD0IE | RXD0IE)
mov #$FF, UIR2
Reset all flags
jsr __HC08Setup
Jump to Subroutine
jsr _main
done: bra done
Branch Always
So, this is an endless loop for some reason
__HC08Setup:
mov #$01,MOR ; disable Watchdog
mov #$01,PPG ; select proper Clock Source for SCI
rts
;-----------------------------------------------------------------------------
; void initSCI();
;
_initSCI:: mov #$40,SCC1 ; Enable SCI
mov #$0c,SCC2 ; RE+TE
;
; Baudrate Calculation for 4.9152 MHz XTAL
;-----------------------------------------------
; BaudRate = ClockSource / (64 * Divisor)
; if ClockSource = BusClock = XTAL/4
; (set SCIBDSCR Bit in OPTION2!) then
; BaudRate = 4.9152 MHz / (4 * 64 * SCP * SCR)
; BaudRate = 19200 Baud / (SCP * SCR)
;-----------------------------------------------
; Rem: in Monitor Mode BusClock = XTAL/2!
;
mov #$00,SCBR ; 19200 Baud
rts
;-----------------------------------------------------------------------------
; putSCI(char c);
;
_putSCI:: brclr #7,*SCS1,_putSCI ; check SCTE flag
sta SCDR
rts
; char getSCI();
;
_getSCI:: brclr #5,*SCS1,_getSCI ; check SCRF flag
lda SCDR
rts
_putchar = _putSCI
_getchar = _getSCI
;-----------------------------------------------------------------------------
; void puts(char *s);
;
_puts:: psha
;
; load HX with integer argument from stack
;
ldx 4,sp
pshx
ldx 6,sp
pulh
;
putsloop: lda ,x
beq putsexit
jsr _putchar
aix #1
bra putsloop
putsexit: pula
rts
;-----------------------------------------------------------------------------
_main:: jsr _initSCI
;
clrh
clrx
delay1: aix #-1
cphx #0
bne delay1
;
mainloop: ldhx #message
pshx
pshh
jsr _puts
ais #2
jsr _getchar
bra mainloop
rts
;-----------------------------------------------------------------------------
message: .ascii "\r\n\r\n"
.ascii "HC08 Welcome Kit\r\n"
.ascii "http://elektronikladen.de/kit08.html\r\n"
.byte 0
;-----------------------------------------------------------------------------
.area memory(abs)
.org VECTORS
.word entry
;-----------------------------------------------------------------------------