elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Comunicación con un uC a través del puerto serie
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Comunicación con un uC a través del puerto serie  (Leído 1,730 veces)
klonner

Desconectado Desconectado

Mensajes: 2


Ver Perfil
Comunicación con un uC a través del puerto serie
« en: 10 Mayo 2010, 17:08 pm »

Buenas, estoy intentando mandar datos entre el PC y un uC (atmel), en VB.

Primero intenté mandar un unico dato y me lo devolvia correctamente, ahora intentamos mandar 3 datos distintos y no manda (o recibe bien).

Adjunto el codigo VB

Código
  1. Private Sub Command1_Click()
  2.  
  3. If MSComm1.PortOpen = True And Text7.Text = 3 Then
  4. MSComm1.Output = Text1.Text
  5. Text7.Text = Text7.Text - 1
  6. End If
  7.  
  8. If MSComm1.PortOpen = True And Text7.Text = 2 Then
  9. MSComm1.Output = Text3.Text
  10. Text7.Text = Text7.Text - 1
  11. End If
  12.  
  13. If MSComm1.PortOpen = True And Text7.Text = 1 Then
  14. MSComm1.Output = Text4.Text
  15. Text7.Text = Text7.Text - 1
  16. End If
  17.  
  18. End Sub
  19. Private Sub Command2_Click()
  20.  
  21. MSComm1.PortOpen = False
  22. End
  23. End Sub
  24.  
  25. Private Sub Command3_Click()
  26.  
  27. If MSComm1.PortOpen = True And Text8.Text = 3 Then
  28. Text2.Text = MSComm1.Input
  29. Text8.Text = Text8.Text - 1
  30. End If
  31.  
  32. If MSComm1.PortOpen = True And Text8.Text = 2 Then
  33. Text5.Text = MSComm1.Input
  34. Text8.Text = Text8.Text - 1
  35. End If
  36.  
  37. If MSComm1.PortOpen = True And Text8.Text = 1 Then
  38. Text6.Text = MSComm1.Input
  39. Text8.Text = Text8.Text - 1
  40. End If
  41.  
  42. End Sub
  43.  
  44. Private Sub Command4_Click()
  45. If MSComm1.PortOpen = True Then
  46. MSComm1.Output = Text7.Text
  47. End If
  48. End Sub
  49.  
  50. Private Sub Command5_Click()
  51. If MSComm1.PortOpen = True Then
  52. Text8.Text = MSComm1.Input
  53. End If
  54. End Sub
  55.  
  56. Private Sub Form_Load()
  57. If MSComm1.PortOpen = True Then
  58. Command1.Enabled = False
  59. End If
  60.  
  61. If MSComm1.PortOpen = False Then
  62. MSComm1.PortOpen = True
  63. Shape1.FillColor = &HFF00&
  64. End If
  65.  
  66. End Sub

Codigo C del uC
Código
  1. void retardo (unsigned int n)
  2. {
  3.    unsigned int i,j;
  4.    for (i=0;i<n;i++)
  5.    {
  6.        for(j=0;j<0xFFFF;j++)
  7. {}
  8.    }  
  9. }
  10. void main (void)
  11. {
  12. SCON = 0x50;  /* uart in mode 1 (8 bit), REN=1 */
  13. TMOD = TMOD | 0x20 ;         /* Timer 1 in mode 2 */
  14. TH1  = 0xFD;                 /* 9600 Bds at 11.059MHz */
  15. TL1  = 0xFD;    /* 9600 Bds at 11.059MHz */
  16. ES = 1;     /* Enable serial interrupt */
  17. EA = 1;     /* Enable global interrupt */
  18. TR1 = 1;  /* Timer 1 run */
  19.   while(1);                    /* endless */
  20. }
  21.  
  22. /**
  23.  * FUNCTION_PURPOSE: serial interrupt, echo received data.
  24.  * FUNCTION_INPUTS: P3.0(RXD) serial input
  25.  * FUNCTION_OUTPUTS: P3.1(TXD) serial output
  26.  */
  27. void serial_IT(void) interrupt 4
  28. {
  29.  
  30.  
  31.   if (RI==1 & count==0)
  32.  
  33. {                
  34.  RI = 0;
  35.  
  36.  count = SBUF;
  37.  
  38.  SBUF = count;        
  39.  i=0;
  40.   retardo(1);        
  41. }
  42.  
  43. if (RI==1 & count !=0)
  44. {
  45. if (i==0){                
  46.  RI = 0;
  47.  i++;          
  48.  uart_data1 = SBUF;          
  49.  SBUF = uart_data1;
  50.  retardo(1);      
  51.  
  52. }
  53. if (i==1){                
  54.  RI = 0;
  55.  i++;          
  56.  uart_data2 = SBUF;
  57.  
  58.  SBUF = uart_data2;        
  59.  retardo(1);        
  60. }
  61.  
  62.  
  63. if (i==3)
  64. {                
  65.  RI = 0;
  66.  i++;          
  67.  uart_data3 = SBUF;
  68.  
  69.  SBUF = uart_data3;
  70.  retardo(1);
  71.  count=0;    
  72. }
  73.  
  74. }
  75.  
  76. else TI = 0;        /* if emission occur */
  77.  
  78. }



En línea

blog personal ----> http://www.robotecnia.net
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines