Jiadong Yao
Member level 1
- Joined
- Mar 19, 2014
- Messages
- 40
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 278
hi, I am working to make the led blink. you first press the button, it will blink once. The second time you press the button, it will blink twice and the third time blink 3 times and so on.
I am using the PIC18F2550, the compiler is C18.
below is the code.
and the problem is that, the led will always blink at a certain rate.
one more question: can i use for loop or while loop inside the while(1)?? because my coach told me that it is not allowed to use these loops and i could only use if statement. Is it this case?
thank you !
- - - Updated - - -
and how to make the layout clearer?
I am using the PIC18F2550, the compiler is C18.
below is the code.
and the problem is that, the led will always blink at a certain rate.
one more question: can i use for loop or while loop inside the while(1)?? because my coach told me that it is not allowed to use these loops and i could only use if statement. Is it this case?
thank you !
Code:
#include <p18cxxx.h>
#include "adc_process.h"
#include "pwm_process.h"
#include "stepper_process.h"
#include <stdio.h>
#include <stdlib.h>
long counter;
long buttonPress = 0;
long i=0;
void Init(void);
void main(void) {
Init(); //initialise the system
while(1) {
if(PORTCbits.RC0 == 0) //C0 equals 1,it connects to the 5V. button is not pressed
{
buttonPress++;
counter = 0;
i=0;
}
if (counter == 0 )
{
if(i == buttonPress*2 )
{
}
else
{
LATCbits.LATC1 = !LATCbits.LATC1;
i++;
}
}
if(counter == 2000)
{
counter=0;
}else
{
counter++;
}
Wait(); //wait until one 1m has elapesed
}
}
void Init(void) {
//configure I/O
TRISCbits.TRISC0 = 1;
TRISCbits.TRISC1 = 0;
LATCbits.LATC1 = 0;
counter = 0;
Init_Timer_Loop();
}
- - - Updated - - -
and how to make the layout clearer?
Attachments
Last edited: