torres.electronico
Well-known-Alfil
Lindo laburito... si no queres usar asm y o cuentas, no digo que no puedas por que vi que lo que te propones lo sacas adelante casi siempre, pero vas a tener bastante laburo
Follow along with the video below to see how to install our site as a web app on your home screen.
Nota: This feature currently requires accessing the site using the built-in Safari browser.
Sip, está laborioso en cuanto a investigar por donde meterla, pero si se puede porque en los ejemplos de la librería utilizan un resultado que arroja flotante y lo multiplican por una cantidad y si da.Lindo laburito... si no queres usar asm y o cuentas,
Creo que por ahí va.It should be ...
((high_%_span - low_%_span ) / (high_count_span - low_count_span)) * (Measured - low_count_span)
((100000 - 0) / (46461 - 22600)) * (Measured - 22600)
Since ((100000 - 0) / (46461 - 22600)) are all constants that are known ahead of time ...
They can be reduced to a single constant ... 4.190939189
4.190939189 * (Measured - 22600)
In floating point format, 4.190939189 = 0x81061C2D.
Which makes the code much easier...
Measured VAR WORD
Measured = 30000 ; 22600 - 46461
...
bexp = $81 ; 4.190939189
bargb0 = $06
bargb1 = $1C
bargb2 = $2D
AINT = Measured - 22600
GOSUB ItoFA
GOSUB FPMUL
BINT = 1000 ; /1000 for % with 3 decimal places
GOSUB ItoFB
GOSUB FPDIV
fpplaces = 3 : gosub fpdisplayr ; put the percentage result on LCD
'****************************************************************
;************* CONFIGURACION DE VARIABLES GENERALES *************
;****************************************************************
Define osc 4 ; definimos el oscilador en 4 mhz
CMCON = 7 ; PUERTO A TODO DIGITAL
TRISA = %11111111 ; PUERTO A TODO COMO ENTRADA
TRISB = %00000000 ; PUERTO B TODO COMO SALIDA
Define LCD_DREG PORTB ;PUERTO B.O.1.2.3 DEL PIC PARA CONTROL DEL LCD
Define LCD_DBIT 0
Define LCD_RSREG PORTB ; PIN RS CONECTADO EN PORTB5
Define LCD_RSBIT 5
Define LCD_EREG PORTB ; PIN E CONECTADO EN PORTB4
Define LCD_EBIT 4
DEFINE LCD_BITS 4 ;LCD CONFIGURADO EN 4 BITS
DEFINE LCD_LINES 2 ;LCD DE 2 LINEAS
START_button var PORTA.0 ; boton inicio
STOP_button var PORTA.1 ; boton parada
CLEAR_button var PORTA.2 ; boton borrar
MAS_button var PORTA.3 ; boton mas
MENOS_button var PORTA.4 ; boton menos
DISP_button var PORTA.5 ; entrada disparo auxiliar
RELAY var PORTB.6 ; salida para control del relay
BEEP VAR PORTB.7 ; salida para el control del buzzer
bandera var byte ;variable auxiliar
Ticks VAR byte ;variable auxiliar para los for-next
setHOUR VAR BYTE ; variable set HORAS programadas
setMINUTE VAR BYTE ; variable set minutos programadas
Hour VAR byte ; variable HORAS cronometro
Minute VAR byte ; variable Minutos cronometro
Second VAR byte ; variable Segundos cronometro
DelayHon VAR byte ; uso futuro
DelayMon var byte ; uso futuro
DelaySon var byte
DelayHoff VAR byte ; uso futuro
DelayMoff var byte ; uso futuro
DelaySoff var byte ; uso futuro
SETHOUR=0 ; valor inicial de la variable
SETMINUTE=0 ; valor inicial de la variable
;*****************************************************************
;******************** INICIO DEL PROGRAMA ************************
;*****************************************************************
Inicio:
HOUR = 0 ; valor inicial de la variable
MINUTE=0 ; valor inicial de la variable
SECOND=0 ; valor inicial de la variable
LCDOUT $FE, 1 ; limpiamos el lcd
HIGH BEEP ; encender buzzer
PAUSE 1000 ; pausa 1 segundo
LOW BEEP ; apagar buzzer
pause 50
MENU:
LCDOUT $fe,2,"RTempo (START)"
LCDOUT $fe,$c0,"RBiestable(STOP)"
if start_button = 0 then
LCDOUT $FE, 1
goto menu2
endif
IF stop_button = 0 then CONFIG2
goto MENU
menu2:
LCDOUT $fe,2,"Ini Tempo(-)"
LCDOUT $fe,$c0,"Prog Tempo(+)"
if mas_button = 0 then TEMPO ;si presionamos boton "MAS",ir a TEMPO
IF MENOS_BUTTON = 0 THEN INI_TEMPO ;si presionamos boton "MENOS",ir a INI_TEMPO
IF stop_button = 0 then
LCDOUT $FE, 1
goto menu
endif
goto menu2
;**************************************************************************
;************* INICIO SUBPROGRAMA PARA CONFIGURAR TIEMPO ******************
;**************************************************************************
TEMPO:
HIGH BEEP
PAUSE 1000
LOW BEEP
PAUSE 800
HIGH BEEP
PAUSE 1000
LCDOUT $FE, 1
LOW BEEP
pause 50
;**************************************************************************
;**************** sub programa para configurar el tiempo ******************
;**************************************************************************
CONFIG:
LCDOUT $fe,2,"INICIO (START)"
LCDOUT $fe,$C0,DEC2 SETHour,":",DEC2 SETMinute,":00"
IF MAS_button = 0 THEN
PAUSE 500
SETMinute = SETMinute + 1
IF SETMinute = 60 THEN
SETMinute = 0
SETHour = SETHour + 1
IF Hour => 24 THEN
Hour = 24
ENDIF
ENDIF
ENDIF
IF CLEAR_button = 0 THEN
SETHour = 0
SETMinute = 0
ENDIF
IF START_button = 0 THEN
LCDOUT $FE, 1
GOTO INI_TEMPO
ENDIF
GOTO CONFIG
;*****************************************************
;************* PROGRAMA DEL TEMPORIZADOR**************
;*****************************************************
INI_TEMPO:
IF SETHOUR = HOUR AND SETMINUTE = MINUTE THEN
IF STOP_button = 0 THEN GOSUB PARADA
LCDOUT $FE, 1
LCDOUT $fe,2,"TIEMPO PROGRAMA"
LCDOUT $fe,$C0," TERMINADO "
high beep
LOW RELAY
PAUSE 2000
low beep
GOTO INICIO
ENDIF
HIGH RELAY
LCDOUT $fe,2,"Set:",DEC2 SETHour,":",DEC2 SETMinute,":00"
LCDOUT $fe,$C0,"Tiempo:",DEC2 Hour,":",DEC2 Minute,":",DEC2 Second
PAUSE 450
GOSUB CONTADOR
IF STOP_button = 0 THEN GOSUB PARADA
GOTO INI_TEMPO
;**************************************************************************
;********************** sub programa para la pausa ************************
;**************************************************************************
PARADA:
LOW RELAY
TICKS=0
LCDOUT $FE, 1
FOR TICKS = 1 TO 4
LCDOUT $fe,2,"Set:",DEC2 SETHour,":",DEC2 SETMinute,":00"
LCDOUT $fe,$C0,"Tiempo:",DEC2 Hour,":",DEC2 Minute,":",DEC2 Second
PAUSE 250
IF START_button = 0 THEN
LCDOUT $FE, 1
HIGH RELAY
RETURN
ENDIF
IF CLEAR_button = 0 THEN inicio
NEXT TICKS
TICKS=0
LCDOUT $FE, 1
FOR TICKS = 1 TO 4
LCDOUT $FE, 1
LCDOUT $fe,2,"TIEMPO DETENIDO"
LCDOUT $fe,$C0,"SEGUIR (START)"
PAUSE 250
IF START_button = 0 THEN
LCDOUT $FE, 1
HIGH RELAY
RETURN
ENDIF
IF CLEAR_button = 0 THEN inicio
NEXT TICKS
GOTO PARADA
;**************************************************************************
;****************** sub programa para el cronometro ***********************
;**************************************************************************
CONTADOR:
Second = Second + 1 ; incrementar 1 en variable segundo
IF Second = 60 THEN ; consigna: si variable segundos es = a 60, entonces
Second = 0 ; ponemos variable segundos en 0
Minute = Minute + 1 ; incrementamos 1 en variable minuto
IF Minute = 60 THEN ; consigna dentro de consigna, si minuto es = 60 entonces
Minute = 0 ; ponemos variable minutos en 0
Hour = Hour + 1 ; incrementamos 1 en variable hora
IF Hour = 24 THEN ; consigna dentro de consigna, si hora = 24 entonces
Hour = 24 ; ponemos como limite maximo, hora = 24... modificar este
; valor si se quiere mas horas
ENDIF ; cerramos 1era consigna
ENDIF ; cerramos 2da consigna
ENDIF ; cerramos 3er consigna
PAUSE 500 ; pausa 1/2 segundo
RETURN ; volver
;*****************************************************
;************* PROGRAMA RELAY BIESTABLE **************
;*****************************************************
CONFIG2:
LCDOUT $FE, 1
CONFIG2a:
LCDOUT $fe,2,"RELAY tiempo ON"
LCDOUT $fe,$C0,"Min:",DEC2 delaymon," Seg:",dec2 delayson
IF MAS_button = 0 THEN
PAUSE 500
delayson = delayson + 1 ; incrementar 1 en variable segundo
IF delayson = 60 THEN ; consigna: si variable segundos es = a 60, entonces
delayson = 0
delaymon = delaymon + 1
IF delaymon = 60 THEN
delaymon = 0
delayhon = delayhon + 1
IF delayhon => 24 THEN
delayhon = 24
ENDIF
ENDIF
ENDIF
endif
IF CLEAR_button = 0 THEN
delayhon = 0
delaymon = 0
delayson = 0
ENDIF
IF START_button = 0 THEN
high beep
pause 1000
low beep
pause 50
LCDOUT $FE, 1
GOTO CONFIG3
ENDIF
GOTO CONFIG2a
CONFIG3:
LCDOUT $fe,2,"RELAY tiempo OFF"
LCDOUT $fe,$C0,"Min:",DEC2 delaymoff," Seg:",dec2 delaysoff
IF MAS_button = 0 THEN
PAUSE 500
delaysoff = delaysoff + 1 ; incrementar 1 en variable segundo
IF delaysoff = 60 THEN ; consigna: si variable segundos es = a 60, entonces
delaysoff = 0
delaymoff = delaymoff + 1
IF delaymoff = 60 THEN
delaymoff = 0
delayhoff = delayhoff + 1
IF delayhoff => 24 THEN
delayhoff = 24
ENDIF
ENDIF
ENDIF
endif
IF CLEAR_button = 0 THEN
delayhoff = 0
delaymoff = 0
delaysoff = 0
ENDIF
IF START_button = 0 THEN
high beep
pause 1000
low beep
pause 50
LCDOUT $FE, 1
GOTO INI_RELAY
ENDIF
GOTO CONFIG3
INI_RELAY:
LCDOUT $fe,2,"ESPERANDO"
LCDOUT $fe,$C0,"INICIO"
IF START_button = 0 THEN INI_RELAY2
IF STOP_button = 0 THEN INICIO
GOTO INI_RELAY
INI_RELAY2
hour=0
minute=0
second=0
LCDOUT $FE, 1
gosub activar_relay
hour=0
minute=0
second=0
LCDOUT $FE, 1
gosub desactivar_relay
IF STOP_button = 0 THEN GOSUB INICIO
GOTO INI_RELAY2
activar_relay:
IF STOP_button = 0 THEN GOSUB INICIO
bandera=1
LCDOUT $fe,2,"SI:",DEC2 delaymon,":",dec2 delayson,"NO:",DEC2 delaymoff,":",DEC2 delaysoff
LCDOUT $fe,$C0,"T:",DEC2 Minute,":",DEC2 Second," R:",dec bandera
HIGH RELAY
pause 500
gosub contador
IF delaymon = MINUTE and delayson = second THEN return
goto activar_relay
desactivar_relay:
IF STOP_button = 0 THEN GOSUB INICIO
bandera=0
LCDOUT $fe,2,"SI:",DEC2 delaymon,":",dec2 delayson,"NO:",DEC2 delaymoff,":",DEC2 delaysoff
LCDOUT $fe,$C0,"T:",DEC2 Minute,":",DEC2 Second," R:",dec bandera
low relay
pause 500
GOSUB CONTADOR
IF delaymoff = MINUTE and delaysoff = second THEN return
goto desactivar_relay
PAUSE 450
IF STOP_button = 0 THEN GOSUB PARADA
goto INI_relay
;*************************************************************************
END ; Fin del programa
;*************************************************************************
El programa está muy mal. Para eso necesitas usar un timer. (P.E. El Timer 1 y algunas banderas "Flags")Primero he hecho un solo cronómetro y me funciona.
El problema es al intentar que sean 4 cronómetros, el tiempo va súper despacio o no cuentan.
Claro que si.He leído por el foro algún ejemplo, éste es el enlace donde lo vi:
https://www.forosdeelectronica.com/f26/cronometro-picbasic-18f2550-128749/#post1005262
¿Podrías compartir el ejemplo, para ver si consigo hacer el de 4 tiempos?
Button pulsador,0,255,10,B0,0,Display ; Si se presiona el pulsador...
While pulsador = 0 ; Mientras esté pulsado...
contador = contador + 1 ; Incrementar "contador"
Pause 1 ; Retardo de 1ms.
If contador = 3000 Then ; Si "contador" llegó a 3000 (3 segundos)...
T1CON = 0 ; Deshabilitar Timer1
horas = 0 ; Limpiar "horas"
minutos = 0 ; Limpiar "minutos"
segundos = 0 ; Limpiar "segundos"
milisegundos = 0 ; Limpiar "milisegundos"
flag = 1 ; Mantener "flag" en 1 (Para que el soltar el pulsador no avance el conteo)
LCDOut $FE,$C3,"00:00:00.00" ; Poner en ceros la pantalla.
EndIf
Wend
While Pulsador = 0
T1CON.0 = 1
Wend
T1CON.0 = 0
No, eso es algo que no logré solucionar con el PIC18F2550.Al cambiarlo quite las banderas.
¿Ésto puede influir en que ahora no me haga un segundo justo?
Para otros conteos puedes aumentar las variables y usar banderas, para que sólo se realice el conteo en cada una cuando el estado de su respectiva bandera sea verdadero.Si está bien, voy a pasar a hacer que se vean dos cronómetros, pero no sé qué estructura seguir.
¿Se puede hacer con el Timer 1 o necesitaría más Timers?
Ya que éste lo estoy usando en el primer cronómetro.
If crono_1 = 1 Then
milisegundos_1 = milisegundos_1 + 1
; Incremento de las siguientes variables del cronómetro 1
EndIf
If crono_2 = 1 Then
milisegundos_2 = milisegundos_2 + 1
; Incremento de las siguientes variables del cronómetro 2
EndIf
; Etc.
DEFINE ADC_BITS 10 ; ADCIN çözünürlük (Bits)
DEFINE ADC_CLOCK 3 ; ADC clock kaynagi (Fosc/8)
DEFINE ADC_SAMPLEUS 50 ; ADC örnekleme zamani (uSec)
CMCON=7
ADCON1=%10000010
TRISA=%00001111
TRISB=%00000000
TRISC=%00000000
PORTA=0
PORTB=0
PORTC=0
VOLT VAR WORD
HVD var word
AMPER var word
MV VAR BYTE
MA VAR BYTE
D_C var PORTB.0
RST VAR PORTB.1
SCK var PORTB.2
SDIN var PORTB.3
SCE VAR PORTB.4
LcdReg var byte
x var byte
y var byte
z var byte
a var byte
PosX var byte
PosY var byte
Chr var byte
LcdData var byte
Offset var byte
Char var byte
DATA @0,$3E,$51,$49,$45,$3E,_ ';// 0
$00,$42,$7F,$40,$00,_ ';// 1
$42,$61,$51,$49,$46,_ ';// 2
$21,$41,$45,$4B,$31,_ ';// 3
$18,$14,$12,$7F,$10,_ ';// 4
$27,$45,$45,$45,$39,_ ';// 5
$3C,$4A,$49,$49,$30,_ ';// 6
$01,$71,$09,$05,$03,_ ';// 7
$36,$49,$49,$49,$36,_ ';// 8
$06,$49,$49,$29,$1E,_ ';// 9
$08,$08,$3E,$08,$08,_ ';// +
$08,$08,$08,$08,$08,_ ';// -
$00,$60,$60,$00,$00,_ ';// .
$7E,$11,$11,$11,$7E,_ ';// A
$1F,$20,$40,$20,$1F,_ ';// V
$7F,$09,$09,$09,$01 ';// F
pause 100
LcdReg = %00100001 'LCD Extended Commands.
call PrintCtrlLcd
LcdReg = $C8 'Set LCD Vop (Contrast).Initial $c5
call PrintCtrlLcd
LcdReg = %00000110 'Set Temp coefficent.
call PrintCtrlLcd
LcdReg = %00010011 'LCD bias mode 1:48.
call PrintCtrlLcd
LcdReg = %00100000 'LCD Standard Commands
call PrintCtrlLcd
LcdReg = $0C 'LCD in normal mode. $0D inverse
call PrintCtrlLcd
GOSUB InicializaLCD
Call CursorHome
Gosub LCD_Clear
;*********************************************
;*********************************************
INICIO:
LCDOUT $FE,1
CALL BORDER_LINE
;--------------------------------------------------------
;En esta seccion colocan la rutina de lectura adc
;mas el acondicionamiento para imprimir en digitos
;--------------------------------------------------------
GOSUB N3310 , subprograma de control del display
GOTO INICIO
;******************************************
;******************************************
N3310:
'~~~~~~~~~~~~ cursor display volt
LcdReg = %10100000 + 17 ' cursor X
call PrintCtrlLcd
LcdReg = %01000010 +40 ' cursor Y
call PrintCtrlLcd
; --------- digitos de la lectura volt 00,0v osea "volt,milivolt"
Char = (VOLT dig 1)
call PrintChar
Char = (VOLT dig 0)
call PrintChar
Char = 12 ; imprimimos el caracter ","
call PrintChar
Char = (MV dig 0)
call PrintChar
;Char = (MV dig 1)
;call PrintChar
Char = 14 ;imprimimos el caracter "v"
call PrintChar
'~~~~~~~~~~~~~~~~~ cursor display amp
LcdReg = %10100000 + 17 ' cursor X
call PrintCtrlLcd
LcdReg = %01000010 + 50 ' cursor Y
call PrintCtrlLcd
'~~~~~~~~~~~~~~~~~ now display results
Char = (amper dig 1)
call PrintChar
Char = (amper dig 0)
call PrintChar
Char = 12 ; imprimimos el caracter ","
call PrintChar
Char = (Ma dig 1)
call PrintChar
Char = 13 ;imprimimos el caracter "a"
call PrintChar
RETURN
InicializaLCD:
D_C=1 ' Seleccionamos el registro de datos en RAM
SCE=1 ' Anulamos la seleccion del chip
pause 100 ' Hacemos una pausa de 100 ms
gosub Reset_LCD ' Reseteamos el LCD
return
Reset_LCD:
RST=0 ' Damos un pulso de reset durante 100 ms
pause 100
RST=1
SCE=0
RETURN
CursorHome:
SCK = 1
LcdReg = %10000000 ' cursor Home
call PrintCtrlLcd
LcdReg = %01000000 ' cursor Home
call PrintCtrlLcd
return
PrintChar:
offset = Char * 5
for a = 1 to 5
read offset, LcdReg
call PrintDataLcd
offset = offset + 1
next a
LcdReg = 0
call PrintDataLcd
return
PrintCtrlLcd: D_C = 0
PrintDataLcd:
for x = 1 to 8
SDIN = LcdReg.7
SCK = 1
LcdReg = LcdReg << 1
SCK = 0
next x
D_C = 1
return
LCD_Clear:
PosX=0:PosY=0:Gosub LCD_GotoXY
D_C = 1
FOR Chr=1 TO 252
LcdData=0:Gosub LCD_ByteOut
LcdData=0:Gosub LCD_ByteOut
next Chr
return
LCD_GotoXY:
D_C = 0
LcdData=%01000000 | PosY :Gosub LCD_ByteOut
LcdData=%10000000 | PosX :Gosub LCD_ByteOut
return
LCD_ByteOut:
SHIFTOUT SDIN,SCK,1,[LcdData]
return
Border_line:
'~~~~~~~~~~~~~~~~~ RAND 0
LcdReg = %10000000 ' cursor X
call PrintCtrlLcd
LcdReg = %01000000 ' cursor Y
call PrintCtrlLcd
for y = 0 to 83
LOokup y, [$FF,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,_ ' UP-side "DIGITAL"
$01,$01,$01,$F9,$F9,$F9,$09,$09,$F9,$F9,$F1,$01,_
$01,$F9,$F9,$F9,$01,$01,$F1,$F9,$F9,$09,$09,$19,_
$19,$11,$01,$01,$F9,$F9,$F9,$01,$09,$09,$09,$F9,$F9,$F9,_
$09,$09,$09,$01,$F1,$F9,$F9,$09,$09,$F9,$F9,$F1,$01,$01,_
$F9,$F9,$F9,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,_
$01,$01,$01,$01,$01,$FF] ,LcdReg
call PrintDataLcd
next y
'~~~~~~~~~~~~~~~~~ RAND 1
LcdReg = %10000000 ' cursor X
call PrintCtrlLcd
LcdReg = %01000001 ' cursor Y
call PrintCtrlLcd
for y = 0 to 83
LOokup y, [$FF,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_ ' DOWN-side "DIGITAL"
$00,$00,$00,$1F,$1F,$1F,$10,$10,$1F,$1F,$0F,$00,$00,_
$1F,$1F,$1F,$00,$00,$0F,$1F,$1F,$10,$11,$1F,$1F,_
$0F,$00,$00,$1F,$1F,$1F,$00,$00,$00,$00,$1F,$1F,$1F,$00,_
$00,$00,$00,$1F,$1F,$1F,$01,$01,$1F,$1F,$1F,$00,$00,$1F,$1F,_
$1F,$10,$10,$10,$10,$00,$00,$00,$00,$00,$00,$00,_
$00,$00,$00,$00,$00,$FF] ,LcdReg
call PrintDataLcd
next y
'=================================== RAND 2
LcdReg = %10000000 ' cursor X
call PrintCtrlLcd
LcdReg = %01000010 ' cursor Y
call PrintCtrlLcd
LOokup 0, [$FF] , LcdReg
call PrintDataLcd
LcdReg = %10000000 + 83 ' cursor X
call PrintCtrlLcd
LcdReg = %01000010 ' cursor Y
call PrintCtrlLcd
LOokup 0, [$FF] , LcdReg
call PrintDataLcd
'=================================== RAND 3
; LcdReg = %10000000 ' cursor X
; call PrintCtrlLcd
; LcdReg = %01000011 ' cursor Y
; call PrintCtrlLcd
;
; LOokup 0, [$FF] , LcdReg
; call PrintDataLcd
;
; LcdReg = %10000000 + 48 ' cursor X
; call PrintCtrlLcd
; LcdReg = %01000011 ' cursor Y
; for y = 0 to 35
; LOokup y, [$18,$38,$60,$60,$38,$18,_ ' "VOLT"
; $00,$30,$78,$48,$78,$30,_
; $00,$78,$78,$40,$40,_
; $00,$08,$08,$78,$78,$08,$08,$00,_
; $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$FF] ,LcdReg
;
; call PrintDataLcd
; next y
'=================================== RAND 4
LcdReg = %10000000 ' cursor X
call PrintCtrlLcd
LcdReg = %01000100 ' cursor Y
call PrintCtrlLcd
LOokup 0, [$FF] , LcdReg
call PrintDataLcd
LcdReg = %10000000 + 83 ' cursor X
call PrintCtrlLcd
LcdReg = %01000100 ' cursor Y
call PrintCtrlLcd
LOokup 0, [$FF] , LcdReg
call PrintDataLcd
'=================================== JOS
LcdReg = %10000000 ' cursor X
call PrintCtrlLcd
LcdReg = %01000101 ' cursor Y
call PrintCtrlLcd
for y = 0 to 83
LOokup y, [$FF,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,_
$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,_
$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,_
$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,_
$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,_
$80,$80,$80,$80,$80,$80,$80,$80,$FF] ,LcdReg
call PrintDataLcd
next y
Return
'=======================================================================
End 'of program
;**********************************
;**********************************
DEFINE OSC 4
;**************** ADC chanel setting ************************
DEFINE ADC_BITS 8
;******************* DEGISKENLER ********************
INTCON = 0
CMCON=7
ADCON1 = 0
;ADCON1=%10000010
TRISA=%00001111
TRISB=%00000000
TRISC=%00000000
PORTA=0
PORTB=0
PORTC=0
DEFINE LCD_DREG PORTC
DEFINE LCD_DBIT 4
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 1
DEFINE LCD_RSREG PORTC
DEFINE LCD_RSBIT 0
DEFINE LCD_LINES 2
D_C var PORTB.0
RST VAR PORTB.1
SCK var PORTB.2
SDIN var PORTB.3
SCE VAR PORTB.4
'Variables usadas por las rutinas del LCD
ascii var byte
Grafico var byte
valor_a VAR BYTE
valor_b var word
LCD_f var word
Fuente var byte
Fuente1 var byte
lcd_chr var word
numero VAR WORD
dato var byte
PosX var byte
PosY var byte
X var BYTE
Y var byte
i var BYTE
j var BYTE
k var BYTE
n var byte
f var byte
z var BYTE 'No usar en otra parte, se usa en rutina "DibujaPunto"
Invertido var bit
canal_a var byte[70]
canal_b var byte[70]
a var byte
Offset var byte
HAM var word
HAM2 VAR WORD
X1 VAR WORD
DUTY VAR BYTE
Char var byte
VOLT VAR WORD
HVD var word
AMPER var word
MV VAR BYTE
MA VAR BYTE
DATA @0,$3E,$51,$49,$45,$3E,_ ';// 0
$00,$42,$7F,$40,$00,_ ';// 1
$42,$61,$51,$49,$46,_ ';// 2
$21,$41,$45,$4B,$31,_ ';// 3
$18,$14,$12,$7F,$10,_ ';// 4
$27,$45,$45,$45,$39,_ ';// 5
$3C,$4A,$49,$49,$30,_ ';// 6
$01,$71,$09,$05,$03,_ ';// 7
$36,$49,$49,$49,$36,_ ';// 8
$06,$49,$49,$29,$1E,_ ';// 9
$08,$08,$3E,$08,$08,_ ';// +
$08,$08,$08,$08,$08,_ ';// -
$00,$60,$60,$00,$00,_ ';// .
$7E,$11,$11,$11,$7E,_ ';// A
$1F,$20,$40,$20,$1F,_ ';// V
$7F,$09,$09,$09,$01 ';// F
Inicio:
X=0
Y=0
Pause 100 ' Hacemos una pausa de 100 ms para estabilizar todo
gosub InicializaLCD
gosub ConfiguraLCD
gosub borra_lcd
gosub cursor_origen
ciclo:
LCDOUT $FE,1
call Border_line
GOSUB F_VOLT
gosub Pantalla
gosub muestreo
gosub Pantalla
; GOSUB F_AMP
;pause 100
gosub borra_lcd
goto ciclo
F_VOLT
adcin 0 , valor_b
mv=(5*valor_b)*/255
volt=(5*valor_b)/255
mv=mv*10/2
LCDOUT $FE,$02,"VOLT =",DEC VOLT,",",DEC1 MV
gosub N3310
RETURN
;F_AMP: ;HESAPA:
; HVD=(HAM+1)*/250
; AMPER=HVD/100
; MA=HVD//100
; RETURN
N3310:
'~~~~~~~~~~~~~~~~~ cursor display volt
lcd_chr = %10100000 + 17 ' cursor X
call lCD_cmd
lcd_chr = %01000010 +40 ' cursor Y
call lCD_cmd
'~~~~~~~~~~~~~~~~~ now display results
char = (VOLT dig 1)
;call lcd_data
call PrintChar
char = (VOLT dig 0)
call PrintChar
;call lcd_data
char = 12
;call lcd_data
call PrintChar
char = (MV dig 0)
;call lcd_data
call PrintChar
;Char = (MV dig 1)
;call PrintChar
char = 14
call PrintChar
;call lcd_data
RETURN
'***************************************************************
'Rutina para muestreo y almacenamiento de medición en RAM.
'***************************************************************
Muestreo:
for i = 0 to 69
adcin 0, valor_a
canal_a[i]= valor_a/8
pause 20
next i
return
'***************************************************************
'Esta rutina muestra las dos señales en el LCD.
'***************************************************************
Pantalla:
x=0
for i = 0 to 69
y=canal_a[i] ;+5
gosub Dibujapunto
pause 1
x = x+1
next i
Return
'***************************************************************
'Esta rutina grafica un punto en la pantalla
'siguiendo coordenadas X,Y (X:0-83; y:0-47).
'***************************************************************
DibujaPunto:
if Y<=7 then
z=7-Y
dato = %00000001 << z
posy=5
endif
if Y>=8 AND Y<=15 then
z=15-Y
dato = %00000001 << z
posy=4
endif
if Y>=16 AND Y<=23 then
posy=3
z=23-Y
dato = %00000001 << z
endif
if Y>=24 and Y<=31 then
posy=2
z=31-Y
dato = %00000001 << z
endif
if Y>=32 AND Y<=39 then
posy=1
z=39-Y
dato = %00000001 << z
endif
if Y>=40 AND Y<=47 then
posy=0
z=47-Y
dato = %00000001 << z
endif
PosX = X
gosub cursor_xy
lcd_chr = dato
gosub lcd_data
return
'*******************************************************************************************
' RUTINAS GESTION LCD NOKIA 3310
'*******************************************************************************************
'-------------------------------------------------------------------------------------------
InicializaLCD:
D_C=1 ' Seleccionamos el registro de datos en RAM
SCE=1 ' Anulamos la seleccion del chip
;Pin_VCC=1 ' Damos alimentacion al LCD
pause 100 ' Hacemos una pausa de 100 ms
gosub Reset_LCD ' Reseteamos el LCD
return
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
ConfiguraLCD:
lcd_chr=%00100001 ' Chip Activo, Direccionamiento horizontal, uso de instrucciones extendidas
gosub lCD_cmd
lcd_chr=$B5 ' Configura el voltage de operacion del LCD (Contraste)
gosub lCD_cmd
lcd_chr=$13 ' Configura bias mux rate a 1:48
gosub lCD_cmd
lcd_chr=%00100000 ' Chip Activo, Direccionamiento horizontal,uso de instrucciones basicas
gosub lCD_cmd
gosub Segmentos_ON ' Configura el display (Todos los segmentos ON)
gosub Display_Normal ' Configura el display (modo Normal)
gosub direccionamiento_vertical
return
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
Display_Blanco:
lcd_chr=%00001000 ' Display Blanco
gosub lCD_cmd
return
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
Display_Inverso:
lcd_chr=%00001101 ' Display Inverso
gosub lCD_cmd
return
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
Display_Normal:
lcd_chr=%00001100 ' Display Normal
gosub lCD_cmd
return
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
Segmentos_ON:
lcd_chr=%00001001 ' Segmentos ON
gosub lCD_cmd
return
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
Direccionamiento_Vertical:
lcd_chr=%00100010 ' Chip Activo, Direccionamiento Vertical,uso de instrucciones basicas
gosub lCD_cmd
return
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
Direccionamiento_Horizonal:
lcd_chr=%00100000 ' Chip Activo, Direccionamiento Vertical,uso de instrucciones basicas
gosub lCD_cmd
return
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
Borra_LCD:
gosub Cursor_Origen ' Colocamos el cursor en el origen
for LCD_f=0 to 503 ' Recorremos todas las posiciones del LCD colocando ceros
lcd_chr=0
gosub LCD_Data
next LCD_f
return
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
Cursor_Origen:
lcd_chr=%01000000 ' Ponemos la direccion Y a 0 (01000yyy)
gosub lCD_cmd
lcd_chr=%10000000 ' Ponemos la direccion X a 0 (1xxxxxxx)
gosub lCD_cmd
return
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
Cursor_XY:
lcd_chr=%10000000 | PosX
Gosub lCD_cmd ' Envia Posicion X
lcd_chr=%01000000 | PosY
Gosub lCD_cmd ' Envia Posicion Y
return
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
Reset_LCD:
RST=0 ' Damos un pulso de reset durante 100 ms
pause 100
RST=1
return
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
lCD_cmd:
D_C=0 ' Seleccionamos el registro de comandos
goto Data_Out
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
LCD_Data:
D_C=1 ' Seleccionamos el registro de datos de RAM
if Invertido=1 then ' Comprobamos si se invierte el dato para la representacion
lcd_chr = lcd_chr ^ $FF
endif
goto Data_Out
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
Data_Out:
SCE=0 ' Seleccionamos el chip del LCD
SCK=0 ' Ponemos a cero la señal de reloj
shiftout SDIN,SCK,1,[lcd_chr\8] 'Enviamos los datos en modo SPI
SCE=1 ' Deseleccionamos el chip para liberar el bus
return
'-------------------------------------------------------------------------------------------
PrintChar:
;dato = %00000001
offset = char * 5
for a = 1 to 5
;lcd_chr=char
read offset, lcd_chr
call LCD_Data
offset = offset + 1
next a
lcd_chr=char
;lcd_chr = 0
call LCD_Data
return
'-------------------------------------------------------------------------------------------
Border_line:
'~~~~~~~~~~~~~~~~~ RAND 0
lcd_chr = %10000000 ' cursor X
call lCD_cmd
lcd_chr = %01000000 ' cursor Y
call lCD_cmd
for y = 0 to 83
LOokup y, [$FF,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,_ 'parte de arriba "DIGITAL"
$01,$01,$01,$F9,$F9,$F9,$09,$09,$F9,$F9,$F1,$01,_
$01,$F9,$F9,$F9,$01,$01,$F1,$F9,$F9,$09,$09,$19,_
$19,$11,$01,$01,$F9,$F9,$F9,$01,$09,$09,$09,$F9,$F9,$F9,_
$09,$09,$09,$01,$F1,$F9,$F9,$09,$09,$F9,$F9,$F1,$01,$01,_
$F9,$F9,$F9,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,_
$01,$01,$01,$01,$01,$FF] ,lcd_chr
call LCD_Data
next y
'~~~~~~~~~~~~~~~~~ RAND 1
lcd_chr = %10000000 ' cursor X
call lCD_cmd
lcd_chr = %01000001 ' cursor Y
call lCD_cmd
for y = 0 to 83
LOokup y, [$FF,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_ ' parte de abajo"DIGITAL"
$00,$00,$00,$1F,$1F,$1F,$10,$10,$1F,$1F,$0F,$00,$00,_
$1F,$1F,$1F,$00,$00,$0F,$1F,$1F,$10,$11,$1F,$1F,_
$0F,$00,$00,$1F,$1F,$1F,$00,$00,$00,$00,$1F,$1F,$1F,$00,_
$00,$00,$00,$1F,$1F,$1F,$01,$01,$1F,$1F,$1F,$00,$00,$1F,$1F,_
$1F,$10,$10,$10,$10,$00,$00,$00,$00,$00,$00,$00,_
$00,$00,$00,$00,$00,$FF] ,lcd_chr
call LCD_Data
next y
'=================================== RAND 2
lcd_chr = %10000000 ' cursor X
call lCD_cmd
lcd_chr = %01000010 ' cursor Y
call lCD_cmd
LOokup 0, [$FF] , lcd_chr
call LCD_Data
lcd_chr = %10000000 + 83 ' cursor X
call lCD_cmd
lcd_chr = %01000010 ' cursor Y
call lCD_cmd
LOokup 0, [$FF] , lcd_chr
call LCD_Data
'=================================== RAND 3
'=================================== RAND 4
lcd_chr = %10000000 ' cursor X
call lCD_cmd
lcd_chr = %01000100 ' cursor Y
call lCD_cmd
LOokup 0, [$FF] , lcd_chr
call LCD_Data
lcd_chr = %10000000 + 83 ' cursor X
call lCD_cmd
lcd_chr = %01000100 ' cursor Y
call lCD_cmd
LOokup 0, [$FF] , lcd_chr
call LCD_Data
'=================================== JOS
lcd_chr = %10000000 ' cursor X
call lCD_cmd
lcd_chr = %01000101 ' cursor Y
call lCD_cmd
for y = 0 to 83
LOokup y, [$FF,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,_
$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,_
$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,_
$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,_
$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,_
$80,$80,$80,$80,$80,$80,$80,$80,$FF] ,lcd_chr
call LCD_Data
next y
Return
'=======================================================================
END
Bueno, acá les comparto un mini tutorial sobre manejo y control de los display graficos nokia 3310-5110
https://sites.google.com/a/educ.ar/eti/file-cabinet/ETI_CtrlGLCDnokia2.pdf?attredirects=0&d=1
pesa 13 megas, por eso no l subi al foro
saludos