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

📄 part3.lst

📁 STH11和PIC单片机汇编语言-源程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
                      00207 ; if that interrupt is disabled.
                      00208 
                      00209 ; Check first for a timer overflow interrupt. The overflow bit gets
MPASM 03.20 Released            PART3.ASM   10-24-2002  12:35:27         PAGE  5


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00210 ; set even if the interrupt is disabled.
                      00211 
0007   1A8B           00212         btfsc   INTCON,T0IE
0008   282D           00213         goto    DoBit           ;we're in the middle of sending or
                      00214                                 ;receiving
                      00215 
                      00216 ; 10 cycles executed on entry to DoBit
                      00217 
                      00218 ; If not a timer overflow interrupt, check for external interrupt:
                      00219 
0009   1A0B           00220         btfsc   INTCON,INTE     ;RB0 is our receive line and it
000A   281D           00221         goto    StartRX         ;generates an interrupt on a high-
                      00222                                 ;to-low transition
                      00223 
                      00224 ; 12 cycles executed on entry to StartRX
                      00225 
                      00226 ; Else, must be something we don't care about:
                      00227 
                      00228         ;do nothing for now
                      00229 
                      00230 ; Restore the W and STATUS registers:
                      00231 
000B   0E12           00232 Restore swapf   SSave,W
000C   0083           00233         movwf   STATUS
000D   0E91           00234         swapf   WSave,F
000E   0E11           00235         swapf   WSave,W
                      00236 
000F   0009           00237         retfie
                      00238 
                      00239 ;------end Main Interrupt Routine------------------------------------
                      00240 
                      00241 
                      00242 ;------Subroutine SerSetup-------------------------------------------
                      00243 
0010                  00244 SerSetup
                      00245 
                      00246 ; set up the option register for internal counting, WDT disabled,
                      00247 ; no prescaler.
                      00248 
0010   0181           00249         clrf    TMR0
0011   1683           00250         bsf     STATUS,RP0
0012   0064           00251         clrwdt                  ;set bits in OPTION_REG to
0013   3088           00252         movlw   b'10001000'     ;enable internal clock counting,
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
0014   0081           00253         movwf   OPTION_REG      ;disable watchdog timer.
0015   1283           00254         bcf     STATUS,RP0      ;switch to bank 0
                      00255 
                      00256 ; set the output line to idle (high)
                      00257 
0016   1485           00258         bsf     PORTA,_SER_OUT  ;set the output line to idle
                      00259                                 ;(high) state
                      00260 
0017   3001           00261         movlw   b'00000001'
MPASM 03.20 Released            PART3.ASM   10-24-2002  12:35:27         PAGE  6


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

0018   0086           00262         movwf   PORTB
                      00263 
                      00264 ; enable the external interrupt via RB0
                      00265 
0019   3090           00266         movlw   b'10010000'     ;set bits in INTCON to enable
001A   008B           00267         movwf   INTCON          ;external interrupt
                      00268 
                      00269 ; initialize the SerialReg:
                      00270 
001B   0190           00271         clrf    SerialReg
                      00272 
001C   0008           00273         return
                      00274 
                      00275 ;------end SetSetup--------------------------------------------------
                      00276 
                      00277 ;------Subroutine StartRX--------------------------------------------
                      00278 ;
                      00279 ; This subroutine is called by the main interrupt routine when an
                      00280 ; external interrupt on RB0 occurs. This means we're receiving the
                      00281 ; start bit for a character. We want to enable the external TMR0
                      00282 ; interrupt and prepare to receive the character.
                      00283 
001D                  00284 StartRX
                      00285 
                      00286 ; wait halfway through the bit to see if it's real:
                      00287 
001D   108B           00288         bcf     INTCON,INTF     ;clear the interrupt
001E   300C           00289         movlw   _StartRxDelay
001F   008C           00290         movwf   BitCount        ;this is the 15th instruction since
                      00291                                 ;the interrupt. Note--we're using
                      00292                                 ;BitCount for this loop purely for
                      00293                                 ;convenience. Usually it's used to
                      00294                                 ;actually count the bits we TX/RX.
                      00295 
0020   0B8C           00296 RXWait  decfsz  BitCount,F      ;this loop takes 3 times the initial
0021   2820           00297         goto    RXWait          ;value of BitCount clock cycles
                      00298         
                      00299 ; now we should be at the middle of the start bit. Is the input still
                      00300 ; low? If not, goto Restore and ignore this interrupt.
                      00301 
0022   1806           00302         btfsc   PORTB,_SER_IN
0023   280B           00303         goto    Restore
                      00304 
                      00305 ; if we get to here it must really be the start bit. Load TMR0,
                      00306 ; disable the external interrupt, and enable the TMR0 interrupt. 
                      00307 
                      00308 ; load up the appropriate delay to get us to the middle of the
                      00309 ; first bit:
                      00310 
