' ' Controle des armes du sumotozor ' Le récepteur radio est branché sur E4 et E5 ' Réalisation : GROUPE EXPOSCIENCE DU LYCEE LOUIS PAYEN ' ( élèves de 1ère SSI - Sciences de l'ingénieur 2005-2006 ) ' Utilisation du Timer pour variation de vitesse par MLI ' ' Pour modifier le timer (CboyF1 16mhz): ' PACTTL.1 PACTL.0 ' 0 0 2,05 ms ' 0 1 4,1 ms ' 1 0 8,2 ms ' 1 1 16,4 ms #include "startcf1.bas" byte t, passage, flag, n, flagp int compteur, compteur2, v ' Configuration DDRD = 0 ' Port D en entrée DDRA = %11111111 ' A0 à A7 en sortie DDRG.2 = 1 ' G2 en sortie DDRG.3 = 1 ' G3 en sortie PACTL.1 = 0 ' selectionner la vitesse (2ms sur cboyF1 16Mhz) PACTL.0 = 0 ' en fonction de ce qu'on souhaite ' Voir tableau en haut du programme TMSK2.6 = 1 ' declencher le timer cli ' autoriser les inter lcdinit() ' initialisation passage = 0 flag = 0 PORTA = 0 PORTG.2 = 0 ' active variateur pince ' pour toujours do do compteur = 0 ' compteur voie 1 compteur2 = 0 ' compteur voie 2 do loop until PORTE.4 = 0 ' attente niveau 0 do loop until PORTE.4 = 1 ' Détection du front montant sur E4 do compteur = compteur +1 loop until PORTE.4 = 0 ' faire de même pour compteur2 sur E5 do loop until PORTE.5 = 1 ' Détection du front montant sur E5 do compteur2 = compteur2 +1 loop until PORTE.5 = 0 loop until compteur>180 AND compteur<320 AND compteur2>180 AND compteur2<320 if compteur>=245 and compteur<=265 and compteur2>=245 and compteur2<=265 then PORTA = 0 ' arreter tous les armes end if print "#1 compt1 = ",compteur print "#2 compt2 = ",compteur2 tempo(50) ' on temporise moins d'une seconde if compteur2 >= 245 and compteur2 <= 265 then ' Neutre avancer/reculer gosub arret_bras gosub vitesse2 if compteur > 265 then flagp = 0 gosub fermer_pince else if flagp = 0 then flagp =1 gosub ouvrir_pince end if end if if compteur < 245 then gosub perceuse_on else gosub perceuse_off end if end if if compteur >= 245 and compteur <= 265 then ' Neutre droit gauche if compteur2 < 245 then if PORTE.2 = 1 then ' si capteur ouvert gosub sortir_bras end if end if if compteur2 > 265 then if PORTE.3 = 1 then ' si capteur ouvert gosub rentrer_bras end if end if if compteur2 > 245 and compteur2 < 265 then gosub arret_bras end if end if if compteur2 > 265 and compteur > 265 then gosub monter end if if compteur2 > 265 and compteur < 245 then gosub descendre end if loop vitesse: ' calcul de la vitesse ' 188 min avance 255 neutre 315 max recul if compteur2 > 255 then ' pour valeur absolue v = compteur2 - 255 else v = 255 - compteur2 end if n = v/3 return vitesse2: ' calcul de la vitesse ' 188 min gauche droite 255 neutre 315 max (à vérifier) if compteur > 255 then ' pour valeur absolue v = compteur - 255 else v = 255 - compteur end if n = v/3 return rentrer_bras: PORTA.4 = 1 PORTA.5 = 0 return sortir_bras: PORTA.4 = 0 PORTA.5 = 1 return arret_bras: PORTA.4 = 0 PORTA.5 = 0 return perceuse_on: PORTA.0 = 0 PORTA.1 = 1 tempo(25) return perceuse_off: PORTA.0 = 0 PORTA.1 = 0 tempo(25) return fermer_pince: PORTA.2 = 0 PORTA.3 = 1 tempo(25) return ouvrir_pince: PORTA.2 = 1 PORTA.3 = 0 tempo(2000) PORTA.2 = 0 PORTA.3 = 0 return monter: PORTA.6 = 1 PORTA.7 = 0 return descendre: PORTA.6 = 0 PORTA.7 = 1 return arret_elevateur: PORTA.6 = 0 PORTA.7 = 0 return ' Fonction interruption du TIMER : interrupt function rtiint at $FFF0 passage=passage+1 if passage 20 then passage=0 end if TFLG2.6 = 1 ' autoriser ints a nouveau end function function tempo(cnt) int i, k for cnt=cnt to 0 step -1 for i=0 to 100 next next return 0 end function //********* driver LCD Good **************************************** #define LCDLINES 4 //+++ lignes/afficheur: 1,2,3,4 #define LCDCOLS 16 //+++ caracters par lignes 16,20 #define LCDBUFSZ (LCDLINES * LCDCOLS) byte lcdbuf(LCDBUFSZ) byte lcdbufpp byte code_lcdpos()=00,00,40,20,60 //+++ pos de lignes dans la mémoire LCD byte code_lcdlng()=80,20,20,20,20 //+++ longeur de lignes dans la mém LCD function lcdnib(nibc) // Controlboy F1 nibc = (nibc AND 0x4F) OR 0x30 PORTM = nibc PORTM = nibc OR 0x80 ' EN = 1 500 ns PORTM = nibc end function function lcdnibw(lcdc) lcdnib(lcdc) lcdtempo(-1) end function function lcdputc(lcdc) lcdnib(lcdc/16) lcdnibw(lcdc AND 0xF) end function function lcdinit() byte c PORTB = 0x30 lcdtempo(5) ' 15 ms lcdnib(3) ' lcd = 3 lcdtempo(1) ' 4.1 ms lcdnib(3) ' lcd = 3 lcdtempo(1) ' .1 ms lcdnibw(3) ' lcd = 3 40us lcdnibw(2) ' lcd = 2 40us lcdputc(0x28) lcdputc(0x08) ' display off lcdputc(0x01) ' clear display lcdtempo(1) lcdputc(0x06) lcdputc(0x0E) ' display on , cursor for c=0 to (LCDBUFSZ-1) lcdbuf(c) = ` ` next c sendlcdbuf() end function function putchar(lcdc) byte put_x if (lcdc==`#`) then lcdbufpp=255 return end if if (lcdbufpp=255) then if (lcdc==`*`) then //+rs232+ lcdbufpp=254 //+rs232+ return //+rs232+ end if //+rs232+ put_x = lcdc AND 7 lcdbufpp = code_lcdpos(put_x) put_x = code_lcdlng(put_x) for lcdc=lcdbufpp to lcdbufpp+put_x-1 lcdbuf(lcdc) = ` ` next lcdc goto sendnow; end if if (lcdbufpp==254) then //+rs232+ do //+rs232+ loop until SCSR.7=1 //+rs232+ SCDR=lcdc //+rs232+ return //+rs232+ end if //+rs232+ if (lcdbufpp>=LCDBUFSZ) then lcdbufpp=0; end if lcdbuf(lcdbufpp) = lcdc lcdbufpp = lcdbufpp+1 sendnow: sendlcdbuf() end function function sendlcdbuf() byte d lcdputc(0x80) for d=0 to LCDBUFSZ-1 ' if d = (LCDBUFSZ/2) then //+++ specific afficheur ' lcdputc(0x80 + 0x28) //+++ specific afficheur ' end if lcdnib ((lcdbuf(d)/16) OR 0x40) lcdnibw (lcdbuf(d) OR 0x40) next d end function function lcdtempo(cnt) int bcl for cnt=cnt to 0 step -1 for bcl=0 to 100 next next end function byte old_keycode function keyget() byte keycode keycode = 0 PORTM = 0x37 ' K=0 J=1 H=1 G=1 if PORTN.3 = 0 then keycode=`1` if PORTN.2 = 0 then keycode=`2` if PORTN.1 = 0 then keycode=`3` if PORTN.0 = 0 then keycode=`?` PORTM = 0x3B ' K=1 J=0 H=1 G=1 if PORTN.3 = 0 then keycode=`4` if PORTN.2 = 0 then keycode=`5` if PORTN.1 = 0 then keycode=`6` if PORTN.0 = 0 then keycode=`?` PORTM = 0x3D ' K=1 J=1 H=0 G=1 if PORTN.3 = 0 then keycode=`7` if PORTN.2 = 0 then keycode=`8` if PORTN.1 = 0 then keycode=`9` if PORTN.0 = 0 then keycode=`?` PORTM = 0x3E ' K=1 J=1 H=1 G=0 if PORTN.3 = 0 then keycode=`*` if PORTN.2 = 0 then keycode=`0` if PORTN.1 = 0 then keycode=`#` if PORTN.0 = 0 then keycode=`?` if keycode==old_keycode then return 0 old_keycode = keycode return keycode end function