Bienvenue aux nouveaux arrivants sur FantasPic !

- Pensez à lire les règles durant votre visite, il n'y en a pas beaucoup, mais encore faut-il les respecter .
- N’hésitez pas à faire des remarques et/ou suggestions sur le Forum, dans le but de l'améliorer et de rendre vos prochaines visites plus agréables.
- Vous pouvez regarder votre "panneau de l'utilisateur" afin de configurer vos préférences.
- Un passage par "l'utilisation du forum" est recommandé pour connaître les fonctionnalités du forum.

--- L’équipe FantasPic ---
Forum général sur l'Assembleur !

Modérateur : mazertoc

Pic 18f25k42
chabb
Débutant
Débutant
Messages : 38
Âge : 90
Enregistré en : décembre 2020
Localisation : 54600
Contact :

#1 Message par chabb » jeu. 3 déc. 2020 17:32

Bonjour, Nouveau sur ce forum.
J'essaye de programmer un Pic 18f25k42. J'écris mon programme en assembleur dans mplabxide. le debug se termine bien 0 error. Je fais "production" ça passe bien et dans le dossier "dist" j'obtiens un fichier.hex Ok. A l'aide de mplabipe
j'ecris ce fichier.hex dans le Pic, tout se passe bien : erase, program, verif Ok. Mais... lorsque je place le chip programmé sur la plaque électronique où il doit fonctionner le résultat est tout à fait fantaisiste.
Quelqun a-t-il travaillé avec ce chip, quel résultat avez-vous obtenu?
Lorsque je debug mon programme je reçois un message : Il semble que l'assembleur asm v5.86 n'est pas assez stable!
est-ce la cause de mes ennuis? Pourtant lorsque j'epluche le fichier.hex je le trouve correct. Merci pou toute réponse même négative.

Pic 18f25k42
satinas
Expert
Expert
Messages : 1225
Enregistré en : novembre 2015

#2 Message par satinas » jeu. 3 déc. 2020 18:23

Bonjour chabb et bienvenue sur le forum

Sans voir ton programme, difficile de te répondre.
Quel programmateur utilises-tu ?
Il faut commencer par quelque chose de simple, une led qui clignote chaque seconde.

Pic 18f25k42
Temps-x
Avatar de l’utilisateur
Expert
Expert
Messages : 2595
Enregistré en : juillet 2016
Localisation : Terre

#3 Message par Temps-x » jeu. 3 déc. 2020 18:50

Bonsoir chabb, satinas, et tout le forum,

Soit le bienvenu sur le forum,

chabb a écrit :Source du message Mais... lorsque je place le chip programmé sur la plaque électronique où il doit fonctionner le résultat est tout à fait fantaisiste.
Quelqun a-t-il travaillé avec ce chip, quel résultat avez-vous obtenu?


J'ai déjà travaillé avec le Pic18F26K22 et j'ai jamais eu des problèmes sur le fonctionnement de cette série, la plupart de mes problèmes venait de moi. :-D

chabb a écrit :Source du message Il semble que l'assembleur asm v5.86 n'est pas assez stable!

Si il est très stable, je peux te l'assurer, version 5.86 qui me pose aucun problème même dans les Pic récent :langue:

MPASM version 5.86.jpg


C'est Surement ton programme qui ne va pas, mets la source ici, avec un schéma électronique, on va essayer de t'aider.



==> A+
Vous n’avez pas les permissions nécessaires pour voir les fichiers joints à ce message.
:roll: Les requins, c'est comme le langage ASM, c'est le sommet de la chaîne alimentaire. :wink:

Pic 18f25k42
chabb
Débutant
Débutant
Messages : 38
Âge : 90
Enregistré en : décembre 2020
Localisation : 54600
Contact :

#4 Message par chabb » ven. 4 déc. 2020 17:57

Bonjour Satinas et Temps-x et merci pour vos reponses rapides.
Je n'ai pas encore bien compris le fonctionnement de ce forum. Hier 3dec. j'ai envoyé un message puis ne le trouvant pas dans la liste des messages je l'ai envoyé une seconde fois. De même aujourd'hui 4 dec. j'ai ecrit et evoyé un trés long message avec mon prog. asm. s'il vous plait l'avez vous reçu? y-a-t-il une limite pour la taille d'un message? Merci de me preter votre attention.

Pic 18f25k42
Jérémy
Administrateur du site
Administrateur du site
Messages : 2722
Âge : 44
Enregistré en : juillet 2015
Localisation : Dans le sud
Contact :

#5 Message par Jérémy » ven. 4 déc. 2020 18:11

 ! Message de modération :
Bonjour chabb,

Aucune trace de ton message sur le forum. Je ne peux donc pas le récupérer. Tu as du faire une erreur de manip ! oops

Oui il y a bien une limitation à 60.000 caractères dans un message. De quoi mettre un joli programme déjà, mais certain y arrive surotut en ASM dehors!! .
Dans ce cas il faut le diviser en 2 messages consécutifs.
Un conseil: sur les longs messages, TOUJOURS, faire une copie dans un notepad ou autre avant de l'envoyer.
C'est en faisant des erreurs, que l'on apprend le mieux !!!

Pic 18f25k42
Temps-x
Avatar de l’utilisateur
Expert
Expert
Messages : 2595
Enregistré en : juillet 2016
Localisation : Terre

#6 Message par Temps-x » ven. 4 déc. 2020 18:58

Bonsoir Jérémy, chabb, satinas, et tout le forum,

Sinon tu mets tout dans un zip que tu joins ici, avec un petit mots d'explication.

Jérémy a écrit :Source du message mais certain y arrive surtout en ASM


En ASM le programme que l'on écrit est toujours plus gros que celui du Langage C, mais à la compilation, il est énormément plus petit :langue:

==> A+
:roll: Les requins, c'est comme le langage ASM, c'est le sommet de la chaîne alimentaire. :wink:

Pic 18f25k42
Jérémy
Administrateur du site
Administrateur du site
Messages : 2722
Âge : 44
Enregistré en : juillet 2015
Localisation : Dans le sud
Contact :

#7 Message par Jérémy » ven. 4 déc. 2020 19:44

Le ZIP n'est pas attractif pour un forum ! il faut telecharger puis décompresser puis rechercher les dossiers.
de plus cela ne rentre pas dans le référencement.

Le ZIP doit être réservé pour les fichiers finis et volumineux.
C'est en faisant des erreurs, que l'on apprend le mieux !!!

Pic 18f25k42
Temps-x
Avatar de l’utilisateur
Expert
Expert
Messages : 2595
Enregistré en : juillet 2016
Localisation : Terre

#8 Message par Temps-x » ven. 4 déc. 2020 19:59

Re

Jérémy a écrit :Source du message Le ZIP n'est pas attractif pour un forum !


Alors faudrait revoir la taille d'un fichier code parce que 60.000 caractères c'est très court, et mettre un code en deux parti c'est pas toujours évident.

Beaucoup de personne sur le forum n'ont pu mettre leurs code, et on fini par le mettre en fichier Zip, c'est une constatation, désolé. :sad:

==> A+
:roll: Les requins, c'est comme le langage ASM, c'est le sommet de la chaîne alimentaire. :wink:

Pic 18f25k42
chabb
Débutant
Débutant
Messages : 38
Âge : 90
Enregistré en : décembre 2020
Localisation : 54600
Contact :

#9 Message par chabb » ven. 4 déc. 2020 21:27

Voici donc mon ASM (18f25k42) Je viens d'envoyer un long message je ne sais ou il est parti bizarre le message disparait dès que
je click sur envoyer. aucune confirmation.
Le programme en sleep demarre par appui sur un bouton------->int0 on rb0

