Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Programming in MikroC

Status
Not open for further replies.

PhilipWarence

New Member
Off Topic Bros. Sorry but I had been frustrating since last night that i cant figure this simple goal out...

void main()
{

PORTB = 0;
TRISB = 0;
{
for( PORTB=0; PORTB<=7; PORTB++)
Delay_ms(50) ;
}
}




Hello guys, Sorry to disturb yah'll. Im a beginner in MikroC. I had just started using this last night. Can i ask what's wrong with my code? My goal is to HIGH all the pins in portb 1 by 1 in PIC16F877A using a loop. But the only thing that happened is only pin RB0 turns high. Help guys. Thank you a lot..
 
Hi PhilipWarence , I have moved your post to its own thread. Next time please start your own instead of hijacking someone else's ;)

Welcome to ETO, and good luck!
Regards,
Matt
 
When PORTB is configured as analog, it always read as 0, so PORTB++ always sets it to 1. It's a good idea to use LATB instead.

If you want to do what you descrbed, do:

C:
TRISB=0; LATB = 1;
while(1) {
  LATB = (LATB<<1)+1;
  // appropriate delay here
}
 
There is no LATB on a 16 series chip. Try adding ADCON1=0x06; at the beginning of your code.

Mike.
 
You need to shift PORTB to light each in turn.

Try this
C:
void main()
   {
   char x;
   PORTB =1;
   TRISB = 0;
   for( x=0; x <8; x++)
      {
      Delay_ms(250) ;
      PORTB<<=1;
      }
   }
Or this to light each one after each other..
C:
void main()
   {
   char x;
   PORTB =1;
   TRISB = 0;
   for( x=0; x <8; x++)
      {
      Delay_ms(250) ;
      PORTB<<=1;
      PORTB+=1;
      }
   }

Or in binary
C:
void main()
   {
   char x;
   PORTB =1;
   TRISB = 0;
   for( x=0; x <256; x++)
      {
      Delay_ms(50) ;
      PORTB = x;
      }
   }

Either case its better to use a buffer!!
 
Ian's code should work well (didn't realize you were trying to light each in turn). However, the ADC still needs turning off.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top