Ce nouvel assembleur 8 bits est à utiliser depuis MpLabX 5.40.
Il faut semble-t-il déclarer dans les options link du projet MpLabX :
- la section de programme reset code.
- la section de programme interrupt code, si interruptions il y a.
Quelques différences avec MPASM, notamment cblock n'est plus reconnu.
Code : Tout sélectionner
;------------------------------------------------------------------------------
; exemple de programme MpLabX 5.45 assembleur pic-as.exe (xc8) 7/1/2021
; - 16F876 16F877 16F876A 16F877A 16LF876A 16LF877A 16F887
; - quartz 16MHz
; - led clignotante à la seconde
; - port série transmit/receive
#include <xc.inc>
OSCF equ 16000000 ; Fosc = 16MHz
FCY equ OSCF/4 ; Fcy = 4MHz
TCY equ 1000000000/FCY ; Tcy = 250ns
VAL_BRG equ FCY/4/38400-1 ; rs = 38400 bauds
;------------------------------------------------------------------------------
; config hardware
;------------------------------------------------------------------------------
#ifdef __16F887
; CONFIG1
CONFIG FOSC = HS ; Oscillator Selection bits (HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
CONFIG WDTE = OFF ; Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
CONFIG PWRTE = OFF ; Power-up Timer Enable bit (PWRT disabled)
CONFIG MCLRE = ON ; RE3/MCLR pin function select bit (RE3/MCLR pin function is MCLR)
CONFIG CP = OFF ; Code Protection bit (Program memory code protection is disabled)
CONFIG CPD = OFF ; Data Code Protection bit (Data memory code protection is disabled)
CONFIG BOREN = OFF ; Brown Out Reset Selection bits (BOR disabled)
CONFIG IESO = OFF ; Internal External Switchover bit (Internal/External Switchover mode is disabled)
CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
CONFIG LVP = OFF ; Low Voltage Programming Enable bit (RB3 pin has digital I/O, HV on MCLR must be used for programming)
; CONFIG2
CONFIG BOR4V = BOR40V ; Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)
CONFIG WRT = OFF ; Flash Program Memory Self Write Enable bits (Write protection off)
#else
; CONFIG
CONFIG FOSC = HS ; Oscillator Selection bits (HS oscillator)
CONFIG WDTE = OFF ; Watchdog Timer Enable bit (WDT disabled)
CONFIG PWRTE = OFF ; Power-up Timer Enable bit (PWRT disabled)
CONFIG CP = OFF ; FLASH Program Memory Code Protection bits (Code protection off)
CONFIG BOREN = OFF ; Brown-out Reset Enable bit (BOR disabled)
CONFIG LVP = OFF ; Low Voltage In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
CONFIG CPD = OFF ; Data EE Memory Code Protection (Code Protection off)
#endif
;------------------------------------------------------------------------------
; macros
;------------------------------------------------------------------------------
movlf macro d8,adr8
movlw d8
movwf adr8
endm
;------------------------------------------------------------------------------
; data en eeprom
;------------------------------------------------------------------------------
psect edata
db 0x13,0x14
db 0x15,0xee
;------------------------------------------------------------------------------
; data en ram
;------------------------------------------------------------------------------
psect udata_bank0
wloopu: ds 1 ; 0x020 bank 0
wlooph: ds 1 ; 0x021
wloopl: ds 1 ; 0x022
save_w: ds 1 ; 0x023
psect udata_bank1
var_bk1: ds 1 ; 0x0a0 bank 1
var_bk2 equ 0x120 ; 0x120 bank 2
;------------------------------------------------------------------------------
; reset
; ajouter au projet MpLabX custom linker option -> -Preset_vect=0h
;------------------------------------------------------------------------------
psect reset_vect, class=code, delta=2
_reset: goto init
;------------------------------------------------------------------------------
; interrupts
; ajouter au projet MpLabX custom linker option -> -Pint_vect=4h
;------------------------------------------------------------------------------
psect int_vect, class=code, delta=2
movwf save_w
movf RCREG,W
addlw 1
movwf TXREG
movf save_w,W
retfie
;------------------------------------------------------------------------------
; code
;------------------------------------------------------------------------------
init: bsf RP0 ; bank 1
movlf VAL_BRG,SPBRG
movlf 0x24,TXSTA ; uart tx on, brgh=1
bcf TRISC,2 ; led
bcf RP0 ; bank 0
movlf 0x90,RCSTA ; uart on, rx on
movf RCREG,W
bsf RP0 ; bank 1
clrf BANKMASK(var_bk1)
bcf RP0 ; bank 0
bsf RP1 ; bank 2
clrf var_bk2
bcf RP1 ; bank 0
bcf RCIF
bsf RP0 ; bank 1
bsf RCIE
bcf RP0 ; bank 0
bsf PEIE
bsf GIE
bcl: call seconde
movlf 'U',TXREG
bsf PORTC,2
call seconde
movlf 'U',TXREG
bcf PORTC,2
goto bcl
seconde: movlw 100
call wait_w_10ms
return
;------------------------------------------------------------------------------
; tempos de 10ms, 100ms et W fois 10ms
;------------------------------------------------------------------------------
wait_100ms: movlw 10 ; tempo de 100ms, modifie wloopu,wlooph,wloopl,W
wait_w_10ms:movwf wloopu ; tempo en dizaines de ms (10ms à 2,55s)
w91: call wait_10ms ; modifie wloopu,wlooph,wloopl,W
decfsz wloopu,F
goto w91
return
wait_10ms: movlw 10000000/4/256/TCY; environ 10ms avec une boucle de 4 cycles
movwf wlooph ; modifie wlooph,wloopl,W
w92: clrf wloopl
w93: clrwdt ; 1 cycle
decfsz wloopl,F ; 1 cycle
goto w93 ; 2 cycles si saut
decfsz wlooph,F
goto w92
return
;------------------------------------------------------------------------------
end _reset

pour le retour
