;*******************************************************************************
; FILENAME : Black_plane-TX
; AUTHOR : Hu Zhiyan
; PURPOSE : Template Code for SN8P1602B
; REVISION : 10/05/2004 V1.0 First issue
;*******************************************************************************
;* (c) Copyright 2004, Kodec development CO., LTD.
;*******************************************************************************
;///////////////////////////////////////////////////////////////////////////////////////
; V
; V1.3
; V1.35 将测试模式的10秒进入睡眠改为5秒,充电指示灯
; V1.36 清除在睡眠模式时,按充电按钮,绿灯闪烁一下问题
; V1.37 将4分钟后进入睡眠改为15分钟
;
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
CHIP SN8P1602B ; Select the CHIP
//{{SONIX_CODE_OPTION
.Code_Option OSG Enable
.Code_Option High_Clk 4M_X'tal
.Code_Option High_Clk/2 Disable
.Code_Option Security Enable
; .Code_Option LVD Enable
.Code_Option Watch_Dog Disable
.Code_Option Low_Power Enable
.Code_Option Noise_Filter Enable
.Code_Option Int_16K_RC By_CPUM
//}}SONIX_CODE_OPTION
;-------------------------------------------------------------------------------
; Include Files
;-------------------------------------------------------------------------------
.nolist ; do not list the macro file
INCLUDESTD MACRO1.H
INCLUDESTD MACRO2.H
INCLUDESTD MACRO3.H
.list ; Enable the listing function
;-------------------------------------------------------------------------------
; Constants Definition
;-------------------------------------------------------------------------------
; ONE EQU 1
;-------------------------------------------------------------------------------
; Variables Definition
;-------------------------------------------------------------------------------
.DATA
org 0h ;Data section start from RAM address 0
Wk00 DS 1 ;Temporary buffer for main loop
Iwk00 DS 1 ;Temporary buffer for ISR
AccBuf DS 1 ;Accumulater buffer
PflagBuf DS 1 ;PFLAG buffer
flag3 equ 09h
flag1 equ 10h
flag2 equ 11h
keyinbuf equ 12h
keychkbuf equ 13h
keycvtbuf equ 14h
key_value equ 15h
key_count equ 16h
LEDbuf equ 17h
txdata equ 18h
;
data_length equ 1ah
low_times equ 1bh
time50ms equ 1ch
time500ms equ 1dh
time4s equ 1eh
times4 equ 1fh
;
sleep_time equ 20h
charge_time equ 21h
key_start equ flag1.0
nokeypress equ flag1.1
RED_flash_enable equ flag1.2
charge_start equ flag1.3 ;?????????????????????????????????????
LED_on equ flag1.4
time50ms_ok equ flag1.5
detect_led_on equ flag1.6
charge_ok equ flag1.7
;
bitok equ flag2.0
code_start equ flag2.1
code_head equ flag2.2
code_sycn equ flag2.3
code_data equ flag2.4
code_current_data_ok equ flag2.5
code_all_data_ok equ flag2.6
before equ flag2.7
;
TX_enable equ flag3.0
charge_continue equ flag3.1
wait_charge equ flag3.2
;
p0buf equ p0
p1buf equ p1
p1mbuf equ p1m
p2buf equ p2
p2mbuf equ p2m
;-------------------------------------------------------------------------------
; Bit Variables Definition
;-------------------------------------------------------------------------------
Wk00B0 EQU Wk00.0 ;Bit 0 of Wk00
Iwk00B1 EQU Iwk00.1 ;Bit 1 of Iwk00
;-------------------------------------------------------------------------------
; Code section
;-------------------------------------------------------------------------------
.CODE
ORG 0 ;Code section start
jmp Reset ;Reset vector
;Address 4 to 7 are reserved
ORG 8
jmp Isr ;Interrupt vector
ORG 10h
;-------------------------------------------------------------------------------
; Program reset section
;-------------------------------------------------------------------------------
Reset:
mov A,#07Fh ;Initial stack pointer and
b0mov STKP,A ;disable global interrupt
b0mov PFLAG,#00h ;pflag = x,x,x,x,x,c,dc,z
mov A,#40h ;Clear watchdog timer and initial system mode
b0mov OSCM,A
call ClrRAM ;Clear RAM
call SysInit ;System initial
b0bset FGIE ;Enable global interrupt
;-------------------------------------------------------------------------------
; Main routine
;-------------------------------------------------------------------------------
Main:
b0bset FWDRST ;Clear watchdog timer
call Mnscan_key ; scan key
call MnRF_TX ; RF TX
call Application
call Mntime_count ; time count
call MnLED ; LED indicator
jmp Main
;-------------------------------------------------------------------------------
; Main application
;-------------------------------------------------------------------------------
Application:
; b0bts1 key_value.6
; jmp App_Normal ; to normal mode
; jmp App_Charge ; to charge mode
app_Normal:
b0bclr wait_charge ; added on 2004/10/16
b0bts1 charge_continue ; when mode the change,will stop the charge mode
jmp nor1
b0bclr charge_continue
b0bclr RED_flash_enable
b0bclr LEDbuf.2
b0bset LEDbuf.6
b0bclr LEDbuf.7
b0bclr charge_start
b0bclr charge_ok
nor1:
b0bset TX_enable ; enable tx
b0bset LEDbuf.6
mov a,#0fh
and a,key_value
b0bts1 fz ; if z=1,the acc is zero
jmp app_normal10
jmp app_normal20
app_normal10:
clr time4s ; if there's key pressed,will clear the 4s count
clr sleep_time
b0bts1 code_all_data_ok ; if the data transmit ok,will get next data
jmp app90
b0bclr code_all_data_ok
b0bts0 key_value.0 ; detect the landing key
jmp landing
b0bts0 key_value.1 ; detect the turbo key
jmp turbo
b0bts0 key_value.2 ; detect the left key
jmp left
b0bts0 key_value.3 ; detect the right key
jmp right
jmp app_normal20
landing:
; mov a,#12h
; mov txdata,a ; get the landing code
jmp app90
turbo:
; mov a,#22h
; mov txdata,a ; get the turbo code
jmp app90
left:
mov a,#42h
mov txdata,a ; get the left code
jmp app90
right:
mov a,#82h
mov txdata,a ; get the right code
jmp app90
app_normal20:
clr txdata
jmp app90
;===================================================
;
app_Charge:
b0bclr LEDbuf.4 ; added on 2004/10/20
b0bts0 key_value.4 ; added on 2004/10/16
b0bset wait_charge ; added on 2004/10/16
b0bts0 wait_charge ; added on 2004/10/16
jmp n12 ; added on 2004/10/16
jmp to_sleep ; added on 2004/10/16
n12: ; added on 2004/10/16
b0bclr TX_enable ; disable TX
b0bts1 key_value.5 ; 1=if the low power p2.1is low
jmp charge10
; b0bset LEDbuf.6 ;////////////////////////////////////
; b0bclr LEDbuf.6
;
b0bts0 charge_continue
jmp ccharge
;
b0bts1 key_value.4 ; p2.3
jmp app_stop_charge10
ccharge:
b0bts0 charge_ok
jmp app_stop_charge20
clr time4s ; if there's key pressed,will clear the 4s count
clr sleep_time
b0bts1 charge_start
clr times4
; b0bts1 charge_start
; clr charge_time
b0bset charge_continue
b0bclr LEDbuf.6
b0bset LEDbuf.2
b0bset RED_flash_enable
b0bset charge_start
jmp app90
app_stop_charge10:
b0bclr charge_ok ; stop charge
clr charge_time
app_stop_charge20:
b0bclr charge_continue
b0bclr RED_flash_enable
b0bclr LEDbuf.2
b0bts0 charge_ok ;