Hi KiKi,
In the line "Config Pind.0 = Output ", this should be "Config [b:3e1e76f11b]Portd.0[/b:3e1e76f11b] = Output ", [b:3e1e76f11b]Pin[/b:3e1e76f11b]x.n is for inputs, [b:3e1e76f11b]Port[/b:3e1e76f11b]x.n for outputs. (even though PINd.0 will work)
Set Pinb.0
Set Pinb.1
Set Pinb.2
Set Pinb.3
With these fours lines, If you are trying to set the internal pullups, these should be all be [b:3e1e76f11b]PORT[/b:3e1e76f11b]bX.n
On this line which you have[i:3e1e76f11b] already defined as an input,[/i:3e1e76f11b] Set Pinb.4 also sets PORTB.4 which I don't think you really want to do.
From what I can see, Pinb.4 is an input (defined), and it will go low when a coin is detected, hence the waiting for the switch to go LOW, is this correct. ?
Since this is an input line, and you wish for it to go low when a coin is inserted but normally sit in the high state, the input line should have a resistor pullup to the high level voltage, and the switch will pull it low. This also should be defined as above, Portb.4=1 or Set Portb.4 (even though it is defined as an input, this is the way to activate the internal pullups.) Pinb is only for reading the pin as an input.
Problem#1: Never ending loop if no coin is inserted.
Program waits until a coin is detected (low), for ever if necessary, in a never ending loop, because if no coin is inserted, this is what it will do and therefor will NOT return to the main DO Loop, to detect any other inputs on any of the other IF statements.
If it were working correcly.
If a coin is detected, it waits 1/2 a second, turns ON the Portd.0 Output, waits for three(4 or 5) counts of the timer routine, Turns Portd.0 off again, and finishes the IF statement.
All correct so far ?
Problem#2: Variable definition and counter incrementing.
Nowhere do you reset "Nilai" to zero except the intial , so after it exits the loop, it gets turned back on again, it just continues on from where it left off when you turned the timer off. This means thet your 'Nilai" counter will actually count 255 (back till it gets to 3 or 4 or 5)
A couple hints for easier reading.
Use [b:3e1e76f11b]Alias [/b:3e1e76f11b]to define names for you inputs and outputs. Like this
Coin1 Alias Pinb.0
Coin2 Alias Pinb.1
In your code do, If Coin1 = 0 And Coin2 = 1 And ..... etc. It makes it a lot easier to read!
The same with outputs, Light Alias Portd.0. In your code use Light = 1 or Light = 0 or Set Light and Reset Light.
There's a we problem to sortout.
Regards
Dean
↧