Ver Mensaje Individual
  #1  
Antiguo 19-03-2008
Avatar de MaMu
MaMu MaMu is offline
Miembro
 
Registrado: abr 2006
Ubicación: Argentina
Posts: 863
Reputación: 19
MaMu Va por buen camino
uC PICs - Migrando de ASM a PASCAL

Estoy retocando las librerias de PICs, y estoy migrando el set de instrucciones a procedimientos en Pascal, para implementarlo en un IDE que quiero hacer en Delphi, para programar los pics en Pascal, incluyendo la parte de programación al uC desde la PC, la cual hare por puerto Serie (utilizando Driver para XP) para el programador JDM. (pueden buscar documentación del mismo en internet, es muy sencillo de construir).

Estoy empezando por la librería de 16F628A (que tengo muchos!!! jeje)
Asi que acá les voy dejando una reseña de lo que ya hay para que vayan viendo y el que se anime, aporte lo suyo.

Código Delphi [-]
unit system;
interface
DeviceDescriptor
   DeviceFamily  PIC14;
   ProgMemSize 2048;
   EEPROMDataMemSize 128;
   DataMemSpaces
      $1:$20:$50; $2:$20:$50; $4:$38:$18;
   ConfigWordOptions
      bod_on          : $3FFF;     bod_off   : $3FBF;
      cp_all          : $03FF;     cp_75     : $17FF;
      cp_50           : $2BFF;     cp_off    : $3FFF;
      pwrte_off       : $3FFF;     pwrte_on  : $3FF7;
      wdt_on          : $3FFF;     wdt_off   : $3FFB;
      lvp_on          : $3FFF;     lvp_off   : $3F7F;
      mclre_on        : $3FFF;     mclre_off : $3FDF;
      er_osc_clkout   : $3FFF;     er_osc_noclkout    : $3FFE;
      intrc_osc_clkout: $3FFD;     intrc_osc_noclkout : $3FFC;
      extclk_osc      : $3FEF;     lp_osc    : $3FEC;
      xt_osc          : $3FED;     hs_osc    : $3FEE;
End;

type byte = TDataMemoryWord;
//          = Bits(bit0,bit1,bit2,bit3,bit4,bit5,bit6,bit7);
var SysTempMem    : array[0..$B] of byte absolute $F:$70;
    SysSWStackTop : byte absolute $F:$7C;
    SysWTemp      : byte absolute $F:$7D;
    SysStatusTemp : byte absolute $F:$7E;
    SysFSRTemp    : byte absolute $F:$7F;
    indf       : byte absolute $F:$00;
    tmr0       : byte absolute $5:$01;
    option     : byte = Bits(PS0,PS1,PS2,PSA,T0SE,T0CS,INTEDG,RBPU) absolute $A:$01;
    pcl        : byte absolute $F:$02;
    status     : byte = Bits(C,DC,Z,PD,TOB,RP0,RP1,IRP) absolute $F:$03;
    fsr        : byte absolute $F:$04;
    pclath     : byte absolute $F:$0A;
    intcon     : byte absolute $F:$0B;
    porta      : byte absolute $1:$05;
    trisa      : byte absolute $2:$05;
    portb      : byte absolute $5:$06;
    trisb      : byte absolute $A:$06;
    pir1       : byte absolute $1:$0C;
    tmr1l      : byte absolute $1:$0E;
    tmr1h      : byte absolute $1:$0F;
    t1con      : byte absolute $1:$10;
    tmr2       : byte absolute $1:$11;
    t2con      : byte absolute $1:$12;
    ccpr1l     : byte absolute $1:$15;
    ccpr1h     : byte absolute $1:$16;
    ccp1con    : byte absolute $1:$17;
    rcsta      : byte absolute $1:$18;
    txreg      : byte absolute $1:$19;
    rcreg      : byte absolute $1:$1A;
    cmcon      : byte absolute $1:$1F;
    pie1       : byte absolute $2:$0C;
    pcon       : byte absolute $2:$0E;
    pr2        : byte absolute $2:$12;
    txsta      : byte absolute $2:$19;
    spbrg      : byte absolute $2:$1A;
    eedata     : byte absolute $2:$1A;
    eeadr      : byte absolute $2:$1B;
    eecon1     : byte absolute $2:$1C;
    eecon2     : byte absolute $2:$1D;
    vrcon      : byte absolute $2:$1F;
    Procedure BitSet(freg,bitnum:byte);macrolike;
    Procedure BitClear(freg,bitnum:byte);macrolike;
    Procedure RLeft(freg:byte);macrolike;
    Procedure RRight(freg:byte);macrolike;
    Procedure Change(a,b:byte);macrolike;
    Procedure Inc(freg:byte);macrolike;
    Procedure Dec(freg:byte);macrolike;
    Procedure SwapF(freg:byte);macrolike;
    Procedure Exit;macrolike;
    procedure Push;
    procedure Pop;
implementation
Procedure BitSet(freg,bitnum:byte);macrolike;
asm
    bsf    freg,bitnum
end;
Procedure BitClear(freg,bitnum:byte);macrolike;
asm
    bcf    freg,bitnum
end;
Procedure RLeft(freg:byte);macrolike;
asm
    rlf    freg,f
end;
Procedure RRight(freg:byte);macrolike;
asm
   rrf     freg,f
end;
Procedure Inc(freg:byte);macrolike;
asm
   incf    freg,f
end;
Procedure Dec(freg:byte);macrolike;
asm
   decf    freg,f
end;
Procedure Change(a,b:byte);macrolike;
asm
   movf    a, w         //    a=a          b=b          w=a
   subwf   b, w         //    a=a          b=b          w=b-a
   subwf   b, f         //    a=a          b=b-(b-a)=a  w=b-a
   addwf   a, f         //    a=a+(b-a)=b  b=a
end;
Procedure SwapF(freg:byte);macrolike;
asm
   swapf   freg,f
end;
Procedure Exit;macrolike;
asm
   return
end;
Procedure PUSH;
asm
    bsf    status, IRP
    movwf  SysWTemp
    movf   SysSWStackTop, w
    movwf  FSR
    movf   SysWTemp, w
    movwf  INDF
    incf   SysSWStackTop, f
end;
Procedure POP;
asm
    bsf    status, IRP
    decf   SysSWStackTop, f
    movf   SysSWStackTop, w
    movwf  FSR
    movf   INDF, w
end;
Procedure BeginOfInterrupt;
asm
         movwf  SysWTemp
         swapf  STATUS,w
         movwf  SysStatusTemp
         movf   FSR,w
         movwf  SysFSRTemp
end;
Procedure EndOfInterrupt;
asm
         movf   SysFSRTemp,w
         movwf  FSR
         swapf  SysStatusTemp,w
         movwf  STATUS
         swapf  SysWTemp,f
         swapf  SysWTemp,w
         retfie
end;

Procedure Halt;
asm
HLT:     goto   HLT
end;
Begin
   asm
         nop                       ; ORG 0 - reset vector
         movlw  32
         movwf  SysSWStackTop      ; stack pointer initialization
         goto   start
         goto   BeginOfInterrupt   ; ORG 4 - interrupt vector
start:
   end;
End.

Lo que necesito hacer es una función booleana que me devuelba el estado de un bit de un registro, ya que seria ideal para leer una entrada por ejemplo.
Seria algo asi...

Código Delphi [-]
Function IsBitEnable(freg,bitnum:byte):boolean;macrolike;

Y se corresponderia a la función

Código Delphi [-]
asm
  btfsc   freg, bitnum    ; salta si es 0
  goto    falso
  goto    verdadero
end;

Si a alguien se le ocurre algo, acepto críticas, sugerencias, etc.

Saludos
__________________
Código Delphi [-]
 
try 
ProgramarMicro(80C52,'Intel',MnHex,True);
except
On Exception do
MicroChip.IsPresent(True);
end;
Responder Con Cita