yes you can as wond3rboy has shown you, you can also use #define for things like #define on=1; #define off=0; that way you can have LED=on or whatever you want.. if i was you i would do a search for 3v0's tuts in C it will give you a good place to start,
yes you can as wond3rboy has shown you, you can also use #define for things like #define on=1; #define off=0; that way you can have LED=on or whatever you want.. if i was you i would do a search for 3v0's tuts in C it will give you a good place to start,
Actually, I wouldn't do it that way. You would want to define them like:
Code:
#define ON (1)
#define OFF (0)
Note that lack of an equals sign or semicolon. The parentheses aren't required, but I'm in the habit of using them for all #defines as it can save you from some problems.
#defines are direct text substitution. The compiler doesn't parse these values (as it would a C statement), it does the substitution and parses the result of the substitution. If you use
Code:
#define on=1;
Then everywhere you have the text "on=1;", it will be replaced with nothing. The first value after the define is substituted for the second, here the second is blank.
So the difference is that the first way won't work like you would expect and the second will.
It removes any confusion over whether you're talking about the LAT, PORT, or TRIS part. Otherwise, it's all too easy to mix up PORT and LAT usage. It's also clearer to read, because "LED" alone doesn't tell us a whole lot for sure.
LATA refers to the LATCH Register of PORTA and subsequently is the output latch for that port. For the 18Fs, there is no difference between the two. Previously one would need to READ a Port using the PORTx register and WRITE to it using the LATCHx Register. Check the data sheet.