NIM


Home


 
Kits are available for this project from
Talking Electronics for $12.00 plus $6.50 postage.
 

 

This project shows what can be done with an 8-pin microcontroller.

NIM is a game played with 19 matches.
The aim is to take one, two or three matches and leave your opponent with the last match.

With this project you play against the "computer" and try to win.
Computers are ideal to show "intelligence."
By coding all the possible combinations and outcomes of a particular situation, the micro is able to diagnose a situation very quickly and come up with an answer that appears to have intelligence.
Alternatively you can approach a problem mathematically and come up with a result.
Many games have an underlying "strategy" and this game is an example.
By knowing this strategy and producing simple routines to analyse each stage of the game we can achieve a result that does not need any complex mathematical interpretation. 
The result is called "linear programming" in which the micro advances down the program according to the input it gets.
This part of the program requires very few instructions. The bulk of the instructions are needed to produce a display.
Since we have only 5 lines to drive 9 segments of a 1.5 digit display, we must use clever circuitry to illuminate any or all the 9 segments.
This is done in a form of scanning/multiplexing, that has never been presented before.
Obviously we cannot "dump" or dive the LEDs constantly because this will only illuminate a maximum of 5 segments.
We need to "time-share" the segments with two on each output. This provides up to 10 segments from 5 lines.
The LEDs on each output are arranged so one segment turns on when the output is HIGH and the other turns on when the output is LOW.
To prevent the LEDs turning on when the output is not driving either, we put two LEDs on each segment.
This means the characteristic voltage drop across 4 LEDs is about 7v and none will turn on.
The remainder of the program is taken up providing effects, such as pulsing the display, debouncing the switch and timing the players response then producing the computers response after 2 seconds.


The complete NIM GAME


The surface-mount components are mounted on the underside


The CIRCUIT
The circuit consists of a single tactile button, 18 LEDs and an 8-pin microcontroller
The one-and-a-half digit display is made up of individual LEDs, with two LEDs in series for each segment. This gives a voltage drop of approx 3.4v and a 22R current-limit resistor is needed. The diode on the input reduces the supply to 5.4v when the two lithium cells are new as the micro can only accept up to 5.5v.
 


NIM CIRCUIT
The display has 2 yellow LEDs in series for each segment

CONSTRUCTION
The project is built on a small PC board with the surface mount components on the underside. The surface mount LEDs are an old-style with three legs.
You just need tweezers, fine solder and a temperature-controller iron to produce a very neat result.
Place solder on one land then sit the component in place and heat the solder very quickly. The l\LEDs must be soldered very quickly otherwise they will lose their brightness. 3 extra LEDs are included in the kit as replacements for any LEDs that have been damaged.


MORE
For more details on modifying the program and burning the PIC chip, see Talking Electronics website and click on Elektor,EPE,Silicon Chip in the index.
You can find details of: 
PICkit-2 and Adapter connected for In-Circuit Programming at this link.


Here is the file you will need for "burning" your chip and/or modifying the program. It comes as .asm, .txt and .hex for using as a file to modify, or to read, or to burn a new chip:

Nim.asm
Nim.txt
Nim.hex

The kit comes with a pre-programmed PIC chip, see parts list below.
	
;****************************************************************

	;Nim  for 12F629.asm
	;  5-7-2014 


	list	p=12F629
	radix	dec
	include	"p12f629.inc"
	
	__CONFIG	
    _MCLRE_OFF & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT  ;Internal osc.

	
	; globals
counter		equ 	20h		;this is the first available file
tempA		equ 	21h
tempB		equ	22h
flickA		equ	23h
timerA		equ	24h

random		equ	25h

fileA		equ	26h
fileB		equ	27h	
fileC		equ	28h
fileD		equ	29h	

filezz		equ	5Fh	;this is the last available file

status		equ	03h
option_reg	equ 	81h


		; bits on GPIO
				
pin7		equ	0	;GP0  
pin6	 	equ	1	;GP1
pin5		equ	2	;GP2 and T0CkI
pin4		equ	3	;GP3 input only
pin3		equ	4	;GP4 
pin2		equ	5	;GP5 


						;bits
				
rp0		equ	5	;bit 5 of the status register
		

Start	org	0x00		;program starts at location 000
		nop
		nop
		nop
		nop		;NOPs to get past reset vector address
		nop
		nop


								

SetUp	bsf	status, rp0 	;Bank 1	
	movlw	b'11110111'	;Turn on T0CKI, prescale for TMR0 = 1:256
	movwf	option_reg
       	bcf	status, rp0	;bank 0   
	movlw   07h         	;Set up W to turn off Comparator ports
        movwf   CMCON       	;must be placed in bank 0  
	clrf 	GPIO       	;Clear GPIO of junk		
	goto 	Main	
		


	;Delay 0.01 sec (10mS)


	;1mS delay
		
_1mS	decfsz	fileA,1			 
	goto 	_1mS	 	
	retlw	00
		

_10mS	movlw 	0Ah
	movwf 	fileB	
DelY	nop
	decfsz 	fileA,1		
	goto 	DelY	
	decfsz 	fileB,1		
	goto 	DelY
	retlw 	00
	
	;100mS delay
							
_100mS	movlw	60h	
	movwf	fileB
BB	call	_1mS
	decfsz 	fileB,1
	goto	BB	
	retlw	00	
		
		
_500mS	movlw	32h	
	movwf	fileC
CC	call	_10mS
	decfsz 	fileC,1
	goto	CC	
	retlw	00
 
		
		
	;Clear the screen
		
clr500mS
	bsf	status, rp0 	;Bank 1			
	movlw	b'11111111'	;
	movwf	TRISIO	   	;	
	bcf	status, rp0	;bank 0 
	call	_500mS
	retlw 	00


_1to19	
	clrf	fileD
	bsf	fileD,3		;create 8h loops for each number  0000 1000
	call	show1
	bsf	fileD,3	
	call	show2
	bsf	fileD,3
	call	show3
	bsf	fileD,3			
	call	show4
	bsf	fileD,3
	call	show5
	bsf	fileD,3			
	call	show6
	bsf	fileD,3
	call	show7
	bsf	fileD,3			
	call	show8
	bsf	fileD,3
	call	show9
	bsf	fileD,3			
	call	show10
	bsf	fileD,3		
	call	show11	
	bsf	fileD,3		
	call	show12
	bsf	fileD,3
	call	show13
	bsf	fileD,3		
	call	show14
	bsf	fileD,3
	call	show15
	bsf	fileD,3		
	call	show16
	bsf	fileD,3
	call	show17
	bsf	fileD,3
	call	show18
	bsf	fileD,3	
	call	show19
	retlw	00
		
		
		
show1	bsf	status, rp0 	;Bank 1			
       	movlw	b'11001101'	;
	movwf	TRISIO	   	;	
	bcf	status, rp0	;bank 0  		
	movlw	b'00100110'	;  
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11111111'	;Set GP1,2 4 5 input to reduce brightness
	movwf	TRISIO	   	;	
	bcf	status, rp0	;bank 0  		
	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	show1
	retlw 	00				
		
		
		
		
show2	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101001'	; 
	movwf	TRISIO	   	;	
	bcf	status, rp0	;bank 0  		
	movlw	b'00010000'		;
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11011101'	;
	movwf	TRISIO	   	;	
	bcf	status, rp0	;bank 0  
	movlw	b'00000010'	;make GP 1 low   
	movwf	GPIO		
	call 	_10mS		
	decfsz 	fileD,1		;  	
	goto 	show2
	retlw 	00
		
		
show3	bsf	status, rp0 	;Bank 1			
       	movlw	b'11001101'	; 
	movwf	TRISIO	       ;	
	bcf	status, rp0	;bank 0  		
	movlw	b'00000000'		;   
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101101'	;
	movwf	TRISIO	       ;	
	bcf	status, rp0	;bank 0  
	movlw	b'00010010'		;
	movwf	GPIO		
	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	show3
	retlw 	00	
		
		
show4	bsf	status, rp0 	;Bank 1			
       	movlw	b'11011111'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00010000'		;   
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11100001'		;  
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  
	movlw	b'00000110'		;   
	movwf	GPIO	
	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	show4
	retlw 	00		
		
		
		
show5	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101001'		; 
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00000100'		; 
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11001111'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  
	movlw	b'00010000'		;  
	movwf	GPIO	

	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	show5
	retlw 	00			
	
	
		
show6	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101001'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00000000'		;  
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11001011'		; 
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  
	movlw	b'00010100'		;   
	movwf	GPIO	

	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	show6
	retlw 	00		
		
		
show7	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101101'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00000001'		;   
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11111101'		; 
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  
	movlw	b'00000011'		; 
	movwf	GPIO	

	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	show7
	retlw 	00				


		
show8	bsf	status, rp0 	;Bank 1			
       	movlw	b'11001001'		; 
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00000000'		;   
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101001'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  
	movlw	b'00010110'		;   
	movwf	GPIO	

	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	show8
	retlw 	00				
				
		
show9	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101001'	;
	movwf	TRISIO	       ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00000100'		; 
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11001101'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  
	movlw	b'00010010'		;
	movwf	GPIO	

	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	show9
	retlw 	00		
		
		
show10	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101000'		; 
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00000001'		;    
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101000'		;   
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  
	movlw	b'00010111'		;   
	movwf	GPIO	

	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	show10
	retlw 	00	
			
		
show11	bsf	status, rp0 	;Bank 1			
       	movlw	b'11111100'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00100111'		;  
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101110'		;
	movwf	TRISIO	   	    ;	
	bcf		status, rp0		;bank 0
	movlw	b'00000001'		;  
	movwf	GPIO
 		
	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	show11
	retlw 	00				
				
show12	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101000'	;
	movwf	TRISIO	   	;	
	bcf	status, rp0	;bank 0  		
	movlw	b'00010001'	;
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11011100'	;
	movwf	TRISIO	       ;	
	bcf	status, rp0	;bank 0  
	movlw	b'00000011'		;   
	movwf	GPIO		
	call 	_10mS		
	decfsz 	fileD,1		;  	
	goto 	show12
	retlw 	00
		
		
show13	bsf	status, rp0 	;Bank 1			
       	movlw	b'11001100'	; 
	movwf	TRISIO	      ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00000001'		;   
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101100'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  
	movlw	b'00010011'		;
	movwf	GPIO		
	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	show13
	retlw 	00	
		
		
show14	bsf	status, rp0 	;Bank 1			
       	movlw	b'11001010'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00000101'		;   
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11111100'		;  
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  
	movlw	b'00000011'		;   
	movwf	GPIO	
	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	show14
	retlw 	00		
		
		
		
show15	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101000'		; 
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00000101'		; 
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11001110'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  
	movlw	b'00010001'		;  
	movwf	GPIO	

	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	show15
	retlw 	00			
	
	
		
show16	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101000'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00000001'		;  
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11001010'		; 
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  
	movlw	b'00010101'		;   
	movwf	GPIO	

	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	show16
	retlw 	00		
		
show17	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101100'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00000001'		;   
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11111100'		; 
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  
	movlw	b'00000011'		; 
	movwf	GPIO	

	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	show17
	retlw 	00				


		
show18	bsf	status, rp0 	;Bank 1			
       	movlw	b'11001000'		; 
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00000001'		;   
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11100000'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  
	movlw	b'00010111'		;   
	movwf	GPIO	

	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	show18
	retlw 	00				
				
		
show19	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101000'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00000101'		; 
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11001100'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  
	movlw	b'00010011'		;
	movwf	GPIO	

	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	show19
	retlw 	00	
		
		
showU	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101011'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00000000'		; 
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101001'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  
	movlw	b'00010110'		;
	movwf	GPIO	

	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	showU
	retlw 	00	

showL	bsf	status, rp0 	;Bank 1			
       	movlw	b'11111011'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00000000'		; 
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101011'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  
	movlw	b'00010100'		;
	movwf	GPIO	

	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	showL
	retlw 	00	

showO	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101001'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00000000'		; 
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11101001'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  
	movlw	b'00010110'		;
	movwf	GPIO	

	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	showO
	retlw 	00	

showE	bsf	status, rp0 	;Bank 1			
       	movlw	b'11111001'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  		
	movlw	b'00000000'		; 
	movwf	GPIO
	call 	_10mS
	bsf	status, rp0 	;Bank 1			
       	movlw	b'11001011'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0  
	movlw	b'00010100'		;
	movwf	GPIO	

	call 	_10mS		
	decfsz 	fileD,1			;  	
	goto 	showE
	retlw 	00			
		
		
			
flicker	movlw	10h
	movwf	flickA
ff	bsf	status, rp0 	;Bank 1			
       	movlw	b'11111111'		;
	movwf	TRISIO	   	    ;	
	bcf	status, rp0		;bank 0 
	call	_1mS
	call	_1mS		
	decfsz	flickA,1
	goto	ff
	retlw 	00	
		
	
	
	
	
	
Main	clrf	fileD
	call	_1to19		;show numbers 1 to 19 on display
Maina	bsf	fileD,3
	call 	show19
	btfsc	GPIO,3		;will be zero when button pushed
	goto	Maina
		
		
		
	movlw	10h
	movwf	tempA
Main19	bsf	fileD,1
	call 	show19
	call	flicker
	decfsz	tempA,1
	goto	Main19			
Main19a	bsf	fileD,3
	call 	show19	
	btfss	GPIO,3		
	goto	Main19a
		
	call	clr500mS
								
	movlw	01Fh
	movwf	timerA	
Main18c	bsf	fileD,3
	call 	show18
	call 	_1mS
	btfss	GPIO,3		;will be zero when button pushed
	goto	Main18		;player has pushed button
	decfsz	timerA,1
	goto	Main18c
	goto	comp18	;player has ended his turn (run out of time)
		
		
		
		

Main18	movlw	10h
	movwf	tempA
Main18a	movf	tempA,0		
	movwf	flickA
	bsf	fileD,1
	call 	show18
	call	flicker
	decfsz	tempA,1
	goto	Main18a			
Main18b	bsf	fileD,3
	call 	show18		
	btfss	GPIO,3		
	goto	Main18b
		
	call 	clr500mS
		
	movlw	01Fh
	movwf	timerA	
Main17c	bsf	fileD,3
	call 	show17
	call 	_1mS
	btfss	GPIO,3		;will be zero when button pushed
	goto	Main17		;player has pushed button
	decfsz	timerA,1
	goto	Main17c
	goto	comp17		
	

Main17	movlw	10h
	movwf	tempA
Main17a	movf	tempA,0		
	movwf	flickA
	bsf	fileD,1
	call 	show17
	call	flicker
	decfsz	tempA,1
	goto	Main17a			
Main17b	bsf	fileD,3
	call 	show17		
	btfss	GPIO,3		;button must be released to get past here
	goto	Main17b
		
	call 	clr500mS
		
	movlw	01Fh
	movwf	timerA	
Main16c	bsf	fileD,3
	call 	show16
	call 	_1mS
	btfss	GPIO,3		;will be zero when button pushed
	goto	Main16		;player has pushed button
	decfsz	timerA,1
	goto	Main16c
	goto	comp16		Main16	movlw	10h
	movwf	tempA
Main16a	movf	tempA,0		
	movwf	flickA
	bsf	fileD,1
	call 	show16
	call	flicker
	decfsz	tempA,1
	goto	Main16a			
Main16b	bsf	fileD,3
	call 	show16		
	btfss	GPIO,3		
	goto	Main16b
		
	call 	clr500mS
		
	movlw	01Fh
	movwf	timerA	
Main15c	bsf	fileD,3
	call 	show15
	call 	_1mS
	btfss	GPIO,3		;will be zero when button pushed
	goto	Main15		;player has pushed button
	decfsz	timerA,1
	goto	Main15c
	goto	comp15		



	

Main15	movlw	10h
	movwf	tempA
Main15a	movf	tempA,0		
	movwf	flickA
	bsf	fileD,1
	call 	show15
	call	flicker
	decfsz	tempA,1
	goto	Main15a			
Main15b	bsf	fileD,3
	call 	show15		
	btfss	GPIO,3		
	goto	Main15b
		
	call 	clr500mS
		
	movlw	01Fh
	movwf	timerA	
Main14c	bsf	fileD,3
	call 	show14
	call 	_1mS
	btfss	GPIO,3		;will be zero when button pushed
	goto	Main14			;player has pushed button
	decfsz	timerA,1
	goto	Main14c
	goto	comp14		

Main14	movlw	10h
	movwf	tempA
Main14a	movf	tempA,0		
	movwf	flickA
	bsf	fileD,1
	call 	show14
	call	flicker
	decfsz	tempA,1
	goto	Main14a			
Main14b	bsf	fileD,3
	call 	show14		
	btfss	GPIO,3		;button must be released to get past here
	goto	Main14b
		
	call 	clr500mS
		
	movlw	01Fh
	movwf	timerA	
Main13c	bsf	fileD,3
	call 	show13
	call 	_1mS
	btfss	GPIO,3	;will be zero when button pushed
	goto	Main13		;player has pushed button
	decfsz	timerA,1
	goto	Main13c
	goto	comp13	;player has ended his turn (run out of time)

	
Main13	movlw	10h
	movwf	tempA
Main13a	movf	tempA,0		
	movwf	flickA
	bsf	fileD,1
	call 	show13
	call	flicker
	decfsz	tempA,1
	goto	Main13a			
Main13b	bsf	fileD,3
	call 	show13		
	btfss	GPIO,3		;button must be released to get past here
	goto	Main13b
		
	call 	clr500mS
		
	movlw	01Fh
	movwf	timerA	
Main12c	bsf	fileD,3
	call 	show12
	call 	_1mS
	btfss	GPIO,3		;will be zero when button pushed
	goto	Main12		;player has pushed button
	decfsz	timerA,1
	goto	Main12c
	goto	comp12		

	
Main12	movlw	10h
	movwf	tempA
Main12a	movf	tempA,0		
	movwf	flickA
	bsf	fileD,1
	call 	show12
	call	flicker
	decfsz	tempA,1
	goto	Main12a			
Main12b	bsf	fileD,3
	call 	show12		
	btfss	GPIO,3		;button must be released to get past here
	goto	Main12b
		
	call 	clr500mS
		
	movlw	01Fh
	movwf	timerA	
Main11c	bsf	fileD,3
	call 	show11
	call 	_1mS
	btfss	GPIO,3		;will be zero when button pushed
	goto	Main11		;player has pushed button
	decfsz	timerA,1
	goto	Main11c
	goto	comp11		
		
		
Main11	movlw	10h
	movwf	tempA
Main11a	movf	tempA,0		
	movwf	flickA
	bsf	fileD,1
	call 	show11
	call	flicker
	decfsz	tempA,1
	goto	Main11a			
Main11b	bsf	fileD,3
	call 	show11		
	btfss	GPIO,3		
	goto	Main11b
		
	call 	clr500mS
		
	movlw	01Fh
	movwf	timerA	
Main10c	bsf	fileD,3
	call 	show10
	call 	_1mS
	btfss	GPIO,3		;will be zero when button pushed
	goto	Main10			;player has pushed button
	decfsz	timerA,1
	goto	Main10c
	goto	comp10		
		
		
Main10	movlw	10h
		movwf	tempA
Main10a	movf	tempA,0		
	movwf	flickA
	bsf	fileD,1
	call 	show10
	call	flicker
	decfsz	tempA,1
	goto	Main10a			
Main10b	bsf	fileD,3
	call 	show10		
	btfss	GPIO,3		
	goto	Main10b
		
	call 	clr500mS
		
	movlw	01Fh
	movwf	timerA	
Main9c	bsf	fileD,3
	call 	show9
	call 	_1mS
	btfss	GPIO,3		;will be zero when button pushed
	goto	Main9		;player has pushed button
	decfsz	timerA,1
	goto	Main9c
	goto	comp9		


		
Main9	movlw	10h
	movwf	tempA
Main9a	movf	tempA,0		
	movwf	flickA
	bsf	fileD,1
	call 	show9
	call	flicker
	decfsz	tempA,1
	goto	Main9a			
Main9b	bsf	fileD,3
	call 	show9		
	btfss	GPIO,3		
	goto	Main9b
		
	call 	clr500mS
		
	movlw	01Fh
	movwf	timerA	
Main8c	bsf	fileD,3
	call 	show8
	call 	_1mS
	btfss	GPIO,3		;will be zero when button pushed
	goto	Main8		;player has pushed button
	decfsz	timerA,1
	goto	Main8c
	goto	comp8		
		
				
Main8	movlw	10h
	movwf	tempA
