Autor Tema: Comunicacion serial en mikrobasic pro para PIC  (Leído 3731 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado Lord_Duran

  • PIC12
  • **
  • Mensajes: 76
Comunicacion serial en mikrobasic pro para PIC
« en: 18 de Agosto de 2010, 21:38:17 »
Saludos.

Tengo problemas con la comunicacion serial en mikrobasic, cuando pongo el código para activar al comunciacion serial, pues todo se va al tacho, antes de eso, todo bien, luego de poner el código, pues nada esta bien, como que se desborda todo.

el código que pongo a continuación esta con las lineas de activacion del modulo USART en commentarios

Código: [Seleccionar]
program EJEMPLO2

'CONFIGURACION PARA LCD
Dim LCD_RS As sbit At RB4_bit
Dim LCD_EN As sbit At RB5_bit
Dim LCD_D4 As sbit At RB0_bit
Dim LCD_D5 As sbit At RB1_bit
Dim LCD_D6 As sbit At RB2_bit
Dim LCD_D7 As sbit At RB3_bit

Dim LCD_RS_Direction As sbit At TRISB4_bit
Dim LCD_EN_Direction As sbit At TRISB5_bit
Dim LCD_D4_Direction As sbit At TRISB0_bit
Dim LCD_D5_Direction As sbit At TRISB1_bit
Dim LCD_D6_Direction As sbit At TRISB2_bit
Dim LCD_D7_Direction As sbit At TRISB3_bit
' DECLARACION DE VARIABLES
Dim temp1 As word
    temp1flt As float
    temptflt As float
    tempStr As string[8]
    temp2 As word
    temp2flt As float
   
Dim control As bit
Dim control1 As bit
Dim controlh As bit

Const tempA As Float = 20.0
Const tempB As Float = 28.0
Const humA As Float = 75.0
Const humB As Float = 80.0

Dim hum1 As word
    hum1flt As float
    RHStr As string[8]
    hum2 As word
    hum2flt As float
    hum3 As word
    hum3flt As float
    humtflt As float
    RH As float

main:
TRISA = %11111111
TRISB = %00000000
TRISC = %00010000
TRISD = %00000000
ADCON1 = %10000010
PORTB = %00000000
PORTC = %00000000
PORTD = %00000000

'UART1_Init(9600)
'Delay_ms(100)

LCD_Init()
LCD_Cmd(_LCD_CLEAR)
LCD_Cmd(_LCD_CURSOR_OFF)
Delay_ms (500)
control = 0
control1 = 0
controlh = 0

while (true)
      temp1 = (Adc_Read(0)*100)
      temp2 = (Adc_Read(1)*100)
      temp1flt = temp1
      temp2flt = temp2
      LCD_Out(1,4,"TEMPERATURA")
      LCD_Cmd(_Lcd_Second_Row)
      temp1flt = temp1flt * 0.0049
      temp2flt = temp2flt * 0.0049
      temptflt = (temp1flt + temp2flt)/2 'TEMPERATURA PARA COMPARAR ------------------
      ' ********RUTINA DE CONTROL DE TEMPERATURA************
      if (temptflt >= tempB) then
         if (control = 0) then  ' AQUI TESTEAR EL RC3
            PORTC.1 = 1
            goto sube  'PORTC.1 = 1     ' ARRIBA
            sube1:
            Delay_Ms (3000)
            goto paraA  'PORTC.1 = 0
            para1:
            PORTC.1 = 0
            control = 1  ' AQUI VER EL RC3
         end if
      end if
      if (temptflt <= tempA) then
         if (control = 1) then
            PORTC.3 = 1  ' ABAJO
            goto baja    ' PORTC.1 = 1
            baja1:
            Delay_Ms (3000)
            goto paraB    ' PORTC.1 = 0
            para2:
            PORTC.3 = 0
            control = 0
         end if
         PORTC.2 = 1  'AIRE CALIENTE
         control1 = 1
      end if
      if (control1=1) then
         if (temptflt <= 25.0) then
            PORTC.2 = 1   ' AIRE CALIENTE
         else
             PORTC.2 = 0  'APAGA AIRE CALIENTE
             control1 = 0
         end if
      end if
      ' ***********FIN RUTINA CONTROL TEMPERATURA*****************
      FloatToStr(temptflt,tempStr)
      LCD_Chr(2,6,tempStr[0])
      LCD_Chr_Cp(tempStr[1])
      LCD_Chr_Cp(tempStr[2])
      LCD_Chr_Cp(tempStr[3])
      LCD_Chr_Cp(tempStr[4])
      LCD_Out_Cp(" C")
      hum1 = Adc_Read(2)
      hum1flt = hum1
      hum2 = Adc_Read(3)
      hum2flt = hum1
      hum3 = Adc_Read(4)
      hum3flt = hum3
      hum1flt = hum1flt * 0.0049
      hum2flt = hum2flt * 0.0049
      hum3flt = hum3flt * 0.0049
      humtflt = (hum1flt + hum2flt + hum3flt)/3
      RH = (humtflt - 0.958)/0.0307  ' HUMEDAD PARA COMPARAR ---------------------------
      ' RUTINA CONTROL DE HUMEDAD
      if (RH >= 80.0) then
         PORTC.0 = 0
      end if
      if (RH <= 75) then
         PORTC.0 = 1
         controlh = 1
      end if
      if (controlh = 1) then
          if (RH <= 77) then
             PORTC.0 = 1
          else
              PORTC.0 = 0
              controlh = 0
          end if
      end if
      ' FIN RUTINA CONTROL DE HUMEDAD
      FloatToStr(RH,RHStr)
      LCD_Cmd(_Lcd_Third_Row)
      LCD_Out(3,2,"HUMEDAD")
      LCD_Cmd(_Lcd_Fourth_Row)
      LCD_Chr(4,2,RHStr[0])
      LCD_Chr_Cp(RHStr[1])
      LCD_Chr_Cp(RHStr[2])
      LCD_Chr_Cp(RHStr[3])
      LCD_Chr_Cp(RHStr[4])
      LCD_Out_Cp(" %")
      Delay_Ms (100)
wend
sube:
     PORTD.4 = 1  ' EN1
     PORTD.5 = 1  ' EN2
     PORTD.0 = 0  ' IN1
     PORTD.2 = 0  ' IN3
     PORTD.1 = 1  ' IN2
     PORTD.3 = 1  ' IN4
     goto sube1
baja:
     PORTD.4 = 1
     PORTD.5 = 1
     PORTD.0 = 1
     PORTD.2 = 1
     PORTD.1 = 0
     PORTD.3 = 0
     goto baja1
paraA:
     PORTD.4 = 1
     PORTD.5 = 1
     PORTD.0 = 0
     PORTD.2 = 0
     PORTD.1 = 0
     PORTD.3 = 0
     goto para1
paraB:
     PORTD.4 = 1
     PORTD.5 = 1
     PORTD.0 = 0
     PORTD.2 = 0
     PORTD.1 = 0
     PORTD.3 = 0
     goto para2
end.

muchas gracias

Desconectado daniel3514

  • PIC10
  • *
  • Mensajes: 16
    • Tech Inside
Re: Comunicacion serial en mikrobasic pro para PIC
« Respuesta #1 en: 02 de Febrero de 2012, 01:03:27 »
saludos, a mi me pasa algo similar, he notado que en el puerto donde esta conectado la UART, por ejemplo el portb en este caso soft_uart, los demas puertos del mismo portb cambian sus estados justo cuando se ejecuta la lectura soft uart...
Open Source: Técnicamente Viable, Económicamente Sustentable, Socialmente Justo...