0024   30AD           00311         movlw   _BitRxDelay
0025   0081           00312         movwf   TMR0            ;4 cycles from read of PORTB
0026   3020           00313         movlw   b'00100000'
0027   008B           00314         movwf   INTCON
MPASM 03.20 Released            PART3.ASM   10-24-2002  12:35:27         PAGE  7


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00315 
                      00316 ; set the SerialReg to indicate that the routines are busy getting
                      00317 ; a character:
                      00318 
0028   3002           00319         movlw   b'00000010'
0029   0090           00320         movwf   SerialReg
                      00321 
                      00322 ; initialize BitCount:
                      00323 
002A   3008           00324         movlw   8
002B   008C           00325         movwf   BitCount
                      00326 
                      00327 ; okay, now we return.
                      00328 
002C   280B           00329         goto    Restore
                      00330 
                      00331 ;------end StartRX---------------------------------------------------
                      00332 
                      00333 
                      00334 ;------DoBit---------------------------------------------------------
                      00335 ;
                      00336 ; sends or receives the next bit. Bits are sent/received from least
                      00337 ; to most significant bit.
                      00338 
002D                  00339 DoBit
                      00340 
                      00341 ; clear the TMR0 overflow interrupt flag:
                      00342 
002D   110B           00343         bcf     INTCON,T0IF
                      00344 
                      00345 ; Are we receiving?
                      00346 
002E   1910           00347         btfsc   SerialReg,2
002F   2840           00348         goto    Sending
                      00349 
                      00350 ; check to see if we're receiving the stop bit:
                      00351 
0030   088C           00352         movf    BitCount,F
0031   1903           00353         btfsc   STATUS,Z
0032   2839           00354         goto    GetStopBit
                      00355 
                      00356 ; if we get to here, we're in the middle of receiving. Get the next
                      00357 ; bit: (16 cycles to get to the next instruction from the start of
                      00358 ; the interrupt).
                      00359 
0033   0C06           00360         rrf     PORTB,W         ;rrf PORTB into W. This sets
                      00361                                 ;the carry bit if RB0 was high.
0034   0C8D           00362         rrf     RXChar,F        ;doing a rrf on RXChar brings
                      00363                                 ;in the carry bit to the MSB.
                      00364 
                      00365 ; Decrement the bit counter.
                      00366 
0035   038C           00367         decf    BitCount,F
MPASM 03.20 Released            PART3.ASM   10-24-2002  12:35:27         PAGE  8


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00368 
                      00369 ; reload TMR0 for the next interrupt, and
                      00370 ; go to the end of the interrupt routine.
                      00371 
0036   30AD           00372         movlw   _BitRxDelay     
0037   0081           00373         movwf   TMR0            ;21 cycles from start of interrupt
0038   280B           00374         goto    Restore
                      00375 
                      00376 ; if we get to here it's because we need to check for the stop bit.
                      00377 
0039                  00378 GetStopBit
0039   1C06           00379         btfss   PORTB,_SER_IN   ;is the RX line low? If so, it's not
003A   285A           00380         goto    Done            ;the stop bit. Otherwise, set the
003B   3001           00381         movlw   b'00000001'     ;SerialReg to show a character has
003C   0090           00382         movwf   SerialReg       ;been received
003D   080D           00383         movf    RXChar,W        ;copy the received character to RXBuff
003E   008E           00384         movwf   RXBuff
003F   285A           00385         goto    Done
                      00386                 
                      00387 ; We got here because we're sending.
                      00388 ; check to see if we're finished sending the stop bit:
                      00389 
0040                  00390 Sending
0040   1990           00391         btfsc   SerialReg,3
0041   285A           00392         goto    Done
                      00393 
                      00394 ; check to see if we need to send the stop bit:
                      00395 
0042   088C           00396         movf    BitCount,F
0043   1903           00397         btfsc   STATUS,Z        ;18th cycle
0044   2852           00398         goto    SendStopBit
                      00399 
                      00400 ; if we get to here, we're in the middle of sending. Send the next
                      00401 ; bit: (16 cycles to get to the next instruction from the start of
                      00402 ; the interrupt).
                      00403 
0045   0C8F           00404         rrf     TXChar,F        ;doing rrf on TXChar puts the
0046   1C03           00405         btfss   STATUS,C        ;least significant bit in the
0047   284B           00406         goto    SendZero        ;carry flag.
0048   0000           00407         nop
0049   1485           00408         bsf     PORTA,_SER_OUT  ;if carry is set, send a one.
004A   284E           00409         goto    EndDoBit        ;PORTA,1 is set on the 24th cycle
                      00410 
004B                  00411 SendZero
004B   1085           00412         bcf     PORTA,_SER_OUT  ;otherwise, send a zero. (24th cycle)
004C   0000           00413         nop                     ;nop's are for taking the same time
004D   0000           00414         nop                     ;to get to reloading TMR0 as for when

⌨️ 快捷键说明

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