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 CCS Technical Support

array assignment problem

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







array assignment problem
PostPosted: Sun Jun 01, 2003 6:58 pm     Reply with quote

I am using CCS C compiler, I encounter one problem, Is there
anyone can help me?
why the statements "m = menu[0]" and "m = menu[i]" can not work properly.

#case
#include <16F74.h>

typedef struct {
int led21;
int led43;
int led65;
int led7;

int menu_id1 : 4;
int menu_id2 : 4;
int menu_id3 : 4;
int menu_id4 : 4;

int led_flash_state : 6;
BOOLEAN modify_state;
BOOLEAN password_req;

int led_flash_en : 6;
BOOLEAN modify_en;
BOOLEAN reserved;
} MENU;

const MENU menu[] = {
{ 0x11, 0x22, 0x33, 0x44, 1, 2, 3, 4, 0x38, TRUE, FALSE, 0X3F, FALSE, TRUE },
{ 0x55, 0x66, 0x77, 0x88, 5, 6, 7, 8, 0x3f, TRUE, FALSE, 0X3F, FALSE, TRUE },
} ;

void main() {
int i;
MENU m;
m = menu[0];
for( i = 0; i < 2; i++ ) {
m = menu[i];
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514932
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

Re: array assignment problem
PostPosted: Mon Jun 02, 2003 3:28 am     Reply with quote

Ok, I'm not sure about this, but as far as I know CCS compiler creates a look-up table for constant arrays. So statements like m = menu[0]; will not compile properly. Take a look at your .LST file and see how your 'const MENU menu[]' is compiled. If it's a bunch of returns, then it will not work the way you intended.

Ali
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514944
Woody
Guest







What is the problem
PostPosted: Mon Jun 02, 2003 3:36 am     Reply with quote

You do not state which version of the compiler you are using or what you mean by "this statement does not work".

The assignment m = menu [i] will perform a standrad 'C' structure assignment. CCS C creates a look-up table for the constant array of structures you have declared amounting to 16 8-bit values in total. A loop is then created to perform the assignment to the ram variable.

I tried this in CCS 3.160 // MPLAB 6.20 SIM and it appears to work fine.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514945
[email protected]
Guest







Re: What is the problem
PostPosted: Mon Jun 02, 2003 6:57 am     Reply with quote

Thanks a lot!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

1. The version of CCS compiler I am using is PCM 3.050.
2. I will try to upgrade my compiler to the latest version.
3. I think, according list file, there is something wrong with
this version of CCS compiler.

/*******************************************************/
The following is symbol file produced by PCM 3.050.

008 PSP_DATA
015-016 CCP_1
015 CCP_1_LOW
016 CCP_1_HIGH
01B-01C CCP_2
01B CCP_2_LOW
01C CCP_2_HIGH
020 @SCRATCH
021 @SCRATCH
021 _return_
022 @SCRATCH
023 @SCRATCH
024 @SCRATCH
026 main.i
027-02E main.m
-00E menu

0004 @const37
0018 main

Project Files:
c:\yili\t.c
C:\Program Files\PICC\devices\16f74.h

/**********************************************************/
The following is list file produced by PCM 3.050.

CCS PCM C Compiler, Version 3.050, 3496

Filename: c:\yili\t.LST

ROM used: 334 (8\%)
Largest free fragment is 2048
RAM used: 14 (7\%) at main() level
14 (7\%) worst case
Stack: 1 locations

*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 018
0003: NOP
.................... #case
.................... #include <16f74.h>
.................... //////// Standard Header file for the PIC16F74 device ////////////////
.................... #device PIC16F74
.................... #list
....................
....................
.................... typedef struct {
.................... int led21;
.................... int led43;
.................... int led65;
.................... int led7;
....................
.................... int menu_id1 : 4;
.................... int menu_id2 : 4;
.................... int menu_id3 : 4;
.................... int menu_id4 : 4;
....................
.................... int led_flash_state : 6;
.................... BOOLEAN modify_state;
.................... BOOLEAN password_req;
....................
.................... int led_flash_en : 6;
.................... BOOLEAN modify_en;
.................... BOOLEAN reserved;
.................... } MENU;
....................
.................... const MENU menu[] = {
.................... { 0x11, 0x22, 0x33, 0x44, 1, 2, 3, 4, 0x3f, TRUE, FALSE, 0X3F, FALSE, TRUE },
.................... { 0x55, 0x66, 0x77, 0x88, 5, 6, 7, 8, 0x38, TRUE, FALSE, 0X3F, FALSE, TRUE },
.................... } ;
0004: BCF 0A.0
0005: BCF 0A.1
0006: BCF 0A.2
0007: ADDWF 02,F
0008: RETLW 11
0009: RETLW 22
000A: RETLW 33
000B: RETLW 44
000C: RETLW 21
000D: RETLW 43
000E: RETLW 7F
000F: RETLW BF
0010: RETLW 55
0011: RETLW 66
0012: RETLW 77
0013: RETLW 88
0014: RETLW 65
0015: RETLW 87
0016: RETLW 78
0017: RETLW BF
....................
.................... void main() {
.................... int i;
.................... MENU m;
0018: CLRF 04
0019: MOVLW 1F
001A: ANDWF 03,F
001B: MOVLW 9F
001C: MOVWF 04
001D: MOVLW 07
001E: MOVWF 00
.................... m = menu[0];
001F: MOVLW 11
0020: MOVWF 27
0021: MOVLW 22
0022: MOVWF 28
0023: CLRF 29
0024: CLRF 2A
0025: MOVLW 11
0026: MOVWF 2B
0027: MOVLW 22
0028: MOVWF 2C
0029: CLRF 2D
002A: CLRF 2E
.................... for( i = 0; i < 2; i++ ) {
002B: CLRF 26
002C: MOVF 26,W
002D: SUBLW 01
002E: BTFSS 03.0
002F: GOTO 14D
.................... m = menu[i];
0030: BCF 03.0
0031: RLF 26,W
0032: MOVWF 20
0033: RLF 20,F
0034: RLF 20,F
0035: MOVLW F8
0036: ANDWF 20,F
0037: MOVF 20,W
0038: CALL 004
0039: BSF 03.6
003A: MOVWF 1F
003B: MOVWF 1E
003C: MOVWF 1D
003D: MOVWF 1C
003E: MOVWF 1B
003F: MOVWF 1A
0040: MOVWF 19
0041: MOVWF 18
0042: MOVWF 17
0043: MOVWF 16
0044: MOVWF 15
0045: MOVWF 14
0046: MOVWF 13
0047: MOVWF 12
0048: MOVWF 11
0049: MOVWF 10
004A: MOVWF 0F
004B: MOVWF 0E
004C: MOVWF 0D
004D: MOVWF 0C
004E: MOVWF 0B
004F: MOVWF 0A
0050: MOVWF 09
0051: MOVWF 08
0052: MOVWF 07
0053: MOVWF 06
0054: MOVWF 05
0055: MOVWF 04
0056: MOVWF 03
0057: MOVWF 02
0058: MOVWF 01
0059: MOVWF 00
005A: BSF 03.5
005B: BCF 03.6
005C: MOVWF 7F
005D: MOVWF 7E
005E: MOVWF 7D
005F: MOVWF 7C
0060: MOVWF 7B
0061: MOVWF 7A
0062: MOVWF 79
0063: MOVWF 78
0064: MOVWF 77
0065: MOVWF 76
0066: MOVWF 75
0067: MOVWF 74
0068: MOVWF 73
0069: MOVWF 72
006A: MOVWF 71
006B: MOVWF 70
006C: MOVWF 6F
006D: MOVWF 6E
006E: MOVWF 6D
006F: MOVWF 6C
0070: MOVWF 6B
0071: MOVWF 6A
0072: MOVWF 69
0073: MOVWF 68
0074: MOVWF 67
0075: MOVWF 66
0076: MOVWF 65
0077: MOVWF 64
0078: MOVWF 63
0079: MOVWF 62
007A: MOVWF 61
007B: MOVWF 60
007C: MOVWF 5F
007D: MOVWF 5E
007E: MOVWF 5D
007F: MOVWF 5C
0080: MOVWF 5B
0081: MOVWF 5A
0082: MOVWF 59
0083: MOVWF 58
0084: MOVWF 57
0085: MOVWF 56
0086: MOVWF 55
0087: MOVWF 54
0088: MOVWF 53
0089: MOVWF 52
008A: MOVWF 51
008B: MOVWF 50
008C: MOVWF 4F
008D: MOVWF 4E
008E: MOVWF 4D
008F: MOVWF 4C
0090: MOVWF 4B
0091: MOVWF 4A
0092: MOVWF 49
0093: MOVWF 48
0094: MOVWF 47
0095: MOVWF 46
0096: MOVWF 45
0097: MOVWF 44
0098: MOVWF 43
0099: MOVWF 42
009A: MOVWF 41
009B: MOVWF 40
009C: MOVWF 3F
009D: MOVWF 3E
009E: MOVWF 3D
009F: MOVWF 3C
00A0: MOVWF 3B
00A1: MOVWF 3A
00A2: MOVWF 39
00A3: MOVWF 38
00A4: MOVWF 37
00A5: MOVWF 36
00A6: MOVWF 35
00A7: MOVWF 34
00A8: MOVWF 33
00A9: MOVWF 32
00AA: MOVWF 31
00AB: MOVWF 30
00AC: MOVWF 2F
00AD: MOVWF 2E
00AE: MOVWF 2D
00AF: MOVWF 2C
00B0: MOVWF 2B
00B1: MOVWF 2A
00B2: MOVWF 29
00B3: MOVWF 28
00B4: MOVWF 27
00B5: MOVWF 26
00B6: MOVWF 25
00B7: MOVWF 24
00B8: MOVWF 23
00B9: MOVWF 22
00BA: MOVWF 21
00BB: MOVWF 20
00BC: MOVWF 1F
00BD: MOVWF 1E
00BE: MOVWF 1D
00BF: MOVWF 1C
00C0: MOVWF 1B
00C1: MOVWF 1A
00C2: MOVWF 19
00C3: MOVWF 18
00C4: MOVWF 17
00C5: MOVWF 16
00C6: MOVWF 15
00C7: MOVWF 14
00C8: MOVWF 13
00C9: MOVWF 12
00CA: MOVWF 11
00CB: MOVWF 10
00CC: MOVWF 0F
00CD: MOVWF 0E
00CE: MOVWF 0D
00CF: MOVWF 0C
00D0: MOVWF 0B
00D1: MOVWF 0A
00D2: MOVWF 09
00D3: MOVWF 08
00D4: MOVWF 07
00D5: MOVWF 06
00D6: MOVWF 05
00D7: MOVWF 04
00D8: MOVWF 03
00D9: MOVWF 02
00DA: MOVWF 01
00DB: MOVWF 00
00DC: BCF 03.5
00DD: MOVWF 7F
00DE: MOVWF 7E
00DF: MOVWF 7D
00E0: MOVWF 7C
00E1: MOVWF 7B
00E2: MOVWF 7A
00E3: MOVWF 79
00E4: MOVWF 78
00E5: MOVWF 77
00E6: MOVWF 76
00E7: MOVWF 75
00E8: MOVWF 74
00E9: MOVWF 73
00EA: MOVWF 72
00EB: MOVWF 71
00EC: MOVWF 70
00ED: MOVWF 6F
00EE: MOVWF 6E
00EF: MOVWF 6D
00F0: MOVWF 6C
00F1: MOVWF 6B
00F2: MOVWF 6A
00F3: MOVWF 69
00F4: MOVWF 68
00F5: MOVWF 67
00F6: MOVWF 66
00F7: MOVWF 65
00F8: MOVWF 64
00F9: MOVWF 63
00FA: MOVWF 62
00FB: MOVWF 61
00FC: MOVWF 60
00FD: MOVWF 5F
00FE: MOVWF 5E
00FF: MOVWF 5D
0100: MOVWF 5C
0101: MOVWF 5B
0102: MOVWF 5A
0103: MOVWF 59
0104: MOVWF 58
0105: MOVWF 57
0106: MOVWF 56
0107: MOVWF 55
0108: MOVWF 54
0109: MOVWF 53
010A: MOVWF 52
010B: MOVWF 51
010C: MOVWF 50
010D: MOVWF 4F
010E: MOVWF 4E
010F: MOVWF 4D
0110: MOVWF 4C
0111: MOVWF 4B
0112: MOVWF 4A
0113: MOVWF 49
0114: MOVWF 48
0115: MOVWF 47
0116: MOVWF 46
0117: MOVWF 45
0118: MOVWF 44
0119: MOVWF 43
011A: MOVWF 42
011B: MOVWF 41
011C: MOVWF 40
011D: MOVWF 3F
011E: MOVWF 3E
011F: MOVWF 3D
0120: MOVWF 3C
0121: MOVWF 3B
0122: MOVWF 3A
0123: MOVWF 39
0124: MOVWF 38
0125: MOVWF 37
0126: MOVWF 36
0127: MOVWF 35
0128: MOVWF 34
0129: MOVWF 33
012A: MOVWF 32
012B: MOVWF 31
012C: MOVWF 30
012D: MOVWF 2F
012E: MOVWF 2E
012F: MOVWF 2D
0130: MOVWF 2C
0131: MOVWF 2B
0132: MOVWF 2A
0133: MOVWF 29
0134: MOVWF 28
0135: MOVWF 27
0136: MOVWF 26
0137: MOVWF 25
0138: MOVWF 24
0139: MOVWF 23
013A: MOVWF 22
013B: MOVWF 21
013C: MOVWF 27
013D: MOVF 22,W
013E: MOVWF 28
013F: MOVF 23,W
0140: MOVWF 29
0141: MOVF 24,W
0142: MOVWF 2A
0143: MOVF 25,W
0144: MOVWF 2B
0145: MOVF 26,W
0146: MOVWF 2C
0147: MOVF 27,W
0148: MOVWF 2D
0149: MOVF 28,W
014A: MOVWF 2E
.................... }
014B: INCF 26,F
014C: GOTO 02C
.................... }
014D: SLEEP
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514950
[email protected]
Guest







Re: array assignment problem
PostPosted: Mon Jun 02, 2003 7:05 am     Reply with quote

Thanks a lot!!!!!!!!!!!!!!!!!!!!!!!!!

1. I have given the more detail of the problem, as well as the list file you require.
2. Please refer to my reply to WOODY.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514951
Woody
Guest







Re: What is the problem
PostPosted: Mon Jun 02, 2003 8:51 am     Reply with quote

There is most definitely a problem with the version of the compiler you have. The list file resulting from compiling your example with version 3.160 bears no resemblance to the one you produced with 3.050. Below is just a fragment...

Hope this helps,

Best regards.


ROM used: 70 (2\%)
Largest free fragment is 2048
RAM used: 16 (8\%) at main() level
16 (8\%) worst case
Stack: 1 locations

0000 .................... m = menu[i];
0030 RLF 26,W
0031 MOVWF 20
0032 RLF 20,F
0033 RLF 20,F
0034 MOVLW F8
0035 ANDWF 20,F
0036 MOVF 20,W
0037 MOVWF 22
0038 MOVLW 08
0039 MOVWF 21
003A MOVLW 27
003B MOVWF 04
003C MOVF 22,W
003D CALL 004
003E MOVWF 00
003F INCF 22,F
0040 INCF 04,F
0041 DECFSZ 21,F
0042 GOTO 03C

0044
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514954
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