View previous topic :: View next topic |
Author |
Message |
amit78
Joined: 17 Jul 2009 Posts: 22 Location: Kolkata, India
|
How to use Assembly in CCS |
Posted: Wed Jun 08, 2022 11:05 pm |
|
|
Dear All,
In PICMicro Datasheet some times we found some Assembly code snippets. I need to know how should we use those codes in our CCS Program.
For example, currently I am using PIC18F97J60. In the datasheet @page 160, I found one set of assembly code. I like to use that code in my C Code. I went to CCS Help but, may be I am missing something. I need little guidance.
Code: |
#asm
CLRF PORTF ; Initialize PORTF by
; clearing output
; data latches
CLRF LATF ; Alternate method
; to clear output data latches
MOVLW 07h ;
MOVWF CMCON ; Turn off comparators
MOVLW 0Fh ;
MOVWF ADCON1 ; Set PORTF as digital I/O
MOVLW 0CEh ; Value used to initialize data direction
MOVWF TRISF ; Set RF3:RF1 as inputs RF5:RF4 as outputs
; RF7:RF6 as inputs
#endasm
|
Need to know how it should work.
Thanks in advance |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jun 09, 2022 1:12 am |
|
|
For your information, the compiler automatically puts the following code at
the start of main():
Code: |
00004: CLRF TBLPTRU
00006: BCF RCON.IPEN
00008: MOVF ADCON1,W
0000A: ANDLW C0
0000C: MOVWF ADCON1
0000E: MOVLW 07
00010: MOVWF CMCON
|
You can get the other two lines you want by doing this:
Code: | #include <18F97J60.h>
#use delay(clock=4M)
#byte LATF = getenv("SFR:LATF");
//================================
void main()
{
LATF=0;
set_tris_f(0xCE);
while(TRUE);
}
|
Then you get this:
Code: |
.... void main()
00004: CLRF TBLPTRU
00006: BCF RCON.IPEN
00008: MOVF ADCON1,W
0000A: ANDLW C0
0000C: MOVWF ADCON1
0000E: MOVLW 07
00010: MOVWF CMCON
.... LATF=0;
00012: CLRF LATF
.... set_tris_f(0xCE);
00014: MOVLW CE
00016: MOVWF TRISF |
|
|
|
amit78
Joined: 17 Jul 2009 Posts: 22 Location: Kolkata, India
|
|
Posted: Thu Jun 09, 2022 2:25 am |
|
|
Thank you So Much for your Prompt Reply.
I will check it. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Thu Jun 09, 2022 5:30 am |
|
|
Both the compiler's built-in help and the manual have entries. Search for #asm. If you really need to include assembly instructions, they're inserted with a starting #asm and ended with #endasm.
Between the manual, help and searching here, you'll be able to figure things out very quickly. |
|
|
JAM2014
Joined: 24 Apr 2014 Posts: 138
|
|
Posted: Thu Jun 09, 2022 2:25 pm |
|
|
Hi,
One question I would ask is "why are you doing this"? CCS has built-in high level functions to do the simple initialization/configuration stuff you want/need to do! This is one of the huge benefits of CCS C. In 10+ years of PIC coding with CCS C, I've only used .asm 1 time, and that was to ensure the fastest possible control of some digital I/O with a particularly time-fussy LED driver chip. I'd be really shocked if you *truly* need to use .asm in your projects. Basically, if you are going to use CCS C then use CCS C, which means using the built-in functions and C syntax to do what you need to do!
Jack |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Thu Jun 09, 2022 2:41 pm |
|
|
Agree with Jack ... WHY is ASM needed ?
I've actually only needed ASM TWICE in 25 years, both were custom very time sensitive interfaces to client's hardware.
curious to know...
Jay |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Thu Jun 09, 2022 5:15 pm |
|
|
I designed several real time control systems for large industrial equipment
and, with careful coding and time slicing, did not need ASM at all. I used ASM a
couple of times in earlier versions of CCS to lock/unlock registers but not any
more since they got that fixed. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jun 09, 2022 6:04 pm |
|
|
temtronic,
He wanted ASM because he wanted the init code published in the PIC data
sheet, and he didn't know that CCS automatically puts it at the start of main.
Now he knows. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri Jun 10, 2022 9:32 pm |
|
|
Thanks PCM Programmer for so brilliant answer (one more time).
The CCS compiler has many years of maturation through which it has achieved good code optimization
compared to earlier versions.
It is always a temptation to use Assembler to solve critical situations, but it is often solved by modifying an
algorithm or optimize some hardware issue.
Best wishes _________________ Humber |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Sat Jun 11, 2022 1:22 am |
|
|
Yes,
Even this has become less and less necessary.
Historically when the V5 compilers started some code got larger than it
had been on the V4 compilers.
I recently had cause to recompile some old V4 code, and was impressed
to see that now the result was nearly 200 bytes smaller than the V4
version.
On performing basic tasks, with a bit of care in how things are defined
and done it is possible now to pretty much do every assembler operation
in C with the same result, by doing direct accesses as PCM shows.
I've posted things like replacements for the flash memory access routines
(where several compiler versions had problems), that are direct translations
of the assembler posted in the data sheets, into C, and are simple, and
result in exactly the same assembler.
It really has become almost totally unneeded now. |
|
|
|