How to write a code for the operation of a hardware switch ?
It can be a simple digital switch to switch it ON and OFF.
This is a discussion on C code for operation of a switch within the C Programming forums, part of the General Programming Boards category; How to write a code for the operation of a hardware switch ? It can be a simple digital switch ...
How to write a code for the operation of a hardware switch ?
It can be a simple digital switch to switch it ON and OFF.
How about saying something about what OS/Compiler/interfaces you've got?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I support http://www.ukip.org/ as the first necessary step to a free Europe.
You can assume.
Is this what you answered on the interview?
--Code:#define ON 1 #define OFF 0 #define ON_OFF_SWITCH_ADDR 0xC0000400 int *on_off_switch_ptr = (int *)ON_OFF_SWITCH_ADDR; int main(int argc, char **argv) { if (argc != 2) printf("Invalid arguments\n"); else { if (strcmp(argv[1], "ON") == 0) *on_off_swtich_ptr = ON; else if (strcmp(argv[1], "OFF") == 0) *on_off_swtich_ptr = OFF; else printf("Choose either ON or OFF\n"); } return 0; }
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I had told the same n of course it is correct.
But i was expecting anyother approach for this. Is there any other approach for d same ?
There is any number of answers - how you do it depends on what the enviroment is.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Yes there is, look up the truth tables for the bitwise operators & | ^
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I support http://www.ukip.org/ as the first necessary step to a free Europe.