Code:
#CONFIG
__config _HS_OSC & _WDT_OFF & _CP_OFF & _BOREN_OFF
#ENDCONFIG
;initiation
;Stereo VU Meter with multiple displays .
;For many years the meters needle based analog phones, have been the instruments most commonly used to measure audio levels .
;Today , most computers use LED or LCD displays to indicate the sound level on the other hand , give a colorful and dramatic appearance .
;This project consists of six forms graphically display the stereo audio signal coming through two analog inputs Pic .
;It has multiple applications , as it could be an audio level indicator , liquid level control , voltage or ampere meter in a power supply , temperature indicator , measuring an RF signal , etc ...
;Outline and electronic components :
;For this project we used a 16F877A PIC microcontroller and LCD HD44780 alphanumeric OLED - ORGANIC 2 rows of 16 characters each. Each character has a 5x8 pixel matrix .
;ATTENTION ! Audio peaks above 5 volts can destroy the PIC , to leave a safety margin or add a zener diode and a resistor to limit .
;Project Description:
;First sliding from right to left appears on the display one copyright logo occupying two characters and my Alias " Zaxione " stop in the middle of the screen and waiting two seconds remaining .
;Then moves in the opposite direction as disappears , begins to indicate the level you are getting for the two analog ports Pic .
;Every time we give you a high -level pulse on the PIC PORTB.2 , changes among the six types of visualization.
;The source code :
;It is written in Basic language , namely the PicBasic Pro 2.50C (PBP ) .
' *******************************************************************************
'* File: VUMETER.PBP *
' * Author : Saul (Alias Zaxione ) *
'* Date: 08/11/2009 *
'* Version: 1.0 *
'* Note : Stereo VU Meter with multiple displays . *
'* Web : http://www.zaxione.com *
' *******************************************************************************
DEFINE OSC 20 ' Oscillator 20 MHz
' *******************************************************************************
ADCON1 = 00000000 ' Set all PORTA and PORTE as analog
PAUSE 500 ' Time to initiation of the LCD
DEFINE LCD_DREG PORTB ' LCD data PORT B ships
DEFINE LCD_DBIT 4 ' LCD uses less than 0 or greater Bit 4
DEFINE LCD_RSREG PORTB ' LCD RS in the PORTB
DEFINE LCD_RSBIT 0 ' LCD RS PORTB.0
DEFINE LCD_EREG PORTB ' LCD E in the PORTB
DEFINE LCD_EBIT 1 ' LCD E PORTB.1
DEFINE LCD_BITS 4 ' LCD using 4 or 8 bits for data
DEFINE LCD_LINES 2 ' Number of lines lcd
' *******************************************************************************
DEFINE ADC_BITS 8 ' Result of 8 or 10-bit ADC
DEFINE ADC_CLOCK 3 ' Set clock
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
' *******************************************************************************
CHANNEL var BYTE ' Variable name
LINE VAR BYTE ' Variable name
COUNTER VAR BYTE ' Variable name
REST VAR BYTE ' Variable name
Mark1 VAR BIT ' Variable name
Mark2 var BYTE ' Variable name
pushbutton Var PORTB.2 ' button in the PORTB.2
TRISA = %11111111
TRISB = %00000100
TRISC = %00000000
' *******************************************************************************
LCDOUT 254,64,1,2,5,5,5,5,2,1 ' position CGRAM 0
LCDOUT 254,72,24,4,26,2,2,26,4,24 ' 1 position CGRAM
LCDOUT $FE,1 ' Clear screen
FOR COUNTER = 144 TO 130 STEP -1 ' Countdown
LCDOUT $FE , COUNTER , 20, 0 , 1," Zaxione " ' Print Screen
PAUSE 150 ' Pause 0.15 seconds
NEXT COUNTER ' Returns to COUNTER
PAUSE 2000 ' Pause for 2 seconds
FOR COUNTER = 130 TO 144 ' Count forward
LCDOUT $FE,COUNTER,20,0,1," Zaxione " ' Print Screen
PAUSE 150 ' Pause 0.15 seconds
NEXT COUNTER ' Returns to COUNTER
LCDOUT $FE,1 ' Clear screen
' *******************************************************************************
GRAF1 :
Mark2 = 1
LCDOUT 254,64 , 0, 16, 16 , 16, 16 , 16, 16 , 0 ' 0 position CGRAM
LCDOUT 254,72 , 0, 24, 24 , 24, 24, 24 , 24, 0 ' 1 position CGRAM
LCDOUT 254,80 , 0, 28, 28 , 28, 28, 28 , 28, 0 ' CGRAM Position 2
LCDOUT 254,88 , 0, 30, 30 , 30, 30, 30 , 30, 0 ' 3 position CGRAM
LCDOUT 254,96 , 0, 31, 31 , 31, 31, 31 , 31, 0 ' 4 position CGRAM
PAUSE 300
GOTO BAR
' *******************************************************************************
GRAF2 :
Mark2 = 2
LCDOUT 254,64 , 0, 24, 24 , 24, 24, 24 , 24, 0 ' 0 position CGRAM
LCDOUT 254,72 , 0, 24, 24 , 24, 24, 24 , 24, 0 ' 1 position CGRAM
LCDOUT 254,80 , 0, 27, 27 , 27, 27, 27 , 27, 0 ' CGRAM Position 2
LCDOUT 254,88 , 0, 27, 27 , 27, 27, 27 , 27, 0 ' 3 position CGRAM
LCDOUT 254,96 , 0, 27, 27 , 27, 27, 27 , 27, 0 ' 4 position CGRAM
PAUSE 300
GOTO BAR
' *******************************************************************************
GRAF3 :
Mark2 = 3
LCDOUT 254,64 , 0, 0 , 0, 16, 16 , 0, 0 , 0 ' 0 position CGRAM
LCDOUT 254,72 , 0, 0 , 0, 24, 24 , 0, 0 , 0 ' 1 position CGRAM
LCDOUT 254,80 , 0, 0 , 0, 28, 28 , 0, 0 , 0 ' 2 Position CGRAM
LCDOUT 254,88 , 0, 0 , 0, 30, 30 , 0, 0 , 0 ' 3 position CGRAM
LCDOUT 254,96 , 0, 0 , 0, 31, 31 , 0, 0 , 0 ' 4 position CGRAM
PAUSE 300
GOTO BAR
' *******************************************************************************
GRAF4 :
Mark2 = 4
LCDOUT 254,64 , 0, 16, 16 , 16, 16 , 16, 16 , 0 ' 0 position CGRAM
LCDOUT 254,72 , 0, 16, 16 , 16, 16 , 16, 16 , 0 ' 1 position CGRAM
LCDOUT 254,80 , 0, 20, 20, 20 , 20, 20 , 20, 0 ' 2 Position CGRAM
LCDOUT 254,88 , 0, 20, 20, 20 , 20, 20 , 20, 0 ' 3 position CGRAM
LCDOUT 254,96 , 0, 21, 21 , 21, 21, 21 , 21, 0 ' 4 position CGRAM
PAUSE 300
GOTO BAR
' *******************************************************************************
GRAF5 :
Mark2 = 5
LCDOUT 254,64 , 0, 0 , 0, 4 , 0, 0 , 0, 0 ' 0 position CGRAM
LCDOUT 254,72 , 0, 0 , 4, 14 , 4, 0 , 0, 0 ' 1 Position CGRAM
LCDOUT 254,80 , 0, 0 , 14, 14 , 14, 0, 0, 0 ' 2 Position CGRAM
LCDOUT 254,88 , 0, 4 , 14, 31 , 14, 4, 0, 0 ' 3 position CGRAM
LCDOUT 254,96 , 0, 14, 31, 31, 31 , 14, 0, 0 ' 4 position CGRAM
PAUSE 300
GOTO BAR
' *******************************************************************************
GRAF6 :
Mark2 = 6
LCDOUT 254,64,0,14,31,31,31,14,0,0 ' 0 position CGRAM
LCDOUT 254,72,0,14,31,31,31,14,0,0 ' 1 position CGRAM
LCDOUT 254,80,0,14,31,31,31,14,0,0 ' 2 Position CGRAM
LCDOUT 254,88,0,14,31,31,31,14,0,0 ' 3 position CGRAM
LCDOUT 254,96,0,0,0,31,0,0,0,0 ' 4 position CGRAM
PAUSE 300
' *******************************************************************************
BAR :
IF Mark1 = 1 THEN ' If true
LINE = $2: ADCIN 7, CHANNEL: Mark1 = 0 ' 1st line LCD shows L channel
ELSE ' If it is not
LINE = $c0: ADCIN 6, CHANNEL: Mark1 = 1 ' 2nd Line LCD shows R channel
ENDIF 'End of the comparison
' *******************************************************************************
REST = ( CHANNEL // 5 ) ' Operation subtracted from the division
LCDOUT $FE,LINE ' Start writing in the LCD
FOR COUNTER = 1 TO(CHANNEL/5) 'Count forward
LCDOUT 4 ' 4 position CGRAM Print
NEXT COUNTER ' Returns to COUNTER
IF REST = 1 THEN LCDOUT 0 ' Print CGRAM position 0
IF REST = 2 THEN LCDOUT 1 ' Print CGRAM Position 1
IF REST = 3 THEN LCDOUT 2 ' Prints 2 position CGRAM
IF REST = 4 THEN LCDOUT 3 ' 3 position CGRAM Print
LCDOUT 20, 20 , 20 ' Clearing 3 characters
' *******************************************************************************
IF (pushbutton = 1) and (Mark2 = 6) THEN GRAF1 '1 ° Viewing
IF (pushbutton = 1) and (Mark2 = 1) THEN GRAF2 '2 ° Viewing
IF (pushbutton = 1) and (Mark2 = 2) THEN GRAF3 '3 ° Viewing
IF (pushbutton = 1) and (Mark2 = 3) THEN GRAF4 '4 ° Viewing
IF (pushbutton = 1) and (Mark2 = 4) THEN GRAF5 '5 ° Viewing
IF (pushbutton = 1) and (Mark2 = 5) THEN GRAF6 '6 ° Viewing
' *******************************************************************************
GOTO BAR
END
;Video of the project in operation:
;In the Downloads area you can find the following files :
; * VUMETER.GIF Circuit Schematic .
; * VUMETER.DSN Scheme for Proteus simulation .
; * VUMETER.PBP Source Code for the PicBasic Pro Compiler ( 2.50C ) .
; * VUMETER.ASM code written in Assembly Language .
; * Language Firmware VUMETER.HEX machine.
;For more information see or expose your questions in the forum " Stereo VU Meter with multiple displays " .
I hope I did not introduce new errors
Bookmarks