Advertisement
AlienTux

Ejemplo PIC-AS en MPLABX

Mar 17th, 2021
2,868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MPASM 4.76 KB | None | 0 0
  1. ;-------------------------------------------------------------------------------
  2. ;
  3. ;  Archivo:   main.s
  4. ;  Fecha de creación/modificación: 08 Febrero 2021
  5. ;  Author: Kurt Kellner
  6. ;  Dispositivo: PIC16F887
  7. ;  Descripción: (Qué hace el programa)
  8. ;  Hardware: (Explicar qué está conectado en dónde)
  9. ;
  10. ;-------------------------------------------------------------------------------
  11.  
  12. ;-------------------------------------------------------------------------------
  13. ; Librerías incluidas
  14. ;-------------------------------------------------------------------------------
  15.  
  16. PROCESSOR 16F887
  17. #include <xc.inc>
  18. #include "test.s"
  19.  
  20. ;-------------------------------------------------------------------------------
  21. ; Palabras de configuración
  22. ;-------------------------------------------------------------------------------
  23.  
  24. ; CONFIG1
  25.   CONFIG  FOSC = XT             ; Oscillator Selection bits (XT oscillator: Crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
  26.   CONFIG  WDTE = OFF            ; Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
  27.   CONFIG  PWRTE = OFF           ; Power-up Timer Enable bit (PWRT disabled)
  28.   CONFIG  MCLRE = OFF           ; RE3/MCLR pin function select bit (RE3/MCLR pin function is digital input, MCLR internally tied to VDD)
  29.   CONFIG  CP = OFF              ; Code Protection bit (Program memory code protection is disabled)
  30.   CONFIG  CPD = OFF             ; Data Code Protection bit (Data memory code protection is disabled)
  31.   CONFIG  BOREN = OFF           ; Brown Out Reset Selection bits (BOR disabled)
  32.   CONFIG  IESO = OFF            ; Internal External Switchover bit (Internal/External Switchover mode is disabled)
  33.   CONFIG  FCMEN = OFF           ; Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
  34.   CONFIG  LVP = OFF             ; Low Voltage Programming Enable bit (RB3 pin has digital I/O, HV on MCLR must be used for programming)
  35.  
  36. ; CONFIG2
  37.   CONFIG  BOR4V = BOR40V        ; Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)
  38.   CONFIG  WRT = OFF             ; Flash Program Memory Self Write Enable bits (Write protection off)
  39.  
  40.  
  41. ;-------------------------------------------------------------------------------
  42. ; Macros
  43. ;-------------------------------------------------------------------------------
  44.  
  45. bank0 MACRO
  46.     bcf STATUS, 5
  47.     bcf STATUS, 6
  48.     endm
  49.  
  50. bank1 macro
  51.     bsf STATUS, 5
  52.     bcf STATUS, 6
  53.     endm
  54.  
  55. bank2 macro
  56.     bcf STATUS, 5
  57.     bsf STATUS, 6
  58.     endm
  59.  
  60. bank3 macro
  61.     bsf STATUS, 5
  62.     bsf STATUS, 6
  63.     endm
  64.  
  65. input macro arg1, arg2
  66.     bank1
  67.     bsf arg1, arg2
  68.     bank0
  69.     endm
  70.  
  71. output macro arg1, arg2
  72.     bank1
  73.     bcf arg1, arg2
  74.     bank0
  75.     endm
  76.  
  77.  
  78. ;-------------------------------------------------------------------------------
  79. ; Variables
  80. ;-------------------------------------------------------------------------------
  81.  
  82. PSECT udata_shr ; variables en memoria RAM compartida entre bancos
  83.  
  84. var1:
  85.     DS 1 ; Variable var1 con 1 localidad reservada en RAM
  86.  
  87. var2:
  88.     DS 2 ; Variable var2 con 2 localidades reservadas en RAM
  89.  
  90. PSECT udata ; variables en cualquier localidad de la memoria RAM
  91.         ; con la excepción de los espacios compartidos (unbanked memory)
  92.  
  93. var3:
  94.     DS 1
  95.  
  96. DABS 1, 0x040, 1, var5
  97.  
  98. var6:
  99.     DB  0xA4
  100.  
  101. PSECT udata_bank3 ; variables en memoria RAM en el banco 3
  102.  
  103. var4:
  104.     DS 1
  105.  
  106.  
  107. ;-------------------------------------------------------------------------------
  108. ; Vector de Reset
  109. ;-------------------------------------------------------------------------------
  110.  
  111. PSECT code, delta=2, abs
  112. ORG 0x0000
  113. resetVector:
  114.     goto main
  115.  
  116. ;-------------------------------------------------------------------------------
  117. ; Loop principal
  118. ;-------------------------------------------------------------------------------
  119.  
  120. PSECT loopPrincipal, delta=2
  121. ;linker: -PloopPrincipal=0x0010
  122.  
  123. ;PSECT loopPrincipal, class=code, delta=2, abs
  124. ;ORG 0x000A
  125. main:
  126.     movlw   'a'
  127.     movwf   var1
  128.     movlw   'b'
  129.     movwf   var3
  130.     movlw   'c'
  131.     banksel (var4)
  132.     ;movwf   BANKMASK(var4)
  133.     ;output  TRISB, 7
  134.     banksel TRISA
  135.     clrf    TRISB
  136.     clrf    TRISC
  137.     banksel PORTA
  138.     clrf    PORTB
  139.     movlw   0x02 ; offset
  140.     incf    var5
  141.     call    table
  142.     movwf   PORTC
  143.     goto    main
  144.  
  145.  
  146. ;-------------------------------------------------------------------------------
  147. ; Subrutinas
  148. ;-------------------------------------------------------------------------------
  149.  
  150. func2:
  151.     movlw   0xFF
  152.     movwf   PORTB
  153.     call    fong3
  154.     return
  155.  
  156. fong3:
  157.     movlw   0x0A
  158.     movwf   PORTB
  159.     return
  160.  
  161. table:
  162.     addwf   PCL, f
  163.     retlw   0xA1 ;equivalente al 0 en mi 7 segmentos
  164.     retlw   0xA2 ;equ... al 1 en mis 7seg
  165.     retlw   0xA3
  166.     retlw   0xA4
  167.  
  168.  
  169. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement