flat assembler
Message board for the users of flat assembler.

flat assembler > Non-x86 architectures > macro to code for PIC

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
edfed



Joined: 20 Feb 2006
Posts: 4209
Location: 2018
hello, do you think it is possible to use fasm and a macro include to code for PIC16f876 for example?

instructions are only 35, all on a fixed size, 14 bits.

it is because i try to code uswing MPLAB ide, and it is boring, it don't have the same syntax as fasm.

[edit]
the answer is YES, definitivelly YES!!
just look here:
http://board.flatassembler.net/topic.php?p=126261#126261

then, you can definitively kick the MPLAB compiler, and Horrible syntax.

_________________
Smile fool iem.design


Last edited by edfed on 02 Mar 2011, 12:51; edited 1 time in total
Post 15 Oct 2008, 12:07
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16782
Location: In your JS exploiting you and your system
Sure, it can probably be done with macros, although I haven't specifically looked into it, so maybe not also.

But even if it can be done I think the more important thought is what about all the debug info that you lose? The MPLAB debugger/simulator/ICE/assembler package is nicely complete. Something that a set of fasm macros could never hope to duplicate.

Also, perhaps you can consider creating fasmpic. Just take the fasmarm source code as the starting point and start coding. I would love to see another version of fasm done in this way.
Post 15 Oct 2008, 13:00
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4209
Location: 2018
good news, i finally writen my first pic x86 code at work.

a pulse generator, with t1 variable, T fixed or variable.. but i've got to fix some problems Wink

globally, i'm not satisfied by the poor risc way to go, but i've understand that W register is transparent in x86.
then, i've assigned the register file with x86 register names.
build some macroinstructions to have the standard x86 instructions, and coded in x86 way.

it's is limited because for the moment i'm forced to use the POOR MPWINASM syntax.

i use ICPROG to program the pic with JDM on COM1. Very Happy

but now, i want to use fasmw to generate the .HEX file from the code using the macroinstruction engine of fasm.

then, it will be possible to see the pic as a customised slow X86 computer.

the great thing is that ICPROG use .HEX files.
it's not .bin, it's an hexadecimal text. representing the memory locations of the code in rom.
..
how to say to fasm that the code below is not for x86, then, not to interpret as binary compilation, but build an ascii hexadecimal representation.

it looks like impossible.


pic16f.inc
Code:
; global equate/macro/include system for all pic16f family
; this file would contain a lot of things, including theses:
compile as .hex

al=20h
ah=21h
bl=22h
bh=23h
cl=24h
ch=25h
dl=26h
dh=27h
el=28h
eh=29h
fl=2ah
fh=2bh
gl=2ch
gh=2dh
hl=2eh
hh=2fh
; 16 general purpose 8 bits registers, wawWWW!
macro   mov op1,op2
        {
        movf op2,0
        movwf  op1
        }
macro   inc op1
        {
        incf op1,1
        movf op1
        }
macro   jmp op1
        {
        goto op1
        }
macro   add op1,op2
        {
        movf op2
        addfw op1,0
        }

macro   jne op1
        {
        btfss STATUS,Z
        jmp op1
        }
...
..
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    



test.asm
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
include 'pic16f.inc'
org 0
        movlw 10
        movwf al
        jmp start
        org 4
        jmp irq
start:
        add al,bl
@@:
        inc al
        bsf PORTA,0
        jne @b
        bcf PORTA,0
        inc bl
        bcf PORTA,1
        jne @b
        bcf PORTA,1
        jmp start
    
Post 30 Oct 2008, 21:28
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
i have not programming ARM and PIC, but 8080 and 8049. 8049 i've been programming with SBASM, while for 8080 i've wrote macros, but think they are not safe, as they replace some x86 instructions, but do not protect against occasional usage of some wrong combinations or x86 instructions, which stay intouched.
also, it is interesting, how to write macro for instruction, which uses # in parameter, like this:
Code:
                ADD     A,#$12    

- is such thing present in fasmarm? i'll make look in there!
Post 31 Oct 2008, 06:10
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4209
Location: 2018
Quote:
also, it is interesting, how to write macro for instruction, which uses # in parameter, like this:
Code:
                ADD     A,#$12    

- is such thing present in fasmarm? i'll make look in there!


