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

Another pair of eyes
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Dec 19, 2005 5:54 pm     Reply with quote

I'm sorry. I'm still not getting it. The default argument is used
I have 1 I2C write. It's list file has a jump to 006C which is outside the #org range. And the fprintf is outside also.
Is it just that I don't understand the list file?
Code:

#include <18F452.H>
#CASE
#USE DELAY(CLOCK=40000000)
#FUSES H4,NOWDT,NOPROTECT,NOLVP
#USE RS232(BAUD=19200,XMIT=PIN_C0,INVERT,STREAM=DEBUG,DISABLE_INTS) // STDERR(same as DEBUG)
#USE RS232(BAUD=19200,ENABLE=PIN_C5,XMIT=PIN_C6,RCV=PIN_C7,STREAM=RS485)
#define hi(x)  (*(&x+1))  //data held at addr of x + 1
#define lo(x)  (*(&x))    //data held at addr of x
char buff[8];
#use I2C(MASTER,SDA=PIN_C4,SCL=PIN_C3,FORCE_HW,FAST,RESTART_WDT)
#separate
void PrgmPIC(void);

//---------------- MAIN --------------------
void main(void){
  fprintf(DEBUG,"Start..");
  PrgmPIC();
  fprintf(DEBUG,"Done\n\r");
  while(1){
  }
}
//===================== PrgmPIC =========================
#org 0x7A00, 0x7FC0 default
void PrgmPIC(void){
  i2c_write(0xA5A5);
  fprintf(DEBUG,"Done\n\r");
}
#org default

Code:
CCS PCH C Compiler, Version 3.239, 30995               19-Dec-05 16:50

               Filename: C:\ccs\Projects\3200I\update_firmware\j.lst

               ROM used: 292 bytes (1%)
                         Largest free fragment is 30992
               RAM used: 14 (1%) at main() level
                         16 (1%) worst case
               Stack:    2 locations

