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.

Can anyone help me in correcting a program

Status
Not open for further replies.

Raaj

New Member
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
 
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);
  }
}
 
Raaj said:
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.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top