' JRTEC essai ultrason
#picaxe 20M2 'directive utilisation pisaxe 20M2
'***** Nomination des Entr?es / Sorties ************
symbol trigG= C.5 'emission G
symbol echoG=C.4 'reception G
symbol trigD= C.1 'emission D
symbol echoD=C.0 'reception D
symbol potsens=C.7 ' potentiometre de tolerence
symbol bloc= C.6 ' blocage auto
symbol potdure=C.3 ' potentioùetre de duré action
'***** Nomination des variables *********************
symbol sauve=bit0 'Mémorisation sauvegarde
symbol cent1=b4 'chiffre des centaines de cm G
symbol dix1=b5 'chiffre des dizaimes de cm G
symbol unit1=b6 'chiffre des unites de cm G
symbol cent2=b7 'chiffre des centaines de cm D
symbol dix2=b8 'chiffre des dizaimes de cm D
symbol unit2=b9 'chiffre des unites de cm D
symbol cent3=b10 'chiffre des centaines de cm DIFFERENCE ou tolerence
symbol dix3=b11 'chiffre des dizaimes de cm DIFFERENCE ou tolerence
symbol unit3=b12 'chiffre des unites de cm DIFFERENCE ou tolerence
symbol sens=b13 'valeur potentiometre yolernce
symbol distg=w13 'distance totale gauche 1
symbol distd=w12 'distance totale droite 2
symbol diFF=w11 'DIFFERENCE
symbol mvt=b13 'caractere du mouvement
symbol totg=w9 'distance g +tol
symbol totd=w10 'distance d +tol
symbol dure=w8 'val de d action en coef µs
symbol dureS=w7
symbol cent4=w6 'chiffre des centaines de temp de durée
symbol dix4=w5 'chiffre des dizaimes de temp de durée
symbol unit4=w4 'chiffre des unites de temp de durée
'********************************************************************
setfreq m8 'Fr?quense horloge interne picaxe ? 8Mhz
'***** Initialisation LCD*******************
dirsB=%111111 'd?fini les I/O ports B en sortie
'*****Donn?es d'initialisation de l'afficheur Type HD44780 ***********
'*****Pour l'affichage, on utilise les ports BO ? B5 du 20M2********
SYMBOL RS = B.0 ; 0 = Command 1 = Data
SYMBOL E = B.1 ; 0 = Idle 1 = Active
SYMBOL DB4 = B.2 ; LCD Data Line 4
SYMBOL DB5 = B.3 ; LCD Data Line 5
SYMBOL DB6 = B.4 ; LCD Data Line 6
SYMBOL DB7 = B.5 ; LCD Data Line 7
SYMBOL RSCMDmask = %00000000 ; Select Command register
SYMBOL RSDATmask = %00000001 ; Select Data register
SYMBOL cpt = b1
SYMBOL car = b2
SYMBOL rsbit = b3
'Nibble commands - To initialise 4-bit mode
DATA 0,( $33 ) ; %0011---- %0011---- 8-bit / 8-bit
DATA 1,( $32 ) ; %0011---- %0010---- 8-bit / 4-bit
'Byte commands - To configure the LCD
DATA 2,( %00101000 ) ; %001LNF00 Display Format
DATA 3,( %00001100 ) ; %00001DCB Display On
DATA 4,( %00000110 ) ; %000001IS Cursor Move
' ; L : 0 = 4-bit Mode 1 = 8-bit Mode
' ; N : 0 = 1 Line 1 = 2 Lines
' ; F : 0 = 5x7 Pixels 1 = N/A
' ; D : 0 = Display Off 1 = Display On
' ; C : 0 = Cursor Off 1 = Cursor On
' ; B : 0 = Cursor Steady 1 = Cursor Flash
' ; I : 0 = Dec Cursor 1 = Inc Cursor
' ; S : 0 = Cursor Move 1 = Display Shift
DATA 5,( $01 ) ; Clear Screen
'***** Envoi de ces donn?es au LCD ***************
PowerOnReset:
FOR cpt = 0 TO 5
READ cpt,car
GOSUB SendInitCmdByte
NEXT
'***** DEBUT PROGRAMME PERSO ************************
DATA 6,("G: Mvt D:") 'Texte sur l'afficheur ligne1 (16c)
DATA 22,("tol: Ac: . s") 'Texte sur l'afficheur ligne1 (16c)
gosub texte 'Texte ligne 1 et 2
pause 4000 'pause de 0.5 s à la mise sous tension
do
gosub mesure
mesure:
readadc potsens , sens ' lecture du potentiometre de sensibilite de 0 a 255 et memo val
readadc potdure , dure 'lecture du potentiometre de sensibilite de 0 a 255 et memo val
dureS=dure*20 ' duré entre 0 et 5100 soit a 8mhz(*5/10000) de 0 a 2.55 seconde
low C.4
pulsout C.4,10
pulsin C.5,1,w13
w13=w13*10/116
w9=w13+b13
bintoascii w13,cent1,cent1,cent1,dix1,unit1
pause 500
low C.0
pulsout C.0,10
pulsin C.1,1,w12
w12=w12*10/116
w10=w12+b13
bintoascii w12,cent2,cent2,cent2,dix2,unit2
if w13>w10 then
gosub gauche
endif
if w12>w9 then
gosub droite
endif
if w12<w9 and w13<w10 then
gosub egal
endif
loop
'***gestion devers *************************************************
gauche:
w11=w13-w12
high B.6 pause dureS
low B.7
bintoascii b13,cent3,dix3,unit3
bintoascii dure,cent4,cent4,cent4,dix4,unit4
mvt="<"
gosub affiche
return
egal:
if w13>w12 then
w11=w13-w12
endif
if w12>w13 then
w11=w12-w13
endif
if w13=w12 then
w11=00
endif
low B.6
low B.7
bintoascii b13,cent3,dix3,unit3
bintoascii dure,cent4,cent4,cent4,dix4,unit4
mvt="="
gosub affiche
return
droite:
w11=w12-w13
low B.6
high B.7 pause dureS
bintoascii b13,cent3,dix3,unit3
bintoascii dure,cent4,cent4,cent4,dix4,unit4
mvt=">"
gosub affiche
return
'***** Affichage des donn?es ************************************
affiche:
car= $80 | $02 'curseur d?but ligne1 3° caractere
gosub SendCmdByte
car=cent1
GOSUB SendDataByte
car=dix1 '
GOSUB SendDataByte
car=unit1 '
GOSUB SendDataByte
car= $80 | $09 'curseur début ligne1 15° caractere
gosub SendCmdByte
car=mvt
GOSUB SendDataByte
car= $80 | $0d 'curseur début ligne1 14° caractere
gosub SendCmdByte
car=cent2
GOSUB SendDataByte
car=dix2 '
GOSUB SendDataByte
car=unit2 '
GOSUB SendDataByte
car= $80 | $44 'curseur début ligne2 3° caractere
gosub SendCmdByte
car=cent3
GOSUB SendDataByte
car=dix3 '
GOSUB SendDataByte
car=unit3 '
GOSUB SendDataByte
car= $80 | $4b 'curseur début ligne2 14° caractere
gosub SendCmdByte
car=cent4
GOSUB SendDataByte
car= $80 | $4d 'curseur début ligne2 15° caractere
gosub SendCmdByte
car=dix4
GOSUB SendDataByte
car= $80 | $4e 'curseur début ligne2 16° caractere
gosub SendCmdByte
car=unit4
GOSUB SendDataByte
sauve=0
'***** Ecriture du texte fixe sur afficheur *********************************************************
texte: 'position du curceur ligne 1 et ecriture du label
car= $80 | $00 'curseur ligne1 1° caractere
gosub SendCmdByte
FOR cpt = 6 TO 7 'lecture texte ligne1
READ cpt,car
GOSUB SendDataByte
NEXT
car= $80 | $05 'curseur ligne1 6 ° caractere
gosub SendCmdByte
FOR cpt = 11 TO 14 'lecture texte ligne1
READ cpt,car
GOSUB SendDataByte
NEXT
car= $80 | $0b 'curseur ligne1 11° caractere
gosub SendCmdByte
FOR cpt = 17 TO 18 'lecture texte ligne1
READ cpt,car
GOSUB SendDataByte
NEXT
car= $80 | $40 'curseur ligne2 1° caractere
gosub SendCmdByte
FOR cpt = 22 TO 25 'lecture texte ligne2
READ cpt,car
GOSUB SendDataByte
NEXT
'
car= $80 | $48 'curseur ligne2 8° caractere
gosub SendCmdByte
FOR cpt = 30 TO 32 'lecture texte ligne2
READ cpt,car
GOSUB SendDataByte
NEXT
car= $80 | $4c 'curseur ligne2 8° caractere
gosub SendCmdByte
FOR cpt = 34 to 34 'lecture texte ligne2
READ cpt,car
GOSUB SendDataByte
NEXT
car= $80 | $4f 'curseur ligne2 8° caractere
gosub SendCmdByte
FOR cpt = 37 to 37 'lecture texte ligne2
READ cpt,car
GOSUB SendDataByte
NEXT
return
'
'***** Sous programmes d'?criture du LCD************
SendInitCmdByte:
PAUSE 5 ; Delay 15mS
SendCmdByte:
rsbit = RSCMDmask ; RSCDmask = 0 ;Send to Command register
SendDataByte:
pinsB = car & $F0 / 4 | rsbit ; Put MSB out first
PULSOUT E,1 ; Give pulse on E
pinsB = car & $0F * 4 | rsbit ; Put LSB out second
PULSOUT E,1 ; Give pulse on E
rsbit = RSDATmask ; RSDATmask = 1 ; Send to Data register next
RETURN