*
0000:  GOTO   008A
.................... #include <18F452.H>
.................... //////// Standard Header file for the PIC18F452 device ////////////////
.................... #device PIC18F452
.................... #list
.................... 
.................... #CASE
.................... #USE DELAY(CLOCK=40000000)
.................... #FUSES H4,NOWDT,NOPROTECT,NOLVP
.................... #USE RS232(BAUD=19200,XMIT=PIN_C0,INVERT,STREAM=DEBUG,DISABLE_INTS) // STDERR(same as DEBUG)
*
0020:  MOVFF  FF2,0F
0024:  BCF    FF2.7
0026:  BCF    F94.0
0028:  BSF    F8B.0
002A:  MOVLW  08
002C:  MOVWF  01
002E:  NOP   
0030:  NOP   
0032:  NOP   
0034:  BSF    01.7
0036:  BRA    0056
0038:  BCF    01.7
003A:  RRCF   0E,F
003C:  BTFSC  FD8.0
003E:  BCF    F8B.0
0040:  BTFSS  FD8.0
0042:  BSF    F8B.0
0044:  BSF    01.6
0046:  BRA    0056
0048:  BCF    01.6
004A:  DECFSZ 01,F
004C:  BRA    003A
004E:  NOP   
0050:  NOP   
0052:  NOP   
0054:  BCF    F8B.0
0056:  MOVLW  A7
0058:  MOVWF  FE9
005A:  DECFSZ FE9,F
005C:  BRA    005A
005E:  BTFSC  01.7
0060:  BRA    0038
0062:  BTFSC  01.6
0064:  BRA    0048
0066:  BTFSC  0F.7
0068:  BSF    FF2.7
006A:  RETLW  00
.................... #USE RS232(BAUD=19200,ENABLE=PIN_C5,XMIT=PIN_C6,RCV=PIN_C7,STREAM=RS485)
.................... #define hi(x)  (*(&x+1))  //data held at addr of x + 1
.................... #define lo(x)  (*(&x))    //data held at addr of x
.................... char buff[8];
.................... #use I2C(MASTER,SDA=PIN_C4,SCL=PIN_C3,FORCE_HW,FAST,RESTART_WDT)
006C:  BCF    FC6.7
006E:  BCF    F9E.3
0070:  MOVFF  0D,FC9
0074:  MOVLW  02
0076:  BTFSC  FC6.7
0078:  BRA    0084
007A:  BTFSS  F9E.3
007C:  BRA    007A
007E:  MOVLW  00
0080:  BTFSC  FC5.6
0082:  MOVLW  01
0084:  MOVWF  01
0086:  GOTO   7A20 (RETURN)
.................... #separate
.................... void PrgmPIC(void);
.................... 
.................... //---------------- MAIN --------------------
.................... void main(void){
008A:  CLRF   FF8
008C:  BCF    FD0.7
008E:  CLRF   FEA
0090:  CLRF   FE9
0092:  BCF    F94.0
0094:  BCF    F8B.0
0096:  BCF    F94.5
0098:  BCF    F8B.5
009A:  MOVLW  81
009C:  MOVWF  FAF
009E:  MOVLW  26
00A0:  MOVWF  FAC
00A2:  MOVLW  90
00A4:  MOVWF  FAB
00A6:  BSF    F94.3
00A8:  BSF    F94.4
00AA:  MOVLW  18
00AC:  MOVWF  FC8
00AE:  MOVLW  28
00B0:  MOVWF  FC6
00B2:  BCF    FC7.7
00B4:  BCF    FC7.6
00B6:  BSF    FC1.0
00B8:  BSF    FC1.1
00BA:  BSF    FC1.2
00BC:  BCF    FC1.3
....................   fprintf(DEBUG,"Start..");
00BE:  CLRF   0D
00C0:  MOVF   0D,W
00C2:  RCALL  0008
00C4:  INCF   0D,F
00C6:  MOVWF  00
00C8:  MOVWF  0E
00CA:  RCALL  0020
00CC:  MOVLW  07
00CE:  SUBWF  0D,W
00D0:  BNZ   00C0
....................   PrgmPIC();
00D2:  CALL   7A18
....................   fprintf(DEBUG,"Done\n\r");
00D6:  CLRF   0D
00D8:  MOVF   0D,W
00DA:  CALL   7A00
00DE:  INCF   0D,F
00E0:  MOVWF  00
00E2:  MOVWF  0E
00E4:  RCALL  0020
00E6:  MOVLW  06
00E8:  SUBWF  0D,W
00EA:  BNZ   00D8
....................   while(1){
....................   }
00EC:  BRA    00EC
.................... }
.................... //===================== PrgmPIC =========================
.................... #org 0x7A00, 0x7FC0 default
.................... void PrgmPIC(void){
00EE:  SLEEP
....................   i2c_write(0xA5A5);
*
7A18:  MOVLW  A5
7A1A:  MOVWF  0D
7A1C:  GOTO   006C
....................   fprintf(DEBUG,"Done\n\r");
7A20:  CLRF   0D
7A22:  MOVF   0D,W
7A24:  RCALL  7A00
7A26:  INCF   0D,F
7A28:  MOVWF  00
7A2A:  MOVWF  0E
7A2C:  CALL   0020
7A30:  MOVLW  06
7A32:  SUBWF  0D,W
7A34:  BNZ   7A22
.................... }
7A36:  RETLW  00
.................... #org default
.................... 

Configuration Fuses:
   Word  1: 2600   H4 NOOSCSEN
   Word  2: 0E0F   BROWNOUT WDT128 NOWDT BORV20 NOPUT
   Word  3: 0100   CCP2C1
   Word  4: 0081   STVREN NODEBUG NOLVP
   Word  5: C00F   NOPROTECT NOCPD NOCPB
   Word  6: E00F   NOWRT NOWRTD NOWRTB NOWRTC
   Word  7: 400F   NOEBTR NOEBTRB
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 19, 2005 6:12 pm     Reply with quote

By re-arranging the program, the .LST file now shows all the calls
are being made in the 0x7A00 range. You'll have to inspect it to
make sure it's doing what you want.

