?? tire gauge.asm
字號:
;;******************File Name: tire gauge .Asm******************
;;HT_IDE Version: V6.6 SP3
;;Program Name: HT46R71D.Prj
;;Main Function: **tire gauge **
;;MCU Body: Ht46R71D
;;VDD: 3V
;;MCU Frequency: 4MHz
;;------------------------------------------------------------
;;Mask Option:
;;-----------------------------------------------------------
;Osc: RC
;Fsys: 4MHz
;Wake_Up PA.0-7: PA.0 Wake_Up
; PA.0-PA.6 Non Wake_Up
;Pull-high PA: PULL-HIGH
;Pull-high PB: PULL-HIGH
;Pull-high PC: PULL-HIGH
;Pull-high PD: PULL-HIGH
;PA Buzzer Function: BZ/BZB Disable
;Clock Source: T1
;Wdt: Enable
;WDT Clock Source: T1
;CLR WDT: One clear instruction
;WDT time-out period: 2^12/fs-2^13/fs
;LVR: Disable
;LVD: Disable
;Int Function: Disable
;LCD Driver Clock: IRCOSC/3
;LCD ON/OFF At HALT: LCD OFF At HALT
;LCD Duty: 1/3 duty(3 com)
;LCD Bias: 1/2 bias
;;================================================
#INCLUDE HT46R71D.INC
;;================================================
#DEFINE R_20MS 5 ;;4mS*5=20mS
#DEFINE PER 100 ;;*******************************
#DEFINE PSI_FULL 10000 ;;***** 100(PSI) *****
#DEFINE BAR_FULL 689 ;;***** = 6.89(BAR) *****
#DEFINE KPA_FULL_L16 0D54H ;;***** = 689.48(KPA) *****
#DEFINE KPA_FULL_H16 01H ;;***** = 7.03(KGF/CM2) *****
#DEFINE KGFCM2_FULL 703 ;;*******************************
#DEFINE TABLE_START_ADDR 0710H ;;the start address of Voltage-Time table
#DEFINE TABLE_NUM 13 ;;the Voltage-Time table number
#DEFINE TABLE_PER 12 ;;for calculating
;;=====================================
#INCLUDE MACRO.ASM
;;---------------------------------------------
MAIN_DATA.SECTION 'DATA'
R_ADDR1 EQU [20H] ;;to save table address
R_ADDR2 EQU [21H] ;;to save table address
R_TMR1H EQU [22H] ;;to save high byte of discharging time
R_TMR1L EQU [23H] ;;to save low byte of discharge time
R_TABLE_L EQU [24H] ;;to save table value
R_TABLE1_H EQU [25H] ;;to save table value
R_TABLE1_L EQU [26H] ;;to save table value
R_TABLE2_H EQU [27H] ;;to save table value
R_TABLE2_L EQU [28H] ;;to save table value
R_60S_L EQU [2DH] ;;for timing 60s(low byte)
R_60S_H EQU [2EH] ;;for timing 60s(high byte)
R_1S EQU [2FH] ;;for timing 1s
R_TEMP0 EQU [24H] ;;for calculating
R_TEMP1 EQU [25H] ;;for calculating
R_TEMP2 EQU [26H] ;;for calculating
R_TO0 EQU [27H] ;;for calculating
R_TO1 EQU [28H] ;;for calculating
R_ADJUST_H EQU [29H] ;;to save the high byte of discharge time for adjusting
R_ADJUST_L EQU [2AH] ;;to save the low byte of discharge time for adjusting
F_TABLE_EQU EQU [2BH].0 ;;for calculating
;F_DIS_EQU EQU [2BH].1 ;;for calculating
F_HALT EQU [2BH].2 ;;the flag of halt mode
;;==================================================
KEY_DATA.SECTION 'DATA'
DEBOUNCE_COUNTER EQU [3FH] ;;for key detecting
R_UNIT EQU [2CH] ;;to save the unit to display
F_REPEAT EQU [2BH].3 ;;the flag of key repeat
F_KEY EQU [2BH].4 ;;the flag of key ok/no
F_KEY_PREV EQU [2BH].5 ;;the flag of previous key
F_ON EQU R_UNIT.6 ;;the flag of power on or wake up
F_KEY_TMP EQU R_UNIT.7 ;;the flag for key detecting
F_ZERO_OUTPUT EQU R_UNIT.5 ;;the flag of zero output of sensor
F_FULL_OUTPUT EQU R_UNIT.4 ;;the flag of full output of sensor
;;=================================================
DISPLAY_DATA.SECTION 'DATA'
R_LCD1 EQU [24H] ;;to save value displayed(decimal)
R_LCD2 EQU [25H] ;;..
R_LCD3 EQU [26H] ;;..
R_DIS EQU [3EH] ;;for display
F_LCD_DOT1 EQU [2BH].6 ;;the flag of dot 1
F_LCD_DOT2 EQU [2BH].7 ;;the flag of dot 2
F_PSI EQU R_UNIT.0 ;;flag of unit (psi)
F_BAR EQU R_UNIT.1 ;;flag of unit (bar)
F_KPA EQU R_UNIT.2 ;;flag of unit (kpa)
F_KGFCM2 EQU R_UNIT.3 ;;flag of unit (kgfcm2)
;;=================================================
CALCULATE_DATA.SECTION 'DATA' ;;for the calculation subroutine
DATA0 EQU [21H]
DATA1 EQU [30H]
DATA2 EQU [31H]
DATA4 EQU [32H]
DATA5 EQU [33H]
DATA6 EQU [34H]
TO0 EQU [35H]
TO1 EQU [36H]
TO2 EQU [37H]
TO3 EQU [38H]
TO4 EQU [39H]
TO5 EQU [3AH]
TO6 EQU [3BH]
COUNT0 EQU [3CH]
COUNT1 EQU [3DH]
COM3 EQU [3EH]
COM4 EQU [3FH]
;;=================================================
KEY_IO_C EQU PAC.0 ;;IO connecting with key
KEY_IO EQU PA.0
LED_IO_C EQU PAC.1 ;;IO connecting with led
LED_IO EQU PA.1
;;-------------------------------------------------
MAIN_CODE.SECTION AT 0 'CODE'
ORG 00H
JMP MAIN
ORG 04H ;;external int interrupt vector
JMP ISR_EXTINT
ORG 08H ;;timer0 interrupt vector
JMP ISR_TMR0
ORG 0CH ;;timer1 interrupt vector
JMP ISR_TMR1
ORG 10H ;;AD interrupt vector
JMP ISR_ADC
;;---------------------------------------- -----------------------
MAIN:
CALL INI_RAM ;;initial RAM
CALL INI_IO ;;initial IO
SET F_ON ;;set the flag of power on/wake up
MAIN_LOOP1: ;;test the discharge time
CLR WDT
CLR R_1S
CLR DATA0
CLR DATA1
CLR DATA2
XMOV R_TO0, 10 ;;charge-discharge for 10 times
MAIN_LOOP2: ;;calculate the average value of discharge time
CALL SBR_ADC ;;test the discharge time Tc during the charge time Ti be fixed
CLR C
XADDM DATA0, R_TMR1L
XADCM DATA1, R_TMR1H
CLR R_TMR1H
XADCM DATA2, R_TMR1H
SDZ R_TO0
JMP MAIN_LOOP2 ;;calculate the summation value of discharge time
XMOV DATA4, 10
CLR DATA5
CLR DATA6
CALL UNBIN_DIV_24 ;;calculate the average value for 10 times
XMOV R_TMR1L, TO0 ;;save low byte of the discharge time to R_TMR1L
XMOV R_TMR1H, TO1 ;;save high byte of the discharge time to R_TMR1H
MAIN_LOOP3: ;;calulate and display
CALL SBR_TABLE ;;to get the opposite offset address of table with dichotomy
CALL SBR_CALT ;;calculate the pressure value with different unit
CALL SBR_DIS ;;display
CLR WDT
SZ F_HALT ;;if at the mode of halt
JMP L_HALT ;;jump to the halt mode
CALL SBR_KEY_SCAN ;;detect key
CALL SBR_KEY_JUMP ;;deal with key
INC R_1S
NEJMP R_1S, 50 ;;1S timing
JMP MAIN_LOOP1 ;;jump to test the discharge time
JMP MAIN_LOOP3 ;;jump to calulate and display
L_HALT:
CLR LED_IO
HALT ;;halt
CLR F_HALT ;;wake up
SET F_KEY_PREV ;;set the previous key flag
XMOV CHPRC, 63H ;;set 3.3V regular output
XMOV ADCR, 41H ;;set the related registor
XMOV ADCD, 07H
XMOV TMR1C, 88H
XMOV R_UNIT, 01H ;;set to 'psi'
SET F_ON ;;set the flag of power on/wake up
SET LED_IO
JMP MAIN_LOOP1 ;;test again
;;---------------------------------------------
ISR_EXTINT: ;;no used
RETI
;;=============================================
ISR_TMR0: ;;no used
RETI
;;============================================
ISR_TMR1: ;;no used
RETI
;;===========================================
ISR_ADC: ;;no used
RETI
;;==========================================
#INCLUDE SUBROUTINE.ASM
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -