Code:
'*******************************************************************************
'* Archivo : VUMETER.PBP *
'* Autor : Saúl (Alias Zaxione) *
'* Fecha : 08/11/2009 *
'* Versión : 1.0 *
'* Nota : VU Meter Estéreo con varias visualizaciones. *
'* Web : http://www.zaxione.com *
'*******************************************************************************
#CONFIG
__config _HS_OSC & _WDT_OFF & _CP_OFF & _BOREN_OFF
#ENDCONFIG
DEFINE OSC 20 'Oscilador de 20 MHz
'*******************************************************************************
' LCD I/O DEFINITIONS
DEFINE LCD_DREG PORTB 'LCD PORT para envío de datos B
DEFINE LCD_DBIT 4 'LCD utiliza los Bit inferior 0 o superior 4
DEFINE LCD_RSREG PORTB 'LCD RS en el PORTB
DEFINE LCD_RSBIT 0 'LCD RS PORTB.0
DEFINE LCD_EREG PORTB 'LCD E en el PORTB
DEFINE LCD_EBIT 1 'LCD E PORTB.1
DEFINE LCD_BITS 4 'LCD se utilizan 4 o 8 bits para datos
DEFINE LCD_LINES 2 'Numero de lineas del lcd
'*******************************************************************************
' LCD DEFINITIONS
DEFINE ADC_BITS 8 'Resultado del ADC 8 o 10 bits
DEFINE ADC_CLOCK 3 'Ajuste del reloj
DEFINE ADC_SAMPLEUS 50 'Ajuste del tiempo de muestreo en microsegundos
'*******************************************************************************
' VARIABLES
CANAL var BYTE 'Nombre de la variable
LINEA VAR BYTE 'Nombre de la variable
CONTADOR VAR BYTE 'Nombre de la variable
RESTO VAR BYTE 'Nombre de la variable
MARCA1 VAR BIT 'Nombre de la variable
MARCA2 var BYTE 'Nombre de la variable
PULSADOR var PORTB.2 'Pulsador en el PORTB.2
'*******************************************************************************
' PROGRAM
PAUSE 500 'Tiempo necesario para la iniciación del LCD 7
ADCON1 = 00000000 'Definir todos los PORTA y PORTE como analógicos
'*******************************************************************************
' INITIAL MESSAGE --> "Zaxione"
LCDOUT 254, 64, 1 ,2 ,5, 5 ,5 ,5 ,2 ,1 'cgram posición 0
LCDOUT 254, 72, 24 ,4 ,26, 2 ,2 ,26 ,4 ,24 'cgram posición 1
LCDOUT $FE, 1 'Borrado de la pantalla
' Shift message Left
FOR CONTADOR = 144 TO 130 STEP -1 'Cuenta atras
LCDOUT $FE, CONTADOR, 20, 0, 1, "Zaxione " 'Imprimir en pantalla
PAUSE 150 'Pausa de 0,15 segundos
NEXT CONTADOR 'Regresa a CONTADOR
PAUSE 2000 'Pausa de 2 segundos
' Shift message Right
FOR CONTADOR = 130 TO 144 'Cuenta hacia delante
LCDOUT $FE, CONTADOR, 20, 0, 1, "Zaxione " 'Imprimir en pantalla
PAUSE 150 'Pausa de 0,15 segundos
NEXT CONTADOR 'Regresa a CONTADOR
LCDOUT $FE, 1 'Borrado de la pantalla
'*******************************************************************************
' VU line style 1 (graphic bitmaps)
GRAF1:
MARCA2 = 1
LCDOUT 254,64, 0 ,16 ,16, 16 ,16 ,16 ,16 ,0 'cgram posición 0
LCDOUT 254,72, 0 ,24 ,24, 24 ,24 ,24 ,24 ,0 'cgram posición 1
LCDOUT 254,80, 0 ,28 ,28, 28 ,28 ,28 ,28 ,0 'cgram posición 2
LCDOUT 254,88, 0 ,30 ,30, 30 ,30 ,30 ,30 ,0 'cgram posición 3
LCDOUT 254,96, 0 ,31 ,31, 31 ,31 ,31 ,31 ,0 'cgram posición 4
PAUSE 300
GOTO BARRA
'*******************************************************************************
' VU line style 2 (graphic bitmaps)
GRAF2:
MARCA2 = 2
LCDOUT 254,64, 0 ,24 ,24, 24 ,24 ,24 ,24 ,0 'cgram posición 0
LCDOUT 254,72, 0 ,24 ,24, 24 ,24 ,24 ,24 ,0 'cgram posición 1
LCDOUT 254,80, 0 ,27 ,27, 27 ,27 ,27 ,27 ,0 'cgram posición 2
LCDOUT 254,88, 0 ,27 ,27, 27 ,27 ,27 ,27 ,0 'cgram posición 3
LCDOUT 254,96, 0 ,27 ,27, 27 ,27 ,27 ,27 ,0 'cgram posición 4
PAUSE 300
GOTO BARRA
'*******************************************************************************
' VU line style 3 (graphic bitmaps)
GRAF3:
MARCA2 = 3
LCDOUT 254,64, 0 ,0 ,0, 16 ,16 ,0 ,0 ,0 'cgram posición 0
LCDOUT 254,72, 0 ,0 ,0, 24 ,24 ,0 ,0 ,0 'cgram posición 1
LCDOUT 254,80, 0 ,0 ,0, 28 ,28 ,0 ,0 ,0 'cgram posición 2
LCDOUT 254,88, 0 ,0 ,0, 30 ,30 ,0 ,0 ,0 'cgram posición 3
LCDOUT 254,96, 0 ,0 ,0, 31 ,31 ,0 ,0 ,0 'cgram posición 4
PAUSE 300
GOTO BARRA
'*******************************************************************************
' VU Line style 4 (graphic bitmaps)
GRAF4:
MARCA2 = 4
LCDOUT 254,64, 0 ,16 ,16, 16 ,16 ,16 ,16 ,0 'cgram posición 0
LCDOUT 254,72, 0 ,16 ,16, 16 ,16 ,16 ,16 ,0 'cgram posición 1
LCDOUT 254,80, 0 ,20 ,20, 20 ,20 ,20 ,20 ,0 'cgram posición 2
LCDOUT 254,88, 0 ,20 ,20, 20 ,20 ,20 ,20 ,0 'cgram posición 3
LCDOUT 254,96, 0 ,21 ,21, 21 ,21 ,21 ,21 ,0 'cgram posición 4
PAUSE 300
GOTO BARRA
'*******************************************************************************
' VU Line style 5 (graphic bitmaps)
GRAF5:
MARCA2 = 5
LCDOUT 254,64, 0 ,0 ,0, 4 ,0 ,0 ,0 ,0 'cgram posición 0
LCDOUT 254,72, 0 ,0 ,4, 14 ,4 ,0 ,0 ,0 'cgram posición 1
LCDOUT 254,80, 0 ,0 ,14, 14 ,14 ,0 ,0 ,0 'cgram posición 2
LCDOUT 254,88, 0 ,4 ,14, 31 ,14 ,4 ,0 ,0 'cgram posición 3
LCDOUT 254,96, 0 ,14 ,31, 31 ,31 ,14 ,0 ,0 'cgram posición 4
PAUSE 300
GOTO BARRA
'*******************************************************************************
' VU Line style 5 (graphic bitmaps)
GRAF6:
MARCA2 = 6
LCDOUT 254,64, 0 ,14 ,31, 31 ,31 ,14 ,0 ,0 'cgram posición 0
LCDOUT 254,72, 0 ,14 ,31, 31 ,31 ,14 ,0 ,0 'cgram posición 1
LCDOUT 254,80, 0 ,14 ,31, 31 ,31 ,14 ,0 ,0 'cgram posición 2
LCDOUT 254,88, 0 ,14 ,31, 31 ,31 ,14 ,0 ,0 'cgram posición 3
LCDOUT 254,96, 0 ,0 ,0, 31 ,0 ,0 ,0 ,0 'cgram posición 4
PAUSE 300
'*******************************************************************************
' Read ADC input
BARRA:
IF MARCA1 = 1 THEN 'Si es verdadero
LINEA = $2 '1ºLinea LCD, muestra canal L
ADCIN 7, CANAL
MARCA1 = 0
ELSE 'Si no lo es
LINEA = $c0 '2ºLinea LCD, muestra canal R
ADCIN 6, CANAL
MARCA1 = 1
ENDIF 'Fin de la comparación
'*******************************************************************************
' Remainder of DIV5 --> nro of pixels columns of last char in VU graph
RESTO = (CANAL // 5) 'Operación restó de la división
LCDOUT $FE, LINEA 'Inicia la escritura en el LCD
FOR CONTADOR = 1 TO (CANAL / 5) 'Cuenta hacia delante
LCDOUT 4 'Imprime cgram posición 4
NEXT CONTADOR 'Regresa a CONTADOR
' Select last character in VU graph depending on the remainder value
IF RESTO = 1 THEN LCDOUT 0 'Imprime cgram posición 0
IF RESTO = 2 THEN LCDOUT 1 'Imprime cgram posición 1
IF RESTO = 3 THEN LCDOUT 2 'Imprime cgram posición 2
IF RESTO = 4 THEN LCDOUT 3 'Imprime cgram posición 3
' ??? Erase 3 full chars after VU indicator
LCDOUT 20, 20, 20 'Borrado de 3 caracteres
'*******************************************************************************
' Select graphic style (progress with push-button presses
IF (PULSADOR = 1) and (MARCA2 = 6) THEN GRAF1 '1º Visualización
IF (PULSADOR = 1) and (MARCA2 = 1) THEN GRAF2 '2º Visualización
IF (PULSADOR = 1) and (MARCA2 = 2) THEN GRAF3 '3º Visualización
IF (PULSADOR = 1) and (MARCA2 = 3) THEN GRAF4 '4º Visualización
IF (PULSADOR = 1) and (MARCA2 = 4) THEN GRAF5 '5º Visualización
IF (PULSADOR = 1) and (MARCA2 = 5) THEN GRAF6 '6º Visualización
'*******************************************************************************
GOTO BARRA
END
Bookmarks