新聞中心

6502單片機(jī)編程代碼1

作者: 時(shí)間:2016-11-24 來(lái)源:網(wǎng)絡(luò) 收藏
;;==============================================================================

;; Power On Reset Area
;;==============================================================================
Reset:
LDX #FFH
TXS
LDA #%01000000
STA R_IntFlags

本文引用地址:http://m.butianyuan.cn/article/201611/320813.htm




%WakeUpBranch L_KeyWakeUp

lda #00
ldx #80H
%ClearAllRAM

%SetAudioMode

%Channel1PowerUpInitial

;%IoPowerUpInitial

%TimerPowerUpInitial

%SentencePowerOnInitial

.IF WaveTableMode
%MelodyPowerUpInitial
.ENDIF

.IF VOL_CTRL ;{
lda #04
jsr F_SetVolCh1
.ENDIF


JMP L_Start
;;==============================================================================
;; Key Wakeup Area
;;==============================================================================
L_KeyWakeUp:
; ldx #00
;L_Lop?:
; dex
; bne L_Lop?
%SetAudioMode

;%IoWakeUpInitial

%Channel1WakeUpInitial

.IF WaveTableMode
%MelodyWakeUpInitial
.ENDIF

L_Start:
LDA #%00000110
STA R_IntFlags ;;;;;;;;臨時(shí)變量
STA P_0DH_INT
CLI

;;==============================================================================
;; 變量賦值
;;==============================================================================


LDA#0
STAR_daochealltime
STAR_zhuozhuanalltime
STAR_youzhuanalltime


LDA#0
STAR_qidongover
STA R_IoBuffer
STAR_PressCount

LDA #0
STA R_BufferCount

LDA#1
STAR_Playingjiashu01
STAR_Playingjiashu02

LDA#0
STAR_jiashu01over
STAR_jiashu01alltime
STAR_jiashu02over
STAR_jiashu02alltime
STAR_daoche_Flag

LDA#100
STAR_DownweidengCount


;;==============================================================================
;;設(shè)置Point C,D狀態(tài)
;;I/O_D全為下拉電阻
;;I/O_C 0,1,2,3為輸出且為低電平
;;==============================================================================

LDA#%00000000
STAP_03H_IOD_Ctrl
LDA#%00000000
STAP_04H_IOD_Data

LDA#%00010000
STAP_00H_IOBC_Ctrl
LDA #%00000000
STAP_0EH_IOC_Buffer

;;==============================================================================
;;DetectKey_Press 主循環(huán)
;;檢測(cè)觸發(fā)按鍵
;;==============================================================================
DetectKey_Press:

LDAP_04H_IOD_Data
STAR_IOD_Buffer

;;啟動(dòng)
LDAR_IOD_Buffer
AND#%10000000
BEQnextA
JSRPlay_qidong
nextA:

;;喇叭
LDAR_IOD_Buffer
AND#%00100000
BNEnextlaba
nextone:
LDA#0
STAR_laba_Flag
JMPnextend
nextlaba:
LDAR_laba_Flag
BNEnextend

LDA#1
STAR_laba_Flag
JSRPlay_laba

nextend:



;;左轉(zhuǎn)
LDAR_IOD_Buffer
AND#%00001000
BEQnextB
JSRFlash_zhuo
nextB:

LDAR_IOD_Buffer
AND#%00001000
BNEnextC
LDA#0
STAR_zhuozhuancount
JSRLed_zhuoDown
nextC:


;;右轉(zhuǎn)
LDAR_IOD_Buffer
AND#%00010000
BEQnextD
JSRFlash_you
nextD:

LDAR_IOD_Buffer
AND#%00010000
BNEnextE
LDA#0
STAR_youzhuancount
JSRLed_youDown
nextE:



;;倒車
LDAR_IOD_Buffer
AND#%00000100
BEQnextF

JSRPlay_daoche
nextF:

LDAR_IOD_Buffer
AND#%00000100
BNEnextG

LDA#0
STAR_daochecount

LDAR_daoche_Flag
BEQnextG
JSRLed_weidengDown

LDA#0
STAR_daoche_Flag


nextG:


;;加速01
LDAR_IOD_Buffer
AND#%00000001
BEQtryB
JSRPlay_jiashu01
LDA#1
STAR_jiashu01over

tryB:



LDAR_jiashu01over
CMP#1
BNEtryx
JSRPlay_jiashu01B
tryx:


LDAR_IOD_Buffer
AND#%00000001
BNEtryZ
LDA#0
STAR_jiashu01alltime

LDAR_jiashu01over
CMP#1
BNEtryZ
JSRPlay_shache

LDA#0
STAR_jiashu01over

tryZ:


LDAR_Downweideng_Flag
CMP#1
BNEDownnext
LDAR_DownweidengCount
BNEDownnext
JSRLed_weidengDown

LDA#0
STAR_Downweideng_Flag

Downnext:



;;加速02
LDAR_IOD_Buffer
AND#%00000010
BEQtryBA
JSRPlay_jiashu02
LDA#1
STAR_jiashu02over
tryBA:


LDAR_jiashu02over
CMP#1
BNEtryBX
JSRPlay_jiashu02B
tryBX:


LDAR_IOD_Buffer
AND#%00000010
BNEtryBZ
LDA#0
STAR_jiashu02alltime


LDAR_jiashu02over
CMP#1
BNEtryBZ
JSRPlay_shache

LDA#0
STAR_jiashu02over

tryBZ:



;;大燈
LDAR_IOD_Buffer
AND#%01000000
BNEelse?

if?:
LDA#0
STAR_PressCount

JMPendif?

else?:
LDAR_PressCount
BNEendif?

LDA#1
STAR_PressCount

JSRLed_dadeng

endif?:



;;空車
LDAR_qidongover
CMP#1
BNEnext?
JSRPlay_kongche
next?:



;;循環(huán)延時(shí)
LDA#3
STAR_BufferCount

Count:
LDAR_BufferCount
BNECount


JMPDetectKey_Press




;;==============================================================================
;; IRQ Area
;;==============================================================================
Irq:

STA R_IntTempA
STY R_IntTempY
LDA P_0DH_INT
STA R_IntTmp
EOR #%00111111
STA P_0DH_INT
LDA R_IntFlags
STA P_0DH_INT

LDA R_IntTmp
AND #%00100000 ;TimerA interrupt
BNE V_TimerAInt

JMP L_CheckTimerBInt



關(guān)鍵詞: 6502單片機(jī)編程代

評(píng)論


技術(shù)專區(qū)

關(guān)閉