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

Need help CCS ASM
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
asmo



Joined: 18 Jul 2009
Posts: 5

View user's profile Send private message

Need help CCS ASM
PostPosted: Sat Jul 18, 2009 1:45 am     Reply with quote

Please can anyone help me editing these codes to make it work with CCS compiler (pcwhd)?
Code:

#asm
MOVLW 15
movwf i,0
ciclo_c1:
dcfsnz i,1,0
bra fine_c1
RRCF dd+1,1,0
RRCF dd,1,0
BCF PORTB,Dnum,0 //D0();
BTFSC STATUS,0,0 //Carry
BSF PORTB,Dnum,0 //D1();
BSF PORTB,CKnum,0 //CKpulse();
BCF PORTB,CKnum,0
BRA ciclo_c1
fine_c1:
#endasm

When compiling it says: Expecting an opcode mnemonic

These codes work fine in MPLAB C18, no error.
I want it to work in CCS. I changed the program for it, but I couldn't do
nothing with asm language, because I don't know anything of it:D
Please help me.
Thanks
Ttelmah
Guest







PostPosted: Sat Jul 18, 2009 4:12 am     Reply with quote

The most likely 'reason', for initial failure, is that by default, CCS, doesn't have the defintions for things like 'PORTB' present. You need to add these with a #byte statement. However there are several detail differences in the CCS assembler that will cause further problems.
That having been said though, what is being done here (rotating a 16bit word, and setting the 'Dnum' bit of portB, according to whether the bit is set or clear, then clocking the CKnum bit, can be done just as well in C, without using assembler at all. If you select fast IO (otherwsie CCS will add the code to control TRIS), this can be just done in C, giving similar code....

Best Wishes
asmo



Joined: 18 Jul 2009
Posts: 5

View user's profile Send private message

PostPosted: Sat Jul 18, 2009 10:25 pm     Reply with quote

Thank you very much for your reply.
I will give you more idea about the prog:
These codes are taken from an open source USB programmer belongs to Alberto Maccioni.
This is the link http://openprog.altervista.org/OP_eng.html
Though I have usb programmer, I was very interested of codes because they teach me programming as a beginner in this field. So I spent long days to learn that. I converted it to MikroC,and now I want to convert it to CCS. In mikroC it was compiled, but problem is I can't read data or programs, it gives 00, or with pic18 it gives always b3b3b3...other things works good.
I thought it will work if I use CCS, but didtn't compile at all with asm codes present there. If I comment out asm codes it compiles, all working except can't program or read devices.
With this open source programmer, "many thanks to ALBERTO", I tought myself many new things especially USB.
I found C18 difficult for me to understand what I need, when converted to mikroC, and CCS, I now understand what I learned in the net, books..about USB.
I will appreciate your help for me if you find me a solution for these asm codes, or you give a clear start how to convert them to CCS.
Sorry for bothering anyone with this.
Sorry for my english, not my native language.
Thanks


Last edited by asmo on Wed Jul 22, 2009 2:36 pm; edited 2 times in total
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Jul 19, 2009 3:55 pm     Reply with quote

I tried converting the code to C but this will compile less optimal and make the code slower. Another problem is that the original source code is not designed very well. A good coding practice is to keep your functions small, not larger than what fits on a single screen. The function where the mentioned assembly code comes from is almost 2500 lines long, in my 20 years of coding practice I've never seen such a long function!

The following code should do the trick.
Code:
#byte PORTB=      0xF81
#byte STATUS=     0xFD8



#asm
  MOVLW 15
  movwf i
ciclo_c1:
  dcfsnz i
  bra fine_c1
  RRCF &(int8)dd+1,1
  RRCF dd,1
  BCF PORTB,Dnum  //D0();
  BTFSC STATUS,0  //Carry
  BSF PORTB,Dnum  //D1();
  BSF PORTB,CKnum //CKpulse();
  BCF PORTB,CKnum
  BRA ciclo_c1
fine_c1:
#endasm
codewiz



Joined: 03 Feb 2009
Posts: 8

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 20, 2009 5:12 am     Reply with quote

Hi ckielstra. I had been confused for a while on what C compiler for PIC to dedicate most of my attention on having used assembler (MPLAB) for a long time. I looked into mikroC but CCS C has been in my mind. After going through the forum, I decided to start up fully with CCS C. I want to learn the basics, tricks and best coding practice for CCSC. I've a question - how did you know that PORTB = 0xF81 and STATUS = 0xFD8?. it will help me if I understand it. I like the forum support. is there any problem if I use mplab ide for ccsc?. Thanks.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Jul 20, 2009 7:15 am     Reply with quote

I would assume he got those two addresses from the PIC datasheet. You have GOT to have the datasheet for the chip you are using.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Ttelmah
Guest







PostPosted: Mon Jul 20, 2009 8:06 am     Reply with quote

As a comment though, my remark about keeping it in C, does still apply:
Code:

#define DATA_BIT PIN_B0
#define CLOCK_BIT PIN_B1

#use FAST_IO(B)

//Obviously TRIS needs to be setup before this point

   for (ctr=15;ctr;ctr--) {
      if (shift_right(&word,2,0)) output_high(DATA_BIT);
      else output_high(DATA_BIT);
      output_high(CLOCK_BIT);
      output_low(CLOCK_BIT);
   }

//Compiles to generate:

....................    for (ctr=15;ctr;ctr--) {
02E6:  MOVLW  0F
02E8:  MOVWF  0E
02EA:  MOVF   0E,F
02EC:  BZ    0304
....................       if (shift_right(&word,2,0)) output_high(PIN_B0);
02EE:  BCF    FD8.0
02F0:  RRCF   10,F
02F2:  RRCF   0F,F
02F4:  BNC   02FA
02F6:  BSF    F8A.0
....................       else output_high(PIN_B0);
02F8:  BRA    02FC
02FA:  BSF    F8A.0
....................       output_high(PIN_B1);
02FC:  BSF    F8A.1
....................       output_low(PIN_B1);
02FE:  BCF    F8A.1
....................    }
0300:  DECF   0E,F
0302:  BRA    02EA


Which is so close to the assembler version, that I'd still say 'keep it in C'....

The 'annoying' thing is that if the internal 'rotate_right' instruction, returned the carry, it could be made to completely match the assembler version. :-)

Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Jul 20, 2009 12:51 pm     Reply with quote

