Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

why this code don't apply my requirements please

Status
Not open for further replies.

antoine magdi

New Member
please help me, why this code don't apply my requirements

-My problem that i have wrote a program in pic basic to design a game and control it; and the code doesn't apply what i want (pratically) and also in the simulation....
-This is notes about the game (my requirements in the game).... plz read it and tell me what's the problem in my code..
-Thanks in advance...

Notes: -it is a game depends on laser beams designed
like a control system contolling the
safety of a safe for example
the player has a 3 opportunity to interrupt
the laser beam and then he loses the game.
every interruption of laser beam;
a led is activated till
the 3 opportunity are ended and
then a sounder is activated indicating that the
the player loases the game
-i used pic16f877a
-portc.5, portc.6, portc.7 (to control the 3 leds that indicate the interruption of the laser beam)
-portc.4 (to control the sounder if the player ended his 3 opportunity)
-portc.3 is to control the activation of a led if the player wins
-the first LDR is related by the LDR before the final one and the two are in series with resistor 10k?
-the second LDR is related by the final LDR and the two are in series with resistor 10k?
-each LDR is in series with a resistor 10k?
-the resistance of the LDR in the presence of the laser beam is between 5KΩ
and 6KΩ


THIS IS MY CODE

'**********************************************
define adc_bits 8
define adc_sampleus 50
'***********************************************
adcon0=%11000001 'to active analog module and set all porta as
'analog to digital conveter
adcon1=%00000000
trisc=0
'***********************************************
'define varriables
adc_result0 var byte
adc_result1 var byte
adc_result2 var byte
adc_result3 var byte
adc_result4 var byte
adc_result5 var byte
adc_result6 var byte
adc_result7 var byte
bn var byte
c var byte
mask1 var byte
mask2 var byte
'***********************************************
'initialize the values of the varriables

portc=0
bn=-1
c=0
mask1=0
mask2=0
'***********************************************

'main function


main:
adcin 0,adc_result0
adcin 1,adc_result1
adcin 2,adc_result2
adcin 3,adc_result3
adcin 4,adc_result4
adcin 5,adc_result5
adcin 6,adc_result6
adcin 7,adc_result7

if adc_result0<140 then c=1
if adc_result1<180 then c=1
if adc_result2<180 then c=1
if adc_result3<140 then c=1
if adc_result4<140 then c=1
if adc_result5<140 then c=1
if adc_result6<140 then c=1
if adc_result7<140 then c=1


if adc_result0>140 then thebegining
if adc_result1>180 then again
if adc_result2>180 then again
if adc_result3>140 then again
if adc_result4>140 then again
if adc_result5>140 then again
if adc_result6>140 then again
if adc_result7>140 then mask1=5

goto main

Thebegining:
if mask1=5 and mask2=10 then 'if the player interrupts the first and the last
'laser beam ---> active a led indicating
portc.3=1 'the victory of the player
goto main
endif

'again: is the function followed when the player interrupt a laser beam

again:
if c=1 then bn=bn+1
c=0

select case bn

case 1
portc.5=1

case 2
portc.6=1

case 3
portc.7=1

case 4
portc.4=1
pause 3500
portc.4=0

end select
'***********************************************

goto main

end
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top