Perhaps it was a typo, but i2c_write() can only take an 8-bit parameter.
Code:
#include <18F452.H>
#CASE
#USE DELAY(CLOCK=40000000)
#FUSES H4,NOWDT,NOPROTECT,NOLVP
#USE RS232(BAUD=19200,ENABLE=PIN_C5,XMIT=PIN_C6,RCV=PIN_C7,STREAM=RS485)
#define hi(x)  (*(&x+1))  //data held at addr of x + 1
#define lo(x)  (*(&x))    //data held at addr of x
char buff[8];

#separate
void PrgmPIC(void);

//================ PrgmPIC =====================
#org 0x7A00, 0x7FC0 default
#USE RS232(BAUD=19200,XMIT=PIN_C0,INVERT,STREAM=DEBUG,DISABLE_INTS) // STDERR(same as DEBUG)
#use I2C(MASTER,SDA=PIN_C4,SCL=PIN_C3,FORCE_HW,FAST,RESTART_WDT)
void PrgmPIC(void){
  i2c_write(0xA5A5);
  fprintf(DEBUG,"Done\n\r");
}
 
#org default

//---------------- MAIN --------------------
void main(void){
  fprintf(DEBUG,"Start..");
  PrgmPIC();
  fprintf(DEBUG,"Done\n\r");
  while(1){
  }
}
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Dec 20, 2005 8:32 am     Reply with quote

Thanks PCM. I'll give that a try.
So simply reissuing #use i2c and #use rs232 is all I needed.
And yes that was a typo. Just quick-and-dirty code trying to show the call.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Dec 20, 2005 4:49 pm     Reply with quote

It works.


---- What I've learned about #org-----
-PCM programmer is patient
-You can use a prototype and move the bootloader to the end of code if you use the #seperate.
-To include compiler generated function in a #org use the 'default' argument.
-If using #useI2C or #USE RS232 reissue the commands in the #org
-I found it best to write_program_memory in blocks of 64. This is the env 'erase' size. It sees this address as an erase boundry and erase the 64 block and then programs.
Code:
//===================== PrgmPIC =========================
//Assumes RX_BUF[0] is defined as global. char RX_BUF[256]; or at least 64
//Notice how we reprogram to 0x7D00 and this function is stored after
//that at address 0x7D18.  This is as high as we could go.
#org 0x7D18, 0x7FFF default
#use I2C(MASTER,SDA=PIN_C4,SCL=PIN_C3,FORCE_HW,FAST,RESTART_WDT)
//#USE RS232(BAUD=19200,XMIT=PIN_C0,INVERT,STREAM=DEBUG) // STDERR(same as DEBUG)
void PrgmPIC(void){
  int32 address;
  int8 data,size;
  #define block 64
  char *ptr_char;
  disable_interrupts(GLOBAL);
  for(address=0;address<0x7D00;address+=block){ //read 8 bytes prgm from fram
    ptr_char=&RX_BUF[0];//&RX_BUF[0] is defined as global. char RX_BUF[256];
    for(size=block;size;ptr_char++,size--){
      if(size==block){
        i2c_start();
        i2c_write((0xA0|(int8)(address>>14))&0xFE);//&0xFE forces to write
        i2c_write(hi(address));
        i2c_write(lo(address));
        i2c_start();
        i2c_write((0xA0|(int8)(address>>14))|1);//|1 forces to read
      }
      if(size==1)
      {
        *ptr_char=i2c_read(0);//No ack on last read of chip
        i2c_stop();
      }
      else
      {
        *ptr_char=i2c_read(1);//The ack will put next data on bus
      }
    }
    write_program_memory(address,&RX_BUF[0],64);//write=8,erase=64
  }
  //Clear the first 5 locations in fram, Setting to factory default 0xFF
  address=0;size=5;data=0xFF;
  i2c_start();
  i2c_write((0xA0|(int8)(address>>14))&0xFE);
  i2c_write(hi(address));
  i2c_write(lo(address));
  for(;size;size--,address++){
    i2c_write(data);
  }
  i2c_stop();
  //fprintf(DEBUG,"Done\n\r");
  reset_cpu();
}
#org default
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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