it is not a pb as i plan to use the same syntax as fasm, then, no #, no $ nothing like mplab syntax.

i just need to learn fasm macroinstructions and then, create the macro to have x86 instructions PIC compiled using fasm.

_________________
Smile fool iem.design
Post 31 Oct 2008, 07:28
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
in this case yes, but if you plan to use existing source or share own - then pb will appear Wink
in 8080 macros i have used parameters directly, while # is special symbol - i have not study fasm macro language too deep yet. Smile
8080 assembler is very easy to implement with macros - mnemonic says exactly what parameters are (unlike x86 or say z80). in other case it is necesary to parse parameters to know their type to choose valid opcode.

++++++++++++++
i see this instruction in fasmarm readme - maybe it will help to do the same:
Code:
eor r0,r5,#0xfffffffc    


Last edited by shoorick on 31 Oct 2008, 08:01; edited 1 time in total
Post 31 Oct 2008, 07:47
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16782
Location: In your JS exploiting you and your system
shoorick wrote:
Code:
                ADD     A,#$12    

- is such thing present in fasmarm? i'll make look in there!
No. I eliminated all the unnecessary hashes. Immediate values can be identified by the fact that they start with a number. No hash required. Hashes were used in the past when compilers were a lot less smart (or maybe the writers were just a bit lazy?) so the programmer had to use a hash to tell the compiler that following is an immediate value.
Post 31 Oct 2008, 07:50
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
already see....
maybe you're right. it's not hard to replace all "#$" with "$". i just though about compatibility with existing sources. but do i need to think hard about this compatibility if i have about 5 of these 8035/48/49, and then do i realy need to think about writing macro Very Happy maybe SBASM will be enough to make 30-bytes binary Very Happy

regards!
Post 31 Oct 2008, 08:07
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4209
Location: 2018
it's not hard to replace #$ by nothing.
just see the fasm syntax, the C syntax, the french syntax, etc etc ..

one interresting question is:
why some assembler wants #$ before a number?
note that a number always start with a number, then, who had this fool idea?
maybe someone that found so simple ( not very serious if you are a brainfuckin scientist) to use it, and invented a strange thing like #$

but recenter the discution now.
the problem is not to use existing code for pic without modifications, but to use my dear x86 syntax, using conditional macroinstructions to generate the good hexadecimal string.

today, i've implemented:
Code:
cli
sti
iret
ret
jmp
    

and as i don't use fasm to compile for now, i use the poor mpasm syntax.
then, as i don't know if there is a conditional macro and totally don't care, i invented poor mnemonics:
Code:
movr ; do it register to register
andr
addr
subr
orr
;and will try to invent 
retp ; return with parameter
; because it don't exists in x86, but can be found if for example you write
mov eax,parameter
ret
    


i insist, the goal is not to be compatible with existing source, all have to be re-writen.
my favourite game is to reinvent the weel everydays in a new way Very Happy
Post 31 Oct 2008, 15:56
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16782
Location: In your JS exploiting you and your system
edfed wrote:
my favourite game is to reinvent the weel everydays in a new way
But the major problem with reinventing the wheel is to decide what colour it should be.
Post 31 Oct 2008, 16:10
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4209
Location: 2018
another interresting feature of fasm & picmacro:
instead of editng asm file with mplabide and compile with mpasmwin, only one program is needed to do both. fasmw.
please note that fasmw.exe is only 9 letters but mplabide.exe + mpasmwin.exe are together 24 letters, then, fasm use less memory than mpxxxxxxx.exe family. Laughing

f9 or ctrl+f9 compile ( cannot execute?)

compile as a .HEX file.
can be done by hand, but i prefer to use fasm.
Post 03 Nov 2008, 17:19
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4209
Location: 2018
finally, i tried just to generate binary words using macros.

and finally, hxd can convert in .HEX 16 file to go under icprog.

i transfered OK a first test code. but the led connected to GPIO5 don't turn on...
then, i should work a little more on the code to obtain my first blinking led, coded and compiled with fasmw, converted with hxd (for the moment) and transfered with icprog... not an easy way, but if it can give good results, it will be very cool.

Code:
;PIC 12F675 instruction set
;
;ADDWF   f, d    Add W and f                     1       00 0111 dfff ffff  C,DC,Z
;ANDWF   f, d    AND W with f                    1       00 0101 dfff ffff  Z
;CLRF    f       Clear f                         1       00 0001 1fff ffff  Z
;CLRW    -       Clear W                         1       00 0001 0xxx xxxx  Z
;COMF    f, d    Complement f                    1       00 1001 dfff ffff  Z
;DECF    f, d    Decrement f                     1       00 0011 dfff ffff  Z
;DECFSZ  f, d    Decrement f, Skip if 0          1(2)    00 1011 dfff ffff
;INCF    f, d    Increment f                     1       00 1010 dfff ffff  Z
;INCFSZ  f, d    Increment f, Skip if 0          1(2)    00 1111 dfff ffff
;IORWF   f, d    Inclusive OR W with f           1       00 0100 dfff ffff  Z
;MOVF    f, d    Move f                          1       00 1000 dfff ffff  Z
;MOVWF   f       Move W to f                     1       00 0000 1fff ffff
;NOP     -       No Operation                    1       00 0000 0xx0 0000
;RLF     f, d    Rotate Left f through Carry     1       00 1101 dfff ffff  C
;RRF     f, d    Rotate Right f through Carry    1       00 1100 dfff ffff  C
;SUBWF   f, d    Subtract W from f               1       00 0010 dfff ffff  C,DC,Z
;SWAPF   f, d    Swap nibbles in f               1       00 1110 dfff ffff
;XORWF   f, d    Exclusive OR W with f           1       00 0110 dfff ffff  Z
;
;
;BCF     f, b    Bit Clear f                     1       01 00bb bfff ffff
;BSF     f, b    Bit Set f                       1       01 01bb bfff ffff
;BTFSC   f, b    Bit Test f, Skip if Clear       1 (2)   01 10bb bfff ffff
;BTFSS   f, b    Bit Test f, Skip if Set         1 (2)   01 11bb bfff ffff
;
;
;ADDLW   k       Add literal and W               1       11 111x kkkk kkkk  C,DC,Z
;ANDLW   k       AND literal with W              1       11 1001 kkkk kkkk  Z
;CALL    a       Call subroutine                 2       10 0aaa aaaa aaaa
;CLRWDT  -       Clear Watchdog Timer            1       00 0000 0110 0100  TO,PD
;GOTO    a       Go to address                   2       10 1aaa aaaa aaaa
;IORLW   k       Inclusive OR literal with W     1       11 1000 kkkk kkkk  Z
;MOVLW   k       Move literal to W               1       11 00xx kkkk kkkk
;RETFIE  -       Return from interrupt           2       00 0000 0000 1001
;RETLW   k       Return with literal in W        2       11 01xx kkkk kkkk
;RETURN  -       Return from Subroutine          2       00 0000 0000 1000
;SLEEP   -       Go into Standby mode            1       00 0000 0110 0011  TO,PD
;SUBLW   k       Subtract W from literal         1       11 110x kkkk kkkk  C,DC,Z
;XORLW   k       Exclusive OR literal with W     1       11 1010 kkkk kkkk  Z
; f = register adress, 7 bits
; d = destination, 1=reg, 0=W, 1 bit
; b = bit adress, 3 bits
; k = immediate value, 8 bits
; a = code adress, 11 bits

REG=1
W=0

INDF1   equ 00h
TMR0    equ 01h
PCL     equ 02h
STATUS  equ 03h
.rp0    equ 5
.c      equ 0
.dc     equ 1
.z      equ 2
FSR     equ 04h
GPIO    equ 05h
.5      equ 5
.4      equ 4
.3      equ 3
.2      equ 2
.1      equ 1
.0      equ 0

PCLATH  equ 0ah
INTCON  equ 0bh
PIR1    equ 0ch
TMR1L   equ 0eh
TMR1H   equ 0fh
T1CON   equ 10h
CMCON   equ 19h
ADRESH3 equ 1eh
ADCON03 equ 1fh
al      equ 20h
ah      equ 21h
bl      equ 22h
bh      equ 23h
cl      equ 24h
ch      equ 25h
dl      equ 26h
dh      equ 27h

INDF1   equ 80h
OPTION  equ 81h
PCL     equ 82h
STATUS  equ 83h
FSR     equ 84h
TRISIO  equ 85h
.5      equ 5
.4      equ 4
.3      equ 3
.2      equ 2
.1      equ 1
.0      equ 0
.input  equ 1
.output equ 0
PCLATH  equ 8ah
INTCON  equ 8bh
PIE1    equ 8ch
PCON    equ 8eh
OSCCAL  equ 90h
WPU     equ 95h
IOC     equ 96h
VRCON   equ 99h
EEDATA  equ 9ah
EEADR   equ 9bh
EECON1  equ 9ch
EECON21 equ 9dh
ADRESL3 equ 9eh
ANSEL3  equ 9fh
al      equ 20h
ah      equ 21h
bl      equ 22h
bh      equ 23h
cl      equ 24h
ch      equ 25h
dl      equ 26h
dh      equ 27h



macro addwf f,d         {dw 0700h or (f and 07fh) or ((d and 1 )shl 7)}
macro andwf f,d         {dw 0500h or (f and 07fh) or ((d and 1 )shl 7)}
macro clrf f            {dw 0180h or (f and 07fh)}
macro clrw              {dw 0100h}
macro comf f,d          {dw 0900h or (f and 07fh) or ((d and 1 )shl 7)}
macro decf f,d          {dw 0300h or (f and 07fh) or ((d and 1 )shl 7)}
macro decfsz f,d        {dw 0b00h or (f and 07fh) or ((d and 1 )shl 7)}
macro incf f,d          {dw 0a00h or (f and 07fh) or ((d and 1 )shl 7)}
macro incfsz f,d        {dw 0f00h or (f and 07fh) or ((d and 1 )shl 7)}
macro iorwf f,d         {dw 0400h or (f and 07fh) or ((d and 1 )shl 7)}
macro movf f,d          {dw 0800h or (f and 07fh) or ((d and 1 )shl 7)}
macro movwf f           {dw 0080h or (f and 07fh)}
macro nop               {dw 0000h}
macro rlf f,d           {dw 0d00h or (f and 07fh) or ((d and 1 )shl 7)}
macro rrf f,d           {dw 0c00h or (f and 07fh) or ((d and 1 )shl 7)}
macro subwf f,d         {dw 0200h or (f and 07fh) or ((d and 1 )shl 7)}
macro swapf f,d         {dw 0e00h or (f and 07fh) or ((d and 1 )shl 7)}
macro xorwf f,d         {dw 0600h or (f and 07fh) or ((d and 1 )shl 7)}
macro bcf f,b           {dw 1000h or (f and 07fh) or ((b and 7 )shl 7)}
macro bsf f,b           {dw 1400h or (f and 07fh) or ((b and 7 )shl 7)}
macro btfsc f,b         {dw 1800h or (f and 07fh) or ((b and 7 )shl 7)}
macro btfss f,b         {dw 1c00h or (f and 07fh) or ((b and 7 )shl 7)}
macro addlw k           {dw 3e00h or (k and 0ffh)}
macro andlw k           {dw 3900h or (k and 0ffh)}
macro call a            {dw 2000h or (a and 7ffh)}
macro clrwdt            {dw 0064h}
macro goto a            {dw 2800h or (a and 7FFh)}
macro iorlw k           {dw 3800h or (k and 0ffh)}
macro movlw k           {dw 3000h or (k and 0ffh)}
macro retfie            {dw 0009h}
macro retlw k           {dw 3400h or (k and 0ffh)}
macro return            {dw 0008h}
macro sleep             {dw 0063h}
macro sublw k           {dw 3c00h or (k and 0ffh)}
macro xorlw k           {dw 3a00h or (k and 0ffh)}


        org 0
boot:
        goto @f
        nop
        nop
        nop
        org 4
interrupt:
        retfie
@@:
        bsf STATUS,5
        movlw 7
        movf TRISIO,REG
        bcf STATUS,5
        movlw 0
mainloop:
        bsf GPIO,5
        addlw 1
        btfss STATUS,2
        goto mainloop
        bcf GPIO,5
@@:
        addlw 1
        btfss STATUS,2
        goto @b
        goto mainloop

    


here, i see it is very easy to build a fixed size opcode ith fasm macro. Very Happy

but i don't have the blinking led for now, then....
Post 20 Feb 2011, 01:05
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4209
Location: 2018
good news, but as i read the full post, it appears that only one post will be usefull here, the current one and next.
then, i think it will be the time to open a new post.

i compiled a source code from the disassembly of a demo i found on internet.
it makes blink a led on pin 0 of GPIO (portA) of a 12F675.

i compared original binary with my compiled binary, and apparenttly, no problem, the compilation gives exactlly the same result.

then, the parser macro itself is OK.

Code:
format binary as 'pic'
;PIC 12F675 instruction set
;
;ADDWF   f, d    Add W and f                     1       00 0111 dfff ffff  C,DC,Z
;ANDWF   f, d    AND W with f                    1       00 0101 dfff ffff  Z
;CLRF    f       Clear f                         1       00 0001 1fff ffff  Z
;CLRW    -       Clear W                         1       00 0001 0xxx xxxx  Z
;COMF    f, d    Complement f                    1       00 1001 dfff ffff  Z
;DECF    f, d    Decrement f                     1       00 0011 dfff ffff  Z
;DECFSZ  f, d    Decrement f, Skip if 0          1(2)    00 1011 dfff ffff
;INCF    f, d    Increment f                     1       00 1010 dfff ffff  Z
;INCFSZ  f, d    Increment f, Skip if 0          1(2)    00 1111 dfff ffff
;IORWF   f, d    Inclusive OR W with f           1       00 0100 dfff ffff  Z
;MOVF    f, d    Move f                          1       00 1000 dfff ffff  Z
;MOVWF   f       Move W to f                     1       00 0000 1fff ffff
;NOP     -       No Operation                    1       00 0000 0xx0 0000
;RLF     f, d    Rotate Left f through Carry     1       00 1101 dfff ffff  C
;RRF     f, d    Rotate Right f through Carry    1       00 1100 dfff ffff  C
;SUBWF   f, d    Subtract W from f               1       00 0010 dfff ffff  C,DC,Z
;SWAPF   f, d    Swap nibbles in f               1       00 1110 dfff ffff
;XORWF   f, d    Exclusive OR W with f           1       00 0110 dfff ffff  Z
;
;
;BCF     f, b    Bit Clear f                     1       01 00bb bfff ffff
;BSF     f, b    Bit Set f                       1       01 01bb bfff ffff
;BTFSC   f, b    Bit Test f, Skip if Clear       1 (2)   01 10bb bfff ffff
;BTFSS   f, b    Bit Test f, Skip if Set         1 (2)   01 11bb bfff ffff
;
;
;ADDLW   k       Add literal and W               1       11 111x kkkk kkkk  C,DC,Z
;ANDLW   k       AND literal with W              1       11 1001 kkkk kkkk  Z
;CALL    a       Call subroutine                 2       10 0aaa aaaa aaaa
;CLRWDT  -       Clear Watchdog Timer            1       00 0000 0110 0100  TO,PD
;GOTO    a       Go to address                   2       10 1aaa aaaa aaaa
;IORLW   k       Inclusive OR literal with W     1       11 1000 kkkk kkkk  Z
;MOVLW   k       Move literal to W               1       11 00xx kkkk kkkk
;RETFIE  -       Return from interrupt           2       00 0000 0000 1001
;RETLW   k       Return with literal in W        2       11 01xx kkkk kkkk
;RETURN  -       Return from Subroutine          2       00 0000 0000 1000
;SLEEP   -       Go into Standby mode            1       00 0000 0110 0011  TO,PD
;SUBLW   k       Subtract W from literal         1       11 110x kkkk kkkk  C,DC,Z
;XORLW   k       Exclusive OR literal with W     1       11 1010 kkkk kkkk  Z
; f = register adress, 7 bits
; d = destination, 1=reg, 0=W, 1 bit
; b = bit adress, 3 bits
; k = immediate value, 8 bits
; a = code adress, 11 bits

REG=1
W=0

INDF1   equ 00h
TMR0    equ 01h
PCL     equ 02h
STATUS  equ 03h
rp0     equ 5
c       equ 0
dc      equ 1
z       equ 2
FSR     equ 04h
GPIO    equ 05h

PCLATH  equ 0ah
INTCON  equ 0bh
PIR1    equ 0ch
TMR1L   equ 0eh
TMR1H   equ 0fh
T1CON   equ 10h
CMCON   equ 19h
ADRESH3 equ 1eh
ADCON03 equ 1fh
al      equ 20h
ah      equ 21h
bl      equ 22h
bh      equ 23h
cl      equ 24h
ch      equ 25h
dl      equ 26h
dh      equ 27h

INDF1   equ 80h
OPTION  equ 81h
PCL     equ 82h
STATUS  equ 83h
FSR     equ 84h
TRISIO  equ 85h
input   equ 1
output  equ 0
PCLATH  equ 8ah
INTCON  equ 8bh
PIE1    equ 8ch
PCON    equ 8eh
OSCCAL  equ 90h
WPU     equ 95h
IOC     equ 96h
VRCON   equ 99h
EEDATA  equ 9ah
EEADR   equ 9bh
EECON1  equ 9ch
EECON21 equ 9dh
ADRESL3 equ 9eh
ANSEL3  equ 9fh
al      equ 20h
ah      equ 21h
bl      equ 22h
bh      equ 23h
cl      equ 24h
ch      equ 25h
dl      equ 26h
dh      equ 27h


macro dw value          {db (((value and 03f00h ) shr 8) and 0ffh),(value and 0ffh)}
macro addwf f,d         {dw 0700h or (f and 07fh) or ((d and 1 )shl 7)}
macro andwf f,d         {dw 0500h or (f and 07fh) or ((d and 1 )shl 7)}
macro clrf f            {dw 0180h or (f and 07fh)}
macro clrw              {dw 0100h}
macro comf f,d          {dw 0900h or (f and 07fh) or ((d and 1 )shl 7)}
macro decf f,d          {dw 0300h or (f and 07fh) or ((d and 1 )shl 7)}
macro decfsz f,d        {dw 0b00h or (f and 07fh) or ((d and 1 )shl 7)}
macro incf f,d          {dw 0a00h or (f and 07fh) or ((d and 1 )shl 7)}
macro incfsz f,d        {dw 0f00h or (f and 07fh) or ((d and 1 )shl 7)}
macro iorwf f,d         {dw 0400h or (f and 07fh) or ((d and 1 )shl 7)}
macro movf f,d          {dw 0800h or (f and 07fh) or ((d and 1 )shl 7)}
macro movwf f           {dw 0080h or (f and 07fh)}
macro nop               {dw 0000h}
macro rlf f,d           {dw 0d00h or (f and 07fh) or ((d and 1 )shl 7)}
macro rrf f,d           {dw 0c00h or (f and 07fh) or ((d and 1 )shl 7)}
macro subwf f,d         {dw 0200h or (f and 07fh) or ((d and 1 )shl 7)}
macro swapf f,d         {dw 0e00h or (f and 07fh) or ((d and 1 )shl 7)}
macro xorwf f,d         {dw 0600h or (f and 07fh) or ((d and 1 )shl 7)}
macro bcf f,b           {dw 1000h or (f and 07fh) or ((b and 7 )shl 7)}
macro bsf f,b           {dw 1400h or (f and 07fh) or ((b and 7 )shl 7)}
macro btfsc f,b         {dw 1800h or (f and 07fh) or ((b and 7 )shl 7)}
macro btfss f,b         {dw 1c00h or (f and 07fh) or ((b and 7 )shl 7)}
macro addlw k           {dw 3e00h or (k and 0ffh)}
macro andlw k           {dw 3900h or (k and 0ffh)}
macro call a            {dw 2000h or ((a/2) and 7ffh)}
macro clrwdt            {dw 0064h}
macro goto a            {dw 2800h or ((a/2) and 7FFh)}
macro iorlw k           {dw 3800h or (k and 0ffh)}
macro movlw k           {dw 3000h or (k and 0ffh)}
macro retfie            {dw 0009h}
macro retlw k           {dw 3400h or (k and 0ffh)}
macro return            {dw 0008h}
macro sleep             {dw 0063h}
macro sublw k           {dw 3c00h or (k and 0ffh)}
macro xorlw k           {dw 3a00h or (k and 0ffh)}
macro null              {dw 3fffh}
    


and lets compile this file, working on real hardware.
Code:
include 'p12fxx.inc'
start:
        goto @f
        null
        null
        null
@@:
        movlw 0ffh
        movwf 21h
        movlw 0ffh
        movwf 22h
        bcf 21h,0
        call initGP.2
