#picaxe 20x2
#no_data
Symbol IO_ADR = $40 'I2C address of 8574 all address line low
'Symbol IO_ADR = $70 'I2C address of 8574AP all address line low
Symbol IO_ADR2 = $71 'I2C addresse du 1er PCF8574AP en lecture
Symbol io_adr3 = $73 'i2c addresse du 2?me pcf8574ap en lecture
symbol io_adr4 = $75 'i2c addresse du 3?me pcf8574ap en lecture
symbol io_adr5 = $77 'i2c addresse du 4?me pcf8574ap en lecture
symbol io_adr6 = $79 'i2c addresse du 5?me pcf8574ap en lecture
symbol flag=bit0
symbol cpt=b1
symbol poidsfaible = b2
symbol Touche = b3
symbol octetlu = b4
symbol temp = b9
symbol nombre=b5
symbol classe=b6
symbol mini=b7
symbol maxi=b8
symbol unite=b10
symbol dizaine=b11
symbol equipement=b12
symbol cptouche1=b13
symbol cptouche2=b14
hi2csetup i2cmaster, io_adr,i2cfast,i2cbyte 'EEPROM 24LC16B
HI2cOut [IO_ADR],(%11110000) 'ESSAI''all rows low, all columns high if you want to use interrupt
hi2cout[io_adr],(%11110000)
hi2cout [io_adr2],(%00000000)
hi2cout [io_adr3],(%00000000)
hi2cout [io_adr4],(%00000000)
hi2cout [io_adr5],(%00000000)
hi2cout [io_adr6],(%00000000)
touches:
'------------------------------------------------dizaine
touche =240
nombre=0
mini=0:maxi=9
gosub lectouche
lookup touche,("0123456789abcdef"),classe
dizaine=touche
cptouche2=1
pause 20
if touche >=0 and cptouche2=1 then
dizaine=touche *10
sertxd("1 - dizaine = ",#dizaine," - classe = ",classe," - touche = ",#touche," - touche2 = ",#cptouche2,13,10)
end if
'------------------------------------------------unite
mini=0:maxi=9
gosub lectouche
lookup touche,("0123456789abcdef"),classe
unite=touche
cptouche1=1
pause 20
if touche>=0 and cptouche1=1 then
unite=touche
sertxd("2 - unite = ",#unite," - classe = ",classe," - touche = ",#touche," - touche1 = ",#cptouche1,13,10)
end if
'------------------------------------------------validation
if unite>0 and dizaine=0 and cptouche1=1 then
goto valide1
elseif unite>=0 and dizaine>=10 and cptouche2=1 then
goto valide2
end if
valide1:
mini=10:maxi=16
gosub lectouche
lookup touche,("0123456789abcdef"),classe
equipement=classe
if equipement="a" and cptouche1=1 and dizaine=0 then
nombre=unite
sertxd("3 - aiguillage = ",#nombre," - classe = ",classe," - touche1 = ",#cptouche1,13,10,13,10)
sertxd("4 unite = ",#unite,13,10,13,10)
goto commandes
end if
valide2:
mini=10:maxi=16
gosub lectouche
lookup touche,("0123456789abcdef"),classe
equipement=classe
if equipement="a" and cptouche2=1 and dizaine =>10 then
nombre=dizaine+unite
sertxd("5 - aiguillage = ",#nombre," - classe = ",classe," - touche2 = ",#cptouche2,13,10,13,10)
sertxd("6 dizaine = ",#dizaine," unite = ",#unite,13,10)
goto commandes
end if
pause 1000
commandes:
select case nombre
case 01
hi2cout [io_adr2],(1):pause 1000
case 02
hi2cout [io_adr2], (2):pause 1000
case 03
hi2cout [io_adr2], (4):pause 1000
case 04
hi2cout [io_adr2], (8):pause 1000
case 05
hi2cout [io_adr2],(16):pause 1000
case 06
hi2cout [io_adr2], (32):pause 1000
case 07
hi2cout [io_adr2], (64):pause 1000
case 08
hi2cout [io_adr2], (128):pause 1000
case 09
hi2cout [io_adr3],(1):pause 1000
case 10
hi2cout [io_adr3], (2):pause 1000
case 11
hi2cout [io_adr3], (4):pause 1000
case 12
hi2cout [io_adr3], (8):pause 1000
case 13
hi2cout [io_adr3], (16):pause 1000
case 14
hi2cout [io_adr3], (32):pause 1000
case 15
hi2cout [io_adr3], (64):pause 1000
case 16
hi2cout [io_adr3], (128):pause 1000
end select
reset
lectouche:
do
poidsfaible=%1 ;init ? xxxx0001
for cpt=1 to 4 ;scann sur bits poids faible
temp=not poidsfaible |%11110000 ;
hi2cout [io_adr],(temp) ;envoi octet
pause 20
hi2cin [io_adr],(octetlu) ;test sur retour octet
if octetlu <240 and flag=0 and octetlu <> temp then ;pins < 11110000 (240) c?d une touche appuy?e, premier passage
pause 20
lookdown octetlu,(238,222,190,126, 237,221,189,125, 235,219,187,123, 231,215,183,119),touche
flag=1
elseif octetlu > 240 and flag=1 then ;rel?chement touche
pause 20
flag=0
if touche <=maxi and touche>=mini then retour
pause 20
endif
poidsfaible=poidsfaible*2 ;d?calage du 0 ? gauche (futur 1...)
next
loop
retour:
return