PIC Assembler 12 Bit Instruction Device Family Shop Talk

MaxHeadRoom

Joined Jul 18, 2013
28,690
Incidentally you can get a 8 pin pic development board with example peripherals, P.B. Analogue, LED etc for $6.00 ebay e.g. 331937809671 c/w 6pin ICP input.
Comes with a Pic.
Max.
 

Attachments

takao21203

Joined Apr 28, 2012
3,702
Finally found a GREAT series of books..

I will hold back on saying which ones they are so I don't get accused of anything.

I am very stoked to find these!

Anybody want to talk about PIC Assembler?
Risc Assembler is a 2 bladed sword of kind. Foe one of course you could learn a lot and build up skills. But its tedious and time consuming even to write small programs. On top of that other people will probably not be familiar with the chip you use and will not be able to read your code, as well after two years youll not be able to understand your own code properly anymore.

Productivity of C language is 10x as much for some tradeoff in performance. But also C language can be spelled in many different ways so you can make up for that to a certain extent. Experienced assembler programmers would often look up the disassembly of what they just programmed, so, knowing some assembler can be helpful.

Also start with C language early, my recommendation and dont get consumed by writing large assembler programs as well digging into optimization. If the chip is too small use a larger one, simply put.

Some day I wrote a scrolling message using assembler and it was quite bad. Its difficult enough in C language! Also in C language theres a large amount of mostly device independent libraries, you can use all the Arduino stuff for PIC also did you know? As well the obvious USB TFT and SD card stuff. Youd get carried away trying to program these in asembler.

In C language you can program anything thats doable in Assembler, actually C language is just a device independent way of using assembler.

Also dont pay attention about people who boast themselves with C++ skills.

It is, compareable to assembler and C, just a syntax of spelling C language. Basically you could spawn objects in memory.
Theres nothing stopping you doing this in plain C and it has been done. Its just kindof a syntax to do things commonly done, means you write a line C++ or two, and it results in several lines C + using libraries.

In the end, all C language source ends up as assembler.

For instance in C you have datatypes, normally byte, word and longword. 8, 16 and 32 bit.

In assembler, you dont have native support for 16 bit on a 8bit controller. So you need to cobble it together manually.
In C you only change the variable definition. The source lines where the variable is used arent changed.
The compiler will automatically spell out the matching assembler constructs.

When you work with pointers (address references), its the same.

Using assembler you do address displacement 1:1 and multiply by two for words.
In C language you dont, basically. Its done automatically according to the data word size.

This makes assembler source codes almost unmaintainable, if you need to change word sizes later. Its OK for 100 or 200 lines but for 20000 lines, youre better off of starting over again.

Long story short, assembler is not device independent, while C language is.
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Thank you Max

We are stocked up with hardware. And then some.

Beginners 'searching around'. Floundering around?

'We're going in!'

Buckling down to hacking our way through the jungle of this first tutorial.
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Thank you Takao

This current tutorial (not PIC'n book lessons ) has you do Assembler and then C.

As of right now PIC'n book is side reading. I think it is for Assembler.

In that if someone says something in a different way you go 'Now I get it!'.

This tutorial is Baseline Assembler and then you bounce over to Baseline C.

10-12 lesson in Assembler so we will be dealing with C kinda soon.
 

MaxHeadRoom

Joined Jul 18, 2013
28,690
Code:
;************************************************************************
                                                                      *
;   Filename:      BA_L1-Turn_on_LED-12F508.asm                         *
;   Date:          3/1/12                                               *
;   File Version:  1.0                                                  *
;                                                                       *
;   Author:        David Meiklejohn                                     *
;   Company:       Gooligum Electronics                                 *
;                                                                       *
;************************************************************************
;                                                                       *
;   Architecture:  Baseline PIC                                         *
;   Processor:     12F2508                                              *
;                                                                       *
;************************************************************************
;                                                                       *
;   Files required: none                                                *
;                                                                       *
;************************************************************************
;                                                                       *
;   Description:    Lesson 1, example 1                                 *
;                                                                       *
;   Turns on LED.  LED remains on until power is removed.               *
;                                                                       *
;************************************************************************
;                                                                       *
;   Pin assignments:                                                    *
;       GP1 = indicator LED                                             *
;                                                                       *
;************************************************************************

    list        p=12F508         
    #include    <p12F508.inc>     


;***** CONFIGURATION
                ; ext reset, no code protect, no watchdog, int RC clock
    __CONFIG    _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC


;***** RC CALIBRATION
RCCAL   CODE    0x1FF       ; processor reset vector
        res 1               ; holds internal RC cal value, as a movlw k
       

;***** RESET VECTOR *****************************************************
RESET   CODE    0x000       ; effective reset vector
        movwf   OSCCAL      ; apply internal RC factory calibration


;***** MAIN PROGRAM *****************************************************

;***** Initialisation
start   
        movlw   b'111101'       ; configure GP1 (only) as an output
        tris    GPIO
        movlw   b'000010'       ; set GP1 high
        movwf   GPIO

;***** Main loop               
        goto    $               ; loop forever


        END
 
Last edited by a moderator:

Mosaic

Joined Aug 2, 2010
16
You can have a look at the Oshonsoft series of PIC simulators as an economical way of testing before assembling.
I started with those. Now I use the Proteus ISIS simulator as it allows mixing electronics (digital/analog) with multiple microcontrolelrs (different types) for a more complete sim environment.

The MPLAB IDE is ok, but I like Proteus.

I still use assembler as I mainly use the 16Fxxx and 16F1xxx series chips. Handling the memory mgmt with those chips is an added 'chore' but it's ok once u do it once or twice.
The 18F & 24F series are better for C compiler use.
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Trouble in paradise.

Could just load source code and get through lesson.

EXCEPT. Have 12F509's here and 12F508's are over at other location.
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Thank you Mosaic

That Oshkosh is interesting.

He has fairly upfront honest purchasing policy.

I like to suffer. We will impose our will on MPLAB X IDE !

Harness the unruly beast.
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Here's source file for 12F508.

Author said that SHOULD run on a 12F509.

That was my idea purchase some 12F509's. It has more memory than 12F508.

Plus that is what's here at this location.
 

Attachments

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Just going to do experiment with this.

Call it good.

My colleague and I have probably read lesson easy 10 times over.

Going to move on to Lesson 2.

Make a fresh start.
 

OBW0549

Joined Mar 2, 2015
3,566
I hate to point out something that ought to be blatantly obvious, but did you remember to edit these two source code lines:

list p=12F508
#include <p12F508.inc>

to reflect the fact that you're using a PIC12F509 instead of a PIC12F508?
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Thank you OBW

No. Plus I'm using 12F509 not 12F508.

It has been bothering me thinking about that too.

Plus the end of memory is in different location.

One option is to wait and bring 10F200 and 12F508 over here.

Another option is plug main program into 12F509 template.
 

be80be

Joined Jul 5, 2008
2,072
It wouldn't mater the led blink code would work on both the chips 12f508 the hex would work on it as well as on the 12f509. Now if your code was bigger then you'd have a problem but that not going to happen with code that's on a chip with less ram.
 
Top