-
new and need help
1st post so please be gentle with me :lol:
Am learning as i go ,what i need is the pic (16f628a) to count to 63 at certain counts it branches off to light some leds, when i programme the pic (im using the velleman programmer/demo board) all that happens is led 6 lights up for a second or so and then goes out and there is no other activity, im posting the programme i came up with and would appreciate if someone could spare a few minutes to explain where ive gone wrong. I suspect its the if then section of the code or maybe the count code, im stumped although i suspect its because i didnt put loop: at the end of main
many thanks smeghead
'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : Smegs Customs *
'* Notice : Copyright (c) 2008 Smegs Customs *
'* : All Rights Reserved *
'* Date : 11/2/2008 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
Z var word 'set up variable Z
main:
for Z = 1 to 63 'set count up
pause 100 'delay
next z 'increment count up
IF z < 50 THEN knight 'if count less than 50 knight sequence
if z > 50 then wash 'if count over 50 then wash
if z = 60 then random1 'if count =60 then random1
knight:
High 0 ' Turn on LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds
Low 0 ' Turn off LED connected to PORTB.0
Pause 25 ' Delay for .5 seconds
High 1 ' Turn on LED connected to PORTB.1
Pause 25 ' Delay for .5 seconds
Low 1 ' Turn off LED connected to PORTB.1
Pause 25 ' Delay for .5 seconds
High 2 ' Turn on LED connected to PORTB.2
Pause 25 ' Delay for .5 seconds
Low 2 ' Turn off LED connected to PORTB.2
Pause 25 ' Delay for .5 seconds
High 3 ' Turn on LED connected to PORTB.3
Pause 25 ' Delay for .5 seconds
Low 3 ' Turn off LED connected to PORTB.3
Pause 25 ' Delay for .5 seconds
High 4 ' Turn on LED connected to PORTB.4
Pause 25 ' Delay for .5 seconds
Low 4 ' Turn off LED connected to PORTB.4
Pause 25 ' Delay for .5 seconds
High 5 ' Turn on LED connected to PORTB.5
Pause 25 ' Delay for .5 seconds
Low 5 ' Turn off LED connected to PORTB.5
Pause 25 ' Delay for .5 seconds
High 6 ' Turn on LED connected to PORTB.6
Pause 25 ' Delay for .5 seconds
Low 6 ' Turn off LED connected to PORTB.6
Pause 50 ' Delay for .5 seconds
High 5 ' Turn on LED connected to PORTB.5
Pause 25 ' Delay for .5 seconds
Low 5 ' Turn off LED connected to PORTB.5
Pause 25 ' Delay for .5 seconds
High 4 ' Turn on LED connected to PORTB.4
Pause 25 ' Delay for .5 seconds
Low 4 ' Turn off LED connected to PORTB.4
Pause 25 ' Delay for .5 seconds
High 3 ' Turn on LED connected to PORTB.3
Pause 25 ' Delay for .5 seconds
Low 3 ' Turn off LED connected to PORTB.3
Pause 25 ' Delay for .5 seconds
High 2 ' Turn on LED connected to PORTB.2
Pause 25 ' Delay for .5 seconds
Low 2 ' Turn off LED connected to PORTB.2
Pause 25 ' Delay for .5 seconds
High 1 ' Turn on LED connected to PORTB.1
Pause 25 ' Delay for .5 seconds
Low 1 ' Turn off LED connected to PORTB.1
Pause 25 ' Delay for .5 seconds
return ' go back to main loop
wash:
high 5 ' led 5 high
pause 1000 'pause
low 5 ' led 5 low
return ' go back to main loop
random1: 'flashing led bit
high 1:high 2:high 3:high 4:high 5 'too stupid to write a real random flashy thing
pause 25
low 1:low 2:low 3
pause 25
high 2:high 6: high0
pause 100
low 0:low 1: low 2: low 3:low 4:low 5:low 6
return 'back to main loop
[TabIndex]
Value=0
-
try to modify this section to..
Code:
MAIN:
for Z = 1 to 63 'set count up
IF z < 50 THEN GOSUB knight 'if count less than 50 knight sequence
if z > 50 then GOSUB wash 'if count over 50 then wash
if z = 60 then GOSUB random1 'if count =60 then random1
pause 100 'delay
next z 'increment count up
GOTO MAIN
see what happen now.
-
many thanks for the relpy i wil try this tomorrow evening and let you know, programmers in garage, as the only computer with a serial port lives in the garage :lol:
so basically if i use the connditions for z, they need to be inside the count code. took me hours to work out the if/then so it would compile without error
again many thanks
-
I couldnt wait so just went to the garage , it worked a treat, so thanks for the prompt reply, so i learned something else today, another question if say i had 2 or 3 count loops with different if /then conditions, would they all have to be done seperately or could they be nested into one big one
many thanks
-
Everything is possible, you just need to think what you want to do. Drawing a kind of flow chart could be handy. You can nest loop without too much problems. For multiple conditions, it's usually easier to read and to add condition using SELECT CASE.
Don't give up!
-
Oh dont worry i wont be giving up, last time i used basic in anger was to programme my zx81 (yes im that old), just a case of relearning forgotten stuff and learning some new. Again thanks for the help it makes all the difference, i spent all day yesterday trying to work out where i was going wrong and finally asked here tonight :):D