📄 main.asm
字号:
;----------------------------------------------------------------------
;
; Copyright 2005 Microchip Technology Inc.
;
; Microchip Technology Inc. ("Microchip") licenses this software to
; you solely for use with Microchip products. The software is owned
; by Microchip and is protected under applicable copyright laws. All
; rights reserved.
;
; SOFTWARE IS PROVIDED "AS IS." MICROCHIP EXPRESSLY DISCLAIMS ANY
; WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT NOT
; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
; PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL MICROCHIP
; BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL
; DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR EQUIPMENT, COST OF
; PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
; BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF),
; ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS.
;
;----------------------------------------------------------------------
;
; Filename: humiditysensor.asm
; File Version: 0.1
; Assembled using: MPLAB IDE v7.20
;
; Author: Steven Bible
; Company: Microchip Technology Inc.
;
;----------------------------------------------------------------------
;
; Program Description
;
; Reads capacitance using a dual slope integration technique.
; Demonstrates reading a Humirel HS1101LF humidity sensor.
;
;----------------------------------------------------------------------
;
; Revision History:
;
; Ver. 0.1 - 2005-11-22: Initial write
;
;----------------------------------------------------------------------
errorlevel -302 ; suppress message 302 from list file
;----------------------------------------------------------------------
; Include Files
;----------------------------------------------------------------------
#include "main.inc" ; Project defines
; ---------------------------------------------------------------------
; Configuration Bits
; ---------------------------------------------------------------------
;
; Fail-Safe Clock Monitor Enable bit:
; _FCMEN_ON = Enabled
; _FCMEN_OFF = Disabled
;
; Internal External Switchover bit:
; _IESO_ON = Enabled
; _IESO_OFF = Disabled
;
; Brown-out Reset Selection bits:
; NOTE: Enabling Brown-out Reset does not automatically enable Power-up
; Timer.
; _BOR_ON = BOR enabled
; _BOR_NSLEEP = BOR enabled during operation and disabled in Sleep
; _BOR_SBODEN = BOR controlled by SBODRN bit (PCON<4>)
; _BOR_OFF = BOR disabled
;
; Data Memory Code Protection bit:
; NOTE: The entire data EEPROM will be erased when the code protection
; is turned off.
; _CPD_ON = Enabled
; _CPD_OFF = Disabled
;
; Program Memory Code protection bit:
; NOTE: The entire program memory will be erased when the code protection
; is turned off.
; _CP_ON = Enabled
; _CP_OFF = : Disabled
;
; RA3/MCLR/Vpp pin function select bit:
; NOTE: When /MCLR is asserted in INTOSC or RC mode, the internal clock
; oscillator is disabled.
; _MCLRE_ON = RA3/MCLR/Vpp pin function is /MCLR
; _MCLRE_OFF = RA3/MCLR/Vpp pin function is digital I/O,
; /MCLR internally tied to Vdd
;
; Power-up Timer Enable bit:
; _PWRTE_ON = Enabled
; _PWRTE_OFF = Disabled
;
; Watchdog Timer Enable bit:
; _WDT_ON = Enabled
; _WDT_OFF = Disabled and can be enabled by SWDTEN bit (WDTCON<0>)
;
; Oscillator Selction bits:
; NOTE: When /MCLR is asserted in INTOSC or RC mode, the internal clock
; oscillator is disabled.
; _EXTRC_OSC_CLKOUT = CLKOUT function on RA4 pin, RC on RA5 pin.
; _EXTRC_OSC_NOCLKOUT = I/O function on RA4 pin, RC on RA5 pin.
; _INTRC_OSC_CLKOUT = Internal oscillator, CLKOUT function on RA4 pin,
; I/O function on RA5 pin.
; _INTRC_OSC_NOCLKOUT = Internal oscillator, I/O function on RA4 and RA5 pins.
; _EC_OSC = I/O function on RA4 pin, CLKIN on RA5 pin.
; _HS_OSC = High speed crystal/resonator on RA4 and RA5 pins.
; _XT_OSC = Crystal/resonator on RA4 and RA5 pins.
; _LP_OSC = Low power crystal on RA4 and RA5 pins.
;
; ---------------------------------------------------------------------
__CONFIG _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
;----------------------------------------------------------------------
; Externally Defined Labels
;
; EXTERN declares symbol names that are used in this module and declared
; as global in another module.
;----------------------------------------------------------------------
;--------------------
; external variables
extern K2_H ; from capacitance.asm
extern K2_L
extern Humid_PwLI_IN ; from humidity.asm
extern Humid_PwLI_OUT
;--------------------
; external subroutines
extern init_f690 ; from initialize_f690.asm
extern CAP_Init ; from capacitance.asm
extern CAP_Read
extern Humid_PwLI ; from humidity.asm
extern SSC_Init ; from ssc.asm
extern SSC_GetByte
extern SSC_SendByte
;----------------------------------------------------------------------
; Local Defines
;----------------------------------------------------------------------
; None
;----------------------------------------------------------------------
; Variables
;----------------------------------------------------------------------
;--------------------
; Uninitialized Data Section
;
; The RES directive reserves space for data storage.
udata
Result_U res 1 ; 24-bit Result variable
Result_H res 1
Result_L res 1
Count res 1 ; general purpose Count variable
CmdStatus res 1 ; command status
;--------------------
; Shared Uninitialized Data Section
;
; Variables that are allocated in RAM that is shared across all RAM banks (unbanked RAM).
; The RES directive reserves space for data storage.
udata_shr
W_TEMP res 1 ; used for context saving
STATUS_TEMP res 1 ; used for context saving
PCLATH_TEMP res 1 ; used for context saving
FSR_TEMP res 1 ; used for context saving
TempISRdata res 1 ; temporary variable for ISR routine
DelayCounter res 1 ; used as a Delay Counter variable
;----------------------------------------------------------------------
; Begin Executable Code Segment
;----------------------------------------------------------------------
;[<label>] code [<ROM_Address>]
ResetVector code
nop ; for ICD use
goto MAIN ; goto MAIN
; interrupt vector location
InterruptVector code
movwf W_TEMP ; save W register
swapf STATUS, W ; swap status to be saved into W
clrf STATUS ; clear IRP, RP1, and RP0 bits
movwf STATUS_TEMP ; save STATUS register
movfw PCLATH
movwf PCLATH_TEMP ; save PCLATH_TEMP register
movfw FSR
movwf FSR_TEMP ; save FSR_TEMP register
;----------------------------------------
; Interrupt Service Routine (ISR)
;
; Description: Arrange the order of the interrupt flag bit tests for
; highest priority at top to lowest priority at bottom.
RAIF_ISR ; Interrupt-on-change (PORTA 1) Interrupt Service Routine
btfss INTCON, RABIF ; check PORT Change interrupt flag
goto End_ISR
; The PORT Change interrupt can be cleared by a reading PORTA.
; This will end the mismatch condition that caused the interrupt
; and clear the RAIF bit.
;
; It is best to do this at the end of the command so that
; multiple PORT Change interrupts occur.
call SSC_GetByte
andlw 0x07 ; mask out lower 3 bits
movwf TempISRdata
movlw HIGH cmdTable
movwf PCLATH
movfw TempISRdata
addlw LOW cmdTable
btfsc STATUS, C
incf PCLATH, F
movwf PCL
cmdTable
goto cmdVersion ; 0x00 - VERSION ( cmd: 1 / arg: 0 )
goto cmd01 ; 0x01 - ( cmd: 1 / arg: 0 )
goto cmd02 ; 0x02 - ( cmd: 1 / arg: 0 )
goto cmd03 ; 0x03 - ( cmd: 1 / arg: 1 )
goto cmd04 ; 0x04 - ( cmd: 1 / arg: 5 )
goto cmd05 ; 0x05 - ( cmd: 1 / arg: 0 )
goto cmd06 ; 0x06 - ( cmd: 1 / arg: 0 )
goto cmdGetStatus ; 0x07 - GETSTATUS ( cmd: 1 / arg: 1 )
;----------------------------------------
; Returns a version number for the firmware
; ( cmd: 1 / arg: 0 )
cmdVersion
movlw .75 ; take some time to turn the bus around
movwf DelayCounter
decfsz DelayCounter, F
goto $ - 1
movlw VERSION
call SSC_SendByte
movlw CMD_Version_ACK
movwf CmdStatus
movfw PORTA ; clear any interrupt on change conditions
bcf INTCON, RABIF
goto End_ISR
;----------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -