Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[Moved] Interfacing PIC16F877 via 3 port.

Status
Not open for further replies.

apizbaygon

Junior Member level 3
Joined
Jan 5, 2013
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,431
Hi,i wanna ask a question...how to program pic16f877a to blink 3 led via 3 different ports..example:port b,c and d
 

Re: Interfacing PIC16F877 via 3 port.

which compiler are you using?
 

Re: Interfacing PIC16F877 via 3 port.

MikroC...i able to blink an led only in one port
 

Re: Interfacing PIC16F877 via 3 port.

if you able to blink the led in one port. Do the same procedure and it will blink in any port.
make the port as output and send logic high.

if still didnt work, post your code and schematic
 

Re: Interfacing PIC16F877 via 3 port.

for port d, i did the same as port b...but only port b is blinking..here is my code


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
void main()
{
  TRISB = 0x00; // Sets all pins in PORTB as output
  PORTB = 1; // Set RB0 to high 00000001
  do // To set infinite loop
    {
    Delay_ms(100); // 100 mili seconds delay
    PORTB = PORTB<<1; //Shifting right by one bit
    if(PORTB >= 0b10000000) //To reset to 00000001
    {                          //when the count becomes 10000000
       Delay_ms(200); // 200 mili seconds delay
       PORTB = 1;
    }
  }while(1); // To set infinite loop
 
  TRISD = 0x00;
  PORTD = 1;
  do
  {
  Delay_ms(200);
  PORTD = PORTD<<1;
  if (PORTD >=0b10000000)
  {
   Delay_ms(350);
   PORTD = 1;
   }
   }while (1);
 
}

 
Last edited by a moderator:

Re: Interfacing PIC16F877 via 3 port.

The part of the program that flashes the portB LED is an infinite loop. The processor just goes around the first loop forever. It never executes the code after the first while(1) statement.

You have to put the code to flash both LEDs inside the same loop.
 

Re: Interfacing PIC16F877 via 3 port.

it work with 2 port but both port only blink 2 led only..for port b it only blink led 1 and 2 while port d blink led 6 and 7...here is the schematic sfsfs.PNG
 

Re: Interfacing PIC16F877 via 3 port.

try this code.
HTML:
void main() {
PORTB=0;  //initialize portb
PORTD=0;  //initialize portd
TRISB=0b00000000;   //configure portB as output
TRISD=0b00000000;   //configure portD as output
ANSELH=0;    //configure an pin as digital I/O
ANSEL=0;
while(1){
PORTB=1;     
delay_ms(1000);   
PORTD=1;
delay_ms(1000);  
}

}
 

need to define ANSEL and ANSELH first...what should i write..sorry,i'm newbie...just have a little knowledge about MikroC
 

comment those lines. ANSEL and ANSELH .. looking into your datasheet, there is no registers like that.

Compile and load the hex. It will work

Best wishes :)
 

it's only light up one led in each port...i want to make those led blink like led chaser for 2 port at the same time
 

yup..based on the schematic given..i want to blink all leds port b, c and d at the same time...
 

try this, i dont have mikro C to compile.
HTML:
void main() {
PORTB=0;  //initialize portb
PORTC=0;  //initialize portc
PORTD=0;  //initialize portd
TRISB=0b00000000;   //configure portB as output
TRISC=0b00000000;	//configure portC as output
TRISD=0b00000000;   //configure portD as output
while(1)
{
PORTB = 0x01;
PORTC = 0x01;
PORTD = 0x01;
delay_ms(1000);
PORTB = 0x02;
PORTC = 0x02;
PORTD = 0x02;
delay_ms(1000);
PORTB = 0x04;
PORTC = 0x04;
PORTD = 0x04;
delay_ms(1000);
PORTB = 0x08;
PORTC = 0x08;
PORTD = 0x08;
delay_ms(1000);
PORTB = 0x10;
PORTC = 0x10;
PORTD = 0x10;
delay_ms(1000);
PORTB = 0x20;
PORTC = 0x20;
PORTD = 0x20;
delay_ms(1000);
PORTB = 0x40;
PORTC = 0x40;
PORTD = 0x40;
delay_ms(1000);
PORTB = 0x80;
PORTC = 0x80;
PORTD = 0x80;
delay_ms(1000);
}
 

thank you very much for the help...
if i want to add push button in the circuit to change the pattern of blinking, what coding i must insert??
 

do
{
if PUSH_BUTTON = pressed
delay_ms(100);
if (check push_button goes high)
{
temp = count++; // increments a variable
if (count==255) count=0;
//do here what you want to here
}
while(check push_BUTTON goes high);
}while(1);
}
 

is it for one push button??
i want to make single push button which when it is push, the pattern will change
 

yes it is for single push button. variable increments when u press the button. Increment as 1,2,3,4..till 255.
 

so, i just put the coding at '//do here what you want to here ' right??
meaning that lots of coding to be put here to change the pattern if the push button goes high??
for this part i really don't understand
 

do
{
if (PUSH_BUTTON == 0) // checks pushbutton is pressed
delay_ms(100); // delay 100 ms
if (!PUSHBUTTON) // checks pushbutton goes high
{
temp = count++; // increments a variable when pushbutton is pressed
if (count==255) count=0; // if count reaches 255 , resets count variable to zero
PORTB = count; // LED glows depending on count value
PORTC = count;
PORTD = count;
}
while(!PUSHBUTTON); // again checks pushbutton is released
}while(1);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top