Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 5th November 2005, 09:39 PM   (permalink)
Default Can anyone help me in correcting a program

Hi ET,

I am doing my Microcontroller course for the first time and have few difficulties nin writing C program for PIC16F877Program must read upper 4 switches connected to PORTB(SB4-SB7)and activate corresponding lamp connected to lower part of PORTB(LB0-LB3, respectively). Also
-If switch SB7 is pressed, all four LB0-LB3 lamps should be ON as long as SB7 is pressed
-If switch SB6 is pressed, all four LB0-LB3 lamps should flash ON and OFFwith 1 sec delay as long as SB6 is pressed

I have written program but this is not working

Char count=0;
void main (void)
{
set_bit (STATUS,5);
set_bit (STATUS,6);
TRISB=0xF0;
set_bit (STATUS, 5);
if(COUNT>=0xF0)
PORTB=0x00
else PORTB=0x0F;
set_bit (STATUS,5);
clear_bit (STATUS,6);
while(1) {
{
PORTB=0x0F;
delay_ms(1000);
PORTB=0xF0;
delay_ms(1000);
}
}

Thanks

Raaj
Raaj is offline   Reply With Quote
Old 5th November 2005, 10:11 PM   (permalink)
Default Re: Can anyone help me in correcting a program

That code isn't even close to accomplish what you described. Did you really write this yourself? It's not reading any input?! See my comment below...

Code:
char count=0;

void main (void)
{
  set_bit (STATUS,5);
  set_bit (STATUS,6);
  TRISB=0xF0;
  set_bit (STATUS, 5);

  PORTB=++COUNT; /* This is weird, what are you trying to do? */

  if(COUNT>=0xF0)
    PORTB=0x00
  else 
    PORTB=0x0F;

  set_bit (STATUS,5);
  clear_bit (STATUS,6);

  while(1) 
  {
    PORTB=0x0F;
    delay_ms(1000);
    PORTB=0xF0;
    delay_ms(1000);
  }
}
__________________
Time is nature\'s way of keeping everything from happening at once.
http://membres.lycos.fr/jrainville/
Joel Rainville is offline   Reply With Quote
Old 6th November 2005, 02:47 AM   (permalink)
Default Re: Can anyone help me in correcting a program

Quote:
Originally Posted by Raaj
Hi ET,

I am doing my Microcontroller course for the first time and have few difficulties nin writing C program for PIC16F877Program must read upper 4 switches connected to PORTB(SB4-SB7)and activate corresponding lamp connected to lower part of PORTB(LB0-LB3, respectively). Also
-If switch SB7 is pressed, all four LB0-LB3 lamps should be ON as long as SB7 is pressed
-If switch SB6 is pressed, all four LB0-LB3 lamps should flash ON and OFFwith 1 sec delay as long as SB6 is pressed

I have written program but this is not working

Thanks

Raaj
As you are useing C then I would let the compiler take care of bank switching - ie get rid of the set_bit status,5 etc.

For the first part of your assignment then a simple way to achieve this would be.

PORTB = PORTB>>4

You can then go onto implement the rest of it.

HTH

Mike.
P.S. it's not nice to change your code after someone Joel) has commented on it.
Pommie is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes




All times are GMT. The time now is 11:35 PM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.