Putting a number on port of Atmega32 via RS232

Status
Not open for further replies.

Bluestar88

Member level 3
Joined
Oct 17, 2014
Messages
59
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Visit site
Activity points
447
Hi guys,
I have a problem with Using Visual basic interfacing with atmega32. My goal is sending a number which enters in Visual basic 6(VOL1 in Picture) and driving PORTB atmega32 by this number. for example if I enter 4 in VOL1, 0000 0100 (its binary) set in PORTB. I activated Usrat in codevision and its hardware (max 232 and DB9). RS232 works well because I could control some pins of atmega32 by code. ( for example I decribed a code of "q", If Check1.Value = 1 Then
MSComm1.Output = "q"
End If
but I dont know how I can do it for sending a number.....please help me...I want to send number via visual basic and putting it on port of atmega32...help me...


- - - Updated - - -



I converted my number to hex and then sent to micro controller by rs232.
my code in visual basic is here is here

Code Basic4GL - [expand]
1
2
3
4
gg = Text1.Text 
tt = Hex(gg)
MSComm1.Output = tt
Text3.Text = tt



in micro I received it by getchar()..my code is here( expressions such as "t", "q" , .... are for other orders)

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
{
a=getchar();
 
       if ( (a !='t')&&(a !='u')&&(a !='v') &&(a !='w')&&(a !='x')&&(a !='y')&&(a !='z')&& (a !='s')&&(a !='g')&&(a !='h') &&(a !='i')&& (a !='j')&&(a !='k')&&(a !='l') && (a !='m')&&(a !='n') &&(a !='f') &&(a !='b')  &&(a !='c') &&(a !='d')&&(a !='e')&& (a !='q'))   
         {  
          
         PORTB=a;
         } 
 
       }



But there is a problem yet....sometimes the number puts on PORT of micro is true (for 1,2 and 3) but the number of 4 does not put correct on the PORT...I do not know why.....please help me.....
 
Last edited:

What can I do to receive accurate number from RS232 in code vision? (Sender is Visul basic and receiver is Code vision)....Please help me...
 

MS suggests this.

Visual Basic does not convert directly between

Char and the numeric types. You can use the Asc or AscW function to convert a Char value to an Integer that represents its code point. You can use the Chr or ChrW function to convert an Integer value to a Char that has that code point.

If the type checking switch (Option Strict Statement) is on, you must append the literal type character to a single-character string literal to identify it as the Char data type. The following example illustrates this.

Code:
Option Strict On
Dim charVar As Char
' The following statement attempts to convert a String literal to Char.
' Because Option Strict is On, it generates a compiler error.
charVar = "Z"
' The following statement succeeds because it specifies a Char literal.
charVar = "Z"C

Programming Tips
Negative Numbers. Char is an unsigned type and cannot represent a negative value. In any case, you should not use Char to hold numeric values.

Interop Considerations. If you interface with components not written for the .NET Framework, for example Automation or COM objects, remember that character types have a different data width (8 bits) in other environments. If you pass an 8-bit argument to such a component, declare it as Byte instead of Char in your new Visual Basic code.
Widening. The Char data type widens to String. This means you can convert Char to String and will not encounter a System.OverflowException error.

Type Characters. Appending the literal type character C to a single-character string literal forces it to the Char data type. Char has no identifier type character.
Framework Type. The corresponding type in the .NET Framework is the System.Char structure.


https://msdn.microsoft.com/en-us/library/7sx7t66b.aspx
 
I get what you are telling...But do you have any example for receiving umber in micro by UDR(Usart or getchar?!!)...I am so confused

- - - Updated - - -

Now, I used this way for sending data to RS232 in visual basic:
Code:
Private Sub Command1_Click()
MSComm1.Output = "o"
MSComm1.Output = "o"

gg = Text1.Text 
tt = Hex$(gg)

MSComm1.Output = tt
Text3.Text = tt

which means at first, I send "O" (optional) to say USART of micro after receving "o", read the RS232 and take it on PORTB.
(the code is here)

Code:
        if (a=='o')
         {    
        

         a=getchar();
         PORTB=a;
         }

But it does not work, why?
Do not have any idea....
please help...
 

now, By using the above program I can receive higher bit (8th bit)not a byte.....I do not know why........
 

I changed my method. I thought to sending a decimal to micro by RS232 and receiving it by getchar() and then I convert it to hexadecimal on putting it on PORTB...I succeed to receiving the number in micro..Now I want to convert it to hexadecimal...Can anyone to help me?? My code is here:
Code:
        if (a=='o')
         {    
         putchar('p');

         s=getchar();
       
         }
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…