Jun 1, 2013 #1 Q qlouis76 Newbie level 4 Joined Jun 1, 2013 Messages 5 Helped 0 Reputation 0 Reaction score 0 Trophy points 1,291 Location Malaysia Visit site Activity points 1,331 Hi, Beginner here for C Programming. Basically using MPlab to work on my C program. Some problem, with input binary number using 4-sliding switch to PIC18F4520 (PortB. RB0 RB1 RB2 RB3). :-( Am I suppose to write the program for each bit for each port to convert binary to decimal? Need some help and suggestion. Thank you
Hi, Beginner here for C Programming. Basically using MPlab to work on my C program. Some problem, with input binary number using 4-sliding switch to PIC18F4520 (PortB. RB0 RB1 RB2 RB3). :-( Am I suppose to write the program for each bit for each port to convert binary to decimal? Need some help and suggestion. Thank you
Jun 1, 2013 #2 H hemnath Advanced Member level 3 Joined Jun 24, 2012 Messages 702 Helped 61 Reputation 120 Reaction score 57 Trophy points 1,308 Location Chennai Visit site Activity points 6,589 which compiler you are using? Am I suppose to write the program for each bit for each port to convert binary to decimal? Click to expand... No. you can do something like this, unsigned int number[8] = {0,1,2,3,4,5,6,7}; void DELAY_ACTUATE() { a = (input_b() & 0b11111111); decimal_value = number[a]; } Best wishes
which compiler you are using? Am I suppose to write the program for each bit for each port to convert binary to decimal? Click to expand... No. you can do something like this, unsigned int number[8] = {0,1,2,3,4,5,6,7}; void DELAY_ACTUATE() { a = (input_b() & 0b11111111); decimal_value = number[a]; } Best wishes
Jun 1, 2013 #3 Q qlouis76 Newbie level 4 Joined Jun 1, 2013 Messages 5 Helped 0 Reputation 0 Reaction score 0 Trophy points 1,291 Location Malaysia Visit site Activity points 1,331 hemnath said: which compiler you are using? No. you can do something like this, unsigned int number[8] = {0,1,2,3,4,5,6,7}; void DELAY_ACTUATE() { a = (input_b() & 0b11111111); decimal_value = number[a]; } Best wishes Click to expand... Thank you. I am using C18 C compiler. I am beginner. it is like this void main () { TRISBbit.TRISB4=1 unsigned int number[4] = {0,1,2,3,4}; //only 4 bit (1111) so maximum is 15 in decimal. void DELAY_ACTUATE() { a = (input_b() & 0b1111); decimal_value = number[a]; } Correct me if I am wrong. Is C program will know example (1001 is 9 )? I am sorry still learning.
hemnath said: which compiler you are using? No. you can do something like this, unsigned int number[8] = {0,1,2,3,4,5,6,7}; void DELAY_ACTUATE() { a = (input_b() & 0b11111111); decimal_value = number[a]; } Best wishes Click to expand... Thank you. I am using C18 C compiler. I am beginner. it is like this void main () { TRISBbit.TRISB4=1 unsigned int number[4] = {0,1,2,3,4}; //only 4 bit (1111) so maximum is 15 in decimal. void DELAY_ACTUATE() { a = (input_b() & 0b1111); decimal_value = number[a]; } Correct me if I am wrong. Is C program will know example (1001 is 9 )? I am sorry still learning.
Jun 1, 2013 #4 errakeshpillai Full Member level 5 Joined Oct 17, 2011 Messages 255 Helped 64 Reputation 128 Reaction score 59 Trophy points 1,328 Location Chennai, India Visit site Activity points 2,738 If the 1001 is suffixed by 0b then it will indicate the compiler that the number following is a binary number.
If the 1001 is suffixed by 0b then it will indicate the compiler that the number following is a binary number.
Jun 3, 2013 #5 Q qlouis76 Newbie level 4 Joined Jun 1, 2013 Messages 5 Helped 0 Reputation 0 Reaction score 0 Trophy points 1,291 Location Malaysia Visit site Activity points 1,331 errakeshpillai said: If the 1001 is suffixed by 0b then it will indicate the compiler that the number following is a binary number. Click to expand... void main () { TRISBbit.TRISB4=1 unsigned int number[4] = {0,1,2,3,4}; //only 4 bit (1111) so maximum is 15 in decimal. void DELAY_ACTUATE() { a = (input_b() & 0b1111); decimal_value = number[a]; } is this correct?
errakeshpillai said: If the 1001 is suffixed by 0b then it will indicate the compiler that the number following is a binary number. Click to expand... void main () { TRISBbit.TRISB4=1 unsigned int number[4] = {0,1,2,3,4}; //only 4 bit (1111) so maximum is 15 in decimal. void DELAY_ACTUATE() { a = (input_b() & 0b1111); decimal_value = number[a]; } is this correct?