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

matrix address problem or bug problem

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



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

matrix address problem or bug problem
PostPosted: Wed Nov 24, 2010 5:06 am     Reply with quote

I wrote the file *. h
Code:
int1 A[3][5]={0};
#locate A=0x24


I wrote the main program
Code:
A[0][0]=1;
A[0][1]=1;
A[1][0]=1;
A[1][1]=1;
A[2][4]=1;

after compiling
lst file I checked wrote

Code:
.................... int1 A[3][5]={0};     
*
001C:  CLRF   24
001D:  CLRF   25
.................... #locate A=0x24       
.................... 
.................................................
..................... A[0][0]=1;
*
0004:  BSF    24.0
.................... A[0][1]=1;
0005:  BSF    24.1
.................... A[1][0]=1;
0006:  BSF    29.0
.................... A[1][1]=1;
0007:  BSF    29.1
.................... A[2][4]=1;
0008:  BSF    2E.4
.................... 


This is not wrong? It is bug? I think right code is
Code:
..................... A[0][0]=1;
*
0004:  BSF    24.0
.................... A[0][1]=1;
0005:  BSF    24.1
.................... A[1][0]=1;
0006:  BSF    24.5
.................... A[1][1]=1;
0007:  BSF    24.6
.................... A[2][4]=1;
0008:  BSF    25.5
.................... 
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 24, 2010 1:56 pm     Reply with quote

Always post your PIC and your compiler version if you suspect a compiler
bug. Then (we, people on the forum) can test it, and maybe compare it
to the latest version.
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

PostPosted: Thu Nov 25, 2010 3:49 am     Reply with quote

the entier code in C is:

Code:
#include <16F677.h>
#device adc=10
#device *=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOPUT                    //No Power Up Timer
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled

#use delay(clock=8M)
#use i2c(Slave,Fast,sda=PIN_B4,scl=PIN_B6,force_hw,address=0xa0)

#RESERVE  0x2A:0x3F        //slot0.2
int16 A=0,B=0,C=0;
#locate A = 0x2A
#locate B = 0x2C
#locate C = 0x2E

int1 D[3][5]={0};
#locate D=0x30


#int_EXT
void  EXT_isr(void)
{
}

#int_AD
void  AD_isr(void)
{
}

#int_SSP
void  SSP_isr(void)
{
A=i2c_isr_state();
B=i2c_read();
}

void main()
{

   setup_adc_ports(sAN0|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_64);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
//   setup_ccp1(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
//   enable_interrupts(INT_EXT);
//   enable_interrupts(INT_AD);
//   enable_interrupts(INT_SSP);
//   enable_interrupts(GLOBAL);
   setup_oscillator(OSC_8MHZ);

for(;;)
   {     
//   enable_interrupts(INT_RA0);
   enable_interrupts(INT_EXT);
//   enable_interrupts(INT_AD);
   enable_interrupts(INT_SSP);
   enable_interrupts(GLOBAL);
   
   D[0][0]=1;        //to verify real adress
   D[0][1]=1;
   D[1][0]=1;
   D[1][1]=1;
   D[2][4]=1;
   
   C++;     //to see if intrerupts it's working for I2C
            //PIN_B4 PIN_B6 are as input, hight
           
   }
}


the equivalent lst is:


Code:

CCS PCM C Compiler, Version 4.107, 3271

               ROM used: 195 words (10%)
                         Largest free fragment is 1853
               RAM used: 36 (28%) at main() level
                         36 (28%) worst case
               Stack:    1 worst case (0 in main + 1 for interrupts)

