?? part3.lst
字號:
00415 ;a one is sent.
00416
00417 ; Decrement the bit counter.
00418
004E 00419 EndDoBit
004E 038C 00420 decf BitCount,F
MPASM 03.20 Released PART3.ASM 10-24-2002 12:35:27 PAGE 9
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00421
00422 ; reload TMR0 for the next interrupt, and
00423 ; go to the end of the interrupt routine.
00424
004F 30B5 00425 movlw _BitTxDelay
0050 0081 00426 movwf TMR0 ;29th cycle
0051 280B 00427 goto Restore
00428
00429
00430 ; Here we need to send the stop bit, turn off the TMR0 interrupt,
00431 ; turn on the external interrupt, and set the SerStatus register
00432 ; flags appropriately.
00433
0052 00434 SendStopBit
0052 0000 00435 nop
0053 0000 00436 nop
0054 0000 00437 nop
0055 1485 00438 bsf PORTA,_SER_OUT ;no. Send the stop bit. (24th cycle)
0056 1590 00439 bsf SerialReg,3 ;set the "sending stop bit" flag
00440
00441 ; reload TMR0 for the next interrupt, and
00442 ; go to the end of the interrupt routine.
00443
0057 30A8 00444 movlw _StopTxDelay
0058 0081 00445 movwf TMR0 ;27th cycle
0059 280B 00446 goto Restore
00447
00448 ; we're completely done sending or receiving. Clean up.
00449
005A 3010 00450 Done movlw b'00010000' ;set bits in INTCON to enable
005B 008B 00451 movwf INTCON ;external interrupt
005C 3001 00452 movlw b'00000001'
005D 0590 00453 andwf SerialReg,F ;clear the busy bits in SerialReg
005E 280B 00454 goto Restore
00455
00456 ;------end DoBit-----------------------------------------------------
00457
00458 ;------Subroutine SendChar-------------------------------------------
00459 ;
00460 ; This is not called by the interrupt handler. Rather, it activates
00461 ; the interrupts needed to send it. Put the character to be sent in
00462 ; the TXChar file register before calling this subroutine.
00463 ;
00464
005F 00465 SendChar
00466
00467 ; send the start bit:
00468
005F 1085 00469 bcf PORTA,_SER_OUT
00470
00471 ; set the SerStatus to indicate that the routines are busy sending
00472 ; a character:
00473
MPASM 03.20 Released PART3.ASM 10-24-2002 12:35:27 PAGE 10
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
0060 3006 00474 movlw b'00000110'
0061 0090 00475 movwf SerialReg
00476
00477 ; load up TMR0 so it overflows at the right time.
00478
0062 0000 00479 nop ;for timing
0063 30B5 00480 movlw _BitTxDelay
0064 0081 00481 movwf TMR0 ;5th cycle after write to PORTA
00482
00483 ; clear the external interrupt flag, disable the external interrupt,
00484 ; and enable the TMR0 interrupt.
00485
0065 30A0 00486 movlw b'10100000'
0066 008B 00487 movwf INTCON
00488
00489 ; set the BitCount for the eight bits to send:
00490
0067 3008 00491 movlw 8
0068 008C 00492 movwf BitCount
00493
0069 0008 00494 return
00495
00496 ;------end SendChar--------------------------------------------------
00497
00498 ;------begin GetAChar------------------------------------------------
00499
006A 00500 GetAChar
006A 2129 00501 call Idle
006B 1C10 00502 btfss SerialReg,0 ;wait for a character to be received
006C 286A 00503 goto GetAChar
006D 1010 00504 bcf SerialReg,0
006E 0008 00505 return
00506
00507 ;------end GetAChar--------------------------------------------------
00508
00509 ;------begin SendAChar-----------------------------------------------
00510
006F 00511 SendAChar
006F 205F 00512 call SendChar
00513
0070 00514 WaitToFinish
0070 2129 00515 call Idle
0071 1890 00516 btfsc SerialReg,1 ;wait for the character to be sent
0072 2870 00517 goto WaitToFinish
0073 0008 00518 return
00519
00520 ;------end SendAChar-------------------------------------------------
00521
00522 ;------Subroutine WaitMS---------------------------------------------
00523 ;
00524 ; WaitMS is an approximate millisecond delay. It assumes a 4 MHz
00525 ; oscillator, meaning instructions are executed at a rate of 1 MHz.
00526 ; I got the timing info (number of cycles per instruction) from the
MPASM 03.20 Released PART3.ASM 10-24-2002 12:35:27 PAGE 11
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00527 ; Microchip PIC16F84 data sheet.
00528
00529 ; the call to this subroutine takes 2 cycles to execute.
00530
0074 00531 WaitMS
0074 30F8 00532 movlw 248 ;1 cycle
0075 009A 00533 movwf MSDelay ;1 cycle
0076 0000 00534 nop ;1 cycle--these nops are added to
0077 0000 00535 nop ;1 cycle make the total number of
0078 0000 00536 nop ;1 cycle instructions executed in
00537 ; the routine to be 1000.
00538 ;the nop instruction simply does
00539 ;nothing except take time to execute.
00540
00541 ; The loop below takes four cycles for every time through except the
00542 ; last, when it takes five (including the time needed to execute the
00543 ; return). So, the total number of instructions executed in getting
00544 ; to and returning from this subroutine is:
00545 ;
00546 ; 2 to get here
00547 ; + 2 to set the MSDelay value
00548 ; + 3 for the nops
00549 ; + 247*4 for the first 247 times through the loop
00550 ; + 5 for the last time through the loop and to return
00551 ; --------
00552 ; = 1000
00553
0079 00554 RepeatWaitMS
0079 0000 00555 nop ;1 cycle
007A 0B9A 00556 decfsz MSDelay,F ;1 cycle if not zero, 2 if zero
007B 2879 00557 goto RepeatWaitMS ;2 cycles
007C 0008 00558 return ;2 cycles
00559
00560 ;------end WaitMS----------------------------------------------------
00561
00562 ;------begin SHT11TXRX-----------------------------------------------
00563 ;
00564 ; Sends a byte command to the SHT11 temp/humidity sensor and retrieves
00565 ; a two-byte response. Sends the response back to the PC as an ASCII
00566 ; string representation of the number.
00567 ;
00568 ; Put the byte to send in SHT11Byte before calling this routine.
00569
007D 00570 SHT11TXRX
00571
00572 ;make _SHT11_DAT an output
00573
007D 1683 00574 bsf STATUS,RP0 ;switch to bank 1
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
007E 1185 00575 bcf TRISA,_SHT11_DAT ;make Port A data line an output
007F 1283 00576 bcf STATUS,RP0 ;switch back to bank 0
00577
00578 ;send the Transmission Start sequence:
MPASM 03.20 Released PART3.ASM 10-24-2002 12:35:27 PAGE 12
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00579
0080 1585 00580 bsf PORTA,_SHT11_DAT ;set the data line high
0081 1505 00581 bsf PORTA,_SHT11_SCK ;take the clock line high
0082 1185 00582 bcf PORTA,_SHT11_DAT ;take the data line low
0083 1105 00583 bcf PORTA,_SHT11_SCK ;take the clock line low
0084 1505 00584 bsf PORTA,_SHT11_SCK ;take the clock line high again
0085 1585 00585 bsf PORTA,_SHT11_DAT ;set the data line high again
00586
00587 ;load up the counter to loop through the eight bits to send:
00588
0086 3008 00589 movlw 8
0087 0094 00590 movwf counter
00591
0088 00592 SHT11SendBitLoop
0088 1105 00593 bcf PORTA,_SHT11_SCK ;take the clock line low
00594
0089 1F93 00595 btfss SHT11Byte,7 ;is the next bit to send a one?
008A 288D 00596 goto SHT11SendZero ;nope. Go send a zero.
008B 1585 00597 bsf PORTA,_SHT11_DAT ;if it's a one, send it.
008C 288E 00598 goto SHT11SendBit
00599
008D 00600 SHT11SendZero
008D 1185 00601 bcf PORTA,_SHT11_DAT ;set the data line to zero
00602
008E 00603 SHT11SendBit
008E 1505 00604 bsf PORTA,_SHT11_SCK ;take the clock line high to send
00605
008F 0D93 00606 rlf SHT11Byte,F ;move the next bit into MSB
00607
0090 0B94 00608 decfsz counter,F ;dec the counter and check for zero.
0091 2888 00609 goto SHT11SendBitLoop ;if not zero, more bits to send
00610
0092 1105 00611 bcf PORTA,_SHT11_SCK ;take the clock line low
00612
00613 ;no more bits to send. Set the data line to be an input and
00614 ;wait for the ack from the SHT11:
00615
0093 1683 00616 bsf STATUS,RP0 ;switch to bank 1
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
0094 1585 00617 bsf TRISA,_SHT11_DAT ;make Port A data line an input
0095 1283 00618 bcf STATUS,RP0 ;switch back to bank 0
00619
00620 ; now look for an ack (SHT11 pulls data line low--should
00621 ; happen on the next rise of the SCK line). If it doesn't
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -