///////////////////////////////////////////////////////////////////////////////////////
LCD部分
///////////////////////////////////////////////////////////////////////////////////////
DATA RAM
; LCD Buffer, 已经转成对应显示的代码,可以直接写入LCD
LCDBuffer0 BYTE
LCDBuffer1 BYTE
LCDBuffer2 BYTE
LCDBuffer3 BYTE
NumberShow BYTE
FlagFlash BYTE
ShowStatus BYTE
NumberShow WORD ;要被显示在LCD上的数
Dividend WORD ;被除数
Divisor WORD ;除数
Quotient WORD ;商
Mode WORD ;余数
CODE
;=================================================================================
;Function InitialLCD(void) 初始化LCD
InitialLCD FUNCTION
CALL ClearCS
MOVE [R0],10000000b ;sys en. CommAND format:100;(commAND ID)
MOVE [R1],00000000b
MOVE [R2],00000000b
MOVE [R3],01000000b ;打开LCD 的SYS时钟OSCILLATOR
MOVE X,00000011b ;take three bits
MOVE A,[R0]
CALL write
MOVE X,00000011b
MOVE A,[R1]
CALL write
MOVE X,00000011b
MOVE A,[R2]
CALL write
MOVE X,00000011b
MOVE A,[R3]
CALL write
lcall delaylong
lcall delaylong
MOVE [R1],00100000b ;If successive commAND have been issued
MOVE [R2],01000000b ;the commAND ID mode , namely 100,can be
MOVE [R3],01000000b ;omitted.
MOVE X,00000011b
MOVE A,[R1]
CALL write
MOVE X,00000011b
MOVE A,[R2]
CALL write
MOVE X,00000011b
MOVE A,[R3]
CALL write
MOVE [LCDBuffer0], 0
MOVE [LCDBuffer1], 0
MOVE [LCDBuffer2], 0
MOVE [LCDBuffer3], 0
RET
InitialLCD ENDF
;=================================================================================
;Function UpdateLCD() 将LCDBuffer0-4的内容全部写入LCD
;Input: LCDBuffer0 - 4
UpdateLCD FUNCTION
CALL SetCS ;CS = 1
MOVE [R1],10100000b ;write datas to ddram(this is a commAND)
MOVE [R2],00000000b ;ddram start address
MOVE A,[R1] ;commAND ID ,can sent once only.
MOVE X,00000011b ;DATA format:101(commAND ID)a5a4a3a2a1a0 (address-code)
CALL write ;d0d1d2d3(display data).
MOVE X,00000110b ;six bits address
MOVE A,[R2]
CALL write
MOVE [R3],00000100b ;R3 表示写入四个字节,每字节写两次
MOVE PTR, LCDBuffer0 ;PTR 等于LCDBuffer0 到 LCDBuffer3 的内存地址
@ MOVE A,[PTR] ;display data;
MOVE X,00001000b ;Eight bits display data
CALL write ;写入8个Bits 数据到LCD DRAM
INC PTR
DEC [R3]
JNZ [R3], @b
RET
UpdateLCD ENDF
;=================================================================================
;Function ShowTime()
;=================================================================================
ShowTime FUNCTION
MOVE [NumberShow],A
CALL ShowNumbers
RET
CALL ShowDots
MOVE A,[FlagFlash]
MOVE [ShowStatus],A
RET
ShowTime ENDF
;=================================================================================
;Function ShowNumbers(NumberShow); 显示多位数字,将每位数字转换成LCDBuffer, 然后统一调用
; UpdateLCD()函数
;Input: NumberShow
ShowNumbers FUNCTION
PUSH AX ;AX 要存储除法的余数,所以先保存起来
MOVE AX, [NumberShow]
MOVE [Dividend], AX ;AX = NumberShow
MOVEW [Divisor], 10000 ;求出千位数
CALL DIV16 ;此时余数ax为千位以内
;显示千位数
MOVE [Dividend], AX
MOVEW [Divisor], 1000
CALL DIV16 ;此时商为千位数,余数在ax里
MOVE [Dividend], AX
MOVE A, 0
MOVE X, [Quotient]
CALL ShowOneNumber
;显示百位数
MOVEW [Divisor], 100
CALL DIV16 ;此时商为百位数,余数在ax里
MOVE [Dividend], AX
MOVE A, 1
MOVE X, [Quotient]
CALL ShowOneNumber
;显示十位数
MOVEW [Divisor], 10
CALL DIV16 ;此时商为十位数,余数在ax里
MOVE [Dividend], AX
MOVE A, 2
MOVE X, [Quotient]
CALL ShowOneNumber
;显示个位数
MOVEW [Divisor], 1
CALL DIV16 ;此时商为个位数,余数在ax里
MOVE A, 3
MOVE X, [Quotient]
CALL ShowOneNumber
CALL UpdateLCD
POP AX
RET
ShowNumbers ENDF
;=================================================================================
;Function ShowOneNumber; 显示一个数字,显示数字时,不改变原来猫头与中间两点的显示
;Input: A,X
; A, 要显示在那个位置上 A = 0, 1, 2, 3
; 笑猫8 不高兴猫8 8 8
; X, 要显示的数据(目前支持0-9,日后可以考虑增加A-F)
ShowOneNumber FUNCTION
MOVE PTR, NumberTAB
ADD PTR, X
PUSH A
PUSH X
CMP A,00H
JNZ @BUFFER1 ; A != 0 时,转去判断是否为1
MOVE A, [LCDBuffer0] ;LCDBuffer0 & LCDBuffer1 需要判断星猫的图标,所以需要将图标的地址(第5位读出来与现在写入的数字进行或操作)
AND A, 00010000b
MOVE X, [PTR]
OR A, X
MOVE [LCDBuffer0], A
POP X
POP A
RET
@BUFFER1
CMP A, 01H
JNZ @BUFFER2 ; A != 1 时,转去判断是否为2
MOVE A, [LCDBuffer1]
AND A, 00010000b
MOVE X, [PTR]
OR A, X
MOVE [LCDBuffer1], A
POP X
POP A
RET
@BUFFER2
CMP A, 02H
JNZ @BUFFER3 ; A != 2 时,转去判断是否为3
MOVE A, [LCDBuffer2] ;LCDBuffer2 需要判断中间两点的图标,所以需要将图标的地址(第5位读出来与现在写入的数字进行或操作)
AND A, 00010000b
MOVE X, [PTR]
OR A, X
MOVE [LCDBuffer2], A
POP X
POP A
RET
@BUFFER3
CMP A, 03H
JNZ @f ; A != 3 时,表示A 在 0 -> 3 范围之外,则不处理
MOVE X, [PTR]
MOVE [LCDBUFFER3], X
POP X
POP A
@ RET
ShowOneNumber ENDF
;=================================================================================
;Function ShowFlags; 显示小数点,以及高兴及不高兴的标志
;Input: A
; A, A.0第一位,决定小数点上面的点是否点亮
; A.1第二位,决定小数点下面的点是否点亮
; A.2 第三位,决定星猫高兴的图标是否点亮
; A.3 第四位,决定星猫不高兴的图标是否点亮
ShowFlags FUNCTION
RET
ShowFlags ENDF
;=================================================================================
;Function ShowHappyCat; 显示高兴的标志, 则不高兴的猫自动熄灭
ShowHappyCat FUNCTION
;显示高兴猫
OR [LCDBuffer0], 00010000B
;熄灭不高兴猫
AND [LCDBuffer1], 11101111b
CALL UpdateLCD
RET
ShowHappyCat ENDF
;=================================================================================
;Function ShowUpsetCat; 显示不高兴的标志, 则高兴的猫自动熄灭
ShowUpsetCat FUNCTION
;显示不高兴猫
OR [LCDBuffer1], 00010000B
;熄灭高兴猫
AND [LCDBuffer0], 11101111b
CALL UpdateLCD
RET
ShowUpsetCat ENDF
;=================================================================================
;Function ShowDots; 显示2点
ShowDots FUNCTION
;显示2点
OR [LCDBuffer2], 00010000B
CALL UpdateLCD
RET
ShowDots ENDF
;=================================================================================
;Function ClearDots; 清除2点
ClearDots FUNCTION
;清楚2点
AND [LCDBuffer2], 11101111B
CALL UpdateLCD
RET
ClearDots ENDF
;=================================================================================
;Function Write(A,X)
write FUNCTION
CALL ClearCS ; CS = 0
@agn CALL ClearWRITE ;WR = 0
RCL A
JNC @f
CALL SetDATA ;DATA = 1
JUMP @@f
@ CALL ClearDATA ;DATA = 0
@@ CALL SetWRITE ;WR = 1
LOOP X,@agn
RET
write ENDF
;=================================================================================
;CS BYTE ; P2.0
;Function ClearCS
ClearCS FUNCTION
AND [PORT2_DATA], 11111110b ;CS = 0
RET
ClearCS ENDF
;Function SetCS
SetCS FUNCTION
OR [PORT2_DATA], 00000001b ;CS = 1
RET
SetCS ENDF
;=================================================================================
;DATAS BYTE ; P2.2
;Function ClearDATA
ClearDATA FUNCTION
AND [PORT2_DATA], 11111011b ;DATA = 0
RET
ClearDATA ENDF
;Function SetDATA
SetDATA FUNCTION
OR [PORT2_DATA], 00000100b ;DATA = 1
RET
SetDATA ENDF
;=================================================================================
;WR BYTE ; P2.1
;Function ClearWrite
ClearWRITE FUNCTION
AND [PORT2_DATA], 11111101b ;WRITE = 0
RET
ClearWRITE ENDF
;Function SetWRITE
SetWRITE FUNCTION
OR [PORT2_DATA], 00000010b ;WRITE = 1
RET
SetWRITE ENDF
;=================================================================================
;BACKLIGHT P2.3, 地电平点亮,所以高地置位正好相反
;Function ClearBackLight
ClearBackLight FUNCTION
OR [PORT2_DATA], 00001000b ;Backlight = 1
RET
ClearBackLight ENDF
;Function SetWRITE
SetBackLight FUNCTION
AND [PORT2_DATA], 11110111b ;Backlight = 0
RET
SetBackLight ENDF
;*********************************************************
;MOVE A,0100h
;MOVE X,0100h
;LOOP X,@
;LOOP A,@d22
;RET
;Function DELAY_20MS
DELAY_20MS FUNCTION
MOVEW [COUNT1],0100H
@@ MOVEW [COUNT2],0100H
@ DEC [COUNT2]
JNZ [COUNT2], @b
DEC [COUNT1]
JNZ [COUNT1], @@b
RET
DELAY_20MS ENDF
;Function DELAYLONG
DELAYLONG FUNCTION
MOVE A,00000100b
@ CALL DELAY_20MS
LOOP A,@b
RET
DELAYLONG ENDF
; 数字显示的代号
; -0- -1- -2- -3- -4- -5- -6- -7- -8- -9-
;NumberTAB DB 5fh,06h,6dh,4fh,36h,3dh,7dh,07h,7fh,3fh
NumberTAB DB afh,06h,6dh,4fh,c6h,cbh,ebh,0eh,efh,cfh
;Function DIV(Dividend, Divisor)
;Dividend 除以Divisor, 商在 Quotient, 余数 存在AX
DIV16 FUNCTION
MOVEW [Quotient], 00H
MOVE AX,[Dividend]
@
CMP AX, [Divisor]
JC @End
SUB AX, [Divisor]
INC [Quotient]
JUMP @b
@End
RET
DIV16 ENDF
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
MAIN()
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
INCLUDE "H61SMS.INC"
INCLUDE ".\SPEECH-LIB\H61_SPEECH.INC"
INCLUDE ".\MIDI-LIB\H61_MIDI.INC"
INCLUDE "LCD.ASM"
PUBLIC SPEECH_OFFS_ADDR
PUBLIC MUSIC_OFFS_ADDR
PUBLIC INSTRUMENT_ADDR
PUBLIC OPT_MAX_PSG_CH
PUBLIC OPT_MIDI_PSG_CH
PUBLIC OPT_PSG_MIX_RATE
PUBLIC FREQ_STEP_TABLE
;*******************************************************************************
;* USER WORKING MEMORY (VARIABLE DEFINITION) *
;*******************************************************************************
DATA RAM A0H
R0 BYTE
R1 BYTE
R2 BYTE
R3 BYTE
;DATAS ; P2.2
;CS ; P2.0
;WR ; P2.1
;BACKLIGHT ; P2.3
COUNT1 WORD
COUNT2 WORD
;*******************************************************************************
;* MAIN PROGRAM CODE START HERE *
;*******************************************************************************
CODE 001FFFH
DB FAH
CODE 002000H
RESET_START ;****************************************
;* POWER ON INIT *
;****************************************
CALL HX_INIT_SYSTEM_CLK
CALL HX_INIT_SPEECH_SYSTEM ; INITIATE SOUND SYSTEM (MIDI/SPEECH)
CALL HX_INIT_MIDI_SYSTEM
;***************************************************
;* INIT CLOCK TIMER0 TOMER1 *
;***************************************************
;****************************************
;* INIT I/O *
;****************************************
MOVE [PORT0_PH_MODE], 11111111B ;set pull high
MOVE [PORT0_IO_MODE], FFH ;set input
MOVE [PORT0_DATA], 00H
MOVE [PORT0_IRQ_MASK], 11111111B
MOVE [PORT0_IRQ_EDGE], 00H
MOVE [PORT1_PH_MODE], FFH
MOVE [PORT1_IO_MODE], FFH
MOVE [PORT1_DATA], 00H
MOVE [PORT2_PH_MODE], FFH ; PLS REFER APP. NOTE
MOVE [PORT2_IO_MODE], 00H
MOVE [PORT2_DATA], FFH
MOVE [PORT3_PH_MODE], FFH
MOVE [PORT3_IO_MODE], FFH
MOVE [PORT3_DATA], 00H
;****************************************
;* INIT SYSTEM TIMER *
;****************************************
MOVE [TIMER0_RELOAD], (SYSTEM_CLOCK/64/T0_IRQ_RATE) ; T0 RELOAD
MOVE [TIMER1_RELOAD], (BASE_CLOCK/8/T1_IRQ_RATE) ; T1 RELOAD
MOVE [TIMER_CONTROL], 10011011B ; TIMER CONTROL
;****************************************
;* INIT INTERRUPT *
;****************************************
MOVE [IRQ_ENABLE], 00000111B ; ENABLE T0, T1 INT
;MOVEW [IRQ_VECTOR], IRQ_PROCESS ; SET INTERRUPT ENTRY ADDRESS
STI
; ENABLE INTERRUPT
MOVE [R0], 00H
MOVE [R1], 00H
MOVE [R2], 00H
MOVE [R3], 00H
;CALL SetBackLight ;点亮LCD背光
CALL ClearBackLight ;关闭LCD背光
;***************************************************
;* *
;***************************************************
JUMP @START
;****************************************************************
; 用高位三位为命令代码
;****************************************************************
@START
CALL InitialLCD
;点亮全部
;lcd on.If succesive commANDs have been
MOVE [R1],00000000b ;issued, the commAND mode ID, namely 100
MOVE [R2],00000000b ;can be omitted.
MOVE [R3],11000000b
MOVE X,00000011b
MOVE A,[R1]
CALL write
MOVE X,00000011b
MOVE A,[R2]
CALL write
MOVE X,00000011b
MOVE A,[R3]
CALL write
;run to here,all contents will display on the lcd
;If successive commANDs have been issued
;**************************
;commAND mode ID, namely 100,can be omitted.
CALL ClearCS
CALL SetCS
MOVE [R1],10100000b ;write datas to ddram(this is a commAND)
MOVE [R2],00000000b ;ddram start address
MOVE A,[R1] ;commAND ID ,can sent once only.
MOVE X,00000011b ;DATA format:101(commAND ID)a5a4a3a2a1a0 (address-code)
CALL write ;d0d1d2d3(display data).
MOVE X,00000110b ;six bits address
MOVE A,[R2]
CALL write
MOVE [R3],00001101b ;13
MOVE PTR,tab1
@sent
MOVE A,[PTR] ;display data
MOVE X,00000100b ;four bits display data
CALL write ;全显示
INC PTR
DEC [R3]
JNZ [R3], @sent ;LOOP MTR,@sent ;;YJW MODIFIED
;************************
CALL DelayLong
CALL DelayLong
CALL DelayLong
CALL DelayLong
; two screen ************************
CALL SetCS ;CS = 1
MOVE [R1],10100000b ;write datas to ddram(this is a commAND)
MOVE [R2],00000000b ;ddram start address
MOVE A,[R1] ;commAND ID ,can sent once only.
MOVE X,00000011b ;DATA format:101(commAND ID)a5a4a3a2a1a0 (address-code)
CALL write ;d0d1d2d3(display data).
MOVE X,00000110b ;six bits address
MOVE A,[R2]
CALL write
MOVE [R3],00001101b
MOVE PTR,tab2
@sent2
MOVE A,[PTR] ;display data;
MOVE X,00000100b ;four bits display data
CALL write ; 显示: 111111
INC PTR
DEC [R3]
JNZ [R3], @sent2
;************************
CALL DelayLong
CALL DelayLong
;three screen************
CALL SetCS ;cs = 1
MOVE [R1],10100000b ;write datas to ddram(this is a commAND)
MOVE [R2],00000000b ;ddram start address
MOVE A,[R1] ;commAND ID ,can sent once only.
MOVE X,00000011b ;DATA format:101(commAND ID)a5a4a3a2a1a0 (address-code)
CALL write ;d0d1d2d3(display data).
MOVE X,00000110b ;six bits address
MOVE A,[R2]
CALL write
MOVE [R3],00001101b
MOVE PTR,tab3
@sent3
MOVE A,[PTR] ;display data
MOVE X,00000100b ;four bits display data
CALL write ; 显示:222222 KWH
INC PTR
DEC [R3]
JNZ [R3], @sent3
CALL SetCS ;CS = 1
CALL DelayLong
CALL DelayLong
;four screen************
CALL SetCS ;cs = 1
MOVE [R1],10100000b ;write datas to ddram(this is a commAND)
MOVE [R2],00000000b ;ddram start address
MOVE A,[R1] ;commAND ID ,can sent once only.
MOVE X,00000011b ;DATA format:101(commAND ID)a5a4a3a2a1a0 (address-code)
CALL write ; d0d1d2d3(display data).
MOVE X,00000110b ;six bits address
MOVE A,[R2]
CALL write
MOVE [R3],00001101b
MOVE PTR,tab4
@sent4
MOVE A,[PTR] ;display data
MOVE X,00000100b ;four bits display data
CALL write ; 显示: 333333
INC PTR
DEC [R3]
JNZ [R3],@sent4
CALL SetCS ;cs = 1
CALL DelayLong
CALL DelayLong
CALL ShowHappyCat
CALL DelayLong
CALL DelayLong
MOVEW [NumberShow], 1234
CALL ShowNumbers
CALL DelayLong
CALL DelayLong
MOVEW [NumberShow], 2345
CALL ShowNumbers
CALL DelayLong
CALL DelayLong
MOVEW [NumberShow], 3456
CALL ShowNumbers
CALL DelayLong
CALL DelayLong
MOVEW [NumberShow], 4567
CALL ShowNumbers
CALL DelayLong
CALL DelayLong
CALL ShowUpsetCat
CALL DelayLong
CALL DelayLong
MOVEW [NumberShow], 5678
CALL ShowNumbers
CALL DelayLong
CALL DelayLong
MOVEW [NumberShow], 6789
CALL ShowNumbers
CALL DelayLong
CALL DelayLong
MOVEW [NumberShow], 7890
CALL ShowNumbers
CALL DelayLong
CALL DelayLong
MOVEW [NumberShow], 8901
CALL ShowNumbers
CALL DelayLong
CALL DelayLong
MOVEW [NumberShow], 9012
CALL ShowNumbers
CALL DelayLong
CALL DelayLong
MOVEW [NumberShow], 0123
CALL ShowNumbers
CALL DelayLong
CALL DelayLong
CALL ShowUpsetCat
CALL DelayLong
CALL DelayLong
CALL ShowDots
CALL DelayLong
CALL DelayLong
CALL ClearDots
CALL DelayLong
CALL DelayLong
JUMP @START ;循环继续开始
;five screen************
tab1 DB 0f0h,0f0h,0f0h,0f0h,0f0h,0f0h,0f0h,0f0h,0f0h,0f0h,0f0h,0f0h,0f0h ;888888 全显
tab2 DB 000h,060h,000h,060h,000h,060h,000h,060h,000h,060h,000h,060h,010h ;111111
tab3 DB 060h,0d0h,060h,0d0h,060h,0d0h,060h,0d0h,060h,0d0h,060h,0d0h,000h ;222222
tab4 DB 040h,0f0h,040h,0f0h,040h,0f0h,040h,0f0h,040h,0f0h,040h,0f0h,010h ;333333
DATA ROM
;------------------------------------------------------------------------------
SPEECH_OFFS_ADDR DD ADPCM_VOICE_DATA_PTR
MUSIC_OFFS_ADDR DD MIDI_SONG_DATA_PTR
INSTRUMENT_ADDR DD INSTRUMENT_DATA
;------------------------------------------------------------------------------
OPT_MAX_PSG_CH DB MAX_PSG_CHANNEL
OPT_MIDI_PSG_CH DB MIDI_PSG_CHANNEL
OPT_PSG_MIX_RATE DB (SYSTEM_CLOCK/MAX_PSG_CHANNEL/MIXING_RATE)-1
;------------------------------------------------------------------------------
ADPCM_VOICE_DATA_PTR
BYTE3 VOICE_ADPCM_0
BYTE3 VOICE_ADPCM_1
ADPCM_VOICE_DATA_PTR_END
;------------------------------------------------------------------------------
MIDI_SONG_DATA_PTR
;INCLUDE "SOUND SOURCE\demo_midi.MPTR"
; BYTE3 MIDI_DATA_PACK_END
MIDI_SONG_DATA_PTR_END
;------------------------------------------------------------------------------
INSTRUMENT_DATA INCLUDE "SOUND SOURCE\demo_midi.Multi ADSR"
;------------------------------------------------------------------------------
FREQ_STEP_TABLE INCLUDE "MIDI-LIB\60-Tone Freq-Table.DAT"
;================================================================================
; [SPEECH]
;================================================================================
VOICE_ADPCM_0 BINARY ".\Sound Source\voice1.ad4"
VOICE_ADPCM_1 BINARY ".\Sound Source\sfx2.ad4"
;================================================================================
; [MUSIC]
;================================================================================
MIDI_DATA_PACK
; BINARY "SOUND SOURCE\demo_midi.MBIN"
MIDI_DATA_PACK_END
;================================================================================
; [INSTRUMENT]
;================================================================================
WAVETABLE BINARY "SOUND SOURCE\demo_midi.Multi WaveTable"
END
文章评论(0条评论)
登录后参与讨论