karenhornby
New Member
Problem with Scrolling line on LCD
I've got this code which SHOULD scroll the words "PRESS THE BUTTON" IF PORTB.1 = 1 AND PORTB.4 = 1 (temp triggers from temp sensors) AND IF PORTB.6 = 0 (pushbutton) AND PORTD.1 = 0 (Main POWER still active) but when I try compiling it, it gives the error *** Variable ' LCDIN ' not defined! ***
any suggestions?
Also it SHOULD play an ANNOYING morse code dot-dash sound for half a second before playing the star wars theme sound while scrolling, can anyone check and see if I've used the sound command correctly please?
The sound will drive a small loudspeaker or piezo sounder through a transistor from PORTD.1 "HOPEFULLY"! which would be loudest small speaker or piezo sounder?
The code for the sound output is a little messy as for some reason I couldnt get the FOR and IF commands to work to make the first bit of sound loop 5 times before it played the 2nd section
I've got this code which SHOULD scroll the words "PRESS THE BUTTON" IF PORTB.1 = 1 AND PORTB.4 = 1 (temp triggers from temp sensors) AND IF PORTB.6 = 0 (pushbutton) AND PORTD.1 = 0 (Main POWER still active) but when I try compiling it, it gives the error *** Variable ' LCDIN ' not defined! ***
any suggestions?
Also it SHOULD play an ANNOYING morse code dot-dash sound for half a second before playing the star wars theme sound while scrolling, can anyone check and see if I've used the sound command correctly please?
The sound will drive a small loudspeaker or piezo sounder through a transistor from PORTD.1 "HOPEFULLY"! which would be loudest small speaker or piezo sounder?
The code for the sound output is a little messy as for some reason I couldnt get the FOR and IF commands to work to make the first bit of sound loop 5 times before it played the 2nd section
Code:
DEVICE = 16F877 ' PIC16F877 PICmicro
XTAL = 4 ' With a 4MHz crystal
' Define LCD pins
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
' Alias pins
RST var PORTC.0 ' Reset pin 'external DS1620
DQ var PORTC.1 ' Data pin 'external DS1620
CLK var PORTC.3 ' Clock pin 'external DS1620
' Allocate variables
temp var word ' Storage for temperature
Low RST ' Reset the device
ADCON1 = 7 ' Set PORTA and PORTE to digital
Low PORTE.2 ' LCD R/W line low (W)
Pause 100 ' Wait for LCD to start
Lcdout $fe,1, "DIESEL"
Lcdout $fe,$C0, "Temp in degrees C" ' Display sign-on message
Define LCD_RWREG PORTC ' which port LCD RW is connected to
Define LCD_RWBIT 2 ' which bit RW is connected to
LcdCols con 20 ' number of Columns in your LCD
' Software variables
sc_rol var byte
CounterA var byte
DataX var byte
input PORTB.1 'Input from DS1620 in Thermostat mode (only HIGH or LOW)
output PORTB.2 'OUTPUT to Solenoid 1 FUEL SUPPLY
input PORTB.4 ' Input from DS1620 in Thermostat mode (only HIGH or LOW)
output PORTB.5 'OUTPUT to Solenoid 2 FUEL RETURN
input PORTB.6 'INPUT from Pushbutton Switch
output PORTC.2 ' output to R/W on LCD panel
input PORTD.0 'input to check MAIN power to circuit still alive
output PORTD.1 'OUTPUT TO WARNING SIREN
MAIN:
high PORTB.0 'toggle the clock pin.
Pause 10 'the conversion will be complete
Low PORTB.0 'before the inputs are read further down.
' Temploop to read the temperature and display on LCD
TempLoop:
RST = 1 ' Enable device
Shiftout DQ, CLK, LSBFIRST, [$ee] ' Start conversion
RST = 0
Pause 1000 ' Wait 1 second for conversion to complete
RST = 1
Shiftout DQ, CLK, LSBFIRST, [$aa] ' Send read command
Shiftin DQ, CLK, LSBPRE, [temp\9] ' Read 9 bit temperature
RST = 0
' Display the decimal temperature
Lcdout $fe,$C0, dec (temp >> 1), ".", dec (temp.0 * 5), " degrees C"
IF PORTB.1 = 1 AND PORTB.4 = 1 THEN ' check to make sure both temperature inputs from DS1620's are HIGH
IF PORTB.6 = 0 AND PORTD.1 = 0 THEN ' check to see if switch on PORTB.6 is pressed of not AND IF main power is turned off
LOW PORTB.2 'switch fuel to diesel
HIGH PORTB.5 'fuel return goes to diesel tank
LcdOut $FE,$C0, "PRESS THE BUTTON"
Pause 250 ' leave it on the screen long enough to see
' before incrementing along the line
For sc_rol=1 to $C0 ' scroll one character to the right routine
For CounterA=20-1 to 1 step -1' work backwards along the line
' from right to left
LcdIn $C0+CounterA-1,[DataX]' Read one character from column x-1...
LcdOut $FE,2+CounterA,DataX '.and write it to the adjacent location
Next CounterA ' and do it for the whole line (less one column)
If sc_rol=1 then LcdOut $FE,2," " ' don't forget I need to add
'a space at the beginning of the line, but you only ever need to do this once
Pause 250 ' Pause for effect...
Next sc_rol
Sound PORTD.1,[120,05] 'DI sound
PAUSE 100
SOUND PORTD.1,[120,20] 'DAH sound
PAUSE 100
Sound PORTD.1,[120,05] 'DI sound
PAUSE 100
SOUND PORTD.1,[120,20] 'DAH sound
PAUSE 100
Sound PORTD.1,[120,05] 'DI sound
PAUSE 100
SOUND PORTD.1,[120,20] 'DAH sound
PAUSE 100
Sound PORTD.1,[97,80,108,80,105,20,104,20,101,20,113,80,108,80,105,20,104,20,101,20,113,80,108,80,105,20,104,20,105,20,101,80]
'SHOULD play an ANNOYING "DI" DAH" morse code kinda sound then play the starwars tune
else
IF PORTB.6 = 0 AND PORTD.1 = 1 THEN ' IF pushbutton switch on PORTB.6 AND Main power is ON
HIGH PORTB.2 'fuel switches to veg oil
HIGH PORTB.5 'fuel return goes to veg oil tank
Lcdout $fe,2, "Veg-Oil"
else
HIGH PORTB.2 'switch fuel to Diesel
LOW PORTB.5 'keep fueel return to OIL tank
Lcdout $fe,2, "FLUSHING" ;clears Injection pump of Veg-Oil
Pause 10000 'PAUSES for TEN SECONDS then (HOPEFULLY) SETS OUTPUTS B2 and B5 LOW
Lcdout $fe,2, "Diesel"
LOW PORTB.5 'switch car to Diesel Fuel
LOW PORTB.2 'switch fuel return to Diesel Fuel
While PORTB.6=0 'wait for button to be pressed again
WEND
endif 'this is short for while end
endif
endif
Goto MAIN ' Do it forever
Last edited: