打印
[PIC®/AVR®/dsPIC®产品]

8位PIC芯片汇编环境搭建——pic-as汇编

[复制链接]
1265|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 JackTang1994 于 2022-2-10 10:22 编辑

#申请原创# #技术资源#
参考资料
http://www.microchip.com.cn/newcommunity//Uploads/202008/5f44c72f4e170.pdf
http://www.microchip.com.cn/newcommunity/Uploads/202105/60a4bb701acd0.pdf

说明:PIC汇编器在安装PIC编译器时已经被安装了,在安装目录

添加汇编器
打开MPLAB X IDE


切换到Embedded面板点击Add按钮,打开编译添加窗口


选择pic-as汇编器路径


创建工程
按照普通工程创建一样创建汇编工程即可,只是在选择编译器时需要选择我们添加的pic-as汇编器


编写代码
向工程中新建*.s后缀的汇编文件

注:.s后缀是GUN风格的汇编文件

添加代码
    #include <xc.inc>

; CONFIG1
  CONFIG  FEXTOSC = OFF         ; External Oscillator Mode Selection bits (Oscillator not enabled)
  CONFIG  RSTOSC = HFINTOSC_32MHZ; Power-up Default Value for COSC bits (HFINTOSC (32 MHz))
  CONFIG  CLKOUTEN = OFF        ; Clock Out Enable bit (CLKOUT function is disabled; I/O function on RA4)
  CONFIG  VDDAR = HI            ; VDD Range Analog Calibration Selection bit (Internal analog systems are calibrated for operation between VDD = 2.3V - 5.5V)

; CONFIG2
  CONFIG  MCLRE = EXTMCLR       ; Master Clear Enable bit (If LVP = 0, MCLR pin is MCLR; If LVP = 1, RA3 pin function is MCLR)
  CONFIG  PWRTS = PWRT_OFF      ; Power-up Timer Selection bits (PWRT is disabled)
  CONFIG  WDTE = OFF            ; WDT Operating Mode bits (WDT disabled; SEN is ignored)
  CONFIG  BOREN = ON            ; Brown-out Reset Enable bits (Brown-out Reset Enabled, SBOREN bit is ignored)
  CONFIG  BORV = LO             ; Brown-out Reset Voltage Selection bit (Brown-out Reset Voltage (VBOR) set to 1.9V)
  CONFIG  PPS1WAY = ON          ; PPSLOCKED One-Way Set Enable bit (The PPSLOCKED bit can be set once after an unlocking sequence is executed; once PPSLOCKED is set, all future changes to PPS registers are prevented)
  CONFIG  STVREN = ON           ; Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a reset)

; CONFIG3

; CONFIG4
  CONFIG  BBSIZE = BB512        ; Boot Block Size Selection bits (512 words boot block size)
  CONFIG  BBEN = OFF            ; Boot Block Enable bit (Boot Block is disabled)
  CONFIG  SAFEN = OFF           ; SAF Enable bit (SAF is disabled)
  CONFIG  WRTAPP = OFF          ; Application Block Write Protection bit (Application Block is not write-protected)
  CONFIG  WRTB = OFF            ; Boot Block Write Protection bit (Boot Block is not write-protected)
  CONFIG  WRTC = OFF            ; Configuration Registers Write Protection bit (Configuration Registers are not write-protected)
  CONFIG  WRTSAF = OFF          ; Storage Area Flash (SAF) Write Protection bit (SAF is not write-protected)
  CONFIG  LVP = ON              ; Low Voltage Programming Enable bit (Low Voltage programming enabled. MCLR/Vpp pin function is MCLR. MCLRE Configuration bit is ignored.)

; CONFIG5
  CONFIG  CP = OFF              ; User Program Flash Memory Code Protection bit (User Program Flash Memory code protection is disabled)
;CONFIG WDTE=OFF // WDT Disabled; SWDTEN is ignored

;this must be linked to the reset vector
PSECT resetVec,class=CODE,reloc=1
resetVec:
    GOTO main

   
PSECT code   
main:
    ; This code example illustrates initializing the PORTA register.
; The other ports are initialized in the same manner.
BANKSEL PORTA ;
CLRF PORTA ;Clear PORTA
BANKSEL LATA ;
CLRF LATA ;Clear Data Latch
BANKSEL ANSELA ;
CLRF ANSELA ;Enable digital drivers
BANKSEL TRISA ;
MOVLW 00111000B ;Set RA[5:3] as inputs
MOVWF TRISA ;and set others as outputs
    END
其中CONFIG配置字代码是IDE自动生成的,可以通过如下方法生成:
点击Window菜单 >> Target Memory Views >> Configuration Bits打开配置字UI界面


在配置字面板中,通过相关的下拉框来选择配置字需要设置的功能。此工程中配置为:关闭看门狗,使用内部32MHZ高速时钟

点击生成源代码按钮,并将生成的源代码复制到汇编文件开头即可。

设置链接器选项
-presetVec=0h,-Map=led.map


编译代码
点击编译按钮
如下,表示编译成功。


调试器设置——使用调试器供电
选择调试器


打开Power设置面板


设置调试器给MCU的供电电压为:5V








使用特权

评论回复
沙发
pzsh| | 2022-2-25 19:42 | 只看该作者
配置PICKIT4供电电压原来在这里

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

28

主题

61

帖子

0

粉丝