Forums

16F628

Started by Unknown November 17, 2004
I need to use PortA.4 for a serout, but it doesn't seem to be working.  I wrote:
CMCON = 7

Is there anything else I need to do?  Serout makes the pin an output so I'm not concerned about direction.

Sid





Ordinarily the Tx pin is on PORTB.2 and Rx is on PORTB.1. Look back
a few threads - we have been discussing the 16F628 all week. Code,
known to work, is posted. --- In , Newzed@a... wrote:
> I need to use PortA.4 for a serout, but it doesn't seem to be
working. I
> wrote:
> CMCON = 7
>
> Is there anything else I need to do? Serout makes the pin an
output so I'm
> not concerned about direction.
>
> Sid



In a message dated 11/17/2004 6:18:33 PM Eastern Standard Time, r...@pacbell.net writes:


Ordinarily the Tx pin is on PORTB.2 and Rx is on PORTB.1.  Look back
a few threads - we have been discussing the 16F628 all week.  Code,
known to work, is posted.


I have to use PortA.4.  It is the only pin available.  Can't I use it for serout?

Sid




--- In , Newzed@a... wrote:
> In a message dated 11/17/2004 6:18:33 PM Eastern Standard Time,
> rstofer@p... writes: > > Ordinarily the Tx pin is on PORTB.2 and Rx is on PORTB.1. Look back
> > a few threads - we have been discussing the 16F628 all week. Code,
> > known to work, is posted.
> >
>
> I have to use PortA.4. It is the only pin available. Can't I use
it for
> serout?
>
> Sid]

I guess you can but it will be bit-banged, not from the on-chip USART.
I don't know if it will matter but PORTA.4 is an open-drain output.
You will need to pull it up with a resistor. If you plan to wiggle it
then you will need to define it as an output.

You didn't say what language you were using and I don't know if the
one you are using provides bit-banged serial IO. I imagine some do
but I don't have any experience doing this.




Sid: I think you're thinking stamps . . . the 16f628 only does tx
on RB1 (or whatvever), mr. stofer is correct.

I think the stamp authors wrote some routines to bit-bang serial com
out any port, because I know the stamp you can change the output pin.

You will need to change your pins around so you free up the right
pin, and change your code to match. Or stay with the stamp, it's a
pretty good deal. Or try the picaxe, I just got one in from mr.
anderson (en?), do a google search, he sells stuff on the cheap. The
picaxe has a bootloader and special pc software to do the deal like
the stamp but not through eprom, check it out.
--- In , Newzed@a... wrote:
> In a message dated 11/17/2004 6:18:33 PM Eastern Standard Time,
> rstofer@p... writes: > > Ordinarily the Tx pin is on PORTB.2 and Rx is on PORTB.1. Look
back
> > a few threads - we have been discussing the 16F628 all week.
Code,
> > known to work, is posted.
> >
>
> I have to use PortA.4. It is the only pin available. Can't I use
it for
> serout?
>
> Sid



In a message dated 11/17/2004 7:38:44 PM Eastern Standard Time, j...@yahoo.com writes:


Sid:  I think you're thinking stamps . . .   the 16f628 only does tx
on RB1 (or whatvever), mr. stofer is correct.



The data sheet defines A.4 as bidirectional I/O and B.2 as synchronous data I/O, bidirectional I/O and USART Tx.  I am using asynchronous data, so I don't understand why I can't use A.4 for serout.  The data sheet says nothing about it being open drain.  As you say, I can use sany Stamp pin for a serout - why not any pin on the 16F628?

It frustratables me!

Sid




--- In , Newzed@a... wrote:
> In a message dated 11/17/2004 7:38:44 PM Eastern Standard Time,
> jrem123@y... writes: > > Sid: I think you're thinking stamps . . . the 16f628 only
does tx
> > on RB1 (or whatvever), mr. stofer is correct.
> >
> >
>
> The data sheet defines A.4 as bidirectional I/O and B.2 as
synchronous data
> I/O, bidirectional I/O and USART Tx. I am using asynchronous
data, so I don't
> understand why I can't use A.4 for serout. The data sheet says
nothing about
> it being open drain. As you say, I can use sany Stamp pin for a
serout - why
> not any pin on the 16F628?
>
> It frustratables me!
>
> Sid

Not so, the datasheet in paragraph 5.1, 2d sentence says "RA4 is a
Schmitt Trigger input and an open drain output." Believe me, they
aren't kidding - I got caught with this on one of these devices.
Same kind of statement in Table 5.1.

Table 5.3 pin RB2 "USART Transmit Pin" - USART: Universal
Synchronous/Asynchronos Receiver Transmitter.

There is no reason you can't use a different pin but, like the
Stamp, it will require bit-banging. If you want to use the USART,
you will have to use the pins it is wired to.


In a message dated 11/17/2004 9:22:00 PM Eastern Standard Time, r...@pacbell.net writes:


There is no reason you can't use a different pin but, like the
Stamp, it will require bit-banging.  If you want to use the USART,
you will have to use the pins it is wired to.


I'm not sure I understand what you mean by bit-banging.  If I put a pullup on A.4, then write:

dat con {prtA.4
serout2 dat, baud, ["A"]

Isn't that enough?

Thanks

Sid




--- In , Newzed@a... wrote:
> In a message dated 11/17/2004 9:22:00 PM Eastern Standard Time,
> rstofer@p... writes: > > There is no reason you can't use a different pin but, like the
> > Stamp, it will require bit-banging. If you want to use the
USART,
> > you will have to use the pins it is wired to.
> >
>
> I'm not sure I understand what you mean by bit-banging. If I put a
pullup on
> A.4, then write:
>
> dat con {prtA.4
> serout2 dat, baud, ["A"]
>
> Isn't that enough?
>
> Thanks
>
> Sid


bit-banging requires precisely timed intervals of turning the pin on
and off to emulate the serial stream. The usart does it all for you
automagically, you just put your word in the txreg and the chip does
the rest.

Once again, the only usart tx pin is the RB2 on the 16F628. There is
no other way to have the chip do the usart function. The *only*
other way to simulate serial transmission is to do the hard coding to
make it happen.



----- Original Message -----
From: jrem <>
To: <>
Sent: Thursday, November 18, 2004 1:35 PM
Subject: [piclist] Re: 16F628 >
>
> --- In , Newzed@a... wrote:
> > In a message dated 11/17/2004 9:22:00 PM Eastern Standard Time,
> > rstofer@p... writes:
> >
> >
> > > There is no reason you can't use a different pin but, like the
> > > Stamp, it will require bit-banging. If you want to use the
> USART,
> > > you will have to use the pins it is wired to.
> > >
> >
> > I'm not sure I understand what you mean by bit-banging. If I put a
> pullup on
> > A.4, then write:
> >
> > dat con {prtA.4
> > serout2 dat, baud, ["A"]
> >
> > Isn't that enough?
> >
> > Thanks
> >
> > Sid > bit-banging requires precisely timed intervals of turning the pin on
> and off to emulate the serial stream. The usart does it all for you
> automagically, you just put your word in the txreg and the chip does
> the rest.
>
> Once again, the only usart tx pin is the RB2 on the 16F628. There is
> no other way to have the chip do the usart function. The *only*
> other way to simulate serial transmission is to do the hard coding to
> make it happen.
>

To clarify:

bit-banging means that the USART is emulated by a piece of software. The
software has to turn the output on and off the same way that the hardware
USART would. Not only that, but it also has to read the input pin the same
way. The software cannot do this by just turning the output on and off in
quick succession, it has to generate accurate bit lengths when outputting
and filter out noise when inputting. This requires accurate timing and
consequently restricts what the PIC is able to do at the same time and the
highest speed that the emulated USART can operate at. All in all, hardware
USARTs are better than software emulated USARTs and you should try to use
the hardware one if possible.

Think of the hardware USART as a little black box. You can drop data in it
on the PIC side and it will get squirted out of a PIC pin (Tx) or data can
get squirted into it on a PIC pin (Rx) and you can take it out of the PIC
side. The problem is that this black box has predefined connections to the
PIC pins. These connections are hardwired and cannot be changed. If you want
to use any other pins other than the predefined ones then you have to do it
as an emulated software USART.

Regards
Sergio Masci

http://www.xcprod.com/titan/XCSB - optimising PIC compiler
FREE for personal non-commercial use