Hi Ttelmah, you beat me on this one. My C implementation resulted in slower code, but your code is indeed very close to the assembly version. I agree this C-code is to be preferred as it has the advantage of being much easier to read and a lot easier to port to other processors (no need to hard code the port addresses, etc).
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Jul 20, 2009 12:53 pm     Reply with quote

codewiz wrote:
is there any problem if I use mplab ide for ccsc?
MPLAB works great for me. I prefer it over the CCS IDE.
asmo



Joined: 18 Jul 2009
Posts: 5

View user's profile Send private message

PostPosted: Tue Jul 21, 2009 4:15 am     Reply with quote

HI ckielstra
HI Ttelmah
Thank you very much for your help.i will try this sooner, and see the result.
I will tell you when done. For now, I wanna ask you another question, and please keep in mind that I don't understand anything of asm. After long time trying to compile those codes,a nd read documentation of CCS, I changed those asm code to this:
Code:

#asm
MOVLW 15
movwf i
movlw 0
ciclo_c1:
dcfsnz i,1
movlw 0
bra fine_c1
RRCF dd+1,1
movlw 0
RRCF dd,1
movlw 0
BCF PORTB,Dnum //D0();
movlw 0
BTFSC STATUS,0 //Carry
movlw 0
BSF PORTB,Dnum //D1();
movlw 0
BSF PORTB,CKnum //CKpulse();
movlw 0
BCF PORTB,CKnum
movlw 0
BRA ciclo_c1
fine_c1:
#endasm

every time i found 0 at the end, i delete it and add new line with
movlw 0
Very Happy Very Happy
I don't know even what means.
It was compiled but when the codes have the variable
dd+1 it generated about 100 errors!!!!
It said "expression must evaluate to a constant.
But if I delete 1 and let only dd, so no problem for compiling, but I am not sure of the result.
Is it possible what I did? If yes how make "dd+1"compiling?
N.B
I very little use the ready function of CCS, in fact I made a header file according to the datasheet . For example I don't use input_high(), or what else..
I use
Code:
 PORTA_F1=1;
