PROYECTO PROGRAMA EN MIKROBASIC PRO 2009

88 views
Skip to first unread message

Lord_Libra

unread,
Aug 18, 2010, 3:13:34 PM8/18/10
to ConexionElectronica
Saludos.

Bueno, al grano, estoy hacinedo un proyecto de control de un
invernadero, es decir, control del sistema de riego y de la
temperatura ambiente dentro de éste, control de motores para el juego
de cortinas, control de un motor para aire acondicionado, control de
la bomba de agua, todo esto desde el PIC16F877.

Lo que no estoy logrando es hacer la parte de la comunicacion serial,
no responde para nada, lo borre del programa esa parte de codigo, y
ahora no se que es lo que pasa, pero ya no compila bien, antes de
ingresar el codigo para comunicacion serial, todo estaba bien, luego
de eso, ya no funciona correctamente.

Bueno, aqui el codigo completo.
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.

Seguramente a muchos les surgiran mejores ideas para mejorar la
programacion, talves ponerle más orden, y qué rutinas se podrian poner
en funciones.

Muchas gracias
Reply all
Reply to author
Forward
0 new messages