Desde 1994 en la Red. La pagina de los aficionados a la electronica, informatica y otras curiosidades de la vida. No dudes en visitarnos.
Ahora 2 visitas.| 3484499 Visitas (desde Dic. 2011), hoy: 327 Visitas 1000 Pag. Vistas , ultimos 36 dias: 11188 Visitas. 38212 Pag. Vistas. Tu IP: 3.137.173.98
Que ando curioseando:
AutosuficienciaCosas de casaElectronicaEn InternetInformáticaMundo MisticoSin categoríaSociedadTe lo recomiendo

Timbre de puerta polifonico con pic 16F84 Door Chime

ASM

    #include def84.asm
    #include macro84.asm

    errorlevel 2

 	org 0x0C			;start of RAM
;VARIABLES
;*********

masque	res	1
masque1	res	1
compteur0	res	1
compteur1	res	1
compteur2	res	1
compteur3 	res 	1
note0	res	1
note1	res	1
note2	res	1
note3	res	1
play0	res	1
play1	res	1
play2	res	1
play3	res	1

accident      res           1
duree	res	1
vitesse	res	1
c1 	res 	1
ptrmorceaul	res	1
ptrmorceauh	res	1
num_morceau	res	1
num0	res	1

;CONSTANTES
;**********

#define 	fa0d     	.0	;notes
#define 	sol0   	.1
#define 	la0    	.2
#define 	si0b    	.3
#define 	si0    	.4
#define 	do0    	.5
#define 	do0d    	.6
#define 	re0    	.7
#define 	mi0    	.8
#define 	fa1    	.9
#define 	fa1d    	.10
#define 	sol1   	.11
#define 	la1    	.12
#define 	si1b    	.13
#define 	si1    	.14
#define 	do1    	.15

#define 	tcr    	.0	;duration
#define 	dcr    	.1
#define 	cr    	.3
#define 	crp    	.5
#define 	n    	.7
#define 	np    	.11
#define 	b    	.15
#define 	bp    	.23
#define 	r    	.31

#define 	fin      	.1	;event
#define 	tempo      	.2
			; power on-off
#define 	power         porta,0x03

;***********************************
 org 0x0
 Go_to_ Main;

 org 0x04

;interrupt routine
;************************
Begin_
  bcf intcon,toif
  Move vitesse,timer
  movlw 0xF0
  bsf    status,rp0		; begin of charge capacitor program
  iorwf  trisb
  bcf    status,rp0
  Dec  duree			;decrement duration and test if zero
  If_ zero then
  Begin_
    _ Morceau			;if duration=0 then call procedure morceau
  Endif_
retfie

Procedure_ Morceau;
;*****************
Begin_
    Movei  0xFF,masque1		;prepare the capacitor mask
    movlw  0x0F
 _  Morceau0
    Move   wreg,accident		;get duration and pitch
    Move   wreg,duree
    swapf  accident
    rrf    accident
    Andi   accident,0x07
    Andi   duree,0x1F
    Inc    duree                  ; 1 to 32
    bcf    carry
    rlf    duree
    bcf    carry
    rlf    duree

    If_eqi accident,fin then		;the end : power off
      bcf  power
la    goto  la
    Endif_
    If_eqi accident,tempo then
      Move duree,vitesse
      Addi 0x03,ptrmorceaul
      If_ carry
        Inc ptrmorceauh
      Endif_
      Go_to_ Morceau
    Endif_

    Inc  ptrmorceaul		; get number of notes to interpret PLAY0...PLAY3
    If_   zero
      Inc  ptrmorceauh
    Endif_
 _  Morceau0
    Move   wreg,play0
    Move   wreg,play1
    swapf play0
    Andi  play0,0x0F
    Andi  play1,0x0F

    Inc   ptrmorceaul
    If_   zero
      Inc  ptrmorceauh
    Endif_
 _  Morceau0
    Move   wreg,play2
    Move   wreg,play3
    swapf play2
    Andi  play2,0x0F
    Andi  play3,0x0F

    Inc  ptrmorceaul
    If_   zero
      Inc  ptrmorceauh
    Endif_

    Movei high Tabnote,pch		;get value for charging capacitors
    Move  play0,wreg
    If_not zero then
   _  Tabnote
      Move wreg,note0
      bcf   masque1,0x7		; capacitor 0
    Endif_

    Movei high Tabnote,pch
    Move  play1,wreg
    If_not zero then
   _  Tabnote
      Move wreg,note1
      bcf   masque1,0x6		; capacitor 1
    Endif_

    Movei high Tabnote,pch
    Move  play2,wreg
    If_not zero then
   _  Tabnote
      Move wreg,note2
      bcf   masque1,0x5		; capacitor 2
    Endif_

    Movei high Tabnote,pch
    Move  play3,wreg
    If_not zero then
   _  Tabnote
      Move wreg,note3
      bcf   masque1,0x4		; capacitor 3
    Endif_

    Move  masque1,wreg		; update outputs RB4..RB7 for envelop generation
    bsf   status,rp0
    And   trisb,wreg
    bcf   status,rp0
End_

Procedure_ Write; 		; Write to EEPROM
;***************
Begin_
   bsf   	status,rp0
   bsf   	eecon1,wren
   Movei 	0x55,eecon2
   Movei 	0xaa,eecon2
   bsf   	eecon1,wr
   Repeat_
   Until_ 	eecon1,eeif
   bcf   	eecon1,wren
   bcf   	eecon1,eeif
   bcf   	status,rp0
End_

Procedure_ Read;		; Read from EEPROM
;***************
Begin_
   bsf    	status,rp0
   bsf    	eecon1,rd
   bcf    	status,rp0
   bsf    	intcon,gie
   Move  	eedata,wreg
End_

Procedure_ Init;
;**************
Begin_
   Movei    0xF0,portb
   Movei    0x00,porta
   bsf      power
   bsf      status,rp0   		;page 1 >0x80..
   Movei    0x0,trisa
   Movei    0xFF,trisb		;port B as input;

   Clr      intcon       		; clear interrupts
   Clr      roption
   bcf      roption,psa   		;timer divisor=max
   bsf      roption,ps0
   bsf      roption,ps1
   bsf      roption,ps2
   bcf      roption,t0cs  		;timer 0 clock source=clock  Q/4
   bsf      roption,rbpu		;
   bcf      status,rp0

   Movei    0x00,eeadr		; read songnumber from EEPROM
 _ Read
   Move     wreg,num0
   Movei    0x01,eeadr
 _ Read
   xorwf    num0,wreg
   addlw    0x01
   If_not   zero then		; Error : rewrite songnumber
   Begin_
     Clr    eeadr
     Clr    eedata
   _ Write
     Movei  0x01,eeadr
     Movei  0xFF,eedata
   _ Write
   Else_
     Inc    num0		;increment songnumber
     If_eqi num0,0x08
       Clr  num0
     Endif_
     Move   num0,eedata
     Clr    eeadr
   _ Write			;save songnumber to EEPROM
     comf   num0,wreg
     Move   wreg,eedata
     Inc    eeadr
   _ Write
   Endif_

   Movei high Tabmorceau,pch	; search for start of song to play
   bcf   carry
   rlf   num0,wreg
 _ Tabmorceau
   Move  wreg,ptrmorceauh
   Movei high Tabmorceau,pch
   rlf   num0,wreg
   addlw 0x01
 _ Tabmorceau
   Move  wreg,ptrmorceaul
   bsf   intcon,toie  		; enable timer interrupt
   Clr   c1
   Movei .1,duree
   Movei 0xFF,timer
End_

Procedure_ Play;
;**************
Begin_
debut
    bsf   intcon,gie		; enable global interrupt (timer)
    clrf  masque		; initialize mask
    bcf   intcon,gie		; disable interrupt

    Decf  compteur0		; decrement counter for note generation
    btfsc zero			; if not zero:
    goto  a0			; reload counter
b0  Dec   compteur1		; counter1
    btfsc zero
    goto  a1
b1  Dec   compteur2		; counter2
    btfsc zero
    goto  a2
b2  Dec   compteur3		; counter3
    btfsc zero
    goto  a3
b3  Move  masque,wreg
    Bset  banque1
    Xor   trisb,wreg		;invert selected outputs RBO..RB3 (square wave)
    Bclr  banque1
    goto  debut

a0   Move note0,compteur0	; reload counter
     bsf  masque,0x00		; update mask
     goto b0
a1   Move note1,compteur1
     bsf  masque,0x01
     goto b1
a2   Move note2,compteur2
     bsf  masque,0x02
     goto b2
a3   Move note3,compteur3
     bsf  masque,0x03
     goto b3
End_

Program_ Main;
;******************
Begin_
_ Init;
_ Play;
End_

 #include morceau.asm

End__

HEX CARRILLON