; BOITE A MUSIQUE ELECTRONIQUE ;
;...............................................................................;
; PIC18F25K42 date:06/02/2020 ;
; Oscillator : internal osc. 64 Mcycles. instruction = 0.0625 microseconde. ;
;...............................................................................;
; Ports assign Ra0: output Load condo Noire ;
; Ra1: output Load condo croche ;
; Ra2: output Load condo double croche ;
; Ra3 RA4 ra5 ra7: input not used ;
; Ra6: clock/4 16Mhz out ;
; ;
; Rb0: input external interrupt int0 ;
; Rb1: output creneau noire ;
; Rb2: output creneau croche ;
; rb3: output creneau double croche ;
; rb4: output 0 to 3 for shade ;
; rb5: output 00= forte; 11= pianissimo ;
; rb6 rb7 not used ;
; No quartz used. internal oscillator 64Mhz ;
; Codified music registered into program memory starting at line 1032 Mem: 57Ch ;
; Program start at line 319 Memory : 000; Interrupt routine at Mem : 008. ;
; Main program begins at line 490 Mem 014Ch. (Sleep). ;
;_______________________________________________________________________________;
;
list p=18f25k42, f=inhx32 ;output assembler hexadecimal 8bits
;#include p18F25k42.inc
org 300000 ;configuration of the chip
config RSTOSC= HFINTOSC_64MHZ
config clkouten = off ;clock out disable
config mclre = extmclr,mvecen= off ;2L bit3=0 MVCEN legacy interr. behav
config borv = vbor_2p45 ;2h vbor = 2v45
config wdte = off ;3L wdt disable
;3H wdt dont care
;4L bben barre=1 safen barre =1 wrtapp barre=1
;4H no protect
;5L EEPROM no protect not used
;All protections are disable (No protect)
org 200000 ;Name of this chip
__idlocs h'200000',h'bc' ;B.C.04 dd 02/2020
__idlocs h'200001',h'05'
__idlocs h'200002',h'dd'
__idlocs h'200003',h'02'
__idlocs h'200004',h'aa'
__idlocs h'200005',h'20'
__idlocs h'200006',h'20'
__idlocs h'200007',h'aa'
;include 18f25k42.inc
;symbolic values
w equ 0 ;working register or note nulle
f equ 1 ;file (Memory position (memoire)
z equ 2 ;zero (bit zero status word)
n equ 0x00 ;note nulle
;
;Names off all possible notes to write a song
;boucle= 3.75 usec. whit clock 64 Mhz we need counters 9 bits.
;one counter is for example do1=0xFE and do1 bit8 = 1 (+256)
la4 equ 0x02 ;Nomber of iterations for; highest note
la4b8 equ 0x03 ;bit 8 = 0
sol#4 equ 0x04 ;one half creneau.
sol#4b8 equ 0x05
sol4 equ 0x06 ;Hors tol?rance +11/1000
sol4b8 equ 0x07
fa#4 equ 0x08
fa#4b8 equ 0x09
fa4 equ 0x0A
fa4b8 equ 0x0B
mi4 equ 0x0C ;H t +8/1000
mi4b8 equ 0x0D
re#4 equ 0x0E ;Hors tol?rance 8/1000
re#4b8 equ 0x0F
re4 equ 0x10
re4b8 equ 0x11
do#4 equ 0x12
do#4b8 equ 0x13
do4 equ 0x14 ;Do 2093 239us.
do4b8 equ 0x15

si3 equ 0x16
si3b8 equ 0x17
sib3 equ 0x18 ;Hors tol?rance +7/1000
sib3b8 equ 0x19
la3 equ 0x1A ;La 1760 284us.
la3b8 equ 0x1B
sol#3 equ 0x1C
sol#3b8 equ 0x1D
sol3 equ 0x1E ;Sol 1568 319us.
sol3b8 equ 0x1F
fa#3 equ 0x20
fa#3b8 equ 0x21
fa3 equ 0x22 ;Nomber of iterations for
fa3b8 equ 0x23
mi3 equ 0x24 ;one half creneau
mi3b8 equ 0x25
re#3 equ 0x26
re#3b8 equ 0x27
re3 equ 0x28
re3b8 equ 0x29
do#3 equ 0x2A
do#3b8 equ 0x2B
do3 equ 0x2C ;Do 1046
do3b8 equ 0x2D

si2 equ 0x2E
si2b8 equ 0x2F
sib2 equ 0x30
sib2b8 equ 0x31
la2 equ 0x32 ;La 880
la2b8 equ 0x33
sol#2 equ 0x34
sol#2b8 equ 0x35
sol2 equ 0x36
sol2b8 equ 0x37
fa#2 equ 0x38
fa#2b8 equ 0x39
fa2 equ 0x3A
fa2b8 equ 0x3B
mi2 equ 0x3C
mi2b8 equ 0x3D
re#2 equ 0x3E
re#2b8 equ 0x3F
re2 equ 0x40
re2b8 equ 0x41
do#2 equ 0x42
do#2b8 equ 0x43
do2 equ 0x44 ;Do 523
do2b8 equ 0x45

si1 equ 0x46
si1b8 equ 0x47 ;bit 8 = 1 for all notes range 1
sib1 equ 0x48
sib1b8 equ 0x49 ;bit 8 = 1
la1 equ 0x4A ;La 440
la1b8 equ 0x4B
sol#1 equ 0x4C
sol#1b8 equ 0x4D
sol1 equ 0x4E
sol1b8 equ 0x4F
fa#1 equ 0x50
fa#1b8 equ 0x51
fa1 equ 0x52
fa1b8 equ 0x53
mi1 equ 0x54
mi1b8 equ 0x55
re#1 equ 0x56
re#1b8 equ 0x57
re1 equ 0x58
re1b8 equ 0x59
do#1 equ 0x5A
do#1b8 equ 0x5B
do1 equ 0x5C ;The lower note possible
do1b8 equ 0x5D ;d01b8=1 then count 256 befor decrement do1
;<<<<<<< special function Registers used >>>>>>>
indf0 equ 0xfef ;indirect adressing
tmr0l equ 0x3fb6 ;timer0 low
tmr0h equ 0x3fb7 ;timer0 hight
pir1 equ 0x39a1 ;pir1 bit 0 : int0 occured
pie1 equ 0x3991 ;anable ext int0 enable
pir3 equ 0x39a3 ;pir3bit 7 : tmr0 int. occured
pie3 equ 0x3993 ;enable timer 0 interrupt
ipr1 equ 0x3981
status equ 0x3FD8 ;adresse du mot status
fsr1l equ 0x3fe1 ;offset ind.adress
porta equ 0x3fca ;adresse port A
lata equ 0x3fba
portb equ 0x3fcb ;adresse port B
latb equ 0x3fbb
anselb equ 0x3a50
ansela equ 0x3A40
trisa equ 0x3fc2 ;OK config port A
trisb equ 0x3fc3 ;OK config port B
bsr equ 0x3fe0 ;bank select
intcon0 equ 0x3fd2 ;interrupt control
int0pps equ 0x3ac0 ;extern.int. on rb0
postinc0 equ 0x3fee ;indirect adressing
fsr0l equ 0x3fe9
adcon1 equ 0xfc1 ;analog-digital control
t0con0 equ 0x3fb8 ;OK timer0 control 0
t0con1 equ 0x3fb9 ;timer0 control 1
osccon1 equ 0x39d9 ;oscillator control
osctune equ 0x39de ;adjust internal oscillator 32 Mhz
vregcon equ 0x39D1 ;Low power in sleep
PMD0 equ 0x39C0 ;PMD 0-7 disable modules not used
PMD1 equ 0x39C1
PMD2 equ 0x39C2
PMD3 equ 0x39C3
PMD4 equ 0x39C4
PMD5 equ 0x39C5
PMD6 equ 0x39C6
PMD7 equ 0x39C0


;<<<<<<< Files registers used by this program >>>>>>>
n0 equ 0x64 ;n0 for Tempo
n1 equ 0x65 ;n1 to n7 = time 1/2 creneau
n2 equ 0x66 ;for a writed note
n3 equ 0x67
n4 equ 0x68
n5 equ 0x69
n6 equ 0x6A
n7 equ 0x6B
frdc1 equ 0x6C ;freq. first double croche
frdc1b8 equ 0x6D ;frdc1 bit 8
frdc2 equ 0x6E ;freq. second double croche
frdc2b8 equ 0x6F
frdc3 equ 0x70 ;freq. third double croche
frdc3b8 equ 0x71
frdc4 equ 0x72 ;freq. fourth double croche
frdc4b8 equ 0x73
frc1 equ 0x74 ;freq. first croche
frc1b8 equ 0x75
frc2 equ 0x76 ;freq. second croche
frc2b8 equ 0x77
frn equ 0x78 ;freq. noire
frnb8 equ 0x79
countdc equ 0x7A ;counter double croche
countdcb8 equ 0x7B ;eighth bit
countc equ 0x7C ;counter croche
countcb8 equ 0x7D
countn equ 0x7E ;counter noire
countnb8 equ 0x7F
cint equ 0x80 ;count 0 to 16 = 1 step = 1 noire
del equ 0x81 ;count delai (20 = 1 sec.)
tempo equ 0x82 ;unfolding speed (rapidité) Tempo
count1 equ 0x83 ;count delais
count2 equ 0x84 ; " "
rep equ 0x85 ;control repeate in song
ped equ 0x86 ;continue noire resonent pedal
newsong equ 0x87 ;bypass song or start music
bitest equ 0x89 ;[ dc1 c1 n dc2 dc3 c2 dc4
song equ 0x8A ;to see the progress in MPLAB
countst equ 0x8B ;count steps " " "
centdc equ 0x8c ;count 0 to 256 if bit8 present for dc
centc equ 0x8d
centn equ 0x8e
essai equ 0x8f
;Glossary : english 1/4 semi breve = amer.1/4 whole note = fr. noire
; or eng. crotchet = amer.quarter note = fr. noire
;eng. quaver = amer. eighth note = fr. croche
;amer. sixteenth note = fr. double croche
;La = A; Si = B; Do = C; Re = D; Mi = E; Fa = F; Sol = G

;<<<<<<<<< MACROS>>>>>>>>
delais macro arg1 ;macro delais. argument contains
movlw arg1 ;the time number to run
movwf del
call DELAI ;50millisec. * del
endm

unload macro
movlw d'14' ;0E hexa 00001110
movwf portb ;discharge condos
clrf cint
clrf ped,f
clrf rep,f
endm

Forte macro ;Forte
bcf latb,5
bcf latb,4
endm

Mf macro ;Mezzoforte
bcf latb,5
bsf latb,4
endm

Piano macro ;Piano
bsf latb,5
bcf latb,4
endm

Pp macro ;Pianissimo
bsf latb,5
bsf latb,4
endm

pedon macro ;Pedal on
bsf ped,0
endm

repris macro go_rep1 ;Repeat at. Reprise
bsf rep,0
goto go_rep1
endm

repris2 macro go_rep2 ;Repeat2
bsf rep,1
goto go_rep2
endm

sectim macro go_cont1 ;Second Time used with repris
btfss rep,0 ;Skip first step to second step
bra $+8 ;and continue
bcf rep,0
goto go_cont1
endm

sectim2 macro go_cont2 ;option repeat2
btfss rep,1
bra $+8 ;+8 because GOTO = 4 bytes in memory
bcf rep,1
goto go_cont2
endm

;<<<<<<<keep frequences for notes in one step (noire)>>>>>>>
temps macro nn0,nn1,nn2,nn3,nn4,nn5,nn6,nn7 ;in 1 step:
movlw nn0 ;nn0 = tempo
movwf n0
movlw nn1 ;nn1 = first double croche
movwf n1
movlw nn2 ;nn2 = first croche
movwf n2
movlw nn3 ;nn3 = noire
movwf n3
movlw nn4 ;nn4 = second double croche
movwf n4
movlw nn5 ;nn5 = third double croche
movwf n5
movlw nn6 ;nn6 = second croche
movwf n6
movlw nn7 ;nn7 = fourth double croche
movwf n7
call loadfr
endm

org 0x00
;................Biginning of program at adress 0................
Init1 ;Initialization at power on
movlw h'00' ; disable interrupt
movwf intcon0
movlw h'90' ;timer0 enable 16 bits postcal 1/1.
bra afterir ;skip interrupt routine
;................Intrrupt service routine at adress 8 .....................
introut movlb h'39' ;bsr= 39h bank 57 access to 0x39xx
btfss pir3,7,1 ;is tmr0 overflow? introut = 1.375 microsec
bra $+d'18' ;no
bcf pir3,7,1 ;yes clear flag tmr0 overflow
movlb h'00'
incf cint,f ;+1 on counter tempo
movf tempo,w ;refresh preload tmr0 hight byte
movwf tmr0h
clrf tmr0l
movf tmr0l,w ;to update timer0 high byte
bra $+d'10' ;out Introut
movlb h'39'
bcf pir1,0,1 ;it is int0 (start button) clear flag
movlb 0
bsf newsong,0 ;set bit 0
retfie 1 ;restore W, Status, BSR

afterir movwf t0con0 ;90= tmr0 16 bits postscal 1/1 enable
movlw 0x26 ;affect value for each note byte and bit 8 if need
movwf la4 ;Number iterations see xls file
movlw 0x28
movwf sol#4
movlw 0x2B
movwf sol4
movlw 0x2D
movwf fa#4
movlw 0x30
movwf fa4
movlw 0x33
movwf mi4
movlw 0x36
movwf re#4
movlw 0x39
movwf re4
movlw 0x3C
movwf do#4
movlw 0x40
movwf do4

movlw 0x43
movwf si3
movlw 0x48
movwf sib3
movlw 0x4C
movwf la3
movlw 0x50
movwf sol#3
movlw 0x55
movwf sol3
movlw 0x5A
movwf fa#3
movlw 0x5F
movwf fa3
movlw 0x65
movwf mi3
movlw 0x6B
movwf re#3
movlw 0x72
movwf re3
movlw 0x78
movwf do#3
movlw 0x7F
movwf do3

movlw 0x87
movwf si2
movlw 0x8F
movwf sib2
movlw 0x98
movwf la2
movlw 0xA1
movwf sol#2
movlw 0xAA
movwf sol2
movlw 0xB4
movwf fa#2
movlw 0xBF
movwf fa2
movlw 0xCA
movwf mi2
movlw 0xD6
movwf re#2
movlw 0xE3
movwf re2
movlw 0xF1
movwf do#2
movlw 0xFF
movwf do2

movlw 0x0E
movwf si1
bsf si1b8,0
movlw 0x1E
movwf sib1
bsf sib1b8,0
movlw 0x2F
movwf la1
bsf la1b8,0
movlw 0x41
movwf sol#1
bsf sol#1b8,0
movlw 0x54
movwf sol1
bsf sol1b8,0
movlw 0x68
movwf fa#1
bsf fa#1b8,0
movlw 0x7E
movwf fa1
bsf fa1b8,0
movlw 0x94
movwf mi1
bsf mi1b8,0
movlw 0xAD
movwf re#1
bsf re#1b8,0
movlw 0xC6
movwf re1
bsf re1b8,0
movlw 0xE1
movwf do#1
bsf do#1b8,0
movlw 0xFE
movwf do1
bsf do1b8,0

movlw h'44'
movwf t0con1 ;fosc/4 prescal 1/16
movlb h'39' ;bank 57
bsf pie1,0,1 ;enable ext. int0 rb0 high pulse
bsf pie3,7,1 ;timer0 enable int.
bsf ipr1,0,1
movlw h'60' ;enter sleep mode on SLEEP instruction
movwf osccon1,1
clrf pir3
movlw 3
movwf vregcon,1 ;bit1: low power in sleep bit0 required
movlw h'FF'
movwf PMD0,1
movwf PMD3,1
movlw h'FE'
movwf PMD1,1
movlw h'67'
movwf PMD2,1
movlw h'E0'
movwf PMD4,1
movlw h'37'
movwf PMD5,1
movlw h'3F'
movwf PMD6,1
movlw 3
movwf PMD7,1
movlb 0 ;bank 0
movlw h'08' ;port A 3 in 0-1-2 out \
movwf trisa ;init tris a 00001000 /
movlw h'c1' ;port B 0 in 1 to 5 out \
movwf trisb ;init tris b 11000001 /

Init2
clrf tmr0h ;tmr0 high
clrf tmr0l ;tmr0 low
clrf porta ;init port A
clrf portb ;init port B
movlb h'3A'
clrf anselb ;digital I/O
clrf ansela
movlb 0
clrf countdc ;clear counters 0 to 255
clrf countc
clrf countn
clrf cint ;clear timer for one step 0 to 16
clrf rep ;for repeate
bsf t0con0,7 ;enable timer0TMR0_Internal
TMR0_Prescale

bsf t0con0,4 ;timer0 16bits
movlw h'80' ;enable global interrupt int0 on failing edge
movwf intcon0
delais 4 ;70ms.pwrt is not eneuf
clrf newsong ;bit 0 is memory start button
clrf countst ;clear count step to see progress
;...............................End initialization ........................

sle sleep ;wait start button depressed external INT0
nop
btfss newsong,0
bra sle
depart
clrf porta ;Load capa = 0
clrf song ;to see in MPLAB
clrf newsong
clrf tempo
clrf cint
clrf countdc
clrf countdcb8
clrf countc
clrf countcb8
clrf countn
clrf countnb8
unload ;unload capa's
incf song,1 ;to follow in MPLAB
call song1 ;song number one step 1
unload
incf song,1
call song2 ;song number 2
unload
incf song,1
call song3 ;song number 3
unload
incf song,f
call song4 ;song number 4
unload
incf song,f
call song5 ;song number 5
unload
incf song,f
call song6 ;song number 6
unload
incf song,f
call song7 ;song number 7
unload
incf song,f
call song8 ;song number 8
goto sle ;wait start button

loadfr ;Analyse of one step, loading frequences and bitest.
;<<<<Word bitest 8 bits, 1 bit by note presente the noire start>>>>
;<<<<at the biginning of the time (cint=0) the croches a cint=0 and cint=8 >>>>
;<<<<doubles croches at cint=0, cint=4, cint=8 cint=12 >>>>

;bitest: used to see if note is presente or not; also to see if tempo change.
;Bit 0 for tempo ;bit 1 first double croche at cint0
;bit 2 first croche at cint0 ;bit 3 Noire at cint0
;bit 4 sec. double croche at cint4 ;bit 5 third double croche at cint8
;bit 6 seconde croche at cint8 ;bit 7 fourth doublecroche at cint12
incf countst,1 ;to follow in mplab
clrf bitest
movf n0,w ;status z if w = 0
bz $+6 ;Tempo not modify
comf n0,w ;complement to 255
movwf tempo
ldc1 movf n1,w ;w = 0 ou Addresse de N1 (44h) load dc1
bz $+d'14'
bsf bitest,1
movwf fsr0l ;indirect addressing
movf postinc0,w
movwf frdc1
movf postinc0,w
movwf frdc1b8
lc1 movf n2,w
bz $+d'14'
bsf bitest,2
movwf fsr0l
movf postinc0,w
movwf frc1
movf postinc0,w
movwf frc1b8
lnoire movf n3,w
bz $+d'14'
bsf bitest,3
movwf fsr0l
movf postinc0,w
movwf frn
movf postinc0,w
movwf frnb8
ldc2 movf n4,w
bz $+d'14'
bsf bitest,4
movwf fsr0l
movf postinc0,w
movwf frdc2
movf postinc0,w
movwf frdc2b8
ldc3 movf n5,w
bz $+d'14'
bsf bitest,5
movwf fsr0l
movf postinc0,w
movwf frdc3
movf postinc0,w
movwf frdc3b8
lc2 movf n6,w
bz $+d'14'
bsf bitest,6
movwf fsr0l
movf postinc0,w
movwf frc2
movf postinc0,w
movwf frc2b8
ldc4 movf n7,w
bz $+d'14'
bsf bitest,7
movwf fsr0l
movf postinc0,w
movwf frdc4
movf postinc0,w
movwf frdc4b8
call bip1t ;Execution 1 step
clrf cint ;return and next step
return 1


;<<Load condensators & counters for notes presentes at the biginning of step>>
;<<<<<<<preload timer 0 according to the tempo desired for this step >>>>>>>
bip1t clrf cint ;cint = 0
clrf porta
btfss bitest,1 ;is there a dc1
bra bra1 ;no
movff frdc1,countdc ;yes load freq. dc1
movff frdc1b8,countdcb8
bsf porta,2 ;start loading capa DC

bra1 btfss bitest,2 ;is there a c1
bra bra2 ;no
movff frc1,countc ;yes load freq. c1
bsf porta,1 ;start loading capa C

bra2 btfss bitest,3 ;is there a noire
bra tmp ;no
movff frn,countn ;yes load freq. noire
bsf porta,0 ;start loading capa N

tmp ;movff tempo,tmr0h ;preload tempo for 1 step in hight byte
movf tempo,w
movwf tmr0h

clrf tmr0l ;clear timer0 low byte update hight byte

;preload=255 time = 1 sec..prelo.200 time = 0.82..prelo.100 time = 0.41 sec.
;preload 60 time = 0.25 sec..preload 175 time=0.72 sec..
;preload 180 time = 0,74 sec..
;Exemple: write d'195' for a time of 0,8 seconde. (75 Noires per minute)

;<<<<<<<Execution of one temps (step) Cint from 0 to 16. 4 boucles, one for>>>
;<<<<<<<each quarter of a step corresponding to 4 doubles croches. >>>>>>>
;<<Sequence 23 instructions below take care of 5 cases:- Note absente>>>
;-Note presente creneau not toggle-Note presente creneau toggle-bit 8 or not>>>
;<<Some instructions bra $+2 or nop make the time always the same. >>>
;<<Entire boucle to count 3 notes in 1/4 of one step is 3.75 micro sec.>>>
exec ;1 iteration = 60 cycles = 3.75 microsec for 1 dc
;cint = 0
dc1 btfss bitest,1 ;Is there a double croche 1
bra $+d'18' ;NOdc note absente
btfss countdcb8,0
bra $+d'8' ;total count < 256
incfsz centdc ;> 256: increment counter à 256
bra $+d'14' ;Cent>0 nonzero continue
bra $+d'18' ;Cent=0
N256 dcfsnz countdc
bra $+d'20' ;Moves & toggle
bra $+d'14' ;count#0
Nodc bra $+2
bra $+2
CentN0 bra $+2
bra $+2
bra compdc ;complement time
Cent0 bcf countdcb8,0
count#0 bra $+2
bra compdc
Mov movff frdc1,countdc ;refresh counter DC
movff frdc1b8,countdcb8
btg portb,3 ;toggle B3 double croche 1
compdc bra $+2
bra $+2

c1 btfss bitest,2 ;Is there a croche 1
bra $+d'18' ;No note absente
btfss countcb8,0
bra $+d'8'
incfsz centc ;Yes increment counter
bra $+d'14' ;count = 0 refresh toggle
bra $+d'18'
dcfsnz countc
bra $+d'20'
bra $+d'14'
bra $+2
bra $+2 ;not zero out whit compensation
bra $+2
bra $+2
bra compc
bcf countcb8,0
bra $+2
bra compc
movff frc1,countc ;zero: refresh counter C
movff frc1b8,countcb8
btg portb,2 ;toggle B2 croche 1
compc bra $+2
bra $+2
nop
noire btfss ped,0 ;pedal for resonance noire only
bra $+4 ;no
bra $+d'8' ;inc yes
nop
btfss bitest,3 ;Is there a noire
bra $+d'18' ;No note absente
btfss countnb8,0 ;yes
bra $+d'8'
incfsz centn
bra $+d'14'
bra $+d'18'
dcfsnz countn ;Yes increment counter
bra $+d'20' ;count = 0 refresh toggle
bra $+d'14'
bra $+2 ;not zero out whit compensation
bra $+2
bra $+2
bra $+2
bra compn
bcf countnb8,0
bra $+2
bra compn
movff frn,countn ;zero: refresh counter N
movff frnb8,countnb8
btg portb,1 ;portb,1 toggle B1 noire
compn bra $+2


cint0_1 nop
btfsc cint,0 ;cint bit 0 present? (cint=1)
clrf porta ;yes stop load condos
btfss cint,2 ;cint = 4? 1/4 of time
bra dc1 ;no
;______________________________________________________________________

;cint = 4 seconde dc
btfss bitest,4 ;is there a double croche 2
bra $+4 ;no
bsf porta,2 ;yes start loading condo dc
;______________________________________________________________________

;cint = 4
dc2 btfss bitest,4 ;Is there a double croche 1
bra $+d'18' ;NOdc No note absente
btfss countdcb8,0
bra $+d'8' ;<256
incfsz centdc ;Yes increment counter à 256
bra $+d'14' ;Cent>0 nonzero continue
bra $+d'18' ;Cent=0
dcfsnz countdc
bra $+d'20' ;Moves & toggle
bra $+d'14' ;count#0
bra $+2
bra $+2
bra $+2
bra $+2
bra compdc2
bcf countdcb8,0
bra $+2
bra compdc2
movff frdc2,countdc ;refresh counter DC
movff frdc2b8,countdcb8
btg portb,3 ;toggle B3 double croche 1 (13cycles)
compdc2 bra $+2
bra $+2

dc2c1 btfss bitest,2 ;Is there a croche 1
bra $+d'18' ;No note absente
btfss countcb8,0
bra $+d'8'
incfsz centc ;Yes increment counter
bra $+d'14' ;count = 0 refresh toggle
bra $+d'18'
dcfsnz countc
bra $+d'20'
bra $+d'14'
bra $+2
bra $+2 ;not zero out whit compensation
bra $+2
bra $+2
bra compc2
bcf countcb8,0
bra $+2
bra compc2
movff frc1,countc ;zero: refresh counter C
movff frc1b8,countcb8
btg portb,2 ;toggle B2 croche 1
compc2 bra $+2
bra $+2
nop
dc2noir btfss ped,0 ;p?dal for resonance noire only
bra $+4 ;no
bra $+d'8' ;inc yes
nop
btfss bitest,3 ;Is there a noire
bra $+d'18' ;No note absente
btfss countnb8,0 ;yes
bra $+d'8'
incfsz centn
bra $+d'14'
bra $+d'18'
dcfsnz countn ;Yes increment counter
bra $+d'20' ;count = 0 refresh toggle
bra $+d'14'
bra $+2 ;not zero out whit compensation
bra $+2
bra $+2
bra $+2
bra compn2
bcf countnb8,0
bra $+2
bra compn2
movff frn,countn ;zero: refresh counter N
movff frnb8,countnb8
btg portb,1 ;toggle B1 noire
compn2 bra $+2

cint4_1 nop
btfsc cint,0 ;cint bit 0 present? (cint=5)
clrf porta ;yes stop load
btfss cint,3 ;cint = 8? half time
bra dc2 ;no
;______________________________________________________________________

;cint = 8 third dc
btfss bitest,6 ;is there a croche 2
bra $+4 ;no
bsf porta,1 ;yes start loading condo c
btfss bitest,5 ;is there a double croche 3
bra $+4 ;no
bsf porta,2 ;yes start loading condo dc
;_________________________________________________________________

;cint = 8
dc3 btfss bitest,5 ;Is there a double croche 1
bra $+d'18' ;NOdc No note absente
btfss countdcb8,0
bra $+d'8' ;<256
incfsz centdc ;Yes increment counter à 256
bra $+d'14' ;Cent>0 nonzero continue
bra $+d'18' ;Cent=0
dcfsnz countdc
bra $+d'20' ;Moves & toggle
bra $+d'14' ;count#0
bra $+2
bra $+2
bra $+2
bra $+2
bra compdc3
bcf countdcb8,0
bra $+2
bra compdc3
movff frdc3,countdc ;refresh counter DC
movff frdc3b8,countdcb8
btg portb,3 ;toggle B3 double croche 1 (13cycles)
compdc3 bra $+2
bra $+2

dc3c2 btfss bitest,6 ;Is there a croche 1
bra $+d'18' ;No note absente
btfss countcb8,0
bra $+d'8'
incfsz centc ;Yes increment counter
bra $+d'14' ;count = 0 refresh toggle
bra $+d'18'
dcfsnz countc
bra $+d'20'
bra $+d'14'
bra $+2
bra $+2 ;not zero out whit compensation
bra $+2
bra $+2
bra compc3
bcf countcb8,0
bra $+2
bra compc3
movff frc2,countc ;zero: refresh counter C
movff frc2b8,countcb8
btg portb,2 ;toggle B2 croche 1
compc3 bra $+2
bra $+2
nop
dc3noir btfss ped,0 ;p?dal for resonance noire only
bra $+4 ;no
bra $+d'8' ;inc yes
nop
btfss bitest,3 ;Is there a noire
bra $+d'18' ;No note absente
btfss countnb8,0 ;yes
bra $+d'8'
incfsz centn
bra $+d'14'
bra $+d'18'
dcfsnz countn ;Yes increment counter
bra $+d'20' ;count = 0 refresh toggle
bra $+d'14'
bra $+2 ;not zero out whit compensation
bra $+2
bra $+2
bra $+2
bra compn3
bcf countnb8,0
bra $+2
bra compn3
movff frn,countn ;zero: refresh counter N
movff frnb8,countnb8
btg portb,1 ;toggle B1 noire
compn3 bra $+2

cint8_1 nop
btfsc cint,0 ;cint bit 0 present? (cint=9)
clrf porta ;yes stop load condos
btfss cint,2 ;cint = 12? 3/4 of time
bra dc3 ;no
;______________________________________________________________________

;cint = 12 fourth dc
btfsc cint,0 ;cint bit 0 present ? (cint=9)
clrf porta ;yes stop load
btfss cint,2 ;cint = 12? 3/4 of the time
bra dc3 ;no
btfss bitest,7 ;is there a double croche 4?
bra $+4 ;no
bsf porta,2 ;yes start loading condo dc
;_______________________________________________________________________

;cint = 12
dc4 btfss bitest,7 ;Is there a double croche 1
bra $+d'18' ;NOdc No note absente
btfss countdcb8,0
bra $+d'8' ;<256
incfsz centdc ;Yes increment counter à 256
bra $+d'14' ;Cent>0 nonzero continue
bra $+d'18' ;Cent=0
dcfsnz countdc
bra $+d'20' ;Moves & toggle
bra $+d'14' ;count#0
bra $+2
bra $+2
bra $+2
bra $+2
bra compdc4
bcf countdcb8,0
bra $+2
bra compdc4
movff frdc4,countdc ;refresh counter DC
movff frdc4b8,countdcb8
btg portb,3 ;toggle B3 double croche 1 (13cycles)
compdc4 bra $+2
bra $+2

dc4c2 btfss bitest,6 ;Is there a croche 1
bra $+d'18' ;No note absente
btfss countcb8,0
bra $+d'8'
incfsz centc ;Yes increment counter
bra $+d'14' ;count = 0 refresh toggle
bra $+d'18'
dcfsnz countc
bra $+d'20'
bra $+d'14'
bra $+2
bra $+2 ;not zero out whit compensation
bra $+2
bra $+2
bra compc4
bcf countcb8,0
bra $+2
bra compc4
movff frc2,countc ;zero: refresh counter C
movff frc2b8,countcb8
btg portb,2 ;toggle B2 croche 1
compc4 bra $+2
bra $+2
nop
dc4noir btfss ped,0 ;p?dal for resonance noire only
bra $+4 ;no
bra $+d'8' ;inc yes
nop
btfss bitest,3 ;Is there a noire
bra $+d'18' ;No note absente
btfss countnb8,0 ;yes
bra $+d'8'
incfsz centn
bra $+d'14'
bra $+d'18'
dcfsnz countn ;Yes increment counter
bra $+d'20' ;count = 0 refresh toggle
bra $+d'14'
bra $+2 ;not zero out whit compensation
bra $+2
bra $+2
bra $+2
bra compn4
bcf countnb8,0
bra $+2
bra compn4
movff frn,countn ;zero: refresh counter N
movff frnb8,countnb8
btg portb,1 ;toggle B1 noire
compn4 bra $+2

cnt12_1 nop
btfsc cint,0 ;cint bit 0 present? (cint=13)
clrf porta ;yes stop load condos
btfss cint,4 ;cint = 16? end of time
bra dc4 ;no

;______________________________________________________________________
;cint = 16 End off step
bcf ped,0 ;terminate resound pedal
bcf rep,7 ;reset memory noire in preceding step
btfsc bitest,3 ;test if Noire present in this step
bsf rep,7 ;for next step
btfss newsong,0 ;was push button depressed ?
bra retu ;No
pop ;Yes remove 2 top of stack to return
pop ;near next song in depart sequence.
clrf newsong
retu return ;end of the step
;<<<<<End program Exec>>>>>
;__________________________________________________________________________
;__________________________________________________________________________

DELAI bra $+2
nop ;|cycle
incfsz count1,f ;|6 cycles 0,125 microsec. = 0,75 usec.
bra DELAI ;/ x 256 = 192 usec.
incfsz count2,f ;\
bra DELAI ;/ x 256 = 50 millisec.
decfsz del,f ;delai= 50xdel; if del= 20 delai = 1 sec.
bra DELAI ;Maxi = 12 sec.
return 1 ;restore W, Status, BSR
;____________________________Enf of mainprogram_________________________________

song1 ;Adorable musique Mozart(La flute enchantee)
Mf
delais 20 ;1 seconde
c1part1 Mf ;Tmp Dc1 C1 N Dc2 Dc3 C2 Dc4
c1m1.1 temps d'230',sol3 ,n ,n ,fa3 ,n ,mi3 ,n
c1m1.2 temps n ,n ,n ,mi3 ,n ,n ,n ,n
c1m1.3 temps n ,n ,mi3 ,n ,n ,n ,fa3 ,n
c1m1.4 temps n ,n ,n ,fa3 ,n ,n ,n ,n
c1m2.1 temps n ,fa3 ,n ,n ,mi3 ,n ,re3 ,n
c1m2.2 temps n ,n ,n ,re3 ,n ,n ,n ,n
c1m2.3 temps d'115',n ,n ,re3 ,n ,n ,n ,n
c1m2.4 temps n ,n ,n ,mi3 ,n ,n ,n ,n
bsf ped,0
c1m2.5 temps d'230',n ,n ,n ,n ,sol3 ,n ,fa3
c1m3.1 temps n ,n ,n ,mi3 ,n ,n ,n ,n
c1m3.2 temps n ,n ,n ,mi3 ,n ,n ,mi3 ,n
Forte
c1m3.3 temps n ,n ,n ,fa3 ,n ,n ,n ,sol3
c1m3.4 temps n ,n ,la3 ,n ,n ,n ,fa3 ,n
c1m4.1 temps n ,n ,n ,mi3 ,n ,n ,n ,n
Mf
c1m4.2 temps n ,n ,n ,re3 ,n ,n ,n ,re3
c1m4.3 temps n ,n ,n ,do3 ,n ,n ,n ,n
sectim c1m8.4
c1part2 Piano
bsf ped,0 ;pedon
nop ;Tmp Dc1 C1 N Dc2 Dc3 C2 Dc4
c1m4.4 temps n ,n ,n ,n ,n ,fa3 ,n ,mi3
c1m5.1 temps n ,n ,n ,re3 ,n ,n ,re3 ,n
bsf ped,0 ;pedon
c1m5.2 temps n ,n ,n ,n ,n ,n ,re3 ,n
c1m5.3 temps n ,n ,n ,mi3 ,n ,n ,mi3 ,n
bsf ped,0 ;pedon
c1m5.4 temps n ,n ,n ,n ,n ,n ,mi3 ,n
c1m6.1 temps n ,n ,n ,fa3 ,n ,n ,n ,n
c1m6.2 temps n ,n ,fa3 ,n ,n ,n ,n ,sol3
c1m6.3 temps n ,n ,n ,mi3 ,n ,n ,n ,n
bsf ped,0 ;spedon
c1m6.4 temps n ,n ,n ,n ,n ,mi3 ,n ,fa3
bcf portb,5 ;MF
bsf portb,4
c1m7.1 temps n ,n ,n ,sol3 ,n ,n ,n ,n
c1m7.2 temps n ,n ,sol3 ,n ,n ,n ,sol3 ,n
bcf portb,5 ;F
bcf portb,4
c1m7.3 temps n ,n ,la3 ,n ,n ,n ,n ,si3
c1m7.4 temps n ,n ,do4 ,n ,n ,n ,fa3 ,n
bcf portb,5 ;MF
bsf portb,4
c1m8.1 temps n ,n ,n ,mi3 ,n ,n ,n ,n
c1m8.2 temps n ,n ,n ,re3 ,n ,n ,n ,re3
bsf portb,5 ;Pp
bsf portb,4
c1m8.3 temps n ,n ,n ,do3 ,n ,n ,n ,n
repris c1part1
c1m8.4 bsf ped,0 ;pedon
temps n ,n ,n ,n ,n ,n ,n ,n
return

;<<<<Place hier your song 129 bytes free only 7 steps>>>

return
;____________________________________________________________________
end ;Music for a quarter of an hour.

Pic 18f25k42
satinas
Expert
Expert
Messages : 1225
Enregistré en : novembre 2015

#10 Message par satinas » ven. 4 déc. 2020 22:08

Ca tombe bien , je regardais "La flûte enchantée" sur la 5. :-)

Il faudrait ajouter les balises code pour le rendre plus lisible, et au préalable le sauvegarder dans ton éditeur de texte avant avec l'option "remplacer les tabulations par des espaces" pour que les tab passent correctement.

Tu l'as récupéré où ce code ?

PS Jérémy, un zip du projet MpLabX aurait été plus pratique :-)


Retourner vers « Langage ASM »

Qui est en ligne

Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 46 invités