Instructables

Step 7: PIC Morse Code

PIC microcontrolers are programed in assembly and can be a bit tricky to learn. I don't really have the time to show you the ins and outs of programing PICs, but I can start you off with a little Morse code program I wrote for the Wii release. You'll need to program the chips before you solder them into the circuit becasue the programing lines are going to be used by the card.

To send a Morse code string use the subroutines "S" for a dot, "L" for a dash, "CS" for a letter separator, and "WS" for a word space.

The sleep command will keep the PIC in a low power state until the button is pressed on the card. Just before sending the PIC to sleep I read the status of the port into the "sandbox" register so that the chip would know how the button changed.

The following code was written for the PIC10F202.

start	init	movlw	b'00010101'			; Configure options (weak pull-up, wake on change)	option 	movlw	0x00				; Future button variable	movwf	state	movlw	0x08				; Set GP0-2 to outputs	tris	GPIOWii	call	S					;WII	call	L	call	L	call	CS	call	S	call	S	call	CS	call	S	call	S	call	WS	call	S					;FOR	call	S	call	L	call	S	call	CS	call	L	call	L	call	L	call	CS	call	S	call	L	call	S	call	WS	call	L					;THE	call	CS	call	S	call	S	call	S	call	S	call	CS	call	S	call	WS		call	S					;WIN	call	L	call	L	call	CS	call	S	call	S	call	CS	call	L	call	S	call	WS	movf	GPIO, W				;Check GPIO for Sleep	nop			sleep	goto	Wii;-------Subs-----------L							; Dash	bcf		GPIO, 0	call	Delay	call	Delay	call	Delay	bsf		GPIO, 0	call	Delay	returnS							; Dot	bcf		GPIO, 0	call	Delay	bsf		GPIO, 0	call	Delay	returnCS							; Space between letters	call	Delay	call	Delay	returnWS							; Space between words	call	Delay	call	Delay	call	Delay	call	Delay	return;------Delays-----------Delay			;199993 cycles	movlw	0x3E	movwf	d1	movlw	0x9D	movwf	d2Delay_0	decfsz	d1, f	goto	$+2	decfsz	d2, f	goto	Delay_0			;3 cycles	goto	$+1	nop			;4 cycles (including call)	return	END                       ; directive 'end of program'
 
Remove these adsRemove these ads by Signing Up