get error in yellow

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
MrDEB
Posts: 12
Joined: Fri Apr 24, 2009 1:45 am
Location: Salmon, Idaho

get error in yellow

Post by MrDEB » Sun Jun 28, 2009 6:23 pm

variable not initialized.
how does one initialize a variable.

Code: Select all

}
// your main code would look like this
 Device = 18F1320
Clock = 8 // 8MHz clock
Config OSC = INTIO2, WDT = OFF, LVP = OFF
Dim day As Byte
Dim nite As Byte
Dim light As Byte
Dim checkPIR As Byte
Dim PlaySound As Byte
dim timeout as byte
Include "Utils.bas"

//While (true) 
    //  If day = light Then PlaySound 
    //  ElseIf day = nite Then checkPIR 
    //  EndIf
    //  If checkPIR = true Then PlaySound
    //  endif
    //  wEnd
//Wend

//###########################
 //CHECK FOR DAYLIGHT OR DARK
//############################

//Device = 18f1320
//Clock = 8
//Config OSC = INTIO2, WDT = OFF, LVP = OFF
//Include "Utils.bas"
Dim but As PORTB.0
Dim led As PORTA.0
SetAllDigital      //set digital so you can read RB0 or it will always read low
TRISA =%00000000  // if your using the junebug This is fool proof to get a led to lite
PORTA =%00000000  // Set's it all low
TRISB =%00000001  // Set's inputs and outputs 
PORTB =%00000000   // Set's it all low
INTCON2.7=0        // sets wpu on portb turns on pullups on PORTB
OSCCON = $72            // 8 MHz clock
portb.1=0
//####################
// day or night checking loop
//####################
//while (true)
if (portb.1) = 1 then day=light  [b]error[/b]
endif
if portb.1 = 0 then day=nite  [b]error[/b]
endif
note I am a newbi at this
it says

Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

Post by Doj » Sun Jun 28, 2009 11:04 pm

Hello MrDeb

To initialise a variable is simply to give it a known value prior to compilation so the code when run will react in the way you expect and not in the way you have written the code.
All code will do what you have told it to do, this may not be what you hope it will do.

Code: Select all

INTCON2.7=0        // sets wpu on portb turns on pullups on PORTB 
OSCCON = $72            // 8 MHz clock 
portb.1=0 

'PUT THE INITIALIZED VALUES OF ALL DECLARED VARIABLES HERE(IN THIS CASE) AND GIVE THEM VALUES WHICH ALLOW THE CODE TO WORK AT FIRST TURN ON AS YOU EXPECT
day=0
nite=0
light=0
checkPIR=0
PlaySound=0
timeout=0
I would say it is essential that you always specify an initial value for every variable that you create, relying on the compiler to give a value is asking for problems and will make your code fail at some point.

MrDEB
Posts: 12
Joined: Fri Apr 24, 2009 1:45 am
Location: Salmon, Idaho

hey thanks doj

Post by MrDEB » Mon Jun 29, 2009 3:57 am

now the syntax is correct.
hopefully the code will do as planned.
will try out tomorrow nite.
I may need to get some photo transistors as I have none in my parts boxes.

Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

Post by Doj » Mon Jun 29, 2009 9:23 am

Best of luck, please report back!

Post Reply