International Electronics and Technology Forum
May 21, 2012, 01:55:48 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Logical Operator C needed?  (Read 436 times)
Frisky
Newbie
*
Posts: 1


« on: May 14, 2011, 07:09:19 PM »

I am trying to write a program for a PIC Microcontroller.
I have to generate the binary-equivalent of the following decimal numbers:
119, 76, 14, 55 & 99.
So, by writing the code below I can generate the output for 119- several LEDs blink continuosly.

Now, if I want to generate the same effect for the other decimal numbers and add all that in the same program what operator should I use?

void main() {
TRISB=0; //MAKING PORT B OUTPUT
while (1) {
PORTB = 0x77; //Make port B high
delay_100ms; //maintain portb as high for 100ms
PORTB = 0x00; //Make port b low
delay_100ms; //maintain port b as low for 100ms
}
Logged
justme
Newbie
*
Posts: 8


« Reply #1 on: May 14, 2011, 08:07:57 PM »

simply add them to the code. no need to even convert to hex:

void main() {
TRISB=0; //MAKING PORT B OUTPUT
while (1) {
PORTB = 0x77; //Make port B high
delay_100ms; //maintain portb as high for 100ms
PORTB = 76; //Make port B high
delay_100ms; //maintain portb as high for 100ms
PORTB = 14; //Make port B high
delay_100ms; //maintain portb as high for 100ms
//etc...
PORTB = 0x00; //Make port b low
delay_100ms; //maintain port b as low for 100ms
}
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC | Privacy Policy Valid XHTML 1.0! Valid CSS!