





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A c code example for programming a microcontroller to control an led matrix using i2c communication and uart interface. The code includes functions for initializing the led matrix, sending data to it, and handling serial communication. The document also defines constants and variables used in the code. This example can be useful for students and researchers in the field of microcontroller programming, embedded systems, and digital electronics.
Typology: Papers
1 / 29
This page cannot be seen from the preview
Don't miss anything!






















GUI Details:
Circuit Block Diagram
Microcontroller Block Diagram
PC software code: '''''''''''''''''''''''' ''variables'' '''''''''''''''''''''''' Dim timercount As Integer Dim temp As Integer Dim chord1 As String Dim chord2 As String Dim chord3 As String Dim counter As Integer Dim chordNum1 As Integer Dim chordNum2 As Integer Dim chordNum3 As Integer Dim tempy As Integer Private Sub cmdDsp1_Click() Timer1.Enabled = False picChord.Cls Call initNone Call initString Call printString End Sub Private Sub cmdDsp2_Click() Timer1.Enabled = False picChord.Cls Call initNone Call initString Call printString End Sub Private Sub cmdDsp3_Click() Timer1.Enabled = False picChord.Cls Call initNone Call initString Call printString End Sub Private Sub Form_Load() MSComm1.PortOpen = True Call initNone End Sub Private Sub cmdStart_Click() Call initTimer Timer1.Enabled = True ''''''''''''''''' ''initial'' ''''''''''''''''' picChord.Cls timercount = 0 Call initNone Call initTimer '''''''''''''''''''''''''''''''''''''''''''''''''''' ''setting count variable'' '''''''''''''''''''''''''''''''''''''''''''''''''''' If comboCount.Text = "5" Then counter = 4 ElseIf comboCount.Text = "10" Then counter = 9 ElseIf comboCount.Text = "15" Then counter = 14 ElseIf comboCount.Text = "20" Then
counter = 19 End If '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''setting chords and serial data'' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Call initString Call initString Call initString ''''''''''''''''''''''''''''''''' ''first iteration'' ''''''''''''''''''''''''''''''''' tempy = Int(Rnd * 3) + 1 Select Case tempy Case Is = 1 Call printString Case Is = 2 Call printString Case Is = 3 Call printString Case Else picChord.Cls End Select End Sub Private Sub Timer1_Timer() timercount = timercount + 1 picChord.Cls Call initNone tempy = Int(Rnd * 3) + 1 Select Case tempy Case Is = 1 Call printString Case Is = 2 Call printString Case Is = 3 Call printString Case Else picChord.Cls End Select If timercount = counter Then Timer1.Enabled = False End If End Sub Private Sub cmdStop_Click() Timer1.Enabled = False End Sub Private Sub cmdClose_Click() End End Sub ''''''''''''''''''''''''' ''functions'' ''''''''''''''''''''''''' Private Sub init1TO5() 'X***** ImageX(0).Visible = True ImageX(0).Refresh For temp = 1 To 5 ImgStr(temp).Visible = True ImgStr(temp).Refresh
Img1to5(2).Visible = False Img1to5(2).Refresh Img1to5(3).Visible = False Img1to5(3).Refresh Img1to5(5).Visible = False Img1to5(5).Refresh Img3to5(0).Visible = False Img3to5(0).Refresh Img0to5(0).Visible = False Img0to5(0).Refresh Img0to5(1).Visible = False Img0to5(1).Refresh Img0to5(2).Visible = False Img0to5(2).Refresh Img0to5(3).Visible = False Img0to5(3).Refresh 'strings For temp = 0 To 5 ImgStr(temp).Visible = False ImgStr(temp).Refresh ImageX(temp).Visible = False ImageX(temp).Refresh Next 'main guitar pic ImgGuitar.Visible = True ImgGuitar.Refresh End Sub Private Sub initTimer() '''''''''''''''''''''''''''''''''''''''''''''''''''' ''setting speed variable'' '''''''''''''''''''''''''''''''''''''''''''''''''''' If comboSpeed.Text = "Fast" Then Timer1.Interval = 2000 ElseIf comboSpeed.Text = "Medium" Then Timer1.Interval = 4000 ElseIf comboSpeed.Text = "Slow" Then Timer1.Interval = 6000 End If End Sub Private Sub initString1() If optMaj1.Value Then chord1 = Combo1.Text & " Major" chordNum1 = Combo1.ListIndex ElseIf optMin1.Value Then chord1 = Combo1.Text & " Minor" chordNum1 = Combo1.ListIndex + 12 ElseIf optDim1.Value Then chord1 = Combo1.Text & " Dim" chordNum1 = Combo1.ListIndex + 24 Else 'opt71.Value Then chord1 = Combo1.Text & " 7" chordNum1 = Combo1.ListIndex + 36 End If End Sub Private Sub initString2() If optMaj2.Value Then chord2 = Combo2.Text & " Major" chordNum2 = Combo2.ListIndex ElseIf optMin2.Value Then chord2 = Combo2.Text & " Minor" chordNum2 = Combo2.ListIndex + 12 ElseIf optDim2.Value Then chord2 = Combo2.Text & " Dim" chordNum2 = Combo2.ListIndex + 24 Else 'opt72.Value Then chord2 = Combo2.Text & " 7"
chordNum2 = Combo2.ListIndex + 36 End If End Sub Private Sub initString3() If optMaj3.Value Then chord3 = Combo3.Text & " Major" chordNum3 = Combo3.ListIndex ElseIf optMin3.Value Then chord3 = Combo3.Text & " Minor" chordNum3 = Combo3.ListIndex + 12 ElseIf optDim3.Value Then chord3 = Combo3.Text & " Dim" chordNum3 = Combo3.ListIndex + 24 Else 'opt73.Value Then chord3 = Combo3.Text & " 7" chordNum3 = Combo3.ListIndex + 36 End If End Sub Private Sub printString1() picChord.Print chord Call pickChord(chordNum1) End Sub Private Sub printString2() picChord.Print chord Call pickChord(chordNum2) End Sub Private Sub printString3() picChord.Print chord Call pickChord(chordNum3) End Sub Private Function send13Byte(b0 As Byte, b1 As Byte, b2 As Byte, b3 As Byte, b4 As Byte, b As Byte, b6 As Byte, b7 As Byte, b8 As Byte, b9 As Byte, b10 As Byte, b11 As Byte, b12 As Byte) MSComm1.Output = Chr(b12) MSComm1.Output = Chr(b11) MSComm1.Output = Chr(b10) MSComm1.Output = Chr(b9) MSComm1.Output = Chr(b8) MSComm1.Output = Chr(b7) MSComm1.Output = Chr(b6) MSComm1.Output = Chr(b5) MSComm1.Output = Chr(b4) MSComm1.Output = Chr(b3) MSComm1.Output = Chr(b2) MSComm1.Output = Chr(b1) MSComm1.Output = Chr(b0) End Function Private Function showChord(c0 As Integer, c1 As Integer, c2 As Integer, c3 As Integer, c As Integer, c5 As Integer) ImgChr0(c0).Visible = True ImgChr0(c0).Refresh ImgChr1(c1).Visible = True ImgChr1(c1).Refresh ImgChr2(c2).Visible = True ImgChr2(c2).Refresh ImgChr3(c3).Visible = True ImgChr3(c3).Refresh ImgChr4(c4).Visible = True ImgChr4(c4).Refresh ImgChr5(c5).Visible = True ImgChr5(c5).Refresh End Function Private Function pickChord(chrNum As Integer) Select Case chrNum
Call send13Byte(30, 0, 32, 16, 8, 16, 0, 0, 0, 0, 0, 0, 0) Call init1TO Call showChord(12, 5, 6, 7, 6, 12) Case Is = 39 'd# Call send13Byte(15, 0, 0, 0, 0, 0, 0, 0, 0, 128, 2, 4, 2) Call init2TO Call showChord(12, 12, 0, 2, 1, 2) Case Is = 4 'emajor Call send13Byte(63, 0, 0, 0, 0, 0, 0, 0, 4, 4, 128, 0, 0) Call init0TO Call showChord(12, 1, 1, 0, 12, 12) Case Is = 16 'eminor Call send13Byte(63, 0, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 0) Call init0TO Call showChord(12, 1, 1, 12, 12, 12) Case Is = 28 'edim Call send13Byte(30, 0, 16, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0) Call init1TO Call showChord(12, 6, 7, 8, 7, 12) Case Is = 40 'e Call send13Byte(63, 0, 0, 0, 0, 0, 0, 0, 4, 0, 128, 0, 0) Call init0TO Call showChord(12, 1, 12, 0, 12, 12) Case Is = 5 'fmajor Call send13Byte(63, 0, 0, 0, 0, 0, 0, 128, 130, 130, 132, 128, 128) Call init0TO Call showChord(12, 2, 2, 1, 12, 12) Img0to5(0).Visible = True Img0to5(0).Refresh Case Is = 17 'fminor Call send13Byte(63, 0, 0, 0, 0, 0, 0, 128, 130, 130, 128, 128, 128) Call init0TO Call showChord(12, 2, 2, 12, 12, 12) Img0to5(0).Visible = True Img0to5(0).Refresh Case Is = 29 'fdim Call send13Byte(30, 0, 8, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0) Call init1TO Call showChord(12, 7, 8, 9, 8, 12) Case Is = 41 'f Call send13Byte(63, 0, 0, 0, 0, 0, 0, 128, 130, 128, 132, 128, 128) Call init0TO Call showChord(12, 2, 12, 1, 12, 12) Img0to5(0).Visible = True Img0to5(0).Refresh Case Is = 6 'f#major Call send13Byte(63, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 4, 4) Call init0TO Call showChord(12, 3, 3, 2, 12, 12) Img0to5(1).Visible = True Img0to5(1).Refresh Case Is = 18 'f#minor Call send13Byte(63, 0, 0, 0, 0, 0, 0, 4, 5, 5, 4, 4, 4) Call init0TO Call showChord(12, 3, 3, 12, 12, 12) Img0to5(1).Visible = True Img0to5(1).Refresh Case Is = 30 'f#dim Call send13Byte(30, 0, 4, 2, 1, 2, 0, 0, 0, 0, 0, 0, 0) Call init1TO Call showChord(12, 8, 9, 10, 9, 12) Case Is = 42 'f# Call send13Byte(63, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 4, 4) Call init0TO Call showChord(12, 3, 12, 2, 12, 12) Img0to5(1).Visible = True Img0to5(1).Refresh Case Is = 7 'gmajor Call send13Byte(63, 0, 0, 0, 0, 0, 0, 2, 4, 0, 0, 0, 2) Call init0TO Call showChord(2, 1, 12, 12, 12, 2)
Case Is = 19 'gminor Call send13Byte(63, 0, 64, 64, 0, 0, 0, 2, 2, 2, 2, 2, 2) Call init0TO Call showChord(12, 4, 4, 12, 12, 12) Img0to5(2).Visible = True Img0to5(2).Refresh Case Is = 31 'gdim Call send13Byte(30, 0, 2, 1, 128, 1, 0, 0, 0, 0, 0, 0, 0) Call init1TO Call showChord(12, 9, 10, 11, 10, 12) Case Is = 43 'g Call send13Byte(63, 0, 0, 0, 0, 0, 0, 2, 4, 0, 0, 0, 128) Call init0TO Call showChord(2, 1, 12, 12, 12, 0) Case Is = 8 'g#major Call send13Byte(63, 0, 32, 32, 64, 0, 0, 1, 1, 1, 1, 1, 1) Call init0TO Call showChord(12, 5, 5, 4, 12, 12) Img0to5(3).Visible = True Img0to5(3).Refresh Case Is = 20 'g#minor Call send13Byte(63, 0, 32, 32, 0, 0, 0, 1, 1, 1, 1, 1, 1) Call init0TO Call showChord(12, 5, 5, 12, 12, 12) Img0to5(3).Visible = True Img0to5(3).Refresh Case Is = 32 'g#dim Call send13Byte(60, 0, 64, 32, 0, 0, 0, 1, 0, 0, 1, 0, 0) Call init0TO Call showChord(3, 4, 5, 3, 12, 12) Case Is = 44 'g# Call send13Byte(63, 0, 32, 0, 64, 0, 0, 1, 1, 1, 1, 1, 1) Call init0TO Call showChord(12, 5, 12, 4, 12, 12) Img0to5(3).Visible = True Img0to5(3).Refresh Case Is = 9 'amajor Call send13Byte(31, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 0) Call init1TO Call showChord(12, 12, 1, 1, 1, 12) Case Is = 21 'aminor Call send13Byte(31, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 128, 0) Call init1TO Call showChord(12, 12, 1, 1, 0, 12) Case Is = 33 'adim Call send13Byte(30, 64, 32, 16, 64, 0, 0, 0, 0, 0, 0, 0, 0) Call init0TO Call showChord(4, 5, 6, 4, 12, 12) Case Is = 45 'a Call send13Byte(31, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 4, 0) Call init1TO Call showChord(12, 12, 1, 12, 1, 12) Case Is = 10 'a#major Call send13Byte(31, 0, 0, 0, 0, 0, 0, 0, 128, 130, 130, 130, 128) Call init1TO Call showChord(12, 12, 2, 2, 2, 12) Img1to5(0).Visible = True Img1to5(0).Refresh Case Is = 22 'a#minor Call send13Byte(31, 0, 0, 0, 0, 0, 0, 0, 128, 130, 130, 132, 128) Call init1TO Call showChord(12, 12, 2, 2, 1, 12) Img1to5(0).Visible = True Img1to5(0).Refresh Case Is = 34 'a#dim Call send13Byte(60, 32, 16, 8, 32, 0, 0, 0, 0, 0, 0, 0, 0) Call init0TO Call showChord(5, 6, 7, 5, 12, 12) Case Is = 46 'a# Call send13Byte(31, 0, 0, 0, 0, 0, 0, 0, 128, 130, 128, 130, 128) Call init1TO