Searching \ for '[PIC] 18F2455 PORTB pin toggling' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: massmind.org/techref/microchip/ios.htm?key=port
Search entire site for: '18F2455 PORTB pin toggling'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] 18F2455 PORTB pin toggling'
2009\05\16@143014 by mahesh nkr06

flavicon
face

Hi,
I am getting a bit wierd result while i simulate the below program in MBPLAB IDE simulator.
The problem is that the PORTB pins 2 and 3 are always at 0 even when i toggle them (tried both PORTB=0xFF and LATB = 0xFF).

I have a PIC board. on this, when i toggle PORTB pins, all the pins except RB5 toggle on it (i have 2 boards both of which behave same).
To debug this issue, i tried simulating it. now i run into this problem.

I hope i am setting all SFR registers correct.(UCON, SPPCON are 0 in the SFR window)
checked the errata of 18F2455 too.
did i miss anything ?

CODE START ====
/************************************************************************
debug_rb5.c
MPLAB IDE v7.40 (running in Wine-0.9.33)
MPLAB C18 v3.02 (feature limited)
MPLINK 4.03, Linker
MP2COD 4.03, COFF to COD File Converter
MP2HEX 4.03, COFF to HEX File Converter
Device: PIC18F2455, 28 PIN SOIC
**************************************************************************/

#include <p18f2455.h>   /* for TRISB and PORTB declarations */

#define FLASH        rom

//NOTE: PORTBbits.RB5 has problems. it does not toggle on the board

extern void _startup (void);     // See c018i.c in your C18 compiler dir

#pragma code _RESET_INTERRUPT_VECTOR = 0x000800

void _reset (void)
{
   _asm goto _startup _endasm
}

#pragma code
/********************************************************************
* Function : InitProcessor()
* This function will contain all the PIC processor related
* initialisations
********************************************************************/
void InitProcessor(void)
{
   TRISB = 0x00;//configure PORTB for output
   PORTB = 0x00;//init it to 0

   INTCON2bits.RBPU = 1;     //pullup portB pins

   TRISC = 0x00; //configure PORTC for output
   PORTC = 0x00;
}/* InitProcessor() */


void main (void)
{
   volatile char temp;

   InitProcessor();
   temp = 0x41;

   while (1 )
   {

//    PORTB = 0x00;
//    PORTC = 0x00;
   LATB = 0x00;
   LATC = 0x00;

   temp = 0x01; //just some junk statement.

//    PORTB = 0xFF; //PORTB=0xF3, LATB = 0xFF. why is this so ?
//    PORTC = 0xFF; //PORTC=0xF7, LATC = 0xC7  ?
   LATB = 0xFF; //PORTB or LATB, same result
   LATC = 0xFF;

   temp = 0x02;
   }
}//main
CODE END ====



     Explore and discover exciting holidays and getaways with Yahoo! India Travel http://in.travel.yahoo.com/


2009\05\16@150316 by Tamas Rudnai

face picon face
Take a look at the DataSheet - Example 10-2 describes how to initialize
PORTB.

Regards,
Tamas
PS: It is not an important note, but PIC is not a processor



On Sat, May 16, 2009 at 7:23 PM, <spam_OUTmahesh_nkr06TakeThisOuTspamyahoo.co.in> wrote:

{Quote hidden}

> -

2009\05\16@162001 by Harold Hallikainen

face
flavicon
face
The trick is that portb comes up as analog. See
http://ww1.microchip.com/downloads/en/DeviceDoc/39632D.pdf .

pdf page 116 states:

On a Power-on Reset, RB4:RB0 are configured as analog inputs by default and
read as ‘0’; RB7:RB5 are configured as digital inputs. By programming the
Configuration bit, PBADEN (CONFIG3H<1>), RB4:RB0 will alternatively be
configured as digital inputs on POR.



Sample initialization from the same page is:

CLRF PORTB ; Initialize PORTB by
          ; clearing output
          ; data latches
CLRF LATB ; Alternate method
          ; to clear output
          ; data latches
MOVLW 0Eh ; Set RB<4:0> as
MOVWF ADCON1 ; digital I/O pins
          ; (required if config bit
          ; PBADEN is set)
MOVLW 0CFh ; Value used to
          ; initialize data
          ; direction
MOVWF TRISB ; Set RB<3:0> as inputs
          ; RB<5:4> as outputs
          ; RB<7:6> as inputs

Harold

--
FCC Rules Updated Daily at http://www.hallikainen.com - Advertising
opportunities available!

2009\05\17@123738 by Mahesh P

flavicon
face


Thanks Harold/Tamas.
setting CONFIG3H to make the PORTB[4:0] pins as Digital helped the simulation.
One thing i could still not understand is:
Why were PORTB[1:0] toggeling (PORTB was 0xF3 when a 0xFF was written to
it) when CONFIG3H told them to come up as analog ?

Regarding my board, i suppose i have zapped the pin RB5 due to static.
This pin is just connected to a bergstick without any pullup/pulldown.
rest of pins have some PU/PD on it.

Thanks
-mp

--- On Sun, 17/5/09, Harold Hallikainen <.....haroldKILLspamspam@spam@hallikainen.org> wrote:

{Quote hidden}

> -

2009\05\18@081822 by VICENTE COLOMAR PRATS

picon face
If you convert F3 to binary, you have 11110011, wich corresponds to all bits
set (1) and RB2, RB3 clear (0). You had those bits analog, so you read a 0
from an analog pin, probably that pins was unconnected or with a low
voltage.

Try to inicialize ALL pins the very first thing your programs does. No
matter you don't use them, is a good policy to leave all non-used pins as
outputs and de-activate all analogs, camparators, pwm, ... you are not going
to use.

And always try to use pull-ups/downs and limiter resistors. I've fried some
pins even playing with leds.

2009/5/17 Mahesh P <EraseMEmahesh_nkr06spam_OUTspamTakeThisOuTyahoo.co.in>

{Quote hidden}

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