tris and option

Started by shaunundergrad July 31, 2003
hi,
new to pic's, all the books on programming use tris and option
however the data sheet for the 12f675 says that tris should not be
used but does not give an alternative way to initilise the ports???
it does give an example and uses GPIO,x can it be used this way??? or
this psuedo cde??

regards

shaun



> new to pic's,

In that case do read http://www.voti.nl/swp

> all the books on programming use tris and option
> however the data sheet for the 12f675 says that tris should not be
> used but does not give an alternative way to initilise the ports???
> it does give an example and uses GPIO,x can it be used this way??? or
> this psuedo cde??

The port direction registers are accessible, in bank 1. But on all
14-bit core PICs I have used the tris instructions still work. But it
would be wise not to rely on this.

Wouter van Ooijen

-- -------
Van Ooijen Technische Informatica: www.voti.nl
consultancy, development, PICmicro products


yes they do still work, but microchip say not to do this anymore,
would like to learn the new correct way, rather than learning old
habits from the start....if anybody has simple source code for the
12f675 using new initilising method....please post

regards

shaun



On Thursday 31 Jul 2003 10:02 pm, shaunundergrad wrote:
> yes they do still work, but microchip say not to do this anymore,
> would like to learn the new correct way, rather than learning old
> habits from the start....if anybody has simple source code for the
> 12f675 using new initilising method....please post
>

TRIS and OPTION are just register files like any other. Initialise them the
same way.

Ian



I think some of the confusion may be with the microchip data sheets.
TRIS and OPTION were originally instructions of their own on the very
first 16X5X PICS. These instructions are simply handled by register
instructions now and just listed for reference more than anything.

Chad

--- Ian Bell <> wrote:
> On Thursday 31 Jul 2003 10:02 pm, shaunundergrad wrote:
> > yes they do still work, but microchip say not to do this anymore,
> > would like to learn the new correct way, rather than learning old
> > habits from the start....if anybody has simple source code for the
> > 12f675 using new initilising method....please post
> >
>
> TRIS and OPTION are just register files like any other. Initialise
> them the
> same way.
>
> Ian


__________________________________





Specifically, you do something like this (change to fit your chip):

banksel PORTA ; in case you are not already in bank 0
clrf PORTA

banksel TRISA ; change to bank 1 (yes I know there are other ways)
movlw 0xff ; set for all inputs
movwf TRISA

banksel PORTA ; get back to bank 0

Same drill for OPTION --- In , Chad Russel <chadrussel@y...> wrote:
> I think some of the confusion may be with the microchip data
sheets.
> TRIS and OPTION were originally instructions of their own on the
very
> first 16X5X PICS. These instructions are simply handled by register
> instructions now and just listed for reference more than anything.
>
> Chad
>
> --- Ian Bell <ian@r...> wrote:
> > On Thursday 31 Jul 2003 10:02 pm, shaunundergrad wrote:
> > > yes they do still work, but microchip say not to do this
anymore,
> > > would like to learn the new correct way, rather than learning
old
> > > habits from the start....if anybody has simple source code for
the
> > > 12f675 using new initilising method....please post
> > >
> >
> > TRIS and OPTION are just register files like any other.
Initialise
> > them the
> > same way.
> >
> > Ian
> >
> > __________________________________
>



> yes they do still work, but microchip say not to do this anymore,
> would like to learn the new correct way, rather than learning old
> habits from the start....if anybody has simple source code for the
> 12f675 using new initilising method....please post

"The port direction registers are accessible, in bank 1."

What part of that scentence did you not understand?

Wouter van Ooijen

-- -------
Van Ooijen Technische Informatica: www.voti.nl
consultancy, development, PICmicro products



Shaun,

between going to page 1 and movlw 0x08 below, add "clrf ADSEL".
This clears the AD selection bits (no ad pins selected).
I tried this and it now works in the simulator.

Regards,

Jim
> hi,
> please look at the following code and tell why the pins won't switch on
>
> ;equates table
> cmcon equ 19h
> gpio equ 05h
>status equ 03h
> trisio equ 85h
> rp0 equ 5
>
> ;initialise port and switch off comparator
>
> bcf status,rp0 ;goto bank 0
> clrf gpio ;clear gpio
> movlw 7h ;load w reg
> movwf cmcon ;switch off comparator
> BSF status,rp0 ;goto bank 1
> movlw 8h ;make pins 0,1,2,4,5 outputs
> movwf gpio ;pin 3 can only be input
> bcf status,rp0 ;back to bank 0
> clrf gpio ;clear gpio
>
> ;main
>
>start movlw 8h ;load w reg
> movwf gpio ;switch on port pins 0,1,2,4,5
> goto start ;loop
> end ;end program > regards
>
>shaun
>
> tried tris still won't simulate pins on, by the way i'm using mplab 6.1


> cheers jim,
> think i've messed around with my original program too much now...not
> simulating....please send me the program you've got working
>
> regards
>
>shaun


;******** Cut and Paste this into MPLAB *********
include <P12F675.inc cmcon equ 19h
gpio equ 05h
status equ 03h
trisio equ 85h

bcf status,5 ;goto bank 0
clrf gpio ;clear gen purp in/out port
movlw 07h ;load w reg
movwf cmcon ;set pin 0,1,2 to digital i/o
bsf status,5 ;goto bank 1
clrf ANSEL
movlw 8h ;make pins 0,1,2,4,5 outputs
movwf trisio ;pin 3 can only be input
bcf status,5 ;back to bank 0
movlw 3fh ;load w reg
movwf gpio ;switch on pins
end ;end program
;*****************************************************************




Shaun,

The program I sent you is exactly the one you sent with your post with the
exception that I added the Include file and I added the "clrf ADSEL"
instruction about halfway down the program. The Include file comes
with MPLAB and it has defines of all the pertinent registers in there
so you can reference them by name instead of by address. If you were
to define the address of ANSEL like the others you defined at the top,
you can dispense with the include file. However, I suggest you use the
include files. That way, you remain consistent when you program your
parts. The "clrf ANSEL" instruction clears the ANalog SELect register
so that NO analog pins are selected. It powers up with all 4 as analog.
Clearing deselects all of them and that behave as digital I/O's.
Hope this helps.

Regards,

Jim > hi jim,
>sorry to be a pain, my prog's slightly different from yours, you've used
>an include file....what issit? and where is from.....did it come with
>mplab??
>
> cheers
>
>shaun