:020000040000FA
:02000000F728DF
:080008000B111C088100F0300F
:100010008316860483129B03031D0F2810200900FA
:10002000FF308D000F3000219A009B009A0E9A0C31
:1000300007309A051F309B059B0A03109B0D031088
:100040009B0D01301A02031926282828851127281C
:1000500002301A0203192D2835281B089C00033092
:100060009E07031C34289F0A10289E0A031D392866
:100070009F0A002196009700960E0F3096050F30CC
:1000800097059E0A031D45289F0A002198009900A4
:10009000980E0F3098050F3099059E0A031D5128C0
:1000A0009F0A03308A00160803195928E02392009A
:1000B0008D1303308A00170803196128E023930089
:1000C0000D1303308A00180803196928E0239400EF
:1000D0008D1203308A00190803197128E023950056
:1000E0000D120D0883168605831208008316081565
:1000F00055308900AA3089008814081E7D2808110F
:100100000812831208008316081483128B1708083C
:100110000800F03086000030850085158316003019
:100120008500FF3086008B0181018111011481144B
:100130000115811281178312003089008320A100EC
:100140000130890083202106013E0319B02889016E
:100150008801762001308900FF3088007620BF2892
:10016000A10A083021020319B628B728A1012108E5
:1001700088008901762021098800890A76200330C9
:100180008A000310210DC8239F0003308A00210D2F
:10019000013EC8239E008B169D0101309B00FF305D
:1001A000810008008B178C018B138E030319E6283E
:1001B0008F030319EA2890030319EE28910303190A
:1001C000F2280C08831686068312D22812088E00A5
:1001D0000C14D82813088F008C14DB281408900006
:1001E0000C15DE28150891008C15E12808008920DF
:0401F000D220080011
:100200001F088A001E0882004A34003400340F346C
:100210000034003405348134503461348034003487
:100220000334803400340334903400340734B13460
:100230005834073480340034053491344734013461
:10024000803400340334903400340334F034003408
:100250000F34E134473405347134403401347034A0
:1002600000340334703400340334803400340B34ED
:10027000913447340334B03400340334E1349734D8
:100280000334C03400340334B034003403349034C5
:1002900000341F3485341B343F34003400340F34B1
:1002A000003400345F3400340034073480340034C8
:1002B0000F3405348B340734803400340F34053464
:1002C00081340734803400340734B5348B3403343C
:1002D000B034003403348034003403340534003443
:1002E0000334803400340F3471344B340734903489
:1002F00000340F3441349B340734703400340F34ED
:1003000017344B3407347034003407349134473495
:1003100003349034003403347034003403344034F4
:1003200000340334703400341F3451348F343F347C
:10033000003400340F34003400340334703400349B
:1003400003347034003407347A342C3407342034C6
:1003500000340334A03400340334A03400340734B0
:10036000A7342C3407347034003403347034003430
:100370000334A03400340B34C734AC340334C034F9
:1003800000340334B03400340334A03400348F34E8
:10039000823461340334803400340334A0340034B4
:1003A0008B34B23461340334B03400340334A034B9
:1003B00000340334803400340734AA342C34073436
:1003C000703400340334703400340334A034003407
:1003D0008734823461340734203400340334603489
:1003E00000340334803400341F3470342A343F34F2
:1003F000003400340F3400340034003450340034FE
:100400000034803400340034B03400340334F53424
:100410008B340334B03400340334B0340034033448
:10042000B03400340334F03400340334B0340034D6
:100430000334B03400340334B03400340334F534BE
:100440008B340334B03400340334B0340034033418
:10045000903400340F34803400340334503400348A
:100460000334703400340334803400340334903463
:1004700000340734B53481340734B03400340334E5
:10048000C53409340334C03400340334E134473410
:100490000334E03400340F34F1348B343F3400340F
:1004A00000340F34003400344A3400340034033450
:1004B000703400340334B03400340334B0340034C6
:1004C0000334E03400340334E03400340734B0340F
:1004D0000034033470340034033470340034033493
:1004E000703400340334703400340134C0340034C8
:1004F0000134B03400340134A03400340134803489
:1005000000340B347034003403347034003403345A
:10051000B13447340334B03400340334E0340034AD
:100520000334E03400340734B134473403347034D6
:1005300000340334B03400340334A7342C34013491
:10054000803400340134A03400340334B2346834CD
:100550000334603400340B3470342A343F340034B4
:1005600000340F340034003407348034003407344E
:1005700025348C34033420340034033440340034C4
:10058000073452348C340334503400340334703420
:1005900000340734803400340734803400340734A6
:1005A00071344E340334B03400340334B034003486
:1005B0000F3482345C340334203400340334503438
:1005C00000340734713440341F3471344B343F34B9
:1005D000003400345434003400340F340034003418
:1005E0000334503400340334C03400340334C03492
:1005F00000340334C03400340334C2345934033477
:10060000C03400340334B53481340334B03400349E
:100610000F3495342C340F34503400340334C03448
:1006200000340334C03400340334C03400340334A1
:10063000C03400340F34F13480340F34D13470348A
:100640001F34C93452343F34003400345F34003432
:1006500000340F34003400340034403400340034AB
:1006600050340034003460340034033474341034B3
:100670000F344034003403344034003403345034F5
:1006800000340334703400340034B03400340034A7
:10069000C03400340534E13447340734E0340034E6
:1006A0000F34B1347B3400344034003400345034DF
:1006B00000340034603400340334743410340F34A4
:1006C00040340034033440340034033450340034B4
:1006D000033440340034073471344E3407347034FA
:0E06E00000340F3452347C343F340034003484
:1007900082070134043401344F3401349A34013473
:1007A000FA34023451340234B1340234EA340334BA
:0207B0002634ED
:1007C0008207FE34F034D634CA34BE34B434AA348A
:1007D000A0348F3487347F3478346B3465345F349D
:0207E0005A3489
:00000001FF

Fuente: http://elektrobilim.org/forum/pic-yardim-soru-ve-istekler/2187-16f84-ile-polifonik-kapi-zili.html

Escribe un comentario

Tu comentario