MPASM 02.61 Released HUMID.ASM 8-20-2002 17:58:18 PAGE 1 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00001 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 00002 ;; Sensirion SHT11 sensor interface ;; 00003 ;; ;; 00004 ;; Copyleft (L) P Pemberton ;; 00005 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 00006 00007 ;; PIC setup and toplevel includes 00008 LIST R=DEC 00009 INCLUDE sxdefs.inc 00163 LIST 00164 PROCESSOR 16C56 ; "SX18AB" 00480 LIST 1010 0F0B 00481 DATA _FUSE ;configuration bits (TURBO, SYNC, OPTIONX, etc.) 1011 00F5 00482 DATA _FUSEX ; (PINS, CARRYX, BOR40, BANKS, PAGES) 00486 LIST 00010 INCLUDE sxregs.inc 00001 ;----------------------------- Basic defines -------------------------------- 00002 00003 ;For instruction destination argument 00000000 00004 W EQU 0 00000001 00005 F EQU 1 00006 00000000 00007 Indir EQU 00h ;Used for indirects thru FSR 00000001 00008 RTCC EQU 01h ;Real Time Clock/Counter 00000002 00009 PC EQU 02h ;Program Counter Low 00000004 00010 FSR EQU 04h ;File Select Register (index register) 00000005 00011 PORTA EQU 05h ;I/O Port A 00000006 00012 PORTB EQU 06h ;I/O Port B 00000007 00013 PORTC EQU 07h ;I/O Port C 00014 00000003 00015 Status EQU 03h ;Status register: 00016 #DEFINE CF Status,0 ; Bit 0 = Carry Flag 00017 #DEFINE DCF Status,1 ; Bit 1 = Digit Carry Flag 00018 #DEFINE ZF Status,2 ; Bit 2 = Zero Flag 00019 #DEFINE PDF Status,3 ; Bit 3 = Power Down Flag 00020 #DEFINE TOF Status,4 ; Bit 4 = Time Out Flag 00021 #DEFINE Pa0 Status,5 ; Bit 5 = Program Page select bit LSB 00022 #DEFINE Pa1 Status,6 ; Bit 6 = Program Page select bit 00023 #DEFINE Pa2 Status,7 ; Bit 7 = Program Page select bit MSB 00024 00025 ;Option EQU 81h ;Option register 00026 #DEFINE PS0 Option,0 ; Bit 0 = Prescaler divider 00027 #DEFINE PS1 Option,1 ; Bit 1 = Divide of 2 thru 256 for RTCC 00028 #DEFINE PS2 Option,2 ; Bit 2 = Divide of 1 thru 128 for WDT 00029 #DEFINE PSA Option,3 ; Bit 3 = Prescaler assign: 0 = RTCC, 1 = WDT 00030 #DEFINE RTE_ES Option,4 ; Bit 4 = RTCC clock edge: 0 = low to high 00031 #DEFINE RTS Option,5 ; Bit 5 = RTCC clock source: 0 = internal 00032 #DEFINE RTE_IE Option,6 ; Bit 6 = RTCC Interrupt Enable: 0 = enabled 00033 #DEFINE RTW Option,7 ; Bit 7 = W-reg mapped to RTCC = 0 00011 EXPAND ; Expand must be ON for ICD 00012 00013 #DEFINE BANK0 BCF STATUS, PA0 00014 #DEFINE BANK1 BSF STATUS, PA0 MPASM 02.61 Released HUMID.ASM 8-20-2002 17:58:18 PAGE 2 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00015 00016 ; SX18AB 00005080 00017 DEVICE EQU PINS18+OSC4MHZ+PAGES2+BANKS2 00000007 00018 RAMBase EQU 07h ;Start of RAM 00019 00020 SEROUT MACRO __byte 00021 MOVLW __byte 00022 ; CALL SER_SEND 00023 ENDM 00024 00025 CHKWZ MACRO __outz, __outnz 00026 IORLW .0 00027 MOVLW __outz 00028 BTFSS STATUS, Z 00029 MOVLW __outnz 00030 ; CALL SER_SEND 00031 ENDM 00032 00033 ; Pindefs 00034 #DEFINE SHT_SDA PORTB, 7 00035 #DEFINE SHT_SCL PORTB, 6 00036 00037 ; Variables 00038 CBLOCK RAMBase 00000007 00039 TEMPERATURE:2 00000009 00040 HUMIDITY:2 0000000B 00041 CHKSUM 0000000C 00042 CHAHI, CHALO 00043 ENDC 00044 00045 ; Reset vector 0000 00046 ORG 0 0000 0A05 00047 GOTO START 00048 ; Interrupt vector 0004 00049 ORG 4 0004 0A05 00050 GOTO START 00051 00052 ; Start of code 0005 00053 ORG 5 00054 0005 00055 START: 00056 ; CALL SER_SETUP ; Set up the serial port 00057 0005 093F 00058 CALL SHT_BUSINIT ; Init the SHT bus 0006 0C05 00059 MOVLW .5 ; Read Humidity 0007 0961 00060 CALL SHT_SEND 0008 0988 00061 CALL SHT_WAITACK ; Wait for an ACK 00062 CHKWZ "A","!" 0009 0D00 M IORLW .0 000A 0C41 M MOVLW "A" 000B 0743 M BTFSS STATUS, Z 000C 0C21 M MOVLW "!" M ; CALL SER_SEND MPASM 02.61 Released HUMID.ASM 8-20-2002 17:58:18 PAGE 3 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00063 000D 09A5 00064 CALL SHT_WAIT ; Wait for the data 00065 CHKWZ "W","!" 000E 0D00 M IORLW .0 000F 0C57 M MOVLW "W" 0010 0743 M BTFSS STATUS, Z 0011 0C21 M MOVLW "!" M ; CALL SER_SEND 00066 0012 0976 00067 CALL SHT_RECEIVE ; Get byte 1 0013 0029 00068 MOVWF HUMIDITY+0 ; Store it 0014 0993 00069 CALL SHT_ACK ; Wait for an ACK 00070 0015 0976 00071 CALL SHT_RECEIVE ; Get byte 2 0016 002A 00072 MOVWF HUMIDITY+1 ; Store it 0017 0993 00073 CALL SHT_ACK ; Wait for an ACK 00074 0018 0976 00075 CALL SHT_RECEIVE 0019 002B 00076 MOVWF CHKSUM 001A 09A0 00077 CALL SHT_NACK 00078 001B 0209 00079 MOVF HUMIDITY+0, W ; Send humidity to host 001C 0923 00080 CALL HEXOUT 001D 020A 00081 MOVF HUMIDITY+1, W 001E 0923 00082 CALL HEXOUT 001F 020B 00083 MOVF CHKSUM, W 0020 0923 00084 CALL HEXOUT 00085 00086 SEROUT " " 0021 0C20 M MOVLW " " M ; CALL SER_SEND 00087 0022 0A22 00088 GOTO $ ; Crash! 00089 00090 ;; Subroutines 00091 0023 00092 HEXOUT: 0023 002D 00093 MOVWF CHALO 0024 038D 00094 SWAPF CHALO, W 0025 0E0F 00095 ANDLW 0x0F 0026 002C 00096 MOVWF CHAHI 0027 0C0F 00097 MOVLW 0x0F Message[305]: Using default destination of 1 (file). 0028 016D 00098 ANDWF CHALO 00099 0029 020C 00100 MOVF CHAHI, W 002A 092E 00101 CALL HEXTAB 00102 ; CALL SER_SEND 00103 002B 020D 00104 MOVF CHALO, W 002C 092E 00105 CALL HEXTAB 00106 ; CALL SER_SEND Warning[227]: Substituting RETLW 0 for RETURN pseudo-op MPASM 02.61 Released HUMID.ASM 8-20-2002 17:58:18 PAGE 4 LOC OBJECT CODE LINE SOURCE TEXT VALUE 002D 0800 00107 RETURN 00108 002E 00109 HEXTAB: 002E 01E2 00110 ADDWF PC, F 002F 0830 0831 0832 00111 DT "0123456789ABCDEF" 0833 0834 0835 0836 0837 0838 0839 0841 0842 0843 0844 0845 0846 00112 00113 ;; Final post-code includes 00114 #DEFINE SER_BAUD .19200 00115 00116 INCLUDE "sht11.inc" 00001 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 00002 ;; Sensirion SHT11 sensor interface ;; 00003 ;; ;; 00004 ;; Copyleft (L) P Pemberton ;; 00005 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 00006 00007 CBLOCK 0000000E 00008 SHT_TEMP 0000000F 00009 SHT_LOOP 00000010 00010 SHT_DEL_0, SHT_DEL_1 00011 ENDC 00012 00013 _SHT_SDA_SETIN MACRO 00014 BANK1 00015 BSF SHT_SDA 00016 BANK0 00017 ENDM 00018 00019 _SHT_SDA_SETOUT MACRO 00020 BANK1 00021 BCF SHT_SDA 00022 BANK0 00023 ENDM 00024 00025 ;; Init the SHT bus 003F 00026 SHT_BUSINIT: 003F 05A3 00027 BANK1 ; Data=output, Clk=output 0040 04E6 00028 BCF SHT_SDA 0041 04C6 00029 BCF SHT_SCL 0042 04A3 00030 BANK0 00031 0043 05E6 00032 BSF SHT_SDA ; Clock and data high 0044 04C6 00033 BCF SHT_SCL 0045 0C09 00034 MOVLW .9 ; 10x clock pulses 0046 002F 00035 MOVWF SHT_LOOP 0047 00036 SHT_RS_LOOP: 0047 05C6 00037 BSF SHT_SCL ; Pulse low 0048 0A49 00038 GOTO $+1 MPASM 02.61 Released HUMID.ASM 8-20-2002 17:58:18 PAGE 5 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0049 0A4A 00039 GOTO $+1 004A 04C6 00040 BCF SHT_SCL ; Pulse high 004B 0000 00041 NOP 004C 02EF 00042 DECFSZ SHT_LOOP, F ; Decrement loop 004D 0A47 00043 GOTO SHT_RS_LOOP ; If not =0, keep going 00044 00045 ; TRANSMISSION START 004E 05E6 00046 BSF SHT_SDA 004F 04C6 00047 BCF SHT_SCL 0050 0000 00048 NOP 0051 05C6 00049 BSF SHT_SCL 0052 0000 00050 NOP 0053 04E6 00051 BCF SHT_SDA 0054 0000 00052 NOP 0055 04C6 00053 BCF SHT_SCL 0056 0000 00054 NOP 0057 0A58 00055 GOTO $+1 0058 05C6 00056 BSF SHT_SCL 0059 0000 00057 NOP 005A 05E6 00058 BSF SHT_SDA 005B 0000 00059 NOP 005C 04C6 00060 BCF SHT_SCL 00061 _SHT_SDA_SETIN 005D 05A3 M BANK1 005E 05E6 M BSF SHT_SDA 005F 04A3 M BANK0 Warning[227]: Substituting RETLW 0 for RETURN pseudo-op 0060 0800 00062 RETURN 00063 00064 ;; Send a byte over the SHT bus 0061 00065 SHT_SEND: 00066 _SHT_SDA_SETOUT 0061 05A3 M BANK1 0062 04E6 M BCF SHT_SDA 0063 04A3 M BANK0 0064 002E 00067 MOVWF SHT_TEMP ; Save data byte 0065 0C08 00068 MOVLW .8 ; 8 data bits 0066 002F 00069 MOVWF SHT_LOOP 0067 00070 SHT_SEND_LOOP: 0067 036E 00071 RLF SHT_TEMP, F ; Rotate data bit into carry 0068 05E6 00072 BSF SHT_SDA ; Set data pin 0069 0703 00073 BTFSS STATUS, W 006A 04E6 00074 BCF SHT_SDA ; If databit clear, clear pin 006B 0000 00075 NOP ; Settling time 006C 05C6 00076 BSF SHT_SCL ; Clock the data in 006D 0000 00077 NOP 006E 04C6 00078 BCF SHT_SCL 006F 0000 00079 NOP 0070 02EF 00080 DECFSZ SHT_LOOP, F ; Decrement loop 0071 0A67 00081 GOTO SHT_SEND_LOOP ; If not done, keep looping 00082 _SHT_SDA_SETIN 0072 05A3 M BANK1 0073 05E6 M BSF SHT_SDA MPASM 02.61 Released HUMID.ASM 8-20-2002 17:58:18 PAGE 6 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0074 04A3 M BANK0 Warning[227]: Substituting RETLW 0 for RETURN pseudo-op 0075 0800 00083 RETURN 00084 00085 ;; Receive a byte from the SHT bus 0076 00086 SHT_RECEIVE: 00087 _SHT_SDA_SETIN 0076 05A3 M BANK1 0077 05E6 M BSF SHT_SDA 0078 04A3 M BANK0 0079 006E 00088 CLRF SHT_TEMP ; Clear data byte 007A 0C08 00089 MOVLW .8 ; 8 data bits 007B 002F 00090 MOVWF SHT_LOOP 007C 00091 SHT_RCV_LOOP: 007C 05C6 00092 BSF SHT_SCL ; Clock the data out 007D 0000 00093 NOP 007E 0403 00094 BCF STATUS, C ; Clear carry 007F 06E6 00095 BTFSC SHT_SDA ; Data bit set? 0080 0503 00096 BSF STATUS, C ; Yup - set carry. 0081 04C6 00097 BCF SHT_SCL ; Clock low 0082 0000 00098 NOP 0083 036E 00099 RLF SHT_TEMP, F ; Store data bit 0084 02EF 00100 DECFSZ SHT_LOOP, F ; Decrement loopvar 0085 0A7C 00101 GOTO SHT_RCV_LOOP ; If not done, keep looping 0086 020E 00102 MOVF SHT_TEMP, W Warning[227]: Substituting RETLW 0 for RETURN pseudo-op 0087 0800 00103 RETURN 00104 00105 ;; Wait for the SHT11 to ACK the transfer 00106 ;; Returns W=0 if SHT acked 0088 00107 SHT_WAITACK: 0088 05C6 00108 BSF SHT_SCL ; Clock high 0089 006F 00109 CLRF SHT_LOOP ; 512mS wait 008A 00110 SHT_ACK_LOOP: 008A 07E6 00111 BTFSS SHT_SDA ; SDA=low=ack 008B 0A91 00112 GOTO SHT_ACKED ; SDA low, SHT has acked 008C 09AC 00113 CALL SHT_ACK_DELAY ; 2mS delay 008D 02EF 00114 DECFSZ SHT_LOOP, F ; Decrement loopvar 008E 0A8A 00115 GOTO SHT_ACK_LOOP ; If not done, keep looping 008F 04C6 00116 BCF SHT_SCL ; Clock low 0090 08FF 00117 RETLW -1 ; SHT didn't ack, return W=-1 0091 00118 SHT_ACKED: 0091 04C6 00119 BCF SHT_SCL ; Clock low 0092 0800 00120 RETLW 0 ; Return, W=0 00121 00122 ;; Send an ACK to the SHT11 0093 00123 SHT_ACK: 00124 _SHT_SDA_SETOUT 0093 05A3 M BANK1 0094 04E6 M BCF SHT_SDA 0095 04A3 M BANK0 0096 04E6 00125 BCF SHT_SDA 0097 0000 00126 NOP MPASM 02.61 Released HUMID.ASM 8-20-2002 17:58:18 PAGE 7 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0098 05C6 00127 BSF SHT_SCL 0099 0000 00128 NOP 009A 04C6 00129 BCF SHT_SCL 009B 0000 00130 NOP 00131 _SHT_SDA_SETIN 009C 05A3 M BANK1 009D 05E6 M BSF SHT_SDA 009E 04A3 M BANK0 Warning[227]: Substituting RETLW 0 for RETURN pseudo-op 009F 0800 00132 RETURN 00133 00134 ;; Send a No-ACK to the SHT11 00A0 00135 SHT_NACK: 00A0 05C6 00136 BSF SHT_SCL ; Clock high 00A1 0000 00137 NOP 00A2 04C6 00138 BCF SHT_SCL ; Clock low 00A3 0000 00139 NOP Warning[227]: Substituting RETLW 0 for RETURN pseudo-op 00A4 0800 00140 RETURN 00141 00142 ;; Wait for the SHT11 to finish taking a measurement 00143 ;; Returns W=0 if SHT finished 00144 00A5 00145 SHT_WAIT: 00A5 006F 00146 CLRF SHT_LOOP ; 512mS wait 00A6 00147 SHT_WAIT_LOOP: 00A6 07E6 00148 BTFSS SHT_SDA ; SDA=low=measurement done 00A7 0800 00149 RETLW 0 ; SDA low, SHT is finished 00A8 09AC 00150 CALL SHT_ACK_DELAY ; 2mS delay 00A9 02EF 00151 DECFSZ SHT_LOOP, F ; Decrement loopvar 00AA 0AA6 00152 GOTO SHT_WAIT_LOOP ; If not done, keep looping 00AB 08FF 00153 RETLW -1 ; SHT failed to ACK 00154 00AC 00155 SHT_ACK_DELAY: 00AC 0C8E 00156 MOVLW 0x8E 00AD 0030 00157 MOVWF SHT_DEL_0 00AE 0C02 00158 MOVLW 0x02 00AF 0031 00159 MOVWF SHT_DEL_1 00B0 00160 SHT_ACK_DELAY_0: 00B0 02F0 00161 DECFSZ SHT_DEL_0, F 00B1 0AB3 00162 GOTO $+2 00B2 02F1 00163 DECFSZ SHT_DEL_1, F 00B3 0AB0 00164 GOTO SHT_ACK_DELAY_0 00165 00B4 0AB5 00166 GOTO $+1 00B5 0000 00167 NOP Warning[227]: Substituting RETLW 0 for RETURN pseudo-op 00B6 0800 00168 RETURN 00169 00170 END MPASM 02.61 Released HUMID.ASM 8-20-2002 17:58:18 PAGE 8 SYMBOL TABLE LABEL VALUE BANK0 BCF STATUS, PA0 BANK1 BSF STATUS, PA0 BANKA BANKS1 00000000 BANKS2 00004000 BANKS4 00008000 BANKS8 0000C000 BANKX BOR13 00010000 BOR25 00020000 BOR40 00030000 C 00000000 CARRYX 00040000 CF Status,0 CHAHI 0000000C CHALO 0000000D CHKSUM 0000000B CHKWZ CMP 00000008 CSA CSA# CSAE CSAE# CSB CSB# CSBE CSBE# DC 00000001 DCF Status,1 DEVICE 00005080 F 00000001 FCALL FGOTO FSR 00000004 HEXOUT 00000023 HEXTAB 0000002E HUMIDITY 00000009 ID IND 00000000 INPUTX IREAD Indir 00000000 LVL 0000000D MODE MOVMW MOVWM OPTIONX 00000200 OSC125KHZ 000000D0 OSC1MHZ 000000A0 OSC250KHZ 000000C0 OSC2MHZ 00000090 OSC31KHZ 000000F0 OSC4MHZ 00000080 MPASM 02.61 Released HUMID.ASM 8-20-2002 17:58:18 PAGE 9 SYMBOL TABLE LABEL VALUE OSC500KHZ 000000B0 OSC62KHZ 000000E0 OSCHS 00000001 OSCLP 00000003 OSCRC 00000000 OSCXT 00000002 OUTPUTX PA0 00000005 PA1 00000006 PA2 00000007 PAGEA PAGES1 00000000 PAGES2 00001000 PAGES4 00002000 PAGES8 00003000 PAGEX PC 00000002 PD 00000003 PDF Status,3 PINS18 00000000 PINS28 00400000 PLP 0000000E PORTA 00000005 PORTB 00000006 PORTC 00000007 PRE7 00080000 PRINTX PROTECT 00000008 PS0 Option,0 PS1 Option,1 PS2 Option,2 PSA Option,3 Pa0 Status,5 Pa1 Status,6 Pa2 Status,7 RA 00000005 RAMBase 00000007 RB 00000006 RC 00000007 RET RETI RETIW RETP RTCC 00000001 RTE_ES Option,4 RTE_IE Option,6 RTS Option,5 RTW Option,7 SEROUT SER_BAUD .19200 SHT_ACK 00000093 SHT_ACKED 00000091 SHT_ACK_DELAY 000000AC MPASM 02.61 Released HUMID.ASM 8-20-2002 17:58:18 PAGE 10 SYMBOL TABLE LABEL VALUE SHT_ACK_DELAY_0 000000B0 SHT_ACK_LOOP 0000008A SHT_BUSINIT 0000003F SHT_DEL_0 00000010 SHT_DEL_1 00000011 SHT_LOOP 0000000F SHT_NACK 000000A0 SHT_RCV_LOOP 0000007C SHT_RECEIVE 00000076 SHT_RS_LOOP 00000047 SHT_SCL PORTB, 6 SHT_SDA PORTB, 7 SHT_SEND 00000061 SHT_SEND_LOOP 00000067 SHT_TEMP 0000000E SHT_WAIT 000000A5 SHT_WAITACK 00000088 SHT_WAIT_LOOP 000000A6 SKIP ST 0000000C STACKX 00000100 START 00000005 STATUS 00000003 SYNC 00000400 Status 00000003 TEMPERATURE 00000007 TO 00000004 TOF Status,4 TRIM0 00000000 TRIM12 00800000 TRIM15 00900000 TRIM18 00A00000 TRIM21 00B00000 TRIM3 00100000 TRIM6 00200000 TRIM9 00300000 TRISX 0000000F TURBO 00000800 W 00000000 WATCHDOG 00000004 WKED 0000000A WKEN 0000000B WKPND 00000009 Z 00000002 ZF Status,2 _DEVICE 000F5F0B _FUSE 00000F0B _FUSEX 000000F5 _INVERT 000F0F8B _PINS 00000000 _ROM 00000001 _SHT_SDA_SETIN _SHT_SDA_SETOUT MPASM 02.61 Released HUMID.ASM 8-20-2002 17:58:18 PAGE 11 SYMBOL TABLE LABEL VALUE __16C56 00000001 __16C57 00000001 __LastBank 00000000 __LastPage 00000007 __NowBank 00000000 __NowPage 00000007 MEMORY USAGE MAP ('X' = Used, '-' = Unused) 0000 : X---XXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0040 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0080 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXX--------- 1000 : ---------------- XX-------------- ---------------- ---------------- All other memory blocks unused. Program Memory Words Used: 180 Program Memory Words Free: 844 Errors : 0 Warnings : 7 reported, 3 suppressed Messages : 1 reported, 0 suppressed
file: /Techref/scenix/contest/humid/HUMID.LST, 29KB, , updated: 2002/8/20 17:58, local time: 2024/11/5 23:39,
18.118.26.249:LOG IN ©2024 PLEASE DON'T RIP! THIS SITE CLOSES OCT 28, 2024 SO LONG AND THANKS FOR ALL THE FISH!
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://linistepper.com/techref/scenix/contest/humid/HUMID.LST"> scenix contest humid HUMID</A> |
Did you find what you needed? |