⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 part3.lst

📁 STH11和PIC单片机汇编语言-源程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
MPASM 03.20 Released            PART3.ASM   10-24-2002  12:35:27         PAGE  1


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00001 ; COPYRIGHT 2002 BY DAVID EK. PERMISSION IS GRANTED TO FREELY USE
                      00002 ; THIS SOFTWARE FOR NONCOMMERCIAL PURPOSES.
                      00003 ;
                      00004 ; NOTE: USE AT YOUR OWN RISK. THE AUTHOR ASSUMES NO LIABILITY FOR DAMAGE
                      00005 ; INCURRED FROM THE USE OF THIS SOFTWARE.
                      00006 ;
                      00007 ; THIS IS THE CODE FOR INSTALLMENT 2 OF THE PIC WX ARTICLES IN
                      00008 ; THE DIGITAL QRP HOMEBREWING COLUMN OF QRP QUARTERLY, FALL 2002.
                      00009 ;
                      00010 ; PIC16F84 code for the NK0E weather station project. The purpose
                      00011 ; of this project is to provide a hardware interface which measures
                      00012 ; temperature, wind speed, wind direction, humidity, and pressure
                      00013 ; and communicates it to a PC via serial communications when
                      00014 ; requested. Note that the data collected and transmitted must be
                      00015 ; processed by the PC in order to obtain the actual measurement
                      00016 ; values (i.e. no calibration is done in the PIC code).
                      00017 ;
                      00018 ; The hardware circuit makes use of two major components: the 
                      00019 ; PIC16F84 itself and a MAX232 TTL-RS232 level converter.
                      00020 ; The MAX232 converts the TTL signals from the PIC to RS232 levels
                      00021 ; for the PC (and vice versa).
                      00022 ;
                      00023 ; The PIC16F84 pin assignments are as follows:
                      00024 ;
                      00025 ; RA1: serial out to PC
                      00026 ; RA2: clock out to SHT11 temp/humid sensor
                      00027 ; RA3: data in/out for SHT11 temp/humid sensor
                      00028 ; RB0: serial in from PC (generates interrupt)
                      00029 ;
                      00030 ; This software implements the following command set:
                      00031 ;
                      00032 ; Received  Reply        Description
                      00033 ;-----------------------------------
                      00034 ; 't'       12345 CR LF  Get the temperature raw data. Five digits
                      00035 ;           or e1 CR LF  are always returned, with leading zeroes
                      00036 ;           or e2 CR LF  if necessary, followed by a carriage return
                      00037 ;                        and line feed. See the SHT11 data sheet
                      00038 ;                        for instructions on computing the temperature.
                      00039 ;                        A return of e1 indicates that the SHT11 didn't
                      00040 ;                        acknowledge the request. A return of e2
                      00041 ;                        indicates that no data was returned by the SHT11
                      00042 ;                        within the wait period (255 ms).
                      00043 ; 'h'       12345 CR LF  Get the humidity raw data. Five digits
                      00044 ;           or e1 CR LF  are always returned, with leading zeroes
                      00045 ;           or e2 CR LF  if necessary, followed by a carriage return
                      00046 ;                        and line feed. See the SHT11 data sheet for
                      00047 ;                        instructions on computing the humidity.
                      00048 ;                        A return of e1 indicates that the SHT11 didn't
                      00049 ;                        acknowledge the request. A return of e2
                      00050 ;                        indicates that no data was returned by the SHT11
                      00051 ;                        within the wait period (255 ms).
                      00052 ; 'v'       version info Gets the version number of the firmware.
                      00053 ;                        returns an ASCII string followed by a 
MPASM 03.20 Released            PART3.ASM   10-24-2002  12:35:27         PAGE  2


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00054 ;                        carriage return and line feed.
                      00055 ;
                      00056 ; Written using Microchip MPLAB v5.40
                      00057 ;
                      00058 ; Please direct any questions, comments, or suggestions to the
                      00059 ; author: David Ek
                      00060 ;         nk0e@earthlink.net
                      00061 ;
                      00062 ; History:
                      00063 ;
                      00064 ; Rev 1 (23 Jul 2002):
                      00065 ;    Creation. Returns dummy temperature data. This version used
                      00066 ;    for installment 2 of the PIC WX articles in QQ.
                      00067 ; Rev 2 (26 Sep 2002):
                      00068 ;    Added code for the Sensirion SHT11 temperature/humidity sensor
                      00069 ;    for installment 3 of the PIC WX articles in QQ.
                      00070 ;
                      00071 ;----------------------------------------------------------------
                      00072 
                      00073         list    p=16f84
                      00074         radix   dec
2007   3FF9           00075         __config _CP_OFF & _WDT_OFF & _XT_OSC
                      00076 
                      00077         include "p16f84.inc"
                      00001         LIST
                      00002 ; P16F84.INC  Standard Header File, Version 2.00    Microchip Technology, Inc.
                      00136         LIST
                      00078 
                      00079 ; defines:
                      00080 
                      00081 ; These are used by the serial comm routines for timing. Note that
                      00082 ; slower speeds may not work well because the delays might be larger
                      00083 ; than 255, requiring the use of the prescalar.
                      00084 
  000F4240            00085 _Clkspd         equ     1000000                 ;external clock / 4
  00002580            00086 _BaudRate       equ     9600                    ;desired baud rate
  00000068            00087 _Period         equ     (_Clkspd/_BaudRate)     ;clock cycles / bit
                      00088 
  0000000C            00089 _StartRxDelay   equ     (_Period/2 - 15)/3      ;this is how long to
                      00090                                                 ;wait to get to the
                      00091                                                 ;middle of the start
                      00092                                                 ;bit. This is loops,
                      00093                                                 ;not clock cycles.
                      00094 
  000000AD            00095 _BitRxDelay     equ     277 - _Period           ;this is what to load
                      00096                                                 ;into TMR0 for correct
                      00097                                                 ;interval between bits
                      00098                                                 ;on RX
                      00099 
  000000B5            00100 _BitTxDelay     equ     285 - _Period           ;this is what to load
                      00101                                                 ;into TMR0 for correct
                      00102                                                 ;interval between bits
                      00103                                                 ;on TX
MPASM 03.20 Released            PART3.ASM   10-24-2002  12:35:27         PAGE  3


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00104 
  000000A8            00105 _StopTxDelay    equ     272 - _Period           ;this is what to load
                      00106                                                 ;into TMR0 for correct
                      00107                                                 ;interval betweeen last
                      00108                                                 ;bit and stop bit on TX
                      00109 
                      00110 ; defines for I/0 pins:
                      00111 
  00000000            00112 _SER_IN         equ     0                       ;Serial input line (PORTB)
  00000001            00113 _SER_OUT        equ     1                       ;Serial output line (PORTA)
  00000002            00114 _SHT11_SCK      equ     2                       ;clock line for SHT11 sensor
                      00115                                                 ;(PORTA)
  00000003            00116 _SHT11_DAT      equ     3                       ;data line for SHT11 sensor
                      00117                                                 ;(PORTA)
                      00118 
                      00119 ; macros for the bin-to-ascii conversion routines:
                      00120 
                      00121 loadw   macro   arg1
                      00122         movlw   high(arg1)
                      00123         movwf   hi
                      00124         movlw   low(arg1)
                      00125         movwf   lo
                      00126         endm
                      00127 dodigit macro   arg1
                      00128         movlw   high(arg1)
                      00129         movwf   shi
                      00130         movlw   low(arg1)
                      00131         movwf   slo
                      00132         call    dosub
                      00133         endm
                      00134 
                      00135 ; memory locations:
                      00136 
                      00137         cblock 0x0C
                      00138 
  0000000C            00139         BitCount        ;number of bits left to send or
                      00140                         ;receive, not including start & stop
                      00141                         ;bits
                      00142 
  0000000D            00143         RXChar          ;received character while being received
  0000000E            00144         RXBuff          ;most recently received character
                      00145 
  0000000F            00146         TXChar          ;character to transmit
                      00147 
  00000010            00148         SerialReg       ;status register:
                      00149                         ;bit 0: on if character has been
                      00150                         ;       received
                      00151                         ;bit 1: on if busy with RX/TX
                      00152                         ;bit 2: on if sending, off if receiving
                      00153                         ;bit 3: on if next bit to send is stop bit
                      00154 
  00000011            00155         WSave           ;copy of W register
                      00156 
MPASM 03.20 Released            PART3.ASM   10-24-2002  12:35:27         PAGE  4


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

  00000012            00157         SSave           ;copy of the Status register
                      00158 
  00000013            00159         SHT11Byte       ;a byte of data sent to or returned by the SHT11
                      00160 
  00000014            00161         counter         ;generic counter register
                      00162 
  00000015            00163         hi              ;hi byte for number to be converted to ascii
  00000016            00164         lo              ;lo byte for number to be converted to ascii
  00000017            00165         shi             ;hi byte for subtractor for conversion to ascii
  00000018            00166         slo             ;lo byte for subtractor for conversion to ascii
  00000019            00167         digit           ;ascii digit converted from binary. Also used as
                      00168                         ;input to SendErrorCode
                      00169 
  0000001A            00170         MSDelay         ;register for WaitMS timing
                      00171 
                      00172         endc
                      00173 
0000                  00174         org     0x00
0000   292A           00175         goto    Main
                      00176 
0004                  00177         org     0x04
                      00178 
                      00179 ;--------------------------------------------------------------------
                      00180 ;-----Serial Communication Routines----------------------------------
                      00181 ;--------------------------------------------------------------------
                      00182 ;
                      00183 ; The serial comm routines generate 1 start bit, 8 data bits, 1 stop bit, 
                      00184 ; no parity. The baud rate is determined by the delay programmed
                      00185 ; into the onboard timer. The sending and receiving is interrupt driven,
                      00186 ; meaning other tasks can be carried on while the characters are being
                      00187 ; sent and received.
                      00188 ;
                      00189 ;-----Main Interrupt Routine-----------------------------------------
                      00190 ;
                      00191 ; for timing: 4 cycles from interrupt time to get here.
                      00192 
                      00193 ; Save the W and STATUS registers:
                      00194 
0004                  00195 Int
0004   0091           00196         movwf   WSave
0005   0E03           00197         swapf   STATUS,W        ;use swapf to prevent any
0006   0092           00198         movwf   SSave           ;status flags from being changed
                      00199 
                      00200 ; cycles so far since interrupt occurred: 7
                      00201 
                      00202 ; Okay, I'm doing something goofy here. Instead of actually checking
                      00203 ; the overflow bits themselves, I'm using the enable bits to determine
                      00204 ; which interrupt occurred. I can do this because there should only
                      00205 ; ever be one type of interrupt active at a time. The problem with
                      00206 ; checking the overflow bits is that the T0IF bit can get set even

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -