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.

Led shift program problem with loop

Status
Not open for further replies.

kgavionics

Full Member level 3
Full Member level 3
Joined
Jun 12, 2012
Messages
167
Helped
7
Reputation
14
Reaction score
11
Trophy points
1,298
Location
Alberta.Canada
Visit site
Activity points
2,482
hi
i have this little program that turn on the first led on portb then it shifts the led to the left.The program works fine,except that the pic execute the first loop then it stops.How can run the loop for ever?

thanks in advance

Code:
#include <stdio.h>
#include <stdlib.h>
#include <p18f452.h>

#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF
void MSDelay(unsigned int);
void main(void)
  { 

 TRISB = 0;

 
   PORTB=0X01;

  for(; ;) [COLOR="#FF0000"]// normally this loop is forever!!!!!!![/COLOR]
{
PORTB=PORTB<<1;
Delay10KTCYx(120);
     
      }

}
 


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
#include <stdio.h>
#include <stdlib.h>
#include <p18f452.h>
 
#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF
 
void MSDelay(unsigned int);
 
unsigned char i = 0;
 
void main(void)
{ 
 
    TRISB = 0x00;
    PORTB = 0X01;
 
    for(; ;) 
    {
        for(i = 0; i < 8; i++){
            PORTB = PORTB << 1;
            Delay10KTCYx(120);
        }
 
        PORTB = 0X01;
     
        }
}

 
when it gets out of the second "for loop", add these "PORTB=0X01;Delay10KTCYx(120); below . just try , i think it ll work well.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top