📄 遥控复位(章新风旋转tv).asm
字号:
*****************************************************************************************************
$Include 'C:\PEMICRO\ics08qtqyz\qtqy_registers.inc'
*****************************************************************************************************
RAMStart EQU $0090
ram_last equ $0FF ; last RAM location
init_stack equ ram_last ; initialize stack pointer to last RAM location
RomStart EQU $EF00 ;FOR QY4 $EE00-$FDFF,FOR QY2,QY1 $F800-FDFF
VectorStart EQU $FFDE
BIGESTHIGH_H EQU $15
BIGESTHIGH_L EQU $a0
BIGESTLOWH EQU $02
BIGESTLOWL EQU $86
SHIJIAN EQU $30
*****************************************************************************************************
org RamStart
HALLCOUNTERH DS 1
HALLCOUNTERL DS 1
RESETSTU DS 1
KS1COU DS 1
KS2COU DS 1
KS3COU DS 1
KS4COU DS 1
KS5COU DS 1
KS6COU DS 1
KS7COU DS 1
M1_4 DS 1
STUDY1_4 DS 1
HALLCOU DS 1
HALLST DS 1
EXTREME DS 1
RXDDATA DS 1
OTHER2 DS 1
TEMP1 DS 1
TEMP2 DS 1
TEMP3 DS 1
TEMP4 DS 1
TCH0LOLD DS 1
TCH0HOLD DS 1
CPCOU DS 1
DATA1 DS 1
DATA2 DS 1
DATA3 DS 1
COMTIME256L DS 1
COMTIME256H DS 1
COMTIME12 DS 1
t00 DS 1
t000 DS 1
t0000 DS 1
T100MSCOU DS 1
KEYST1 DS 1
KEYST2 DS 1
XIANWEI DS 1
SYSSTU DS 1
T1SCOU DS 1
org RomStart
**********************************************************************
***********************************************************************
;* Equates for ROM Subroutines and start of RAM
EraRnge equ $2806 ;FLASH erase routine in ROM
PgrRnge equ $2809 ;FLASH programming routine in ROM
CtrlByt equ $88 ;control byte for ROM subroutines
CPUSpd equ $89 ;CPU speed in units of 0.25MHz
LstAddr equ $8A ;last FLASH address to be programmed
;*********************************************************************
;* *
;* RdBlock - Reads a block of data from FLASH and puts it in RAM *
;* *
;* Calling convention: ldhx #Blk1page *
;* lda #Blk1Size *
;* jsr RdBlock *
;* *
;* Inputs: H:X - pointing to start of FLASH page used for data *
;* A - block size *
;* *
;* Returns: H:X - pointing to start of FLASH block containing data *
;* A - data from first byte of block *
;* *
;* Uses: FindClear *
;* *
;*********************************************************************
RdBlock: psha ;save block size
bsr FindClear ;find first erased block
cmp #$FF ;was an erased block found ?
bne skipdec ;if not then don’t go back a block
txa ;get LS byte of address
and #$3F ;only look at address within page
beq skipdec ;if 0 then no data so don’t go back
txa ;if not get LS byte of address again
sub 1,sp ;and subtract block size to point
tax ;to start of valid data block
VERADD:
PSHX
LDA ,X
CMP $8C
BNE VERADD_BAD
AIX #1
LDA ,X
CMP $8D
BNE VERADD_BAD
AIX #1
LDA ,X
CMP $8E
BEQ VEREND
VERADD_BAD: BCLR 3,SYSSTU
VEREND:
PULX
AIS #1
RTS
skipdec: BCLR 3,SYSSTU
lda ,x ;get first byte of data
ais #1 ;de-allocate stack
rts
;*********************************************************************
;* *
;* WrtBlock - Writes a block of data into FLASH from RAM buffer *
;* *
;* Calling convention: ldhx #Blk1page *
;* lda #Blk1Size *
;* jsr WrtBlock *
;* *
;* Inputs: H:X - pointing to start of FLASH page used for data *
;* A - block size *
;* *
;* Returns: nothing *
;* *
;* Uses: FindClear, EraRnge (ROM), PgrRnge (ROM) *
;* *
;*********************************************************************
WrtBlock: mov #13,CPUSpd ;3.2MHz/0.25MHz = 13
clr CtrlByt ;page (not mass) erase
psha ;save block size
bsr FindClear ;find first available erased block
cmp #$FF ;erased block found ?
beq blkfnd ;if so write to it
jsr EraRnge ;if not then erase page
txa ;get LS byte of FLASH address
and #$C0 ;and reset it to start of page
tax ;H:X now pointing to first block
blkfnd: pula ;get block size
pshx ;save start address LS byte
add 1,sp ;add block size to LS byte
deca ;back to last address in block
tax ;last address now in H:X
sthx LstAddr ;save in RAM for use by ROM routine
pulx ;restore X (H hasn’t changed)
jmp PgrRnge ;program block (includes RTS)
;*********************************************************************
;* *
;* FindClear - Finds first erased block within page *
;* *
;* Inputs: H:X - pointing to start of page used for required data *
;* Stack - block size last thing on stack *
;* *
;* Returns if erased block found: *
;* H:X - pointing to start of first erased block in page *
;* A - $FF *
;* Returns if no erased block found (page full): *
;* H:X - pointing to start of last written block *
;* A - $00 *
;* *
;*********************************************************************
FindClear: lda #$40 ;number of bytes in a page
sub 3,sp ;less number in first block
psha ;save bytes left
floop: lda ,x ;get first data byte in block
cmp #$FF ;erased byte ?
beq finish1 ;if so then exit, otherwise try next
pula ;bytes left
sub 3,sp ;less number in next block
psha ;resave bytes left
bmi finish2 ;enough for another block ?
txa ;yes, get LS byte of address
add 4,sp ;add block size
tax ;put it back (can’t be a carry)
bra floop ;and try again
finish2: clra ;no room (A shouldn’t be $FF)
finish1: ais #1 ;fix stack pointer
rts
*****************************************************************************************************
* Init_Timer - Turns on TIM channel 0 for an Input Capture ,channel 1 for unbuffered output compare *
* and Software compare only. *
*****************************************************************************************************
Init_Timer:
lda TSC
mov #$72,TSC ; Timer - Cleared + Stopped.Clicks once every 4 BUS Cycles
mov #$9c,TMODH; mov #$4c,TMODH;
mov #$40,TMODL
lda TSC1
mov #$10,TSC1 ; Timer Channel 1
; Set for Output Compare operation.and software compare only.
lda TSC0
mov #$48,TSC0 ; Timer Channel 0, Set for input Capture operation.FALLING EDGE.
;xia jiang bu zhuo
bclr 5,TSC ; Start the timer 1
rts
*****************************************************************************************************
* START - This is the point where code starts executing *
*****************************************************************************************************
Start:
SEI
clra
STA COPCTL
lda $FFC0 ; load the TRIM value stored in FLASH
cmp #$FF
beq no_trim
sta osctrim ; if the TRIM value has been calibrated and stored previously,
; use this stored value.
no_trim:
ldhx #init_stack+1 ; initialize
txs ; the stack pointer
CLRH
CLRX
mov #$01,CONFIG1
mov #$00,CONFIG2
MOV #$06,KBSCR
clr KBIER ; not enabled as keyboard interrupt pin
mov #$06,INTSCR ; IRQ interrupt requests disabled
mov #$1F,ADSCR ; ADC module power off
bsr Init_Timer
clr PORTA
mov #%00010010,DDRA
mov #%00101100,PTAPUE
clr PORTB
mov #%00000111,DDRB
MOV #%11111000,PTBPUE
*******************************************************************************
******************************************************************************
CLRH
LDX #RAMSTART
CRM_LOOP:
CLR ,X
INCX
BNE CRM_LOOP
CLI ; NOT Allow interrupts to happen
********************************************************************************
MAIN:
fixcop:
sta copctl ; Clear COP to prevent watchdog reset
*******************************************************************************
M1PRO: BRCLR 0,M1_4,M1STOP
M1RUN: BRCLR 1,M1_4,M1DOWN
M1UP: BSET 0,PORTB
delayUP00: inc t00
bne M1PROEND
inc t000
lda #$17
cmp t000
bhs M1PROEND
clr t000
BSET 1,PORTA
BRA M1PROEND
M1DOWN: BCLR 0,PORTB
delayDOWN00: inc t00
bne M1PROEND
inc t000
lda #$17
cmp t000
bhs M1PROEND
clr t000
BSET 1,PORTA
BRA M1PROEND
M1STOP: BCLR 1,PORTA
delaystop00: inc t00
bne M1PROEND
inc t000
lda #$17
cmp t000
bhs M1PROEND
clr t000
nop
BCLR 0,PORTB
M1PROEND:
M2PRO:
M2leftPRO: BRCLR 2,M1_4,M2leftSTOP
M2leftRUN:
BSET 2,PORTB
BRA M2leftPROEND
M2leftSTOP: BCLR 2,PORTB
M2leftPROEND:
M2rightPRO: BRCLR 3,M1_4,M2rightSTOP
M2rightRUN:
BSET 1,PORTB
BRA M2rightPROEND
M2rightSTOP: BCLR 1,PORTB
M2rightPROEND:
M2PROEND:
sta copctl ; Clear COP to prevent watchdog reset
****************************************************************************
* PORTB^6 XIANWEI^0
* ptb5(M2+) de xian wei
****************************************************************************
KEYS5SCAN: BRSET 6,PORTB,KEYS5LOW
KEYS5HIGH: LDA KS5COU
SUB #$20
BLO KEYS5HIGH1
MOV #$20,KS5COU
BSET 0,XIANWEI
BRA KEYS5SCANEND
KEYS5HIGH1: INC KS5COU
BRA KEYS5SCANEND
KEYS5LOW: LDA KS5COU
BEQ KEYS5LOW1
DEC KS5COU
BRA KEYS5SCANEND
KEYS5LOW1: BCLR 0,XIANWEI
KEYS5SCANEND:
**************************************************************************
* PORTB^7 XIANWEI^1
* ptb3(M-) de xian wei
**************************************************************************
KEYS6SCAN: BRSET 7,PORTB,KEYS6LOW
KEYS6HIGH: LDA KS6COU
SUB #$20
BLO KEYS6HIGH1
MOV #$20,KS6COU
BSET 1,XIANWEI
BRA KEYS6SCANEND
KEYS6HIGH1: INC KS6COU
BRA KEYS6SCANEND
KEYS6LOW: LDA KS6COU
BEQ KEYS6LOW1
DEC KS6COU
BRA KEYS6SCANEND
KEYS6LOW1: BCLR 1,XIANWEI
KEYS6SCANEND:
**************************************************************************
* KEYST1 EXTREME^0
* M1_4
* EXTREME
* *
*
*
**************************************************************************
HALL: BRCLR 2,PORTA,HALLLOW
HALLHIGH: LDA HALLCOU
SUB #$04
BLO HALLHIGH2
MOV #$04,HALLCOU
BRSET 0,HALLST,HALLEND
BRA HALLHIGH3 ;IF THE HALL MAICHONG IS OK THEN BRA
HALLHIGH2: INC HALLCOU
BRA HALLEND
HALLHIGH3: BSET 0,HALLST
COUNTINC:
BRSET 0,KEYST1,COUNTHIGH
BRSET 1,KEYST1,COUNTLOW
BRSET 0,KEYST2,COUNTHIGH
BRSET 1,KEYST2,COUNTLOW
COUNTHIGH:
LDA HALLCOUNTERL
ADD #$01
STA HALLCOUNTERL
LDA HALLCOUNTERH
ADC #$00
STA HALLCOUNTERH
COUNTHIGH2: LDA HALLCOUNTERH
CMP #BIGESTHIGH_H ;COMPER WHIS THE HIGHEST
BLO HALLEND
LDA HALLCOUNTERL
CMP #BIGESTHIGH_L
BHS COMEHIGHEST
BRA HALLEND
COUNTLOW: LDA HALLCOUNTERL
SUB #$01
STA HALLCOUNTERL
LDA HALLCOUNTERH
SBC #$00
STA HALLCOUNTERH
COUNTLOW2: LDA HALLCOUNTERH
CMP #BIGESTLOWH
BHS HALLEND ;THE LOWEST IS (01:BIGESTLOWL)
LDA HALLCOUNTERL
CMP #BIGESTLOWL
BLO COMELOWEST
BRA HALLEND
COMEHIGHEST: ;BCLR 0,HALLST
BSET 0,EXTREME
;BCLR 0,M1_4
;BCLR 1,M1_4
;CLR KEYST1
BRA HALLEND
COMELOWEST: ;BSET 0,HALLST
BSET 1,EXTREME
;BCLR 0,M1_4
;BCLR 1,M1_4
;CLR KEYST1
BRA HALLEND
HALLLOW: LDA HALLCOU
BEQ HALLLOW2
DEC HALLCOU
BRA HALLEND
HALLLOW2: BRCLR 0,HALLST,HALLEND
BCLR 0,HALLST
BRA COUNTINC
HALLEND:
sta copctl ; Clear COP to prevent watchdog reset
******************************************************************************
* SYSSTU^7 SYSSTU^3
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -