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

CCS plus assembly
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
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

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

CCS plus assembly
PostPosted: Thu Mar 16, 2017 12:42 am     Reply with quote

Good day! I have a question that I am trying to figure out. Is there any way to include Assembler code in CCS? Sometimes the functions of CCS are not very efficient and they cause problems do to bugs, the best way that I can think of to overcome this, and it probably always works is to add an Assembler instruction in the code.
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Thu Mar 16, 2017 12:49 am     Reply with quote

Look at ex_glint.c
ex_fir.c (PCD)
ex_macro.c

Each shows a small piece of assembler being included in the CCS code.
99% of such functions can be coded without using assembler. #byte and #word to talk directly to SFR's etc..
The CCS assembler allows C variables to be accessed by name in the assembler. The command list is in the manual.
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

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

PostPosted: Thu Mar 16, 2017 1:02 am     Reply with quote

Thank you! You deserve a beer!
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Mar 16, 2017 5:47 am     Reply with quote

While Mr T's comment about coding functions in C vs Assembler is true, you may be able to 'refine' a C function. Some programmers code for speed, others for compact code, others don't seem to do care and create 'bloatware'.
When you cut code in Assembler you have a better understanding of what's happening 'inside the PIC'. Microchip has several 'Tips and Tricks' books, where simply resequencing the code or thinking 'upside down' can save bytes or microseconds.
In the good old days of 2Mhz clocks it was important, not so much now with 64Mhz speeds, however if you want clean,tight code, it's worth investigating HOW code works.

Jay
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

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

PostPosted: Thu Mar 16, 2017 5:58 am     Reply with quote

This is useful also, and I like Microchip, the direction in which they work should continue and not stop! They are doing things right! But I just dont have the time at the moment to read a 600 page datasheet or 6000 page book. Plus I have to read Kernighan and Ritchie, and I should some day.
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
jeremiah



Joined: 20 Jul 2010
Posts: 1355

View user's profile Send private message

PostPosted: Thu Mar 16, 2017 6:21 am     Reply with quote

Arakel wrote:
But I just dont have the time at the moment to read a 600 page datasheet


I understand the sentiment here, but please consider:
If you want to be programming microcontrollers, then you simply have to make the time to read the 600 page data sheets. Eventually you will get to the point where you no longer need to read the whole thing and your instincts will help you skim through new ones quickly. Before you get to that point though, you need to get a better understanding of how everything works and all the available options. Otherwise you going to run into problems. There are no shortcuts to real learning.
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

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

PostPosted: Thu Mar 16, 2017 7:13 am     Reply with quote

I understand that, this is the very reason why I first must read what I have now and then continue forward.
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Thu Mar 16, 2017 7:45 am     Reply with quote

The only thing that I've done which has required the use of assembly is getting a PIC to boot from its internal oscillator and then doing an immediate switchover to an external crystal. The necessary registers are locked and can only be accessed once a special time sensitive unlock sequence is generated, and that's what I used assembly for. For everything else - plain old C suffices, especially given that you can directly access special function registers very easily.

Just remember that C is portable; assembly isn't. Just the other day I actually had someone ask my opinion about keeping all their specialized IP, created over the past 2 decades, which is entirely written in assembly. ...For an obsolete family of processors. I don't think they particularly liked my answer, but to me there's really only one alternative: start fresh in C. At least with C you have a relatively easy migration path in future. With assembly, if you change processor families or change manufacturers, all your IP is quite useless.
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

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

PostPosted: Thu Mar 16, 2017 7:51 am     Reply with quote

They still use assembly, especially for mainframes, I dont think that they change the manufacturer, but especially It might have been for the mainframes used the by US emigration service, they use assembly.
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Mar 16, 2017 7:53 am     Reply with quote

just a note... not all C is the same ! We've all seen C code presented here, from another compiler, that will not work as written in CCS C. There's always tweeks to be done.
Every high level language has 'variations' though the closest to 'universal' or machine/OS independent I seen was COBOL. Once you entered the machine/OS specifics in the first section (say 10-20 lines), the 'main' program would compile and execute on any machine from an IBM mainframe to the lowly TRS80-II.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Thu Mar 16, 2017 8:37 am     Reply with quote

It's worth saying, that I have things like the unlock sequence, and things like flash I/O routines, that exactly match the data sheet, but are coded in C....

'Core' C, will 99.9% translate between almost any compiler (with the limitation of being 'aware' of data sizes). However we are writing in 'embedded C', which implies working directly with some parts of the chip, rather than relying on an 'OS' outside. Exactly the same is true of any language. Even languages like Pascal, when you get involved in directly accessing hardware, customisation for the machine becomes necessary.

Historically, perhaps ten years ago, a lot of CCS code would involve some assembler sections. Nowadays the need for these is getting less and less. However there are still the odd 'tiny' part, where it cleaner, safer, & probably quicker to write, in assembler. Sometimes there are little parts of the initialisation or setup, where the default is very 'safe', but often over complex....
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Thu Mar 16, 2017 8:42 am     Reply with quote

temtronic wrote:
just a note... not all C is the same ! We've all seen C code presented here ,from another compiler, that will not work as written in CCS C. There's always tweeks to be done.


I know and I agree. I'm just pointing out that tweaking C code - which is written in a sort of quasi-recognizable format - isn't all that difficult if you've been involved with coding or firmware for any length of time. Migrating a bunch of MOV, MUL, ADD, etc, perhaps with some instructions that don't exist on the platform to which you're migrating is a herculean task. Easier to start with a high level flowchart of what the program does and start fresh. Cheaper too.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

PostPosted: Sat Mar 18, 2017 7:03 am     Reply with quote

Used assembler with CCS when I had no choice.
With my old CCS compiler and PIC18F2520 was a problem using
Code:
setup_ccp2(CCP_CAPTURE_FE);
setup_ccp2(CCP_CAPTURE_RE);

So I used
Code:
   #asm
   movlw 0x04//FE
   movwf 0xFBA//CCP2CON
   #endasm   

   #asm
   movlw 0x05//RE
   movwf 0xFBA//CCP2CON
   #endasm
   

Worked flawlessly. But yes, you need to learn the hardware

Best wishes
Joe
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Sat Mar 18, 2017 1:06 pm     Reply with quote

However that doesn't need assembler:

Code:

#byte CCP2CON = getenv("SFR:CCP2CON")

//then

     CCP2CON=CCP_CAPTURE_FE;
//will set falling edge

     CCP2CON=CCP_CAPTURE_RE;
//will set rising edge

Much cleaner....
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

PostPosted: Sun Mar 19, 2017 5:23 am     Reply with quote

As I suppose you know from my questions Ttelmah, I am not really a C programmer Very Happy
Just not long time ago learned that I can use "getenv" for certain things.
So using assembler to overcome the bug was natural to me Smile

Best wishes
James
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