TRISB_F5=0;
INTCON_PEIE = 1;            // enable Peripheral Interrupt Enable
 INTCON_GIE = 1; .......etc

because I don't want to spend time to look how to make a pin high or low..especially if I use more than one compiler.

Many thanks in advance.



hi AGAIN!
After writting to you i copied the asm codes and it was compiled perfectly.but i need more time to do all the codes in the loooong function.Also i was happy for the tranlation to c, this is what i need and what i understand, so i'll try it sooner.
have a nice time..
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Jul 21, 2009 5:18 am     Reply with quote

As first point, your substitution of the access bit in PIC18 assembly by a MOVLW 0 is basically incorrect. As the CCS C handbook clarifies in the #asm chapter "The compiler will set the access bit depending on the value of the file register". Thus, these parameter can't and doesn't need to be set in CCS assembler.

Quote:
when the codes have the variable dd+1 it generated about 100 errors!!!!
Generally setting variable address offsets in CCS assembler works for me, if the variable is an array. Apparently, it doesn't work with simple variables. You can define some kind of structure or array as a workaround.

Quote:
i don't understand anything of asm
Yes, obviously. Personally, I would either try to understand some of it or leave it well alone.

P.S.: using &dd+1 instead of dd+1 with a simple variable works, too.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Jul 21, 2009 12:10 pm     Reply with quote

FvM wrote:
P.S.: using &dd+1 instead of dd+1 with a simple variable works, too.
Yes, this compiles but be aware that dd is an int16. Starting with the v4.000 version of the compiler the pointer arithmetic has changed from K&R to ANSI; with an int16 this means a '+1' will give you the next int16 address at the next 2 bytes offset. What the original coder intended is to retrieve the value at the next byte, this can be achieved by first casting the int16 to an int8. See my posted code in the other routine above:
Code:
  RRCF &(int8)dd+1,1
codewiz



Joined: 03 Feb 2009
Posts: 8

View user's profile Send private message Send e-mail

PostPosted: Tue Jul 21, 2009 9:35 pm     Reply with quote

Oh! I got it. The chip in question is the 18F2550. I just looked at the data sheet and those are the addresses of PORTB and STATUS registers in the file map. I'm clarified now. Thanks. I think, the best way for me to pick up most of the CCS C is study already written code. Having defined PORTB can I then access it's bit as PORTB.2 in CCS C? Thanks.
asmo



Joined: 18 Jul 2009
Posts: 5

View user's profile Send private message

PostPosted: Wed Jul 22, 2009 2:45 pm     Reply with quote

Thank you very much ckielstra, I used your codes in all the program, and now no problem, it worked great. YES, I must use "&(int8)dd+1", if I use int16 instead, it reads half program. I am sure you are good programmer.
Next time I will use C codes given by Ttelmah, so I can understand what happens inside.
Thank you, thank you, all of you Very Happy
asmo



Joined: 18 Jul 2009
Posts: 5

View user's profile Send private message

PostPosted: Wed Jul 22, 2009 11:04 pm     Reply with quote

hi Ttelmah!
I have this in the program,how can i define "word",the compiler said "undefined identifier word"?can you please tell me how to do that?



Code:



#byte TRISB = 0xF93
#byte PORTB = 0xF81
#bit         PORTB_F5                      =PORTB.5
#bit         PORTB_F6                      =PORTB.6
#define D_bit           LATB_F5
#define CK_bit          LATB_F6

// #define DATA_BIT PIN_B0
//#define CLOCK_BIT PIN_B1

#use FAST_IO(B)

//Obviously TRIS needs to be setup before this point

   for (i=15;i;i--) {
      if (shift_right(&word,2,0)) output_high(D_bit);
      else output_high(D_bit);
      output_high(CK_bit);
      output_low(CK_bit);
   }
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 1, 2  Next
Page 1 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