2
« en: Lunes 31 de Agosto de 2009, 20:26 »
#include <basicsystem.bas>
#pragma DATA 0x2007, _XT_OSC & _WDT_OFF
'#pragma DATA _CONFIG, _INTOSC_OSC_NOCLKOUT & _PWRTE_ON & _WDT_OFF & _CP_OFF & _LVP_OFF & _MCLRE_ON
#pragma OPTIMIZE "a"
Extern Sub lcd()
dim dato as byte
dim cont as byte
dim cadena as string(38)
dim j as byte
dim cadena2 as string(15)
dim puls1 as bit
dim puls2 as byte
dim est as byte
dim est2 as byte
dim est3 as byte
dim est4 as byte
dim savep2 as byte
dim savep3 as byte
Sub main()
'cmcon = 7
trisa =0x18 'configuro porta 3 y 4 como entrada
trisb =0x00
call delay_s (1)
call inicialitzaLCD ()
call control(0x38)
call control(0x80)
cadena = "EME sound 40w Sound Amplifier 1.0" '34
for j=0 to 34 step 1
dato = cadena(j)
call datoLCD (dato)
next j
puls1=0
puls2=0
call delay_ms (250)
for j=0 to 21 step 1 'desplaçament a l'esquerra
call control(0x18)
call delay_ms (255)
next j
'................................................. ..........
call control (0x01) 'BORRAR DISPLAY
'................................................. ..........
ini:
if puls1=1 then
puls2=savep2
call primera ()
savep2=puls2
else
'segunda linea display
puls2=savep3
call segunda ()
savep3=puls2
end if
goto ini
' call control (0x01) 'BORRAR DISPLAY
end sub
sub primera()
call control(0x38 ) 'posiciono texto al principio
call control(0x80 ) 'posiciono texto en la primera linea
call compro(puls1, puls2) 'compruebo si he pulsado
'................................................. ..........
if puls1=0 then
Select Case est4
Case 0
cadena="AMPLIFICADOR OFF"
Case 1
cadena="AMPLIFICADOR ON"
End Select
else
est=puls2&1
Select Case est
Case 0
cadena="AMPLIFICADOR<OFF"
est4=0
Case 1
cadena="AMPLIFICADOR< ON"
est4=1
End Select
end if
'................................................. ..........
'en la posicion 92 es donde puedo situar el cursor
'................................................. ..........
for j=0 to 15 step 1
dato = cadena(j)
call datoLCD (dato)
next j
end sub
sub segunda()
call control(0x38 ) 'posiciono texto al principio
call control(0xC0 ) 'posiciono texto en la segunda linea
call compro(puls1,puls2) 'compruebo si he pulsado
'................................................. ..........
if puls1=1 then
Select Case est3
Case 0
cadena2="VENTILACION OFF"
Case 1
cadena2="VENTILACION MIN"
Case 2
cadena2="VENTILACION MED"
Case 3
cadena2="VENTILACION MAX"
End Select
else
est2=puls2&3
Select Case est2
Case 0
cadena2="VENTILACION <OFF"
est3=0
Case 1
cadena2="VENTILACION <MIN"
est3=1
Case 2
cadena2="VENTILACION <MED"
est3=2
Case 3
cadena2="VENTILACION <MAX"
est3=3
End Select
end if
'................................................. ..........
'paso los valores al LCD
for j=0 to 15 step 1
dato = cadena2(j)
call datoLCD (dato)
next j
'................................................. ..........
end sub
'--------------------------------------------------------------
'subrutina de comprobacion por si se a pulsado el algun pulsador
sub compro( byref puls1 as byte, byref puls2 as byte)
if porta.4=0 then
call delay_us(100) 'delay antirrebote
if porta.4=0 then
puls1=puls1+1
call delay_us(100) 'delay antirrebote
end if
end if
'----------------------
'espero que acabe de pulsar el boton
espera2:
if porta.4=0 then
goto espera2
end if
'--------------------------------------------------------------
if porta.3=0 then
call delay_us(100) 'delay antirrebote
if porta.3=0 then
puls2=puls2+1
call delay_us(100) 'delay antirrebote
end if
end if
'---------------------
'espero que acabe de pulsar el boton
espera:
if porta.3=0 then
goto espera
end if
end sub
'--------------------------------------------------------------
'SUBRUTINA LCD INIALIZA
sub inicialitzaLCD ()
dim cont as byte
cont = 0x38 'MODO TRANSFERENCIA
'DISPLAY 5X7, DISPLAY CON 2 LINEAS
'DISPLAY A 8 BITS
call control (cont)
cont = 0x06 'MODO FUNCIONAMIENTO
'INC CONT DIRECCIONES, DISPLAY QUIETO
call control (cont)
cont = 0x01 'BORRAR DISPLAY
call control (cont)
cont = 0x0c 'ON/OFF
'DISPLAY ON, CURSOR ON, NO PARPADEO CURSOR
call control (cont)
end sub
'--------------------------------------------------------------
'--------------------------------------------------------------
'SUBRUTINA CONTROL
sub control (cont as byte)
portb = cont
porta.0 = 0 'RS
porta.1 = 0 'R/W
porta.2 = 0
porta.2 = 1 'impuls
porta.2 = 0
call delay_100us(17) 'ret 1.64mS
end sub
'---------------------------------------------------------------
'---------------------------------------------------------------
'SUBRUTINA LEER DATO
sub datoLCD (dato as byte)
portb = dato
porta.0 = 1 'RS
porta.1 = 0 'R/W
porta.2 = 0
porta.2 = 1 'impuls
porta.2 = 0
call delay_10us(4) 'ret 40uS
end sub