@@:
        movlw 5
        call @f
        bsf 23h,0
        call initGP.1
        movlw 5
        call @f
        bcf 23h,0
        call initGP.1
        goto @b
        goto $
@@:
        movwf 24h
        movf  24h,W
        movwf 25h
        movlw 64h
        movwf 26h
        movlw 0Ah
        goto @f
@@:
        movwf 27h
        movlw 7Fh
        movwf 28h
mainloop:
        movf 26h,W
        movwf 2Ah
.1:
        movf 25h,W
        movwf 29h
.2:
        movlw 17h
.3:
        addwf 28h,W
        btfsc STATUS,c
        goto .3
        decfsz 29h,REG
        goto .2
        decfsz 2Ah,REG
        goto .1
        decfsz 27h,REG
        goto mainloop
        return
initGP:
.1:
        goto @f
@@:
        movf 23h,W
        movwf GPIO ;PORTA
        return
.2:
        goto @f
@@:
        movf 21h,W
        dw 65h  ;TRIS PORTA
        return
    

i just can't find the exact mnemonic for 65h opcode, assumed to be TRIS PORTA, but i don't find the reference in pic datasheet...

just for the fun, i tested to increase the speed of the blink, and it works, the led blinktwice faster after changing just a single value in the code, then, yeah, i am very happy!!!

the original file was disassembled with icprog, maybe it is a 16F84 specific instruction, and undocumented in later MCU.

the method to flash the PIC is simple, but a little boring:

open binary file with hxd
copy the hexadecimal field
paste it in a icprog buffer
set fuses and oscillator calibration value
flash device using RCD programmer as JDM device
and it is ok.

but the goal is to have:
1: compile
2: flash device

directlly from fasm menu.
this goal tend to be very hard to do for me, then, i will just consider this next todo list for the moment:

1: .HEX conversion

2: sections creation, because pic files needs to contain the content of every memory zones.
program eeprom, data eeprom, fuses, and oscillator calibration value.

3: the complete set of labels about the target MCU.

4: and later, X86 based macro instruction, to code with our dear old X86 mnemonics.
Post 22 Feb 2011, 15:17
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
there is the ready hex2bin convertor (converts in both directions) - search inet.

will you continue with x51 and AVR? Wink
Post 22 Feb 2011, 16:43
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4209
Location: 2018
found a solution, just load file as .bin under icprog, it is possible, reverse byte order or not (depend on the macro dw used for that Very Happy)

i've also found a way to know instruction set as recognised by icprog

it appears that there are 2 undocumented instructions

macro option {dw 0062h}
macro tris reg {dw 0060h and reg} ;reg=1,5,6 or 7
microchip says to don't use these instruction to be compatible with future products... but who cares? if it works on you target, use them because it will save you 2 instructions (bank switch forward and back). i tested tris GPIO with succes on 12F675.

and there are 4 nop in total
opcodes 0, 20h, 40h and 60h

apparently, the instruction set of all pic 14 bits is the same.
then, the include file is named now pic14.inc



for other MCU/CPU, i have a SEGA megadrive (68000+Z80), some 6809, and other things.
for the programming, i also need to do a parallel eprom programer (27C512, etc...).
i son't know what MCU to use, i still need to do something with PIC before to think about programming other device. i am curious to program for ARM, X51 or any assembler based component.


Last edited by edfed on 02 Mar 2011, 12:54; edited 1 time in total
Post 23 Feb 2011, 00:51
View user's profile Send private message Visit poster's website Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Great work edfed, it would be great to use fasm for PIC, let me know if you have a basic board layout and i build one and help you test and debug.
I would like to code a DexOS port.
Post 23 Feb 2011, 01:47
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
edfed wrote:
i also need to do a parallel eprom programer (27C512, etc...).

if you do not have a lot of UV EPROMs, i would suggest you to make adaptor to use flash instead of them to not boring yourself with erasing, like on the picture below (it is 32 pin adapter, but you will need 28 pin, unused address pins of plcc socket connect to the ground).

also, flash programming is a bit easier then UV EPROMs, as flash has internal timing.

_________________
UNICODE forever!


Last edited by shoorick on 31 Jan 2016, 19:59; edited 1 time in total
Post 23 Feb 2011, 05:53
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4209
Location: 2018
i have mainly uvproms, but i think they will become components for some artwork, because it is a little obsolete.

i have some flash proms from PC mother boards, then, it is the best compromise if i want to do some advanced things like disasm a BIOS ROM... flash it...things like that.


about the pic14bit.zip file, it can be found here:
http://fool.codercat.org/pic14bit.zip
this file is huge, then i cannot put it here.
there is a program to draw PCB inside (sprint layout), with the icsp file at "sprint/macro/interface.icsp.lay'

maybe it will be interresting to present the project as plain html file, with illustrations and downloads links.


Last edited by edfed on 25 Sep 2011, 21:34; edited 1 time in total
Post 23 Feb 2011, 16:24
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4209
Location: 2018
today, just tested to make some better led management and code cleaning...
apparentlly, the code generated by HLL for pic is... say nothing it is better:

then, lets go for the last code:

Code:
include 'pic14.inc'
start:
        goto @f
        nop
        nop
        nop
@@:
        movlw 0ffh ;set all bits to 1
        movwf 21h
        movlw 0ffh ;what for? i don't know
        movwf 22h ; but can save 2 instrucitons
        bcf 21h,0 ;clear bits corresponding to the pin to use as outputs
        bcf 21h,4
        bcf 21h,5
        movf 21h,W 
        tris GPIO ;give it to GPIO controler, tris is undocumented, but i think is equivalent to movf TRISIO in bank 1, without the need to switch a bank

@@:
        movlw 1
        call delay
        bsf 23h,0  ;white led ON
        call GP.out
        movlw 1
        call delay
        bcf 23h,0 ;white led OFF
        call GP.out
        movlw 1
        call delay
        bsf 23h,4 ;green led ON
        call GP.out
        movlw 1
        call delay
        bcf 23h,4 ;green led OFF
        bsf 23h,5 ;red led ON
        call GP.out
        movlw 1
        call delay
        bcf 23h,5 ;red led OFF
        call GP.out
        goto @b

        goto $ ;is that needed? can save 1 word if deleted

GP:
.out:
        movf 23h,W ;load reg 23h in W
        movwf GPIO ;then, store it in GPIO 
        return

delay:
        movwf 2Ah ;load reg 2Ah with delay in W
.1:
        clrf 29h ;reg 29h = 0 then, 256 times
.2:
        clrf 28h ;idem reg 28h
.3:
        decfsz 28h,REG ;count 256 times
        goto .3
        decfsz 29h,REG ;count 256 times
        goto .2
        decfsz 2Ah,REG ;count delay times
        goto .1
        return
    


compiles in 98 bytes, then, 49 instructions, blink 3 leds.

@@:
white led only on GP0 during one time ;GP0
blank during one time (dead time)
green led only one time ;GP4
red led only one time ;GP5
blank one time
goto @b

the valid configuration is obtained by hand in icprog, and a save as gives this file:


Description: change extension to .HEX
use calibration value from file 0000h

Download
Filename: blinkled.txt
Filesize: 6.39 KB
Downloaded: 478 Time(s)


_________________
Smile fool iem.design


Last edited by edfed on 24 Feb 2011, 16:39; edited 1 time in total
Post 24 Feb 2011, 15:41
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4209
Location: 2018
just for the fun, compiles in less than 70 bytes, 35 instructions, 2 macros
and use x86 register names for the delay routine.

Code:
include 'pic14.inc'
macro timer d {movlw d
               call delay}
macro gpout o {movlw o
               movwf GPIO}
start:
        movlw 1100'1110b
        tris GPIO
        goto @f
        align 8
@@:
        timer 255
        gpout 0000'0001b
        timer 255
        gpout 0000'0000b
        timer 255
        gpout 0001'0000b
        timer 255
        gpout 0010'0000b
        timer 255
        gpout 0000'0000b
        goto @b

delay:
        movwf al
.1:
        clrf ah
.2:
        decfsz ah,REG
        goto .2
        decfsz al,REG
        goto .1
        return
    


it is the return of asm size optimisation.

next to do, provide a complete file for the icprog program, with fuses data eeprom and oscal values.

next next:
use timer, watchdog, ADC, pwm, interrupts... etc.
and drive 40 leds with just 5 pins ((N*N-N)*2)

and implement fool8 in data eeprom.

note:
i've made an error, option is not 0063h but 0062h.
Post 24 Feb 2011, 16:34
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
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
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.