微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 6502单片机编程代码1

6502单片机编程代码1

时间:11-24 来源:互联网 点击:
;;==============================================================================

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




%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 ;;;;;;;;临时变量
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


;;==============================================================================
;;设置Point C,D状态
;;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 主循环
;;检测触发按键
;;==============================================================================
DetectKey_Press:

LDAP_04H_IOD_Data
STAR_IOD_Buffer

;;启动
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:



;;左转
LDAR_IOD_Buffer
AND#%00001000
BEQnextB
JSRFlash_zhuo
nextB:

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


;;右转
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?:



;;循环延时
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

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top