Hello ! I'm having trouble with my school homework as none of my friends know how to do this . So this code is for requirement 1 which is
1. PORTC pin 7 is connected to LED 7 and pin0 is connected to LED 0
2. A delay of 3 second interval between each output.
Basically what they're asking is :
LED7 LED0 Both LEDS off
0 0
LED7 LED0
1:1 0 Blink 5 times with ratio of 1:1
LED7 LED0
0 2:1 Blink 10 times with ratio of 2:1
LED7 LED0
1:1 1:1 Blink 10 times with ratio of 1:1
Now the problem is i need to rewrite the code so that it will do this for my next requirement :
1. No input are required
2. PORTD to LEDs (RD0 to L0 , RD1 to L1 and so on )
3. Write user-define delay functions
4. write user-defind function for the specific tasks
5. Use "for' loop to repeat a task. <<<< this is the part I don't understand.
So now its
L7-L0
All LEDs off, No function require
L7-L0
All LEDs Blinking , Blink with ratio of 1:1
L7-L0
Running LED from L0 to L7 , Introduce logical shift left command (<<)
L7-L0
Running LED from L7 to L0 , Introduce logical sh*t right command (>>)
Im pretty much stuck at requirement 2 and i would appreciate any help given .. Thanks
Here is the code for requirement 1 .
[C] writing user-defined functions and 'for loop' - Pastebin.com[
^]
What I have tried:
I'm pretty much stuck with this and don't know what to do . I'm sorry if this is the basics but im pretty much new to this
[EDIT - the code from the link]
#include <p18f4520.h>
#include <delays.h>
#pragma config OSC = HS //set external High-speed (HS) oscillation
#pragma config WDT = OFF //disable the Watchdog feature of the MCU
#pragma config LVP = OFF //disable low voltage programming (LVP)
#pragma config PBADEN = OFF //Port B Analogue to Digital module is OFF
#define L0 PORTCbits.RC0 //RC0 assigned as L0
#define L7 PORTCbits.RC7 //RC7 assigned as L7
void delay_long(void)
{
int x;
for(x; x<20000;x++)
{
}
}
void delay_short(void)
{
int x;
for(x=0; x<10000;x++)
{
}
}
void display_1(void)
{
L0=0;
L7=1;
delay_short();
L7=0;
delay_short();
}
void display_2(void)
{
L7=0;
L0=1;
delay_long();
L0=0;
delay_short();
}
void main(void)
{
int i;
TRISCbits.TRISC0 =0; TRISCbits.TRISC7 =0;
i=0; PORTCbits.RC0 = 0; PORTCbits.RC7 = 0;
while(1)
{
L0=0; L7=0;
Delay10KTCYx(3000);
for(i=0; i<5;++) {
display_1(); }
Delay10KTCYx(3000);
for(i=10; i<10; i++) {
display_2(); }
Delay10KTCYx(3000);
for(i=0; i<10;i++) {
L0=1; L7=1;
delay_short(); L0=0; L7=0;
delay_short(); }
} }