*
0000:  MOVLW  00
0001:  MOVWF  0A
0002:  GOTO   05B
0003:  NOP
0004:  MOVWF  7F
0005:  SWAPF  03,W
0006:  CLRF   03
0007:  MOVWF  41
0008:  MOVF   7F,W
0009:  MOVWF  40
000A:  MOVF   0A,W
000B:  MOVWF  47
000C:  CLRF   0A
000D:  SWAPF  40,F
000E:  MOVF   04,W
000F:  MOVWF  42
0010:  MOVF   20,W
0011:  MOVWF  43
0012:  MOVF   21,W
0013:  MOVWF  44
0014:  MOVF   22,W
0015:  MOVWF  45
0016:  MOVF   23,W
0017:  MOVWF  46
0018:  BCF    03.7
0019:  BCF    03.5
001A:  BTFSS  0B.4
001B:  GOTO   01E
001C:  BTFSC  0B.1
001D:  GOTO   03B
001E:  MOVLW  8C
001F:  MOVWF  04
0020:  BTFSS  00.6
0021:  GOTO   024
0022:  BTFSC  0C.6
0023:  GOTO   03E
0024:  MOVLW  8C
0025:  MOVWF  04
0026:  BTFSS  00.3
0027:  GOTO   02A
0028:  BTFSC  0C.3
0029:  GOTO   041
002A:  MOVF   42,W
002B:  MOVWF  04
002C:  MOVF   43,W
002D:  MOVWF  20
002E:  MOVF   44,W
002F:  MOVWF  21
0030:  MOVF   45,W
0031:  MOVWF  22
0032:  MOVF   46,W
0033:  MOVWF  23
0034:  MOVF   47,W
0035:  MOVWF  0A
0036:  SWAPF  41,W
0037:  MOVWF  03
0038:  SWAPF  7F,F
0039:  SWAPF  7F,W
003A:  RETFIE
.................... #include <16F677.h>
.................... //////// Standard Header file for the PIC16F677 device ////////////////
.................... #device PIC16F677
.................... #list
.................... 
.................... #device adc=10
.................... #device *=8
.................... 
.................... #FUSES NOWDT                    //No Watch Dog Timer
.................... #FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
.................... #FUSES NOPROTECT                //Code not protected from reading
.................... #FUSES NOBROWNOUT               //No brownout reset
.................... #FUSES NOMCLR                   //Master Clear pin used for I/O
.................... #FUSES NOCPD                    //No EE protection
.................... #FUSES NOPUT                    //No Power Up Timer
.................... #FUSES IESO                     //Internal External Switch Over mode enabled
.................... #FUSES NOFCMEN                  //Fail-safe clock monitor disabled
.................... 
.................... #use delay(clock=8M)
.................... #use i2c(Slave,Fast,sda=PIN_B4,scl=PIN_B6,force_hw,address=0xa0)
.................... 
.................... #RESERVE  0x2A:0x3F        //slot0.2
.................... int16 A=0,B=0,C=0;
.................... #locate A = 0x2A
.................... #locate B = 0x2C
.................... #locate C = 0x2E
.................... 
.................... int1 D[3][5]={0}; 
*
0081:  CLRF   30
0082:  CLRF   31
.................... #locate D=0x30
.................... 
.................... 
.................... #int_EXT
.................... void  EXT_isr(void) 
.................... {
.................... }
.................... 
*
003B:  BCF    0B.1
003C:  BCF    0A.3
003D:  GOTO   02A
.................... #int_AD
.................... void  AD_isr(void) 
.................... {
.................... }
.................... 
003E:  BCF    0C.6
003F:  BCF    0A.3
0040:  GOTO   02A
.................... #int_SSP
.................... void  SSP_isr(void) 
.................... {
.................... A=i2c_isr_state();
0041:  BSF    03.5
0042:  BTFSC  14.5
0043:  GOTO   04C
0044:  BCF    03.5
0045:  CLRF   24
0046:  BSF    03.5
0047:  BTFSS  14.2
0048:  GOTO   04C
0049:  BCF    03.5
004A:  BSF    24.7
004B:  BSF    03.5
004C:  BCF    03.5
004D:  MOVF   24,W
004E:  INCF   24,F
004F:  CLRF   2B
0050:  MOVWF  2A
.................... B=i2c_read();
0051:  BCF    14.6
0052:  BTFSS  0C.3
0053:  GOTO   052
0054:  MOVF   13,W
0055:  BSF    14.4
0056:  CLRF   2D
0057:  MOVWF  2C
.................... }
.................... 
0058:  BCF    0C.3
0059:  BCF    0A.3
005A:  GOTO   02A
.................... void main()
.................... {
005B:  CLRF   04
005C:  MOVLW  1F
005D:  ANDWF  03,F
005E:  MOVLW  71
005F:  BSF    03.5
0060:  MOVWF  0F
0061:  MOVF   0F,W
0062:  BSF    06.6
0063:  BSF    06.4
0064:  MOVLW  A0
0065:  MOVWF  13
0066:  MOVLW  36
0067:  BCF    03.5
0068:  MOVWF  14
0069:  CLRF   2B
006A:  CLRF   2A
006B:  CLRF   2D
006C:  CLRF   2C
006D:  CLRF   2F
006E:  CLRF   2E
006F:  BSF    03.6
0070:  BCF    1F.0
0071:  BCF    1F.1
0072:  BCF    1F.2
0073:  BCF    1F.3
0074:  BCF    03.6
0075:  BCF    1F.6
0076:  MOVLW  00
0077:  BSF    03.6
0078:  MOVWF  1E
0079:  CLRF   19
007A:  CLRF   1A
007B:  BSF    03.5
007C:  CLRF   1E
007D:  BCF    03.5
007E:  CLRF   1B
007F:  BCF    03.6
0080:  BCF    0D.5
.................... 
....................    setup_adc_ports(sAN0|VSS_VDD);
*
0085:  BSF    03.6
0086:  BCF    1F.0
0087:  BCF    1F.1
0088:  BCF    1F.2
0089:  BCF    1F.3
008A:  BCF    03.6
008B:  BCF    1F.6
008C:  MOVLW  01
008D:  BSF    03.6
008E:  MOVWF  1E
....................    setup_adc(ADC_CLOCK_DIV_64);
008F:  BSF    03.5
0090:  BCF    03.6
0091:  BCF    1F.4
0092:  BSF    1F.5
0093:  BSF    1F.6
0094:  BCF    03.5
0095:  BSF    1F.7
0096:  BSF    1F.0
....................    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
0097:  BSF    03.5
0098:  MOVF   01,W
0099:  ANDLW  C7
009A:  IORLW  08
009B:  MOVWF  01
....................    setup_timer_1(T1_DISABLED);
009C:  BCF    03.5
009D:  CLRF   10
....................    setup_timer_2(T2_DISABLED,0,1);
009E:  MOVLW  00
009F:  MOVWF  21
00A0:  MOVWF  12
00A1:  MOVLW  00
00A2:  BSF    03.5
00A3:  MOVWF  12
.................... //   setup_ccp1(CCP_OFF);
....................    setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
00A4:  BCF    03.5
00A5:  BSF    03.6
00A6:  CLRF   19
00A7:  CLRF   1A
00A8:  BSF    03.5
00A9:  CLRF   1E
00AA:  BCF    03.5
00AB:  CLRF   1B
00AC:  BCF    03.6
00AD:  BCF    0D.5
.................... //   enable_interrupts(INT_EXT);
.................... //   enable_interrupts(INT_AD);
.................... //   enable_interrupts(INT_SSP);
.................... //   enable_interrupts(GLOBAL);
....................    setup_oscillator(OSC_8MHZ);
00AE:  MOVLW  71
00AF:  BSF    03.5
00B0:  MOVWF  0F
00B1:  MOVF   0F,W
.................... 
.................... for(;;)
....................    {       
.................... //   enable_interrupts(INT_RA0);
....................    enable_interrupts(INT_EXT);
00B2:  BCF    03.5
00B3:  BSF    0B.4
.................... //   enable_interrupts(INT_AD);
....................    enable_interrupts(INT_SSP);
00B4:  BSF    03.5
00B5:  BSF    0C.3
....................    enable_interrupts(GLOBAL);
00B6:  MOVLW  C0
00B7:  BCF    03.5
00B8:  IORWF  0B,F
....................     
....................    D[0][0]=1;        //to verify real adress
00B9:  BSF    30.0
....................    D[0][1]=1; 
00BA:  BSF    30.1
....................    D[1][0]=1; 
00BB:  BSF    35.0
....................    D[1][1]=1; 
00BC:  BSF    35.1
....................    D[2][4]=1;
00BD:  BSF    3A.4
....................     
....................    C++;     //to see if intrerupts it's working for I2C 
00BE:  INCF   2E,F
00BF:  BTFSC  03.2
00C0:  INCF   2F,F
....................             //PIN_B4 PIN_B6 are as input, hight
....................             
....................    }
00C1:  GOTO   0B3
.................... }
00C2:  SLEEP

Configuration Fuses:
   Word  1: 34D4   INTRC_IO NOPROTECT NOBROWNOUT NOMCLR NOCPD NOWDT NOPUT IESO NOFCMEN


problem1 corect word resoves is...

...
Code:
................. 
.................... int1 D[3][5]={0}; 
*
0081:  CLRF   30
0082:  CLRF   31
.................... #locate D=0x30
.................... 
.................... 

....................     
....................    D[0][0]=1;        //to verify real adress
00B9:  BSF    30.0
....................    D[0][1]=1; 
00BA:  BSF    30.1
....................    D[1][0]=1; 
00BB:  BSF    30.5       ____________________________________
....................    D[1][1]=1; 
00BC:  BSF    30.6      ____________________________________
....................    D[2][4]=1;
00BD:  BSF    31.6      ____________________________________
....................     


problem no2 is: intrerrupts not work when I make start condition I2C in my own demo board whith 2 pull up resistor 2K and 2 swithnes grounded.
counterul from "c" continue to work so intrerupts not work.
example to start condition:
time=0; sda, PIN_B4=0; scl,PIN_B6=0;
time=1; sda, PIN_B4=1; scl,PIN_B6=0;
time=2; sda, PIN_B4=1; scl,PIN_B6=1;
time=3; sda, PIN_B4=0; scl,PIN_B6=1; //start condition in this moment
time=4; sda, PIN_B4=0; scl,PIN_B6=0; //counterul"c" from addres 0x2E continue to counting, where is the problem?
A=i2c_isr_state();
B=i2c_read();
A, B are to see real statement I2C at the end of ACK(acknowleged bit)
in the master mode equivalent in my manualy switch/quartz work's very well

thanks for reply PCM programmer
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Nov 25, 2010 11:02 am     Reply with quote

Yes it's a bug. By defining the array large enough, you are able to corrupt all kinds of data.
The int1 array has been addressed correctly in PCM V4.087. Then the compiler got's confused
somewhere on the way to V4.093.

It's not understandable at first sight, how "C++;" should be related to I2C interrupts,
so I ignored the second problem.
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

PostPosted: Fri Nov 26, 2010 3:22 am     Reply with quote

thanks for reply FvM
Now I understand why my programs work sometimes hoticly; other projects.
I'll must to try older version without bug's.
Problem no. 2 is to see, understand what state have internal buffer of I2c at the end of acknowledge bit.
Normally internal intrerupt, intrerupts program in this case value or data "C" to continue of counting, and microcontroller use internal "ALU" or core to work only with SSP of I2C until see stop condition and value "C" continue to counting where it left off.
This interrupts normally, theoretically is good for transfer higher speed on I2C.
For lower speed like 10-20 bits/second (not 100K bits/secound) works fine without interrupting routine. Theoretically....
Where I wrong?
Best wishes
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

PostPosted: Fri Nov 26, 2010 7:43 am     Reply with quote

Solution for the first problem is resolved with 4.084.
In version 4.107 ram used 28%, rom used 10% and work confused.
In version 4.084 ram used 30%, rom used 10% and work fine.
Compiler have bug problem.
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