// Attention : Le fonctionnement du programme requiert la DLL nommée : mcHID.dll. // N'oubliez pas d'inclure dans le même répertoire de votre programme cette fameuse DLL !!! unit FormMain; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Buttons, StdCtrls; const // input and out buffer size constants... BufferInSize = 55; BufferOutSize = 55; type // input and output buffers... TBufferIn = array[0..BufferInSize] of byte; TBufferOut = array[0..BufferOutSize] of byte; // main form TForm1 = class(TForm) Edit1: TEdit; SpeedButton1: TSpeedButton; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; SpeedButton2: TSpeedButton; SpeedButton3: TSpeedButton; SpeedButton4: TSpeedButton; SpeedButton5: TSpeedButton; SpeedButton6: TSpeedButton; SpeedButton7: TSpeedButton; procedure FormCreate(Sender: TObject); procedure SpeedButton1Click(Sender: TObject); procedure SpeedButton2Click(Sender: TObject); procedure SpeedButton3Click(Sender: TObject); procedure SpeedButton4Click(Sender: TObject); procedure SpeedButton5Click(Sender: TObject); procedure SpeedButton6Click(Sender: TObject); procedure SpeedButton7Click(Sender: TObject); private FBufferOut:TBufferOut; public end; var Form1: TForm1; implementation uses cUSBInterface, cUSBInterfaceTypes; const // VENDOR et PRODUCT ID. // Attention, ne pas changer ces 2 constantes sinon l'interface LCD ne sera plus reconnue. VENDOR_ID = 1240; PRODUCT_ID = 0004; {$R *.DFM} procedure TForm1.FormCreate(Sender: TObject); begin Connect(Application.Handle); // Indispensable !!! //*** Nombre maximal de caractères admissibles pour chaque ligne du LCD *** // Ligne n°1 // Edit1.MaxLength:=8 // 8 caractères maxi à saisir dans Edit pour un afficheur n X 8 caractères. // Edit1.MaxLength:=16; // 16 caractères maxi à saisir dans Edit pour un afficheur n X 16 caractères. Edit1.MaxLength:=20; // 20 caractères maxi à saisir dans Edit pour un afficheur n X 20 caractères. // Ligne n°2 // Edit2.MaxLength:=8 // 8 caractères maxi à saisir dans Edit pour un afficheur n X 8 caractères. // Edit2.MaxLength:=16; // 16 caractères maxi à saisir dans Edit pour un afficheur n X 16 caractères. Edit2.MaxLength:=20; // 20 caractères maxi à saisir dans Edit pour un afficheur n X 20 caractères. // Ligne n°3 // Edit3.MaxLength:=8 // 8 caractères maxi à saisir dans Edit pour un afficheur n X 8 caractères. // Edit3.MaxLength:=16; // 16 caractères maxi à saisir dans Edit pour un afficheur n X 16 caractères. Edit3.MaxLength:=20; // 20 caractères maxi à saisir dans Edit pour un afficheur n X 20 caractères. // Ligne n°4 // Edit4.MaxLength:=8 // 8 caractères maxi à saisir dans Edit pour un afficheur n X 8 caractères. // Edit4.MaxLength:=16; // 16 caractères maxi à saisir dans Edit pour un afficheur n X 16 caractères. Edit4.MaxLength:=20; // 20 caractères maxi à saisir dans Edit pour un afficheur n X 20 caractères. end; procedure TForm1.SpeedButton1Click(Sender: TObject); // Bouton "Transfert ligne 1 du LCD" var DevHandle:cardinal; Long, i : Integer; begin FBufferOut[1] := 1; // Première ligne du LCD Long := Length(Edit1.text); // Détermine le nombre de caractères tapés dans Edit.text. if Long = 0 Then Exit; // Si aucun caractère tapé dans Edit.text, sortir de la procédure. For i:= 1 to (Long+1) Do Begin FBufferOut[i+1]:=Ord(Edit1.Text[i]); // Transfert de la chaine de caractère vers le PIC. End; FBufferOut[long+2]:=Ord('#'); // Ajoute à Edit.Text l'indispensable caractère '#' de fin de chaîne. DevHandle := GetHandle(VENDOR_ID, Product_ID); // Transfert USB PC vers PIC. Write(DevHandle,@FBufferOut); end; procedure TForm1.SpeedButton2Click(Sender: TObject); // Bouton "Transfert ligne 2 du LCD" var DevHandle:cardinal; Long, i : Integer; begin FBufferOut[1] := 2; // Seconde ligne du LCD Long := Length(Edit2.text); // Détermine le nombre de caractères tapés dans Edit.text. if Long = 0 Then Exit; // Si aucun caractère tapé dans Edit.text, sortir de la procédure. For i:= 1 to (Long+1) Do Begin FBufferOut[i+1]:=Ord(Edit2.Text[i]); // Transfert de la chaine de caractère vers le PIC. End; FBufferOut[long+2]:=Ord('#'); // Ajoute à Edit.Text l'indispensable caractère '#' de fin de chaîne. DevHandle := GetHandle(VENDOR_ID, Product_ID); // Transfert USB PC vers PIC. Write(DevHandle,@FBufferOut); end; procedure TForm1.SpeedButton3Click(Sender: TObject); // Bouton "Transfert ligne 3 du LCD" var DevHandle:cardinal; Long, i : Integer; begin FBufferOut[1] := 3; // Troisième ligne du LCD Long := Length(Edit3.text); // Détermine le nombre de caractères tapés dans Edit.text. if Long = 0 Then Exit; // Si aucun caractère tapé dans Edit.text, sortir de la procédure. For i:= 1 to (Long+1) Do Begin FBufferOut[i+1]:=Ord(Edit3.Text[i]); // Transfert de la chaine de caractère vers le PIC. End; FBufferOut[long+2]:=Ord('#'); // Ajoute à Edit.Text l'indispensable caractère '#' de fin de chaîne. DevHandle := GetHandle(VENDOR_ID, Product_ID); // Transfert USB PC vers PIC. Write(DevHandle,@FBufferOut); end; procedure TForm1.SpeedButton4Click(Sender: TObject); // Bouton "Transfert ligne 4 du LCD" var DevHandle:cardinal; Long, i : Integer; begin FBufferOut[1] := 4; // Quatrieme ligne du LCD Long := Length(Edit4.text); // Détermine le nombre de caractères tapés dans Edit.text. if Long = 0 Then Exit; // Si aucun caractère tapé dans Edit.text, sortir de la procédure. For i:= 1 to (Long+1) Do Begin FBufferOut[i+1]:=Ord(Edit4.Text[i]); // Transfert de la chaine de caractère vers le PIC. End; FBufferOut[long+2]:=Ord('#'); // Ajoute à Edit.Text l'indispensable caractère '#' de fin de chaîne. DevHandle := GetHandle(VENDOR_ID, Product_ID); // Transfert USB PC vers PIC. Write(DevHandle,@FBufferOut); end; procedure TForm1.SpeedButton5Click(Sender: TObject); // Bouton "Efface le LCD". var DevHandle:cardinal; begin FBufferOut[1] := 5; // Efface le LCD DevHandle := GetHandle(VENDOR_ID, Product_ID); // Transfert USB PC vers PIC. Write(DevHandle,@FBufferOut); end; procedure TForm1.SpeedButton6Click(Sender: TObject); // Bouton "Rétro eclairage inactif". var DevHandle:cardinal; begin FBufferOut[1] := 6; // Eteint le rétro éclairage. DevHandle := GetHandle(VENDOR_ID, Product_ID); // Transfert USB PC vers PIC. Write(DevHandle,@FBufferOut); end; procedure TForm1.SpeedButton7Click(Sender: TObject); // Bouton "Rétro eclairage actif". var DevHandle:cardinal; begin FBufferOut[1] := 7; // Allume le rétro éclairage. DevHandle := GetHandle(VENDOR_ID, Product_ID); // Transfert USB PC vers PIC. Write(DevHandle,@FBufferOut); end; end.