PDA

View Full Version : new to PIC programming could really do with some help



karenhornby
- 5th March 2008, 09:22
I've got a problem with this section of code and could really do with some help please.
The LCD scrolling section looks ok to me, but when I try compiling it I get this error

Error at Line [68] In file [OILCON~3.BAS] *** Variable ' LCDIN ' not defined! ***

Also can anyone tell me if I've worked out how to generate sound on PORTD.1 correctly please?
I know the sound section seems a little crude but for some reason I cannot get the FOR NEXT commands to work.

The circuit will have a high signal from the main power supply and have a battery backup across the Vdd and Vss pins of the 16F877 (interlock? to make sure the power is not turned OFF BEFORE the switch on PORTB.6 has been pressed) along with a blocking diode to make sure the battery never gets charged

Sorry for asking so many questions in one post, but a week ago I hadnt even considered about learning how to program PIC's and I only started learning about how to program them a few days ago.

apart from the problem with the LCDIN not defined?? could someone check the code marked in red and see if it looks ok please?
I would just put it all together and try it but at the moment I havent even got a development board to test any of my programming


DEVICE = 16F877 ' I'm going to use a 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
DQ var PORTC.1 ' Data pin
CLK var PORTC.3 ' Clock pin
' 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 warning Sound via transistor and speaker



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," " ' 'add a space
Pause 250 ' Pause
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,10 5,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

skimask
- 5th March 2008, 14:03
I've got a problem with this section of code and could really do with some help please.
The LCD scrolling section looks ok to me, but when I try compiling it I get this error

Which version of PBP?
'cause that looks like Proton Basic...not MeLabs PicBasicPro