Searching \ for '[PIC] Pic16f84a vs pic16f628' 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/devices.htm?key=16F
Search entire site for: 'Pic16f84a vs pic16f628'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] Pic16f84a vs pic16f628'
2005\09\01@120752 by o Yipmantin

flavicon
face
Hi all,

At time I have no way to solve a little problem using a pic16f628.
The original program was working well in a pic16f84a, but when I change
the headers and compile it for a pic16f628 never works.

The program is simple, at start time; it turns on 3 leds one by one with
a delay of 20 mS between each one, so after 60mS the 3 leds must be ON.

       +---------------------------------------
LED1 ---!    +----------------------------------
LED2 --------!     *----------------------------
LED2 --------------!

After 1 second, the sequence must be to turn OFF each led with a delay
of 10 mS between each on.

With a PIC16F84A it works well but when I use a pic16f628, the leds
never be turned to ON in sequence.

       +----*
LED1 ---!    !----------------------------------
            +-----+ LED2 --------!     !----------------------------
                  +----+
LED2 --------------!    !-----------------------

Question is: What´s wrong?

Augusto, OA4CVT

2005\09\01@122723 by David Van Horn

picon face
>         +----*
> LED1 ---!    !----------------------------------
>              +-----+
> LED2 --------!     !----------------------------
>                    +----+
> LED2 --------------!    !-----------------------
>
> Question is: What´s wrong?


Looks like you aren't OR-ing the bits into the I/O ports.
What you want, is to load values like this:

$01        ;00000001
$03        ;00000011
$07        ;00000111

What you describe, looks like this:

$01        ;00000001
$02        ;00000010
$04        ;00000100


2005\09\01@122859 by William Chops Westfield

face picon face
On Sep 1, 2005, at 9:07 AM, Augusto Yipmantin wrote:

> The original program was working well in a pic16f84a, but when I change
> the headers and compile it for a pic16f628 never works.
>
The 628 has peripherals not present on the 84a that share the IO pins,
and must be turned off in order to use those pins and normal digitial
IO.  The usual problem is the analog comparator module (unfortunately
it makes a lot of sense that pins that might be connected to analog
voltages power up in analog mode!), and you need to insert
initialization
code like:

   CLRF PORTA  ;Initialize PORTA by
               ;setting
               ;output data latches
   MOVLW 0x07  ;Turn comparators off and
   MOVWF CMCON ;enable pins for I/O  ;functions

(This from "example 5-1" of the 628a datasheet.)

BillW

2005\09\01@123210 by Michael Rigby-Jones

picon face


{Quote hidden}

Almost certainly you have forgotten to disable the comparator, so the analog pins always read back zero.  This means if you perform a bsf on the port, all the other pins will get set to zero.

Regards

Mike

=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================

2005\09\01@123430 by Maarten Hofman

face picon face
>
> With a PIC16F84A it works well but when I use a pic16f628, the leds
> never be turned to ON in sequence.
> Question is: What´s wrong?

Well... I'm not sure what you did so far (some code might be useful), but did you check the following:
* Did you turn off the comparators? (movlw 0x07 movwf CMCON)
* Did you make sure the registers start at 0x20 instead of the lower location allowed in 16F84A? (Or better: made sure that the system automatically alocates your registers?)
* Did you make sure the oscillator settings are such that the proper oscillator is used? (The 16F628 has an internal one which might run at a different frequency than your external one)
* Did you make sure to keep the RP0/RP1 bits set correctly, so they keep pointing to the same register bank?
Greetings,
Maarten Hofman.

2005\09\01@125952 by olin piclist

face picon face
Augusto Yipmantin wrote:
> At time I have no way to solve a little problem using a pic16f628.
> The original program was working well in a pic16f84a, but when I change
> the headers and compile it for a pic16f628 never works.

Did you check the __CONFIG directive and adjust it to the new processor?
Did you disable the comparator so that the comparator inputs aren't analog?
Is your code properly written to pay attention to banks?  Did you remember
to switch linker files?

If proper design was used in the first place, switching from a 16F84 to
16F628 should be very easy.  If it wasn't, then it could be hassle,
especially if banking was never properly addressed in the first place.  If
you're in the second case (and just about all 16F84 project are) then now is
a good time to embrace proper programming so that moving this code to the
next PIC won't be such a hassle.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

2005\09\01@131350 by olin piclist

face picon face
William Chops Westfield wrote:
> and you need to insert initialization code like:
>
> (This from "example 5-1" of the 628a datasheet.)

Argh.  See rule 1.

>    CLRF PORTA  ;Initialize PORTA by
>                ;setting
>                ;output data latches

The bank must be set for access to PORTA before this instruction.

>    MOVLW 0x07  ;Turn comparators off and
>    MOVWF CMCON ;enable pins for I/O  ;functions

Another banking problem waiting to happen.  In addition, if you do an IFDEF
on CMCON you can put it as standard intialization code to turn off the
comparator if it exists.  This same snippet would then produce no
instructions on a 16F84, but init the comparator to off on the 16F628.  It's
a good idea to use the same strategy for the A/D converter.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

2005\09\01@131704 by o Yipmantin

flavicon
face
Thank you for your suggestions.
I will disable the comparators.

Augusto, OA4CVT
VHF EME 1x15 Yagi, 130 Watts, SP2000

-----Mensaje original-----
De: piclist-bouncesspamKILLspammit.edu [.....piclist-bouncesKILLspamspam.....mit.edu] En nombre
de Olin Lathrop
Enviado el: Jueves, 01 de Septiembre de 2005 05:01 p.m.
Para: Microcontroller discussion list - Public.
Asunto: Re: [PIC] Pic16f84a vs pic16f628

Augusto Yipmantin wrote:
> At time I have no way to solve a little problem using a pic16f628.
> The original program was working well in a pic16f84a, but when I
change
> the headers and compile it for a pic16f628 never works.

Did you check the __CONFIG directive and adjust it to the new processor?
Did you disable the comparator so that the comparator inputs aren't
analog?
Is your code properly written to pay attention to banks?  Did you
remember
to switch linker files?

If proper design was used in the first place, switching from a 16F84 to
16F628 should be very easy.  If it wasn't, then it could be hassle,
especially if banking was never properly addressed in the first place.
If
you're in the second case (and just about all 16F84 project are) then
now is
a good time to embrace proper programming so that moving this code to
the
next PIC won't be such a hassle.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

2005\09\01@132335 by Wouter van Ooijen

face picon face
> [snip 84a-to-628 transition]
> Question is: What´s wrong?

What is wrong: you did not include the code.

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: http://www.voti.nl/hvu

2005\09\01@134750 by Maarten Hofman

face picon face
>
> Another banking problem waiting to happen. In addition, if you do an IFDEF
> on CMCON you can put it as standard intialization code to turn off the
> comparator if it exists. This same snippet would then produce no
> instructions on a 16F84, but init the comparator to off on the 16F628.
> It's
> a good idea to use the same strategy for the A/D converter.

Nice idea! Don't forget to add one for CMCON0 too! Thank you.

2005\09\01@140636 by olin piclist

face picon face
Maarten Hofman wrote:
>  Nice idea! Don't forget to add one for CMCON0 too!

I just checked, and my standard init code does not address CMCON0.  I don't
have a manual for a PIC with comparator where I am right now, but I don't
remember CMCON0.  What PIC has that, and what does it do?

By the way, all the initialization stuff I've been talking about is in my
standard PORT module at http://www.embedinc.com/pic.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

2005\09\01@143114 by Maarten Hofman

face picon face
>
> I just checked, and my standard init code does not address CMCON0. I don't
> have a manual for a PIC with comparator where I am right now, but I don't
> remember CMCON0. What PIC has that, and what does it do?

Well, I just ported the evil code discussed in another thread to 16F688 (probably one of the more interesting devices in the 16F series), and that PIC turns out to be using CMCON0... Just like CMCON on other PICmicros it needs to be initialised to 0x07 in order to allow proper digital I/O, together with clearing of ANSEL. It also has CMCON1, which is related to Timer1, but which doesn't impact the ports. Also note that the 16F688 uses PORTC instead of PORTB. Thank you for the reference to the document, I'll read it now.

2005\09\13@201542 by Herman Aalderink

picon face
Augusto Yipmantin wrote:

>Hi all,
>
>At time I have no way to solve a little problem using a pic16f628.
>The original program was working well in a pic16f84a, but when I change
>the headers and compile it for a pic16f628 never works.
>

On this webpage
http://www.winpicprog.co.uk/pic_tutorial.htm

you can find following in Tutorial 1 :
http://www.winpicprog.co.uk/pic_tutorial1.htm

This simple program repeatedly switches all the output pins high and low.

;Tutorial 1.1 - Nigel Goodwin 2002
LIST    p=16F628         ;tell assembler what chip we are using
include "P16F628.inc"    ;include the defaults for the chip
__config 0x3D18          ;sets the configuration settings
                         ;(oscillator type etc.)

org    0x0000            ;org sets the origin, 0x0000 for the 16F628,
                         ;this is where the program starts running  
movlw    0x07
movwf    CMCON            ;turn comparators off (make it like a 16F84)

bsf     STATUS,        RP0    ;select bank 1
movlw     b'00000000'        ;set PortB all outputs
movwf     TRISB
movwf    TRISA            ;set PortA all outputs
bcf    STATUS,        RP0    ;select bank 0

Loop  
   movlw    0xff
   movwf    PORTA            ;set all bits on
   movwf    PORTB


............. specifically for moving from F84 to F628

Herman in PHL.

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