HAPPY BIRTHDAY


Home


PIC Programmer MkV

Instruction Set for PIC12F629
PIC12F629 data
(pdf)
BlankF629.asm

PIC12F629.inc


See more projects using micros:
Pic A PIC Project

Notepad2.zip     Notepad2.exe 
Library of Sub-routines "Cut and Paste
"
Library of routines:   A-E   E-P    P-Z 

 

 

Why spend $10.00 on a Happy Birthday musical card when you can produce the tune yourself.
This project uses just 4 components and a small prototype PC board to produce a project that will teach you a lot about programming.
The circuit uses a piezo diaphragm connected to pins 3 and 5.
That's the only component.
All the work is done by the program.
The project is so easy, we don't need to provide any construction details.


The PIC chip on a prototype PC board

Here are the files:
HappyBirthday.asm
HappyBirthday.hex

Here is the program.
You must use the .hex file to "burn" the chip or the .asm file as these are laid out so that the compiler and programmer can understand the data.
The following program is just for viewing.

;**********************************************
;HAPPY BIRTHDAY TUNE                          * 
;  11-5-2010                                  *
;                                             *
;**********************************************


	list	p=12F629
	radix	dec
	include	"p12f629.inc"
	
	errorlevel  -302 ; Don't complain about BANK 1 Registers 

	__CONFIG	_MCLRE_OFF & _CP_OFF & _WDT_OFF 
                          & _INTRC_OSC_NOCLKOUT  ;Internal osc.


;===============================
;
;       Configuration Bits
;
;===============================


note	equ	21h	;value of HIGH and LOW for note
gap	equ	22h 	;gap between notes - uses "gap_1" delay
loops	equ	23h 	;loops of HIGH/LOW 
temp1	equ	24h 	;temp file for note 
jump	equ	25h
D1	equ	26h	;used in 250mS delay
D2	equ	27h	;used in 250mS delay
D3	equ	28h	;used in 250mS delay
gapDela	equ	29h	;used in gap delay
tempA	equ	2Ah	;used in gap delay



;****************************************************************
;Beginning of program
;****************************************************************
org	0x00
	nop
	nop
	nop
	nop
	nop			
SetUp	bsf	status, rp0 	;Bank 1		
	call    0x3FF       	;retrieve calibration value 
	movwf   OSCCAL      	; 
       	movlw	b'00001011'	;Set TRIS  
	movwf	TRISIO	   	;GP2,4 outputs			
	bcf	status, rp0	;bank 0		
	movlw   07h         	;turn off Comparator 
        movwf   CMCON       	;must be placed in bank 0 
        clrf	jump		;jump value for table		
	goto 	M1		


;****************************************************************
;* Delays 			*
;****************************************************************
	
		
	;gap_1 produces gap between notes - 3rd byte in table
			
gap_1	movlw	.2
	movwf	gapDela
gap_1a	decfsz	tempA
	goto	gap_1a
	decfsz	gapDela,1 ;produces loops
	goto	gap_1a
	decfsz	gap,1	;
	goto	gap_1
	retlw	00	

	
	;250mS second delay
		
_250mS	nop
	goto	$+1		
	decfsz 	D1,1
	goto 	_250mS
	decfsz 	D2,1
	goto 	_250mS		
	retlw 	00	
		

;********************************
;* Table			*
;********************************

table1	addwf   pcl,f   ;02h,1  add W to program counter
	nop		;
	retlw   .100    ;loops - cycles of HIGH/LOW "G" -Hap
	retlw   .142 	;note - value of HIGH/LOW
        retlw   .50     ;gap between notes             
          
        retlw   .100	;"G"-py
        retlw   .142
        retlw   .50        
        
        retlw   .220	;"A"  birth
        retlw   .126
        retlw   .50                
       
        retlw   .200	;"G"   day
        retlw   .142
        retlw   .50       
        
        retlw   .240	;"C"   to
        retlw   .105    
        retlw   .50        
        
        retlw   .240	;"B"   you
        retlw   .113
        retlw   .240        
        
	retlw   .97     ; "G" -Hap
	retlw   .142 	
        retlw   .20              
          
        retlw   .97	;"G"-py
        retlw   .142
        retlw   .20       
        
         retlw   .220	;"A"  birth
        retlw   .126
        retlw   .20                
       
        retlw   .200	;"G"   day
        retlw   .142
        retlw   .20        
         
        retlw   .240	;"D"  to 
        retlw   .94    
        retlw   .20        
         
        retlw   .240	;"C"  you 
        retlw   .105    
        retlw   .240        
        
        retlw   .97     ; "G"   -Hap
	retlw   .142 	
        retlw   .20              
          
        retlw   .97	;"G"  -py
        retlw   .142
        retlw   .20        
        
        retlw   .240	;"G+"- BIRTH
        retlw   .71
        retlw   .1  
        
        retlw   .240	;"G+"- BIRTH
        retlw   .71
        retlw   .20          
        
        retlw   .240	;"E" -day
        retlw   .84
        retlw   .20           
              
        retlw   .240	;"C"  
        retlw   .105    
        retlw   .20        
        
        retlw   .240	;"B" 
        retlw   .113
        retlw   .20
        
        retlw   .220	;"A"  
        retlw   .126
        retlw   .240 
                
        retlw   .240	;"F"  
        retlw   .80
        retlw   .2 
        
        retlw   .240	;"F"  
        retlw   .80
        retlw   .2 
        
        retlw   .240	;"E"
        retlw   .84
        retlw   .2           
        
        retlw   .240	;"C"   
        retlw   .105    
        retlw   .2        
           
        retlw   .240	;"D"   
        retlw   .94    
        retlw   .2
        
        retlw   .240	;"C"   
        retlw   .105    
        retlw   .2
                     
	retlw   0FFh
        

M1	call	_250mS
	call	_250mS
		
Main	incf	jump,1  ;increment pointer 
	movf	jump,w		
	call	table1
	movwf	loops	;first value from table	
	movlw	0ffh
	xorwf	loops,w	;see if value is "0ffh"
	btfsc	status,z
	goto	SetUp			
	incf	jump,1
	movf	jump,w
	call	table1
	movwf	temp1	;temp for note for HIGH/LOW
		
tune	movf	temp1,w
	movwf	note		
	bsf	gpio,2
	bcf	gpio,4
	goto	$+1
	goto	$+1
	goto	$+1
	decfsz	note,1
	goto	$-4		
	movf	temp1,w
	movwf	note		
	bcf	gpio,2
	bsf	gpio,4
	goto	$+1
	goto	$+1
	goto	$+1
	decfsz	note,1
	goto	$-4
	decfsz	loops,f
	goto	tune
	incf	jump,1 ;look for gap value
	movf	jump,w			
	call	table1
	movwf	gap
	bcf	gpio,2	;to produce silence
	bcf	gpio,4	;to produce silence
	call	gap_1	;mS gap
	goto	Main
				
		
	END	
 

GOING FURTHER
This project provides you with the tools to create your own tune or download one of the "old favourites" and annoy everyone in the household with its incessant playing.
 

15/5/2010