reverses a pin's data direction.
Setting up a particular pin as an input or output requires writing a 1 or 0 to the corresponding bit of that port's TRIS register. However, the TRIS registers are write-only, so your program must keep copies of their contents in normal RAM to perform operations like Reverse. Here is a program fragment that shows how this works:
; *************************************************************************** ; *** Bubble Software Parallax to PIC Source Converter. Copyright 1999. *** ; *** http://www.bubblesoftonline.com email: sales@picnpoke.com *** ; *************************************************************************** ; ; PULSOUT port, pin, time ; Generates an output pulse in 10-cycle (10 us at 4 MHz) units, ; based on a 16-bit (1 to 65,535) value. The pulse is the reverse ; of the pin's state when pulsout is called. For instance, if the ; specified pin is initially 1, Pulsout will invert it to make a ; negative-going pulse. P = pic16c55 #include <16c55.inc> ; processor assembler definitions _CONFIG _xt_osc & _wdt_off & _protect_off org 8 TRISB_copy Res d'1' org 0 MOVLW b'11110000' ; Make a copy of TRISB. MOVWF TRISB_copy MOVF TRISB_copy,w ; Move copy into TRISB. TRIS 6h ; >>TRISB now contains 11110000b. ; ... ; Other instructions. MOVLW b'10000000' ; Reverse bit 7 of copy. XORWF TRISB_copy MOVF TRISB_copy,w ; Move copy into TRISB. TRIS 6h ; >>TRISB now contains 01110000b. endmov TRISB_copy,#11110000b ; Make a copy of TRISB. mov !rb,TRISB_copy ; Move copy into TRISB. ; >>TRISB now contains 11110000b. ... ; Other instructions. XOR TRISB_copy,#10000000b ; Reverse bit 7 of copy. mov !rb, TRISB_copy ; Move copy into TRISB. ; >>TRISB now contains 01110000b.
Instead of moving a value directly into RB's TRIS register, the program moves it into a file register named TRISB_copy. Then it puts the value into TRIS. Later, when the equivalent of the Reverse instruction is required, the program reverses (inverts) the corresponding bit of the copy, and writes the copy to TRIS. This must be done consistently throughout a program in order to work properly. If at some point the copy no longer corresponds to the contents of TRIS, the method breaks down. That's why the programs in this book avoid TRIS manipulations whenever possible; they depend too heavily on the code in the rest of the program. The result could be bugs in the operation of these routines. However, don't let this stop you from incorporating powerful TRIS-copy techniques into your programs.
See also:
file: /Techref/microchip/seepicsrc/psbpix/reverse.htm, 3KB, , updated: 2001/5/25 13:48, local time: 2024/12/22 04:10,
3.137.170.38:LOG IN
|
©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://massmind.ecomorder.com/Techref/microchip/seepicsrc/psbpix/reverse.htm"> microchip seepicsrc psbpix reverse</A> |
Did you find what you needed? |
Welcome to ecomorder.com! |
Welcome to massmind.ecomorder.com! |
.