Main8a	movf	tempA,0		
	movwf	flickA
	bsf		fileD,1
	call 	show8
	call	flicker
	decfsz	tempA,1
	goto	Main8a			
Main8b	bsf	fileD,3
	call 	show8		
	btfss	GPIO,3		
	goto	Main8b
		
	call 	clr500mS
		
	movlw	01Fh
	movwf	timerA	
Main7c	bsf	fileD,3
	call 	show7
	call 	_1mS
	btfss	GPIO,3		;will be zero when button pushed
	goto	Main7			;player has pushed button
	decfsz	timerA,1
	goto	Main7c
	goto	comp7		
		
Main7	movlw	10h
	movwf	tempA
Main7a	movf	tempA,0		
	movwf	flickA
	bsf	fileD,1
	call 	show7
	call	flicker
	decfsz	tempA,1
	goto	Main7a			
Main7b	bsf	fileD,3
	call 	show7		
	btfss	GPIO,3		
	goto	Main7b
		
	call 	clr500mS
		
	movlw	01Fh
	movwf	timerA	
Main6c	bsf	fileD,3
	call 	show6
	call 	_1mS
	btfss	GPIO,3		;will be zero when button pushed
	goto	Main6		;player has pushed button
	decfsz	timerA,1
	goto	Main6c
	goto	comp6	
		
			
Main6	movlw	10h
	movwf	tempA
Main6a	movf	tempA,0		
	movwf	flickA
	bsf	fileD,1
	call 	show6
	call	flicker
	decfsz	tempA,1
	goto	Main6a			
Main6b	bsf	fileD,3
	call 	show6		
	btfss	GPIO,3		;button must be released to get past here
	goto	Main6b
		
	call 	clr500mS
		
	movlw	01Fh
	movwf	timerA	
Main5c	bsf	fileD,3
	call 	show5
	call 	_1mS
	btfss	GPIO,3		;will be zero when button pushed
	goto	Main5		;player has pushed button
	decfsz	timerA,1
	goto	Main5c
	goto	comp5	
	
	
	
Main5	movlw	10h
	movwf	tempA
Main5a	movf	tempA,0		
	movwf	flickA
	bsf	fileD,1
	call 	show5
	call	flicker
	decfsz	tempA,1
	goto	Main5a			
Main5b	bsf	fileD,3
	call 	show5		
	btfss	GPIO,3		;button must be released to get past here
	goto	Main5b
		
	call 	clr500mS
		
	movlw	01Fh
	movwf	timerA	
Main4c	bsf	fileD,3
	call 	show4
	call 	_1mS
	btfss	GPIO,3		;will be zero when button pushed
	goto	Main4		;player has pushed button
	decfsz	timerA,1
	goto	Main4c
	goto	comp4		
		
		
Main4	movlw	10h
	movwf	tempA
Main4a	movf	tempA,0		
	movwf	flickA
	bsf	fileD,1
	call 	show4
	call	flicker
	decfsz	tempA,1
	goto	Main4a			
Main4b	bsf	fileD,3
	call 	show4		
	btfss	GPIO,3		;button must be released to get past here
	goto	Main4b
		
	call 	clr500mS
		
	movlw	01Fh
	movwf	timerA	
Main3c	bsf	fileD,3
	call 	show3
	call 	_1mS
	btfss	GPIO,3		;will be zero when button pushed
	goto	Main3		;player has pushed button
	decfsz	timerA,1
	goto	Main3c
	goto	comp3		
			
Main3	movlw	10h
	movwf	tempA
Main3a	movf	tempA,0		
	movwf	flickA
	bsf	fileD,1
	call 	show3
	call	flicker
	decfsz	tempA,1
	goto	Main3a			
Main3b	bsf	fileD,3
	call 	show3		
	btfss	GPIO,3		;button must be released to get past here
	goto	Main3b
		
	call 	clr500mS
		
	movlw	01Fh
	movwf	timerA	
Main2c	bsf	fileD,3
	call 	show2
	call 	_1mS
	btfss	GPIO,3		;will be zero when button pushed
	goto	Main2		;player has pushed button
	decfsz	timerA,1
	goto	Main2c
	goto	Main1c	;player has ended his turn (run out of time)


Main2	movlw	10h
	movwf	tempA
