PDA

View Full Version : how to loop thru setting port bits?



wdmagic
- 24th February 2013, 13:00
I have a variable array, now I need to cycle thru it and set PORTB bits based on values in that array, heres my code


FOR CNT = 0 to 7
IF TEMP[CNT] < 100 then PORTB.CNT = 0
IF TEMP[CNT] >= 100 then PORTB.CNT = 1
NEXT CNT

Now "TEMP[CNT]" works fine, but it throws an error on "PORTB.CNT"

Error is Bad Variable Modifyer ".CNT"

I Changed it to PORTB.(CNT)

New Error, Bad Token "."

HenrikOlsson
- 24th February 2013, 13:16
Hi,
Try

IF TEMP[CNT] < 100 then PORTB.0(CNT) = 0
For more info see Melanies excellent write up (http://www.picbasic.co.uk/forum/showthread.php?t=544) and the follow up discussions.

/Henrik.

wdmagic
- 24th February 2013, 13:38
ok i didnt get a error on compile but i cant test it yet as Ive got alot more code to finish. but no errors looks good so far.