Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Pic18F27J13 PORTA odd behaviour

Status
Not open for further replies.

GraffZeppelin

New Member
Hello,

I am trying to simulate some digital outputs from Pic18F27J13 in Proteus, but what happens is that only the last RA2 bit is set to high.
If I erase the lines PORTAbits.RA2 = 1; and PORTAbits.RA2 = 0; , then only pin RA1 is getting high. Same for RA0..

My setting :


Code:
/* Main.c file generated by New Project wizard * * Created:   Thu Jan 23 2014 * Processor: PIC18F27J13 * Compiler:  HI-TECH C for PIC18 */
#include <htc.h>
void delay_ms(unsigned int ui_value);
void main(void)
  {                      
  TRISA = 0;      
PORTAbits.RA0 = 0;       
PORTAbits.RA1 = 0;       
PORTAbits.RA2 = 0;                      
  
   while (1)   
            {
            PORTAbits.RA0 = 1;      
            PORTAbits.RA1 = 1;    
            PORTAbits.RA2 = 1;
                   delay_ms(50);
            PORTAbits.RA0 = 0;      
            PORTAbits.RA1 = 0;    
            PORTAbits.RA2 = 0;    
                   delay_ms(50);              
             } 
} 
  
  void delay_ms(unsigned int ui_value)
{
                     while (ui_value-- > 0) 
                       {
                           __delay_ms(1);
                        }
}

What could be the issue?
 
Strange...

This is from the header file of a similar chip

C:
// Register: LATA
volatile unsigned char  LATA  @ 0x10C;
// bit and bitfield definitions
volatile bit LATA0  @ ((unsigned)&LATA*8)+0;
volatile bit LATA1  @ ((unsigned)&LATA*8)+1;
volatile bit LATA2  @ ((unsigned)&LATA*8)+2;
volatile bit LATA4  @ ((unsigned)&LATA*8)+4;
volatile bit LATA5  @ ((unsigned)&LATA*8)+5;
#ifndef _LIB_BUILD
volatile union {
  struct {
  unsigned   LATA0  : 1;
  unsigned   LATA1  : 1;
  unsigned   LATA2  : 1;
  unsigned    : 1;
  unsigned   LATA4  : 1;
  unsigned   LATA5  : 1;
  unsigned   : 1;
  unsigned   : 1;
  };
  struct {
  unsigned   LATA  : 6;
  unsigned   : 2;
  };
} LATAbits @ 0x10C;

LATAbits.LATA0 is clearly defined!! What version of the compiler are you using?
 
Strange...

This is from the header file of a similar chip

C:
// Register: LATA
volatile unsigned char  LATA  @ 0x10C;
// bit and bitfield definitions
volatile bit LATA0  @ ((unsigned)&LATA*8)+0;
volatile bit LATA1  @ ((unsigned)&LATA*8)+1;
volatile bit LATA2  @ ((unsigned)&LATA*8)+2;
volatile bit LATA4  @ ((unsigned)&LATA*8)+4;
volatile bit LATA5  @ ((unsigned)&LATA*8)+5;
#ifndef _LIB_BUILD
volatile union {
  struct {
  unsigned   LATA0  : 1;
  unsigned   LATA1  : 1;
  unsigned   LATA2  : 1;
  unsigned    : 1;
  unsigned   LATA4  : 1;
  unsigned   LATA5  : 1;
  unsigned   : 1;
  unsigned   : 1;
  };
  struct {
  unsigned   LATA  : 6;
  unsigned   : 2;
  };
} LATAbits @ 0x10C;

LATAbits.LATA0 is clearly defined!! What version of the compiler are you using?


It's the newest version from Hi-tech webpage.. but nevermind that, I changed LATAbits.LATA.0 to LATAbits.LATA0 and it works !

Thank You for Your help! ;)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top