Main2a	movf	tempA,0		
	movwf	flickA
	bsf	fileD,1
	call 	show2
	call	flicker
	decfsz	tempA,1
	goto	Main2a			
Main2b	bsf	fileD,3
	call 	show2		
	btfss	GPIO,3		;button must be released to get past here
	goto	Main2b
		
	call 	clr500mS
		
	bsf	fileD,7
	call 	show1
	call 	clr500mS	
	bsf	fileD,6
	call	showO
	call 	clr500mS		
	goto	Main
		
Main1c	clrf	fileD
	call 	clr500mS
	bsf	fileD,4
	call 	show1
	call 	clr500mS
	bsf	fileD,4
	call 	show1
	call 	clr500mS
	bsf	fileD,4
	call 	show1
	call	clr500mS
	call	clr500mS
	bsf	fileD,4
	call	showU
	call	clr500mS
	bsf	fileD,4
	call	showL
	call	clr500mS
	bsf	fileD,4
	call	showO
	call	clr500mS
	bsf	fileD,4
	call	show5
	call	clr500mS
	bsf	fileD,4
	call	showE
	call	clr500mS
	call	clr500mS
	goto	Main
		
			
comp18	call 	clr500mS
	bsf	fileD,6
	call 	show17
	call 	clr500mS
	goto	Main16c
		
comp17	call 	clr500mS
	goto	Main16c		
		
		
comp16	call 	clr500mS
	bsf	fileD,6
	call 	show15
	call 	clr500mS
	bsf	fileD,6
	call 	show14
	call 	clr500mS		
	goto	Main13c	
		
comp15	call 	clr500mS
	bsf	fileD,6
	call 	show14
	call 	clr500mS
	goto	Main13c		
		
comp14	call 	clr500mS
	goto	Main13c	
		
comp13	call 	clr500mS
	goto	Main12c			
		
comp12	call 	clr500mS
	bsf	fileD,6
	call 	show11
	call 	clr500mS
	bsf	fileD,6
	call 	show10
	call 	clr500mS		
	goto	Main9c			
		
comp11	call 	clr500mS
	bsf	fileD,7
	call 	show10
	call 	clr500mS
	goto	Main9c			
		
comp10	call 	clr500mS
	goto	Main9c			
		
		
comp9	call 	clr500mS
	goto	Main8c			
				
		
		
comp8	call 	clr500mS
	bsf	fileD,6
	call 	show7
	call 	clr500mS
	bsf	fileD,6
	call 	show6
	call 	clr500mS		
	goto	Main5c			
		
comp7	call 	clr500mS
	bsf	fileD,6
	call 	show6
	call 	clr500mS
	goto	Main5c		
		
comp6	call 	clr500mS
	goto	Main5c			
		
		
comp5	call 	clr500mS
	goto	Main4c	
		
comp4	call 	clr500mS
	bsf	fileD,6
	call 	show3
	call 	clr500mS
	bsf	fileD,6
	call 	show2
	goto	Main1c				
		
		
comp3	call 	clr500mS
	bsf	fileD,6
	call 	show2
	goto	Main1c			
				
						
	

	end		
		

 
 

 

NIM
Parts List

Cost: au
$
12.00 plus $6.50 postage
Kits are available

5  -  22R   SM resistors  (220)
1  -  47k   SM resistor (4702) or (473)

1  -  100n SM capacitor

18  - Yellow SM LEDs
1  -  SPDT mini slide switch
1  -  mini tactile push button

1  -  PIC12F629 chip (with NIM routine)
1  -  8 pin IC socket 
1  -  1N4148 diode
2  -  3v lithium cells
1  -  coin-cell battery holder
20cm  - very fine solder 
1  -  NIM PC board
 
JUST THE MICRO:
Pre-programmed PIC12F629 micro with NIM routine $5.00 plus $3.00 post

GOING FURTHER
Th
is project is one of a number of projects using a PIC microcontroller.
The overall concept of Talking Electronics is to show what can be done with a "micro" and you can add this project to PIC Fx-1 where you can study the program and add extra routines to produce individual effects.
You can then "burn" or flash" your program into a new chip by using the PIC Fx-1 project and see what results you get.

This project has been designed for a greeting card. Instead of opening a $6.00 card to see the words "Happy Birthday," you get a game using electronics.

 26/7/2014