1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| Imports System
Imports System.Windows.Forms
Imports System.Threading
Public Structure Tmr2_Counters
Dim CTR, PREDIV, PR2, POSTDIV As UInt16
Dim T, Ecart As ULong
End Structure
Public Class Form1
Private mon_thread As Thread ' déclaration d'un Thread
Private Delegate Sub MonDélégué(ByVal T_C As Tmr2_Counters) ' déclaration d'un délégué d'affichage
Private Delegate Sub suivi(ByVal cc As UInt16) ' déclaration d'un délégué d'affichage
Dim Vasy As Boolean
Private Sub OkTMR2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OkTMR2.Click
mon_thread = New Thread(AddressOf Recherche) 'créer le thread mais ne le démarre pas
mon_thread.Start()
End Sub
Private Sub Recherche()
Dim Tmr2_Counters_1 As Tmr2_Counters
Vasy = True
For Tmr2_Counters_1.CTR = 1 To 256
Invoke(New suivi(AddressOf aff_suivi), Tmr2_Counters_1.CTR)
For Each Tmr2_Counters_1.PREDIV In {2, 4, 16}
For Tmr2_Counters_1.PR2 = 1 To 255
For Tmr2_Counters_1.POSTDIV = 1 To 16
With Tmr2_Counters_1
.T = .CTR * .PREDIV * (.PR2 + 1) * .POSTDIV * 4 / Fosc.Text
.Ecart = Math.Abs(.T - Periode.Text)
If .Ecart <= Tolerence.Text Then
Invoke(New MonDélégué(AddressOf DéléguéAffichage), Tmr2_Counters_1)
End If
End With
Next
Next
Next
If Vasy = False Then
Exit Sub
End If
Next
End Sub
Private Sub aff_suivi(ByVal CTR As UInt16)
StatBox.Text = CTR.ToString + "/256"
End Sub
Private Sub DéléguéAffichage(ByVal T_C As Tmr2_Counters)
With T_C
TextTMR2.AppendText(String.Format("{0,3:G} {1,3:G} {2,3:G} {3,3:G} {4:D} {5:D}" + vbCrLf, .CTR, .PREDIV, .PR2 + 1, .POSTDIV, .T, .Ecart))
End With
End Sub
Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
End
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label3.Text = " CTR PREDIV PR2+1 POSTDIV T ERR"
End Sub
Private Sub STOP_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles STOP_Button.Click
Vasy = False
End Sub
End Class |
Partager