What am I doing wrong here? I tried to configure port A as all digital
inputs, but can't read from it. If I replace port A with port C, it works.
Here's the init/main part of my code...
[ includes, config, etc up here ]
movlw B'00111111'
movwf TRISA ; Port A is all inputs
movlw B'00000110'
movwf ADCON1 ; Port A is all digital
movlw B'00000000'
movwf ADCON0 ; Turn off A/D
tris PORTB ; Port B is all outputs
tris PORTC ; Port C is all outputs
loop:
movf PORTA,0 ; Grab data at port A
movwf PORTB ; Dump to port B
goto loop
Pic Dude wrote:
>
> What am I doing wrong here? I tried to configure port A as all digital
> inputs, but can't read from it. If I replace port A with port C, it works.
> Here's the init/main part of my code...
The dreaded old bank select problem. Read piclist.com and the data
sheets about register banks and bank switching.
you have to disable the a/d converters, sharing the pins of port a. they
are enabled by default. so port a works well as digital output, but you
will always read a 0, until you disable the a/d's (took me about 2 days of
debugging a driver, that worked well on a 16f84 before...)
tino
Pic Dude wrote:
>
> What am I doing wrong here? I tried to configure port A as all digital
> inputs, but can't read from it. If I replace port A with port C, it
works.
> Here's the init/main part of my code...
The dreaded old bank select problem. Read piclist.com and the data
sheets about register banks and bank switching.
>>
movlw B'00111111'
movwf TRISA ; Port A is all inputs
movlw B'00000110'
movwf ADCON1 ; Port A is all digital
movlw B'00000000'
movwf ADCON0 ; Turn off A/D
tris PORTB ; Port B is all outputs
tris PORTC ; Port C is all outputs
loop:
movf PORTA,0 ; Grab data at port A
movwf PORTB ; Dump to port B
goto loop
end
<<
For one thing, you've totally ignored bank settings. You do need to pay
attention to these. Check out my DBANKIF and related macros if you want a
more automatic way of setting the banks. You can find them in STD.INS.ASPIC
at http://www.embedinc.com/pic.
Secondly, don't use the TRIS instruction. I'm surprised the assembler
didn't give you a warning. This is an old instruction that is (has) being
obsoleted. Note that it's not in the list of instructions on page 136 of
DS30292C.
It looks like you may have programmed some old chips a long time ago. It's
time to sit down and read the manual again for the chip you are using now.
> -----Original Message-----
> From: Olin Lathrop [SMTP:EraseMEolin_piclistspam_OUTTakeThisOuTEMBEDINC.COM]
> Sent: Thursday, February 28, 2002 12:34 PM
> To: PICLISTspam_OUTMITVMA.MIT.EDU
> Subject: Re: [PIC]: Experimenting with F872 -- can't read from PORTA
> ???
>
> >>
> movlw B'00111111'
> movwf TRISA ; Port A is all inputs
> movlw B'00000110'
> movwf ADCON1 ; Port A is all digital
> movlw B'00000000'
> movwf ADCON0 ; Turn off A/D
> tris PORTB ; Port B is all outputs
> tris PORTC ; Port C is all outputs
>
> loop:
> movf PORTA,0 ; Grab data at port A
> movwf PORTB ; Dump to port B
> goto loop
>
> end
> <<
>
> For one thing, you've totally ignored bank settings. You do need to pay
> attention to these. Check out my DBANKIF and related macros if you want a
> more automatic way of setting the banks. You can find them in
> STD.INS.ASPIC
> at http://www.embedinc.com/pic.
>
> Secondly, don't use the TRIS instruction. I'm surprised the assembler
> didn't give you a warning. This is an old instruction that is (has) being
> obsoleted. Note that it's not in the list of instructions on page 136 of
> DS30292C.
>
> It looks like you may have programmed some old chips a long time ago.
> It's
> time to sit down and read the manual again for the chip you are using now.
>
Is there even one mid-range device that dosen't support the TRIS instruction
on ports A,B and C?
> Pic Dude wrote:
> >
> > What am I doing wrong here? I tried to configure port A as all digital
> > inputs, but can't read from it. If I replace port A with port C, it
works. {Quote hidden}
> > Here's the init/main part of my code...
> The dreaded old bank select problem. Read piclist.com and the data
> sheets about register banks and bank switching.
>
> Quentin
>
> --
> http://www.piclist.com hint: The PICList is archived three different
> ways. See http://www.piclist.com/#archives for details.
>
>
>
0x06 is what I have, but as B'00000110'.
But you've sorta hit on a point of confusion I had with the table explaining
the ADCON1 register (REGISTER 10-2, PAGE 82 of the datasheet).
What does the columns "Vref+" and "Vref-" mean in that table? For
PCFG3:PCFG0 = '011x' (all digital), the table entries for Vref+ and
Vref- are "Vdd" and "Vss". So what does that mean that I need to do?
Thanks. I'll check that out.
Yep, I'm aware of TRIS being obsolete, but I was being sloppy since
I started with some sample code that used it. I did get warnings, but
figured I'd feel like a pro if I already had some bad habits :-)
Actually I've never programmed PICs before. Last thing I programmed
was an 8051 over 10 years ago, but most of my assembly was on a
Z80 (TRS-80 computer) about 20 years ago. Ack!!!!
> Is there even one mid-range device that dosen't support the TRIS
instruction
> on ports A,B and C?
Officially many of them don't, including the 16F872. Some silicon, may,
this rev, support the instruction without it being listed. You definitely
don't want to be writing TRIS in new code for these chips.
>> Is there even one mid-range device that dosen't support the TRIS
>> instruction on ports A,B and C?
> Officially many of them don't, including the 16F872.
Same for 873,4,6,7 (TRIS is not mentioned in the instruction set).
But it does still work in all chips I use....
Wouter van Ooijen
--
Van Ooijen Technische Informatica: http://www.voti.nl
Jal compiler, Wisp programmer, WLoader bootloader, PICs kopen
> 0x06 is what I have, but as B'00000110'.
> But you've sorta hit on a point of confusion I had with the table
explaining
> the ADCON1 register (REGISTER 10-2, PAGE 82 of the datasheet).
> What does the columns "Vref+" and "Vref-" mean in that table? For
> PCFG3:PCFG0 = '011x' (all digital), the table entries for Vref+ and
> Vref- are "Vdd" and "Vss". So what does that mean that I need to do?
Vref+ and Vref- are optional external voltage references for the ends of the
A/D range. Modes that don't use them use the supply and ground as
references.
> Pic Dude wrote:
> >
> > What am I doing wrong here? I tried to configure port A as all digital
> > inputs, but can't read from it. If I replace port A with port C, it
works.
> > Here's the init/main part of my code...
> The dreaded old bank select problem. Read piclist.com and the data
> sheets about register banks and bank switching.
>
> Quentin
>
More likely it is the dreaded old "PORT A initializes as analogs problem",
read the description of ADCON1 in the datasheet.
At 01:12 AM 2/28/02 -0600, Pic Dude wrote:
>What am I doing wrong here? I tried to configure port A as all digital
>inputs, but can't read from it. If I replace port A with port C, it works.
>Here's the init/main part of my code...
>
> [ includes, config, etc up here ]
bank1 ;macro to set RAM bank 1
> movlw B'00111111'
> movwf TRISA ; Port A is all inputs
> movlw B'00000110'
> movwf ADCON1 ; Port A is all digital
> tris PORTB ; Port B is all outputs
> tris PORTC ; Port C is all outputs
Celebrating 18 years of Engineering Innovation (1984 - 2002)
.-. .-. .-. .-. .-. .-. .-. .-. .-. .-
`-' `-' `-' `-' `-' `-' `-' `-' `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.
At 10:57 PM 2/28/02 -0600, Pic Dude wrote:
>Yep. It was the prob. Solved.
>
>I must say though that I think its weird that I address ADCON0/1 as
>1FH and 9FH respectively, but still have to switch banks.
RAM banks in the 14 bit series are addressable with only 7 address
bits. 0x9F is above 0x80 so you have to switch the bank select bits to match.
Celebrating 18 years of Engineering Innovation (1984 - 2002)
.-. .-. .-. .-. .-. .-. .-. .-. .-. .-
`-' `-' `-' `-' `-' `-' `-' `-' `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.
> At 10:57 PM 2/28/02 -0600, Pic Dude wrote:
> >Yep. It was the prob. Solved.
> >
> >I must say though that I think its weird that I address ADCON0/1 as
> >1FH and 9FH respectively, but still have to switch banks.
>
> RAM banks in the 14 bit series are addressable with only 7 address
> bits. 0x9F is above 0x80 so you have to switch the bank select bits to
match. {Quote hidden}
>
> dwayne
>
>
> Dwayne Reid <RemoveMEdwaynerspam_OUTKILLspamplanet.eon.net>
> Trinity Electronics Systems Ltd Edmonton, AB, CANADA
> (780) 489-3199 voice (780) 487-6397 fax
>
> Celebrating 18 years of Engineering Innovation (1984 - 2002)
> .-. .-. .-. .-. .-. .-. .-. .-. .-. .-
> `-' `-' `-' `-' `-' `-' `-' `-' `-'
> Do NOT send unsolicited commercial email to this email address.
> This message neither grants consent to receive unsolicited
> commercial email nor is intended to solicit commercial email.
>
> --
> http://www.piclist.com#nomail Going offline? Don't AutoReply us!
> email RemoveMElistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body
>
>
>
> -----Original Message-----
> From: Olin Lathrop [SMTP:RemoveMEolin_piclistKILLspamEMBEDINC.COM]
> Sent: Thursday, February 28, 2002 2:18 PM
> To: PICLISTSTOPspamspam_OUTMITVMA.MIT.EDU
> Subject: Re: [PIC]: Experimenting with F872 -- can't read from PORTA
> ???
>
> > Is there even one mid-range device that dosen't support the TRIS
> instruction
> > on ports A,B and C?
>
> Officially many of them don't, including the 16F872. Some silicon, may,
> this rev, support the instruction without it being listed. You definitely
> don't want to be writing TRIS in new code for these chips.
>
I know that TRIS and OPTION is not listed within the data sheets of nearly
all of the more modern devices, I just wondered if anyone knew of a 14bit
device that definetly does not have support for these instructions? They
still work on a 16F84A and a 16F876 and 16F877 to my knowledge.
>> Is there even one mid-range device that dosen't support the TRIS
>instruction
>> on ports A,B and C?
>
>Officially many of them don't, including the 16F872. Some silicon, may,
>this rev, support the instruction without it being listed. You definitely
>don't want to be writing TRIS in new code for these chips.
If you don't use TRIS, how you configure a port for input or output with
these devices?
> -----Original Message-----
> From: Carlos Ojea [SMTP:EraseMEcarlosojeaEraseMELEVELTELECOM.ES]
> Sent: Friday, March 01, 2002 8:13 AM
> To: @spam@PICLIST@spam@spam_OUTMITVMA.MIT.EDU
> Subject: Re: [PIC]: Experimenting with F872 -- can't read from PORTA
> ???
>
> >> Is there even one mid-range device that dosen't support the TRIS
> >instruction
> >> on ports A,B and C?
> >
> >Officially many of them don't, including the 16F872. Some silicon, may,
> >this rev, support the instruction without it being listed. You
> definitely
> >don't want to be writing TRIS in new code for these chips.
>
>
> If you don't use TRIS, how you configure a port for input or output with
> these devices?
>
Same as with any 14 bit device, you set the bank registers to give you
access to Bank1, and write directly to the appropriate TRIS register
(instead of using the 'TRIS' instruction, confusing isn't it?).
>> If you don't use TRIS, how you configure a port for input or output with
>> these devices?
>>
>Same as with any 14 bit device, you set the bank registers to give you
>access to Bank1, and write directly to the appropriate TRIS register
>(instead of using the 'TRIS' instruction, confusing isn't it?).
>
>Mike