free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
ashishdaga
Mon May 12 2008, 05:32AM
 User Offline
Registered Member #7524
Joined: Tue Apr 29 2008, 02:48PM

Posts: 8
Thanked 0 times in 0 posts
i have interfaced a microcontoller 8051 with visual basic 2008.the serial communication is working correctly
i wanted to know that during runtime can the form update itself according to the data send by the nicrocontroller.
let me give an example to explain my problem

i send a 3 from the microcontroller then VB shud display "connection established"
in the same form when i send 4 from the microcontroller then VB shud display "danger occurred".
the above part shud occur at runtime continuosly as the 8051 keeps monitoring external events and sends it to PC.
this problem can be elaborated as

Dim a As Integer
Dim b As Integer
Label1.Text = a + b
Label1.Text = a - b

i want during runtime first a+b shud be displayed
then after sometime a-b shud be displayed in the same form

Back to top


ashishdaga
Mon May 12 2008, 05:34AM
 User Offline
Registered Member #7524
Joined: Tue Apr 29 2008, 02:48PM

Posts: 8
Thanked 0 times in 0 posts
sorry moderator by mistake two threads have opened. plz delete one of them.
http://www.8051projects.net/forum-t9489.html delete this

[ Edited Mon May 12 2008, 05:47AM ]
Back to top


Ajay
Mon May 12 2008, 05:15PM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3745
Thanked 695 times in 654 posts
I am writing a small code with a button and a lable.
so whenever button is clicked label will change

CODE:
Dim a As Boolean
Private Sub Command1_Click()
If a Then
    Label1.Caption = "Click to change"
    a = False
Else
    Label1.Caption = "Text changed!"
    a = True
End If
End Sub

Private Sub Form_Load()
a = False
Label1.Caption = "Click button to change text"
End Sub
 


You need to change caption of label not text

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


ashishdaga
Mon May 12 2008, 05:55PM
 User Offline
Registered Member #7524
Joined: Tue Apr 29 2008, 02:48PM

Posts: 8
Thanked 0 times in 0 posts
but the main problem is the microcntroller will send data based on external events and so i want the caption to change automatically based on what the microcontroller state.the vb code is continuously communicating with the microcontroller.so when it caotures data say a 3 it shud display "connection established" within the caption.
when it captures data 4 from the microcontroller it shud display "danger occurred".
the display within the label shud continuosly change based on micrcontroller input
and all the above display changes shud occur within the same form and same label.
is it possible in visual basic????

[ Edited Mon May 12 2008, 05:56PM ]
Back to top


Ajay
Mon May 12 2008, 06:14PM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3745
Thanked 695 times in 654 posts
whenever event occurs simply change the caption of lable using
CODE:
label.caption = "text to display"
 

within that event loop or condition

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


ashishdaga
Tue May 13 2008, 05:04PM
 User Offline
Registered Member #7524
Joined: Tue Apr 29 2008, 02:48PM

Posts: 8
Thanked 0 times in 0 posts
actually my code is working fine in single step i can recieve and send with the microcontroller but the problem is when i run the .exe the current event is not being taken into account and the vb does not display the text correspnding to the event.
here is my vb.net code

CODE:
Public Class Form1
    Const check As Integer = 1
    Const ack As Integer = 2
    Const danger As Integer = 3
    Const tout As Integer = 4
    Const incr As Integer = 5
    Const reset1 As Integer = 6
    Const endack As Integer = 7
    Const sendadd As Integer = 8
    Const taskcomp As Integer = 9
    Const ready As Integer = 10
    Const invalid As Integer = 11
    Dim rst As Integer
    Dim i As Integer
    Dim data1 As String
    Dim status(255) As Integer
    Dim dng_address As String
    Dim instr As Integer
    Dim toutaddr As Integer
    Dim endacko As Integer
    Dim readyinp As Integer
    Dim temp As Integer
    Private Sub MONITOR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MONITOR.Click
        Label2.Text = "SYSTEM IS MONITORING"
        AxMSComm1.InBufferCount() = 0 'CLEAR THE BUFFERS
        AxMSComm1.OutBufferCount() = 0
        AxMSComm1.Settings = "9600,n,8,1" ' SEND SETTINGS TO PORT
        AxMSComm1.PortOpen = True ' MAKE THE PORT OPEN
back: AxMSComm1.Output = ready & Chr(13) 'SEND READY COMMAND TO MICROCONTROLLER
        While (AxMSComm1.InBufferCount = 0) 'WAIT FOR READY COMMAND FROM MICROCONTROLLER
        End While
        Dim temp2 As String
        temp2 = AxMSComm1.Input 'ASSIGN TEMP2 AS INPUT RECEIVED FROM MIC
        ' if there is input from 8051
        PictureBox5.Image = System.Drawing.Image.FromFile("c:\4.jpg") 'DISPLAY IMAGE OF NOKIA CONNECTION ESTABLISHED
        Label4.Text = "CONNECTION ESTABLISHED"
        Label2.Enabled = False
        GoTo checkinput ' JUMP TO CHECKINPUT IF RECEIVED FROM MIC

checkinput:
        Label2.Text = "SYSTEM IS CHECKING THE INPUT"
        If (rst = 1) Then 'IF RESET BUTTON IS PRESSED CALL RESET SUBROUTINE
            Call reset()
        Else
            AxMSComm1.InBufferCount() = 0
            AxMSComm1.Output = check & Chr(13) 'SEND CHECK COMMAND TO MIC
            While (AxMSComm1.InBufferCount = 0) 'WAIT TILL MIC REPLIES
            End While
            data1 = AxMSComm1.Input
            Select Case data1 ' COMPARE THE DATA ONE RECEIVED WITH ALL POSSIBLE PARAMETERS
                Case endack
                    GoTo endacknowledge
                Case danger
                    GoTo danger_tree
                Case tout
                    GoTo tout_tree
            End Select
        End If
        Label2.Enabled = False

endacknowledge: Label2.Text = "END ACKNOWLEDGE SIGNAL RECEIVED"
        GoTo checkinput 'AGAIN CHECK FOR THE INPUT FROM MIC

danger_tree: Label2.Text = "SOME DANGER OCCURED"
        PictureBox6.Image = System.Drawing.Image.FromFile("c:\3.jpg") 'DISPLAY DANGER IMAGE IN PIC BOX 6 IF DANGER COMMAND IS RECEIVED
        My.Computer.Audio.Play("C:\fire alarm.wav", AudioPlayMode.WaitToComplete) 'PLAY DANGER SIREN
        AxMSComm1.InBufferCount() = 0
        AxMSComm1.OutBufferCount() = 0
        AxMSComm1.Output = sendadd & Chr(13) 'SEND ADDRESS command TO MIC
        While (AxMSComm1.InBufferCount = 0) ' WAIT FOR THE ADDRESS TO COME IN BUFFER
        End While
        dng_address = AxMSComm1.Input 'ASSIGN ADDRESS TO DNG_ADDRESS
        Select Case dng_address 'COMPARE THE ADRESS RECEIVED WITH 1,2,3,4...... AND SHOW DANGER IN CORRESPONG PICBOX
            Case 1
                PictureBox1.Image = System.Drawing.Image.FromFile("c:\1.jpg")
                status(1) = 1 'IF DANGER IS IN TREE 1 MARK THE ARRAY LOCATION 1 AS AFFECTED
            Case 2
                PictureBox2.Image = System.Drawing.Image.FromFile("c:\1.jpg")
                status(2) = 1
            Case 3
                PictureBox3.Image = System.Drawing.Image.FromFile("c:\1.jpg")
                status(3) = 1
            Case 4
                PictureBox4.Image = System.Drawing.Image.FromFile("c:\1.jpg")
                status(4) = 1
            Case 5
                PictureBox5.Image = System.Drawing.Image.FromFile("c:\1.jpg")
                status(5) = 1
        End Select
        For Me.i = 1 To 5
            If status(i) = 1 Then
                AxMSComm1.Output = incr & Chr(13) 'IF DANGER OCCURS IN ANY CASE THAN SEND INCREMENT COMMAND TO MIC
                temp = i
            Else
            End If
        Next
        While (AxMSComm1.InBufferCount = 0) 'WAIT UNTIL SENDADDRESS COMMAND COMES FROM MIC
        End While
        Dim temp3 As String
        temp3 = AxMSComm1.Input
        AxMSComm1.Output = (temp - 1) & Chr(13) 'VB SENDS ADDR-1 TO MIC TO INCR
        AxMSComm1.OutBufferCount() = 0
        While (AxMSComm1.InBufferCount = 0) ' WAIT TILL TASK COMPLETE COMMAND IS RECEIVED
        End While
        Dim temp4 As String
        temp4 = AxMSComm1.Input
        AxMSComm1.InBufferCount() = 0
        Label2.Enabled = False
        GoTo checkinput 'AGAIN CHECK FOR INPUT
tout_tree: Label2.Text = "TIMEOUT OCCURED" ' TIMEOUT IS THE CASE WHEN THERE IS PROBLEM IN BATTERY ETC
        My.Computer.Audio.Play("C:\fire alarm.wav", AudioPlayMode.WaitToComplete) 'PLAY DANGER SIREN
        AxMSComm1.Output = sendadd & Chr(13) 'VB WANTS ADDRESS OF TIMEOUT LOCATION
        While (AxMSComm1.InBufferCount = 0) 'WAIT TILL ADDRESS OF TIMEOUT LOCATION IS RECEIVED
        End While
        toutaddr = AxMSComm1.Input
        PictureBox6.Image = System.Drawing.Image.FromFile("c:\3.jpg")
        Select Case toutaddr 'COMPARE THE ADRESS RECEIVED WITH 1,2,3,4...... AND SHOW TIMEOUT IN CORRESPONG PICBOX
            Case 1
                PictureBox1.Image = System.Drawing.Image.FromFile("c:\5.jpg")
                status(1) = 2
            Case 2
                PictureBox2.Image = System.Drawing.Image.FromFile("c:\5.jpg")
                status(2) = 2
            Case 3
                PictureBox3.Image = System.Drawing.Image.FromFile("c:\5.jpg")
                status(3) = 2
            Case 4
                PictureBox4.Image = System.Drawing.Image.FromFile("c:\5.jpg")
                status(4) = 2
            Case 5
                PictureBox5.Image = System.Drawing.Image.FromFile("c:\5.jpg")
                status(5) = 2
        End Select
        For Me.i = 1 To 5
            If status(i) = 2 Then
                AxMSComm1.Output = incr & Chr(13) 'SEND INCREMENT COMMAND TO MIC
                AxMSComm1.OutBufferCount() = 0
                temp = i
            Else
            End If
        Next
        While (AxMSComm1.InBufferCount = 0) 'Mic WANTS ADDR OF WHICH LOCATION TO INCREMENT
        End While
        Dim temp5 As String
        temp5 = AxMSComm1.Input
        AxMSComm1.Output = (temp - 1) & Chr(13) 'VB SENDS ADDR-1 TO MIC
        AxMSComm1.OutBufferCount() = 0
        While (AxMSComm1.InBufferCount = 0) 'WAIT TILL TASK COMPLETE CODE IS RECEIVED
        End While
        Dim temp6 As String
        temp6 = AxMSComm1.Input
        Label2.Enabled = False
        GoTo checkinput
    End Sub
    Private Sub RESET2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RESET2.Click
        rst = 1
    End Sub

    Function reset() As Single
        Dim TEMP_RESET As Integer
        Label2.Text = "RESETTING THE NETWORK PLZ WAIT"
        rst = 0
        For Me.i = 1 To 5
            If status(i) = 1 Or status(i) = 2 Then 'IF TIMEOUT OR DANGER HAS OCCURED
                AxMSComm1.Output = reset1 'SENDS RST COMMAND TO MIC
                AxMSComm1.OutBufferCount() = 0
                TEMP_RESET = i
                status(i) = 0
            End If
        Next
        While (AxMSComm1.InBufferCount = 0) 'Mic WANTS ADDR OF WHICH LOCATION TO RESET
        End While
        Dim粑TEMP4 As Integer
        TEMP4 = AxMSComm1.Input
        AxMSComm1.Output = TEMP_RESET - 1 'VB SENDS ADDR-1 TO MIC
        While (AxMSComm1.InBufferCount = 0) 'WAIT TILL TASC COMPLETE CODE IS RECEIVED BY VB
        End While
        Dim TEMP5 As Integer
        TEMP5 = AxMSComm1.Input


        PictureBox1.Image = System.Drawing.Image.FromFile("c:\2.jpg") ' CHANGE THE PICTURES AS DEFAULT
        PictureBox2.Image = System.Drawing.Image.FromFile("c:\2.jpg")
        PictureBox3.Image = System.Drawing.Image.FromFile("c:\2.jpg")
        PictureBox4.Image = System.Drawing.Image.FromFile("c:\2.jpg")
        PictureBox5.Image = System.Drawing.Image.FromFile("c:\2.jpg")
        Label2.Enabled = False
    End Function

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label3.Text = TimeString
    End Sub
End Class
 


Back to top


ashishdaga
Tue May 13 2008, 05:09PM
 User Offline
Registered Member #7524
Joined: Tue Apr 29 2008, 02:48PM

Posts: 8
Thanked 0 times in 0 posts
my only problem is the label12.text does not changes during run-time according to the events.thus when a particular event occurs say danger it shud display "some danger occurred" in label12.text.
i am using vb.net so label12.text is same as label12.caption in VB6
so basically i want the text to change according to the event received and this shud happen continuously


Back to top


Ajay
Wed May 14 2008, 02:31PM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3745
Thanked 695 times in 654 posts
try cleaning the o/p files and re-build the whole project again. coz if the logic is working in step execution then it must work in final exe.

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems