Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 19th November 2007, 06:14 AM   (permalink)
Default

Quote:
Originally Posted by Peter_wadley
Ok,

The help file for mikroC has everything I was looking for.

Yes, it seems as though the machine code produced by mikroC is VERY wasteful in terms of memory!!

Just to make an lcd output a couple sentences ate all my 628As ROM!... or RAM...
I have solved that issue if you want to connect your LCD in 4-bit mode using mikroC, mikroPascal, and mikroBasic. The following program creates an optimized module to insert into your program that has a very small ROM footprint, and leaves plenty of room on your 16F628A:

LCD4 Optimized LCD Module

Last edited by wschroeder; 19th November 2007 at 06:21 AM.
wschroeder is offline  
Old 19th November 2007, 11:06 AM   (permalink)
Default

Quote:
Originally Posted by Peter_wadley
Also, why are the 18Fs better suited for C? I have read a bit on the RISC (Reduced Instruction Set Computer) design.
They're better suited for any language, including assembler.

Besides more RAM/FLASH and a more comprehensive and cohesive instruction set there's direct access to the top-of-stack as well as stack push and pop operations. Very exciting empowering stuff;

Code:
;
;  jump table example (completely 256 byte boundary tolerant)
;
        rcall   Jump            ; WREG = index 0..3
table   goto    Func_0          ; index 0 function
        goto    Func_1          ; index 1 function
        goto    Func_2          ; index 2 function
        goto    Func_3          ; index 3 function
Code:
;
;  Jump function
;
Jump    rlncf   WREG,W          ; WREG *= 2
        addwf   TOSL,F          ; add to return address Lo
        movlw   0               ;
        addwfc  TOSH,F          ; propogate Carry
        addwfc  TOSU,F          ; propogate Carry
        return                  ; return to table + WREG*2
My favorite PutString or PutLCD function;
Code:
;
;  PutString macro usage
;
        PutStr  "Az-El Rotor Maintenance/n/n/r"
        PutStr  "1 - Calibrate Az rotor/n/r"
        PutStr  "2 - Calibrate El rotor/n/r"
        PutStr  "3 - Return to Main Menu/n/r"
;
Code:
;
;  the PutString macro
;
PutStr  macro   pStr
        rcall   PutString       ;
        db      pStr,0          ; null terminated inline string table
        endm
;
Code:
;******************************************************************
;
;  PutString - print in-line string via Stack and TBLPTR
;
;  string must be terminated with a 0 byte and does not need
;  to be word aligned
;
PutString
        movff   TOSL,TBLPTRL    ; copy return address into TBLPTR
        movff   TOSH,TBLPTRH    ;
        clrf    TBLPTRU         ; assume PIC with < 64-KB
PutNext
        tblrd   *+              ; get in-line string character
        movf    TABLAT,W        ; last character (00)?
        bz      PutExit         ; yes, exit, else
        rcall   Put232          ; print character
        bra     PutNext         ; and do another
PutExit
        btfsc   TBLPTRL,0       ; odd address? no, skip, else
        tblrd   *+              ; make it even (fix Program Counter)
        movf    TBLPTRH,W       ; setup new return address
        movwf   TOSH            ; 
        movf    TBLPTRL,W       ;
        movwf   TOSL            ;
        return                  ; to 1st instruction following string table
Mike, K8LH is offline  
Old 19th November 2007, 11:33 AM   (permalink)
Default

Quote:
Originally Posted by Mike, K8LH
They're better suited for any language, including assembler.
Thats great I was wondering what language to use when I using 18F & DS pics.Its better I can stay with assembler for another 15 years.I didn't have a problem with assembler until now also easy to understand.

I like assembler very much.
Suraj143 is offline  
Old 19th November 2007, 11:52 AM   (permalink)
Default

Peter,

I hope you don't give up on Assembler completely.

While it's hard to beat the built-in high level language library functions, creating your own Assembler functions isn't difficult. And macros can often be used effectively to create very readable and intuitive code.

Take Warren's (wschroeder's) excellent BASIC LCD functions for example. I suspect they're similar to what I use in Assembler;

Code:
        radix   dec
;******************************************************************
;
;  Host program example macro usage
;
Line1   equ     128             ;
Line2   equ     128+64          ;
Line3   equ     128+20          ;
Line4   equ     128+64+20       ;
;
        PutLCD  cmd,0x0C        ; display on, cursor off
        PutLCD  cmd,Line1+10    ; lcd line 1, htab 10
        PutLCD  str,"GMT"       ; print "GMT" string
        PutLCD  cmd,Line2+10    ; lcd line 2, htab 10
        PutLCD  dat,'?'         ; print "?" character
        PutLCD  cmd,0x10        ; cursor shift left
        PutLCD  cmd,0x0F        ; cursor on (blink)
Code:
;--< macro definitions >-------------------------------------------

cmd     equ     1               ; single byte command/control type
dat     equ     2               ; single byte character/data type
dec     equ     3               ; single byte variable 0..9
str     equ     4               ; multi-byte string character type

PutLCD  macro   ptype,pdata
    if ptype == cmd             ; creates 2 instructions
        movlw   pdata           ;
        call    PutCmd          ; low level driver, RS=0
    endif
    if ptype == dat             ; creates 2 instructions
        movlw   pdata           ;
        call    PutDat          ; low level driver, RS=1
    endif
    if ptype == dec             ; creates 3 instructions
        movf    pdata,W         ; Wreg = variable
        iorlw   '0'             ; 0..9 -> ASCII "0..9"
        call    PutDat          ; low level driver, RS=1
    endif
    if ptype == str             ; creates 1 instruction + inline table
        call    PutString       ; (18F version)
        db      pdata,0         ; null terminated inline table
    endif
        endm

Last edited by Mike, K8LH; 19th November 2007 at 12:03 PM.
Mike, K8LH is offline  
Old 19th November 2007, 12:29 PM   (permalink)
Default

I understand why those who are already familiar with PIC assembler might want to continue using it, especially if they are not familiar with C. I can also understand that you may be used to trying to squeeze every ounce of performance, or space in RAM/ROM out of a PIC if you've been using the 16 series.

The 18 series are *fast*... much faster than the 16F84 or 628a's most of the current crop of PIC affectionados have been using. The flash ROM has also expanded significantly giving you more room to move. The prices seem so reasonable that it's hard to imagine wanting to continue to use the 16 series except in the most price-sensitive applications.

For me, as an engineer wanting to design his first PIC-based product, using the 18 series and C meant that my productivity was *very* quickly to the point where I was writing useful code, without needing to learn PIC assembler which is quite frankly baroque.

C is C is C... the wrinkles involved in 8-bit vs 16 or 32-bit *are* part of C, so moving from a 6809 to a 68000 to a PIC18, PIC24 etc. is straightforward. In fact moving to the new PIC32 series is *much* easier if you know C... the assembler is so totally different that most PIC assembler fans are going to find the learning curve very steep and therefore simply decide to ignore them.

I have found learning the PIC architecture and I/O capabilities to be a great deal of fun :-) Using C I've got a lot further in my design in the time I've spent than I would have had I learned the assembler (and I'm a *very* good assembler programmer.)

So... *please* give some thought to learning C. You're a computer scientist, programmer or engineer, and learning *new* languages, concepts, etc. is part of your vocation or hobby as the case may be.

</rant off>
P.

PS: I re-wrote all of the library routines I used in my prototype... they are fine for a first stab as and as a basis for learning, but near useless for serious applications.

Last edited by aussiepoof; 19th November 2007 at 12:48 PM.
aussiepoof is offline  
Old 19th November 2007, 12:46 PM   (permalink)
Default

All very valid points. C also seems pretty much the defacto 'standard' for professional/commercial development.

Mike
Mike, K8LH is offline  
Old 19th November 2007, 03:31 PM   (permalink)
Default

I agree with all that has been said about C but do find that often mc code written in C is inefficient due to a lack of understanding of the underlying hardware. So, I would add to the discussion, learn to read data sheets at the same time as you learn C or if you know C, take time to read the relevant sections in the data sheet.

Mike.
Pommie is online now  
Old 19th November 2007, 04:30 PM   (permalink)
Default

Quote:
Originally Posted by Mike, K8LH
C also seems pretty much the defacto 'standard' for professional/commercial development.
Yes, but not all...
wschroeder is offline  
Old 19th November 2007, 05:32 PM   (permalink)
Default

I should have mentioned I enjoy programming in C18, BASIC, and Assembler and I recognize strengths and weaknesses in each. I agree it does take more time to write a program in Assembler than it would to write the same program in C18 or BASIC.

I really shouldn't encourage or discourage the use of one language over another. I can write tight, simple, elegant code in each. I can also write loose, sloppy, unintelligent code in each.

Mike
Mike, K8LH is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Using Oscilloscopes mechie Electronic Theory 9 29th November 2007 10:49 PM
USB Time Delay Fan Control Karaethon Micro Controllers 53 14th March 2006 10:36 PM
With limited time, what ways to increase qualifications? sram Chit-Chat 1 8th January 2006 09:18 PM
Drawing Waveforms or how to draw waveforms walters General Electronics Chat 105 11th December 2005 12:24 PM
to set accurate time on laptop for visual satallite tracking John walker Electronic Projects Design/Ideas/Reviews 4 12th October 2005 05:30 PM



All times are GMT. The time now is 02:18 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker