Searching \ for '[PIC]: Setting Equates to part of a port?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=port
Search entire site for: 'Setting Equates to part of a port?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Setting Equates to part of a port?'
2001\09\24@204051 by JP

flavicon
face
I need to set a variable name to 4 pins of portb (16F84).  Is it possible?  E.g. I need to assign the name LCD to portb, bits 4,5,6,7.

If I were assigning it to just portb then I would use

LCD equ portb

But I have no idea how to do this just using 4 bits!

JP.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\09\24@213343 by Gennette, Bruce

flavicon
face
I don't think equ will be possible.  But how about a named macro that
mentions/addresses all 4 bits?

Bye.

{Original Message removed}

2001\09\25@074301 by JP

flavicon
face
How would that work?

jp.

----- Original Message -----
From: "Gennette, Bruce" <spam_OUTbruce.gennetteTakeThisOuTspamTAFE.NSW.EDU.AU>
To: <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU>
Sent: Tuesday, September 25, 2001 2:32 AM
Subject: Re: [PIC]: Setting Equates to part of a port?


> I don't think equ will be possible.  But how about a named macro that
> mentions/addresses all 4 bits?
>
> Bye.
>
> {Original Message removed}

2001\09\25@115929 by Jeff DeMaagd

flavicon
face
There are many things you have to explicitly define.

For one you can't "just" address a nibble, only bits and bytes.  Any
permutation requires a few extra instructions to read, mask, modify &
write.

If you want to know how to make macros, the available manuals should do
fine.  If  you do not have one download one.  For MPASM, download
DS33014G from the microchip site.

For learning what instructions to use, I think it would do you good to
get a close look at the instruction set and learn how each instruction
works.

Jeff

----- Original Message -----
From: JP <piclistspamKILLspamMAILANDNEWS.COM>


> How would that work?
>
> ----- Original Message -----
> From: "Gennette, Bruce" <.....bruce.gennetteKILLspamspam.....TAFE.NSW.EDU.AU>
>
> > I don't think equ will be possible.  But how about a named macro
that
> > mentions/addresses all 4 bits?
> >
> > {Original Message removed}

2001\09\25@190348 by Tony Nixon

flavicon
picon face
JP wrote:
>
> How would that work?
>
> jp.
>
> ----- Original Message -----
> From: "Gennette, Bruce" <EraseMEbruce.gennettespam_OUTspamTakeThisOuTTAFE.NSW.EDU.AU>
> To: <PICLISTspamspam_OUTMITVMA.MIT.EDU>
> Sent: Tuesday, September 25, 2001 2:32 AM
> Subject: Re: [PIC]: Setting Equates to part of a port?
>
> > I don't think equ will be possible.  But how about a named macro that
> > mentions/addresses all 4 bits?
> >
> > Bye.

I don't think I would write a macro. A subroutine might be better,
especially if it gets called a lot which is possible with LCD use.

The problem is that by writing the 4 bits to PORTB, you have to protect
the other 4 bits. However, if these bits (0 - 3)are all set as INPUTS,
just write your data directly to the PORT.

If some or all of these bits (0 - 3) are set as OUTPUTS you need to
preserve thier current state before writing to the upper nibble of the
port. You can use a shadow register for this purpose. The idea is to
write all data to this register first and then write it to the port.

Example

       movlw 0h                ; initialise all port bits
       movwf PBshadow          ; and shadow register
       movwf PORTB


You could write a MACRO for routines that may not get called a lot.

Example

Led_ON  MACRO
       bsf PBshadow,LED        ; RB0 = LED = ON
       movf PBshadow,W
       movwf PORTB
       ENDM

Let the assembler include it in your code by...

       Led_ON                  ; Turn RB0 LED on


If you want to write 8 bits of data to the upper nibble of PORTB (as in
4 bit LCD mode) then this code could be used...

       movlw 'A'               ; write 'A' to LCD
       call LCDout
       ....

;
; ROUTINE ENTERS WITH 8 BIT DATA IN W
;
LCDout  movwf LCDdata           ; save data
       call Nib_Out            ; upper nibble to PORTB
       call LCDclock           ; clock the data into LCD

       swapf LCDdata,W
       call Nib_Out            ; lower nibble to PORTB
       call LCDclock           ; clock the data into LCD
       return
;
; ROUTINE ENTERS WITH DATA IN W
; UPPER NIBBLE = DATA
; LOWER NIBBLE = DON'T CARE
;
Nib_Out andlw b'11110000'       ; mask lower nibble
       movwf Temp              ; save data
       movlw b'00001111'       ; mask upper nibble in
       andwf PBshadow,W        ; current PORTB data
       iorwf Temp,W            ; merge with new upper nibble
       movwf PBshadow          ; update current data
       movwf PORTB             ; update PORTB
       return

There are probably better routines around but this should give you the
idea.


--
Best regards

Tony

mICros
http://www.bubblesoftonline.com
@spam@salesKILLspamspambubblesoftonline.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...