Toggle question

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
dman776
Posts: 115
Joined: Mon May 28, 2007 3:59 pm
Location: Texas

Toggle question

Post by dman776 » Fri Jun 01, 2007 4:02 pm

Is this a bug?

This code produces an error: Parameter must be a single port pin.

---
Dim LED1 As LATB.5
while true
toggle(LED1)
wend
-----

If I do, Dim LED1 As PORTB.5 it works.

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Fri Jun 01, 2007 4:30 pm

I think I am right in saying that, even if you dim your LED alias as Port.Pin, when writing to a port it will use the LAT, not the PORT register. It's not a bug, just use the Port.Pin definition always and let the compiler worry about using LAT... It's very clever really and saves you the worry.

Regards,

Steven

dman776
Posts: 115
Joined: Mon May 28, 2007 3:59 pm
Location: Texas

Post by dman776 » Fri Jun 01, 2007 5:07 pm

great. thanks for the info.

User avatar
mister_e
Posts: 28
Joined: Fri Oct 06, 2006 2:02 pm
Location: Montréal, Canada
Contact:

Post by mister_e » Fri Jun 01, 2007 5:19 pm

always worthwhile to look at the generated asm

Code: Select all

I1_F1_000003 ; L#MK Toggle(LED1)
        BTG LATB,5
        BCF TRISB,5,0
        BRA WHILE_0
So yeah, it will use LATB. Yet another kinda fussy writing stuff ;)

Post Reply