please dont rip this site


The PIC Source Book: High

writes a high (1) to the specified pin.

This is the equivalent of the assembly-language command setb pin, where pin is the bit address of the pin. PBASIC also changes the pin's data direction to output by writing a 0 to the appropriate bit of the TRIS register. (In assembly, a 0 in TRIS means makes a pin an output; a 1 makes it an input. This is the opposite of the BASIC Stamp.) The assembly-language example here changes only the output latch, not TRIS.

Of course, using setb means that you cannot choose which pin to write while the program is running. The pin address is coded as part of the machine-language instruction. The accompanying program listing is a port- and pin-independent version of setb. Write the pin number to pin, the port number to w, and call High.

High, like the other routines that accept pin and port arguments, requires the short table Pinz. Remember that tables must be located in the first 256 words of a 512-word program memory page.

One hint on using High: always assign the port number to w immediately before calling the routine. If you don't, some other instruction that uses w may change its contents, causing an error.

Demonstrating High.

To see High in operation, either run the program with the PSIM simulator, or connect the circuit below to an erasable PIC or PIC emulator, such as the Parallax downloader. Assemble and run HIGH.SRC. When you apply power to the PIC, the LEDs will light up one at a time until all are lit.


;
; ***************************************************************************
; ***  Bubble Software Parallax to PIC Source Converter. Copyright 1999.  ***
; ***  http://www.bubblesoftonline.com                 email: sales@picnpoke.com  ***
; ***************************************************************************
;
; HIGH port (in w), pin
; Outputs a high to the specified port and pin.

; Device data and reset vector
	P = pic16c55
	#include <16c55.inc>   ; processor assembler definitions
	_CONFIG _xt_osc & _wdt_off & _protect_off
        reset   start

        org     8
pin     Res      d'1'       ; Pin number to set (0-7).

; Variables for the demo program--not required by High.
p_index	Res      d'1'       ; Copy of pin number, port number.
temp    Res      d'1'       ; Temporary variables for time delay
temp2   Res      d'1'       ; between outputs.

        org     0

; Table to convert pin number (0-7) into bit mask (00000001b to 10000000b).
Pinz         ADDWF pcl                  
             RETLW d'1'                 
             RETLW d'2'
             RETLW d'4'
             RETLW d'8'
             RETLW d'16'
             RETLW d'32'
             RETLW d'64'
             RETLW d'128'

; The following demonstration code should show the value of being able to
; set a particular bit of a port based on a calculation performed while the
; program is running. As the variable p_index is incremented from 0 to 15,
; it is used to specify the pin and port to set using High.

start        MOVLW d'0'                 ; All outputs on rb.
             TRIS 6h
             MOVLW d'0'                 ; All outputs on rc.
             TRIS 7h
             CLRF 6h                    ; Start with 0s on rb, rc (all LEDs off).
             CLRF 7h                    
             CLRF p_index               ; Clear p_index.
start_loop   MOVLW d'7'                 ; Copy three lsbs of p_index into
             MOVWF pin
             MOVF p_index               ; variable pin.
             ANDWF pin
             MOVLW d'1'                 ; IF p_index.3 = 0
             BTFSC p_index,d'3'         ; THEN w = 1
             MOVLW d'2'                 ; ELSE w = 2
             CALL High                  
             CALL delay                 ; Wait a while between highs. 
             INCF p_index               ; Next pin/port.
             BTFSS p_index,d'4'         ; IF p_index < 15 (rc.7)
             GOTO start_loop            ; THEN :loop ELSE done
done         GOTO $                     ; Endless loop.


; HIGH (cont)
; To use the routine High, put the pin number into the variable pin
; and the port number into w. Then call High. 

High         MOVWF fsr                  ; Point to the port number.
             MOVLW 5h                   ; Add offset for port RA.
             ADDWF fsr
             MOVF pin,w                 
             CALL Pinz                  ; Get bit mask from the table.
             IORWF indirect             ; Turn on the selected bit
             RETLW 0h                   

; Delay routine for demonstration. Not required by High.

delay        DECFSZ temp                ; Time delay to provide spacing
             GOTO delay
             DECFSZ temp2               ; between highs.
             GOTO delay
             RETLW 0h                   

             end


; HIGH port (in w), pin
; Outputs a high to the specified port and pin.

        org     8
pin     ds      1       ; Pin number to set (0-7).

; Variables for the demo program--not required by High.
p_index         ds      1       ; Copy of pin number, port number.
temp    ds      1       ; Temporary variables for time delay
temp2   ds      1       ; between outputs.

; Device data and reset vector
        device  pic16c55,xt_osc,wdt_off,protect_off
        reset   start
        org     0

; Table to convert pin number (0-7) into bit mask (00000001b to 10000000b).
Pinz    jmp     pc+w
        retw    1,2,4,8,16,32,64,128

; The following demonstration code should show the value of being able to
; set a particular bit of a port based on a calculation performed while the
; program is running. As the variable p_index is incremented from 0 to 15,
; it is used to specify the pin and port to set using High.

start   mov     !rb, #0 ; All outputs on rb.
        mov     !rc, #0 ; All outputs on rc.
        clr     rb      ; Start with 0s on rb, rc (all LEDs off).
        clr     rc
        clr     p_index ; Clear p_index.
:loop   mov     pin,#7  ; Copy three lsbs of p_index into
        AND     pin,p_index     ; variable pin.
        mov     w,#1    ; IF p_index.3 = 0
        snb     p_index.3       ; THEN w = 1
        mov     w,#2    ; ELSE w = 2
        call    High
        call    delay   ; Wait a while between highs. 
        inc     p_index ; Next pin/port.
        sb      p_index.4       ; IF p_index < 15 (rc.7)
        jmp     :loop   ; THEN :loop ELSE done
done    jmp     $       ; Endless loop.


; HIGH (cont)
; To use the routine High, put the pin number into the variable pin
; and the port number into w. Then call High. 

High    mov     fsr,w   ; Point to the port number.
        ADD     fsr,#RA ; Add offset for port RA.
        mov     w,pin
        call    Pinz    ; Get bit mask from the table.
        OR      indirect,w      ; Turn on the selected bit
        ret

; Delay routine for demonstration. Not required by High.

delay   djnz    temp,delay      ; Time delay to provide spacing
        djnz    temp2,delay     ; between highs.
        ret

See also:

See:


file: /Techref/microchip/seepicsrc/psbpix/high.htm, 9KB, , updated: 2011/1/8 14:46, local time: 2024/11/1 03:30,
TOP NEW HELP FIND: 
18.118.184.91: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?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://linistepper.com/techref/microchip/seepicsrc/psbpix/high.htm"> The PIC Source Book: High</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?