Searching \ for 'PIC16F874 Outputs are Weird?' 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=output
Search entire site for: 'PIC16F874 Outputs are Weird?'.

Truncated match.
PICList Thread
'PIC16F874 Outputs are Weird?'
2000\05\19@113633 by Ian Smith

flavicon
face
I have been trying to use all five ports on the PIC16F874 as digital
io outputs, but can only get some ports to work right.

I pared the program down to almostg nothing to post here.  I am siply
trying to set the first three output pins on portd to high, one at
a time.  But the PIC only lights one pin at a time, instead of having
them all set at the end.  So after setting three pins, only the third
is on at the end of the program.

I *think* I have all the A/D stuff set right.. but maybe not?
I have case sensitivity turned off on the compiler.

Code was based on Fr. Thomas McGahee's USART example, expanded and
cut down for here.

list            p=16f874

include <p16f874.inc>

list

__config        _hs_osc & _wdt_off & _pwrte_on & _cp_off


       org     h'0000'
       bcf     status,rp0      ; Bank 0

       bcf     intcon,gie      ;turn gie off
       clrf    sspcon          ;sync serial not used if in async mode.
       clrf    pir1            ;clear peripheral flags
       clrf    pir2            ;all of them
       clrf    portd

       bsf     status,rp0      ; Bank 1

       clrf    pie1            ;disable peripheral interrupts
       clrf    pie2            ;all of them
       movlw   b'00000110'     ;set all i/o as digital. no analog.
       movwf   adcon1
       movlw   b'00000000'     ;set all i/o as output for portd
       movwf   trisd

       bsf     option_reg,not_rbpu
       bsf     option_reg,intedg
       bcf     option_reg,t0cs
       bcf     option_reg,t0se
       bcf     option_reg,psa

       clrf    intcon
       clrf    pie1
       bcf     pie2,ccp2ie     ;disable ccp2ie

       bcf     status,rp0      ;Bank 0

main
       bsf     portd,0
       bsf     portd,1
       bsf     portd,2
end

2000\05\19@124506 by Mike Morris

flavicon
face
<x-flowed>Hi,

The "end" directive does not halt execution. Your program is running off
the end of the program address space and back to 0 where it starts over. Add:

loop    goto    loop

after your portd bsf's (just before the 'end' directive) putting it into an
endless loop.

- Mike


At 11:35 AM 5/19/2000 -0400, you wrote:
{Quote hidden}

</x-flowed>

2000\05\19@130358 by Ian Smith

flavicon
face
On Fri, 19 May 2000, Mike Morris wrote:
> The "end" directive does not halt execution. Your program is running off
> the end of the program address space and back to 0 where it starts over. Add:
>
> loop    goto    loop
>
> after your portd bsf's (just before the 'end' directive) putting it into an
> endless loop.

Still no luck.   I put delays between the bsf's and you could see pin 0
light, then go out as 1 came on, which went out as pin 2 lit.  Why would
a 'bsf porta,2' clear bit 1?

--
Ian

2000\05\19@145621 by rleggitt

picon face
"bsf porta,2" reads porta, ORs with 4, writes the result back to porta. So
the real question is, why is bit 1 reading as zero? The A/D system can
force porta bits to read zero. Or your hardware may not be allowing the
output level to rise above the 'on' threshold. Then there's always rise
time issues... bcf and bsf on i/o ports is iffy at best.

-- Rich


On Fri, 19 May 2000, Ian Smith wrote:

{Quote hidden}

2000\05\21@192432 by Tony Nixon

flavicon
picon face
Ian Smith wrote:
>
> I have been trying to use all five ports on the PIC16F874 as digital
> io outputs, but can only get some ports to work right.
>
> I pared the program down to almostg nothing to post here.  I am siply
> trying to set the first three output pins on portd to high, one at
> a time.  But the PIC only lights one pin at a time, instead of having
> them all set at the end.  So after setting three pins, only the third
> is on at the end of the program.

>
>         bsf     option_reg,not_rbpu
>         bsf     option_reg,intedg
>         bcf     option_reg,t0cs
>         bcf     option_reg,t0se
>         bcf     option_reg,psa

       movlw b'11000111'
       movwf option_reg

>         bcf     status,rp0      ;Bank 0
>
> main
>         bsf     portd,0
>         bsf     portd,1
>         bsf     portd,2
> end

Try not to code BSF's and BCF's in succession especially on the IO
ports. From what I understand, the PIC is not too keen on this.

I gather LVP and DEBUG are off and there are no floating inputs....

--
Best regards

Tony

http://www.picnpoke.com
.....salesKILLspamspam.....picnpoke.com

2000\05\21@205912 by Ian Smith

flavicon
face
On Mon, 22 May 2000, Tony Nixon wrote:
> Try not to code BSF's and BCF's in succession especially on the IO
> ports. From what I understand, the PIC is not too keen on this.
>
> I gather LVP and DEBUG are off and there are no floating inputs....

I am guessing that the various ports are diffrent enough to allow BSF's
in a row on some, but not others.  The code works if I use portb but
not portd or porte.

I'll avoid the BSF's now that I learned they are read-set-write operations
and they also don't like being quickly set in series.

I could always set aside a few bytes of ram space to mirror what my
program thinks the output should be.  The extra cycles will not hurt me in
this case.

Related question... I am using the USART in portc.  How safe is it to
use movwf instructions to set the other 6 pints as output?  Should I
leave those two bits as ser or clear, or will the movwf instructions
scramble the serial output?

Thanks for the help.

--
Ian

2000\05\21@213521 by Tony Nixon

flavicon
picon face
Ian Smith wrote:

> I am guessing that the various ports are diffrent enough to allow BSF's
> in a row on some, but not others.  The code works if I use portb but
> not portd or porte.

It may be possible that the PSPMODE bit, TRISE<4> is set to 1, which
enables PORTD for a parallel port, and the analog inputs have not been
set to digital.

       movlw b'00000110'       ; set all as digital IO
       movwf ADCON1

Check the TRIS for PORTD(E).

> Related question... I am using the USART in portc.  How safe is it to
> use movwf instructions to set the other 6 pints as output?  Should I
> leave those two bits as ser or clear, or will the movwf instructions
> scramble the serial output?

The MOVWF (ADDWF, SUBWF) PORTC data will always be written to the output
latches, but these are isolated from the TX and RX pins when the USART
is enabled, or when the TRIS bits = 1.

When enabled, the USART appears to override the TRISC <7,6> settings.

A major point with IO pins, is if you decide to change one to be an
OUTPUT, then make sure you specifically set it's output state before
doing so. If you have used BSF, BCF on the ports previously, or disabled
a periferal, you may not know the logic state of the output latch.

--
Best regards

Tony

http://www.picnpoke.com
EraseMEsalesspam_OUTspamTakeThisOuTpicnpoke.com

2000\05\22@195032 by Thomas McGahee

flavicon
face
Once you set the system to use the uart then you no longer have
direct control of the tx and rx bits. When you use a movwf on portc
it will not affect either tx or rc.

Fr. Tom McGahee

{Original Message removed}

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