DEVICE 16F84A   			'dclarations de base
	declare xtal 4		
DECLARE WATCHDOG = OFF	
	DECLARE SDA_PIN portA.4 
	DECLARE SCL_PIN portA.3 
		
	trisB=%00000000
	trisA=%00000111
	portB=%00000000

	Dim I,J,L,V as byte		'dclarations de variables
	Dim K,tour as word
	DIM OCTETPOURNOKIA AS BYTE
	dim temp,btnvar2 as byte
	dim pos_cursor_X as byte  
	dim pos_cursor_Y as byte  
	dim X as pos_cursor_X
	dim Y as pos_cursor_Y
	DIM octet as word
	Dim image as word
	dim dessin_flech as word
		

	symbol RESE portb.7		'affectation des broches du Pic
	symbol SCE portb.6
	symbol DATCOM portb.5
	symbol SDIN portb.4
	symbol SCK portb.3
	SYMBOL BUZZ PORTb.0			
		
		
	data $21,$C5,$13,$20,$09,$08,$0c
	gosub RESEnokia			'dbut de programme
	gosub initnokia
	gosub clearscreen
	tour=8
	image=510
	dessin_flech=2536
	clear btnvar2
	sound BUZZ, [124,5,119,5,120,5]
start:	
	X=0
	Y=0
	gosub set_cursor							
	gosub affiche_ecran

loop:	
	delayms 50
	gosub fleche
	button portA.1,1,255,250,btnvar2,1,suite
	delayms 50
	goto loop	
suite:
 	sound BUZZ, [124,5]
      image=image+504
	if image>=2536 then image=510:tour=8
	goto start	

					'sous routines					
affiche_ecran:
	while tour<>image
	OCTETPOURNOKIA=BUSIN %10100000, tour
	gosub nokiadata
	tour=tour+1
	wend 
	return

RESEnokia:
	RESE=0
	SCE=1
	DATCOM=1
	delayms 250
	RESE=1
	return
		
nokiacommand:
	SCE=0
	DATCOM=0
	gosub nokiawrite
	DATCOM=1
	SCE=1 				
	return
		
nokiadata:
	SCE=0
	DATCOM=1
	gosub nokiawrite
	DATCOM=0
	SCE=1 				
	return
		
nokiawrite:
	shout SDIN, SCK, MSBFIRST, [OCTETPOURNOKIA]  
	return
		
initnokia:
	restore
	for I=1 to 7
	read OCTETPOURNOKIA
	gosub nokiacommand
	next I
	return
		
clearscreen:
	for K =1 to 504
	OCTETPOURNOKIA=0
	gosub nokiadata
	next K
	delayms 500
	return
		
set_cursor:
	X=128|pos_cursor_X
	Y=64|pos_cursor_Y
	OCTETPOURNOKIA=X
	gosub nokiacommand
	OCTETPOURNOKIA=Y
	gosub nokiacommand
	return

fleche:				'animation fleche
      X=65
      Y=5
	gosub set_cursor
	for I=1 to 20
	OCTETPOURNOKIA=BUSIN %10100000, I+dessin_flech
	gosub nokiadata
	next I
	delayms 50
	dessin_flech=dessin_flech+24
	if dessin_flech>=2716 then dessin_flech=2536
	return


