So iam new to the Arduino world iam trying to get some code running with some port manipulation and an arduino mega iam having some trouble passing variables to serial print..iam using it with an harddrive...
id like to read PINL and depending on what i get back i wanna print PINA DATA TO an variable..
on the serial monitor i want some string to stay on the screen
"DATA REGISTER" = variable
"ERROR REGISTER" = variable
""BIN; if (PINL== ob01000010) "" that = data register then i want to read PINA convert to hex and print to the variable
any help anyone?
void setup() {
Serial.begin(9600);
DDRA = 0b00000000; // Sets ports to read
DDRC = 0b00000000; // Sets ports to read
DDRL = 0b00000000; // Sets ports to read
byte Data = (PINA,HEX);
Serial.println("Data Register");
Serial.println("Error Register");
}
I dont know what else to try..i was doing Serial.println(PINA,HEX); but it just prints over and over..i wanna pass that to an variable so when.... BIN; if (PINL== ob01000010) prints PINA values as hex to "data register"
so when BIN; if (PINL==0b01000100) i wanna pass PINAs VALUE TO "data register"
and when BIN; (PINL==0b01110110) i wanna pass PINAS value to "error regsiter"
so serial monitor would always look like
DATA REGISTER = X
ERROR REGISTER = X
and only x would even change and string would stay on screen..i having an hard time passing multiple variables
quiksilver4730:
and only x would even change and string would stay on screen..i having an hard time passing multiple variables
The Serial Monitor is not that sophisticated.
If you want a line of text to stay on the screen and the value following it to change then you need to use a separate terminal emulator program such as PuTTY or RealTerm and learn the appropriate escape codes that are needed to set the location on screen where new text will appear. Most of the terminal emulators support VT100 escape codes.
Thank you for that info iam sure that is true..But for right now iam trying to learn how to use the arduino...it should be simple enough to print 8 strings and read portl pins to decided what string to address to pass an variable from PORTA in hex..thank you for your thoughts
void setup() {
Serial.begin(9600);
DDRA = 0b00000000; // Sets ports to read
DDRC = 0b00000000; // Sets ports to read
DDRL = 0b00000000; // Sets ports to read
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(PINA,HEX);
BIN; if(PINL == 0b01000010)
Serial.println("Data Register");
BIN; if (PINL == 0b01001010)
Serial.println("Error Register");
Its comparing it to binary..that part of the code works as i want it to and any other way i have found has an compile error....Yes the question is how do i get the above code not to run over and over and only read AND write PINA value when PINL = the address i want..
quiksilver4730:
It must do something otherwise it does not work and doesn't do anything..
Well,strictly speaking, it evaluates the constant value 2, finds it to be non-zero, and returns the value "true", which is promptly ignored/thrown-away.
i can change anyone of the 8bits and get back the right value PINL(==0b0000001) so i dont see how that is possible how else would i compare 8 bits? what would be correct?...the code i have does work
here is my current code it always keep updating..i want serial Monitor to always display 1 ,2 ,3 etc and only update (x PINA in hex) when (PINL) is = to its address..what would be the proper way?any hints or tips thanks all!
1=x
2=x
3=x
4=x
void setup() {
Serial.begin(9600);
DDRA = 0b00000000; // Sets ports to read
DDRC = 0b00000000; // Sets ports to read
DDRL = 0b00000000; // Sets ports to read
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(PINA,HEX);
BIN; if(PINL == 0b01000010)
Serial.println("1");
BIN; if (PINL == 0b01001010)
Serial.println("2");
BIN; if (PINL == 0b01010010)
Serial.println("3");
BIN; if (PINL == 0b01011010)
Serial.println("4");
BIN; if (PINL == 0b01100010)
Serial.println("5");
BIN; if (PINL == 0b01101010)
Serial.print("6");
BIN; if (PINL == 0b01110010)
Serial.print("7");
BIN; if (PINL == 0b01111010)
Serial.print("8");
}
I asked how else i would do it and what would be correct Iam trying to learn man?..The first thing i said was iam new to the arduino world and there is not many examples of port manipulation..and Yes you are 100% correct i do not need the BIN; thank you for that info!!..any hints on any of the above questions would be greatly appreciated!!
Yes you are 100% correct i don't need the BIN; still works fine iam wrong!! thank you for the help..yes PINL would be..
42 PORTL 7
43 PORTL 6
44 PORTL 5
45 PORTL 4
46 PORTL 3
47 PORTL 2
if i have data register= on the serial monitor...and "if (PINL == 0b01001010)" i want to print the value of PINA in hex to data register = and so on for 7 other values ..
I'm sorry, there seems to be some misunderstanding here.
I don't know what you mean by
and only update (x PINA in hex) when (PINL) is = to its address.
PINL is a memory-mapped register; it has a single very well-defined address in the memory space of the processor - like I said, I'm posting from my phone, and I don't have a processor datasheet to hand - I guess it is above 0x100,
Such a number is obviously not representable in eight bits, so the value on an eight bit port cannot ever be equal to its address in such a case.