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?
 
Use the latches for outputs..

LATAbits.LATA.0 = 1;
LATAbits.LATA.1 = 1;
LATAbits.LATA.1 = 1;

It should solve your problem...
 
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.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…