CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

CCS compile error? -- PIC16F676

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cindy
Guest







CCS compile error? -- PIC16F676
PostPosted: Wed Mar 02, 2005 3:24 am     Reply with quote

Hi, Buddy,

I found sth strange when debugging PIC16F676. original and after compile code is listed below. please compare these two sets code and take note the line with *****. Even the name is wrong, (should be TRISA/TRISC), it sets the correct register in fact.

1, Can anybody explain why this happens?
(I found CCS change my variable names also.)

2, above code set RA5=0, but when I run, RA5=1 instead, why???
previously I thought the problem of compiler, so I change these code to asmbly, but RA5 still set to 1.

Very much appreciate for your reply

Cindyw
-------------------

Original Code-
//-----------------------
#asm
bcf 0x03,0x5 //bank 0
clrf 0x05 //;Init PORTA
clrf 0x07 //;Init PORTC
bsf 0x03,0x5 //bank 1
movlw 0x08
movwf 0x85 ;//set TRISA RA0-2,RA4,5 as output
movlw 0x0f
movwf 0x87 ;//set TRISC Rc4,5 as output,other as input
#endasm
//---------------------------------------------------------------------

After compile by CCS-PCWH, IDE ver.3.43, PCB etc. ver.3.188
//----------------------------------------------------------------------
bcf STATUS,0x5 //bank 0
clrf PORTA
clrf PORTC
bsf STATUS,0x5 //bank 1
movlw 0x08
bsf STATUS,0x5 //bank 1
movwf PORTA *****
movlw 0xf
movwf PORTC *****


Remarks:

PORTA address in Bank0, #05h
TRISA address in Bank1, #85h

PORTC address in Bank0, #07h
TRISC address in Bank1, #87h


[/code]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 02, 2005 1:19 pm     Reply with quote

The compiler doesn't try to simulate your ASM code when it generates
the .LST file. It doesn't try to keep track of the bank in your ASM code.
It just looks up the register number in a symbol table and puts it into
the .LST file.

Look at the Program Memory window in MPLAB. You should see the
correct ASM instructions there.


With respect to your RA5 problem, it's probably because RA5 can
be configured as the Oscillator input pin, or as a general purpose i/o pin.
You may not have it configured correctly. Or, there may be some other
problem. If you want some help on this, then do this:

1. Post a complete (but small) test program which shows the problem.
Make sure you post your all compiler directives, such as
the #fuses statement, etc. That's essential.

2. Post your version of the compiler. Look at the top of the .LST file
which is generated after you compile a program. The version number
will be a number like this: 3.219
cindyw



Joined: 21 Oct 2004
Posts: 9

View user's profile Send private message

MPLAB SIM & ICD2 get different result
PostPosted: Thu Mar 03, 2005 2:31 am     Reply with quote

[quote="PCM programmer"]

Look at the Program Memory window in MPLAB. You should see the
correct ASM instructions there.

----------------
Above after compile code is from view/program Memory window in MPLAB.[/b]

Here is a testing code. I found the PORTA is correct by running MPLAB SIM , however, the actual test result by run MPLAB ICD2, PinPA5 always on(PORTA=0x20)

compiler version 3.188

Thanks PCM programmer Very Happy


Code:

#include <16F676.h>
#DEVICE adc=8   //only use 8 bit  ??

#fuses INTRC_IO,NOWDT,NOPROTECT//NOBROWNOUT    //MCLR
#use delay (clock=4000000)  //4M hz internal osc
//#endif


void init();
/************************************************************
          Main program
*************************************************************/
void main() { int temp;
   
           init();  // init for ADC, I/O, Timer
CHANNEL_1:  output_high(PIN_A4 );

           temp=read_adc();   //read noise
           output_low(PIN_A4 );  //RA4--Status_LED
           delay_us(100);
           delay_us(100);
                  
            
   goto CHANNEL_1;       
          

}

void init()
{
 //----I/O initialization---
/*
    OUTPUT_low( RLY)   ;   //can not use OUTPUT_A( 0x00);OUTPUT_C( 0x0F) 
    OUTPUT_low( status_led)   ;
    OUTPUT_low( LED1)   ;
    OUTPUT_low( LED2)   ;
    OUTPUT_low( CUR)   ;  // change on 19/1/2005
 */ // change to asm code due to register not set correctly
     #asm
     bcf  0x03,0x5;   //bank 0
     clrf    0x05;               //;Init PORTA
                  clrf    0x07;         //;Init PORTC

     bsf  0x03,0x5;   //bank 1

    
     movlw 0x08;
     movwf 0x85 ;//set TRISA RA0-2,RA4,5  as output, system not recognize TRISA, use address instead
     movlw 0x0f;
     movwf 0x87 ;//set TRISC Rc4,5 as output,other as input
      #endasm
 //----ADC initialization---
   SETUP_ADC_PORTS(sAN4|sAN5|sAN6|sAN7|VSS_VDD); // AN4:7 A/D. others digital
   setup_adc( ADC_CLOCK_INTERNAL );   //internal oscillator 2-6us
   set_adc_channel(5);   
   SETUP_COMPARATOR(NC_NC_NC_NC);   // add to off comparators in 7/12   
 
//----Timer initialization---
     SETUP_TIMER_1(T1_INTERNAL|T1_DISABLED|T1_DIV_BY_8);    //prescale=1:8, internal clock, need disable??
             
 }


---code end


_________________
CC


Last edited by cindyw on Thu Mar 03, 2005 2:34 am; edited 1 time in total
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group