void main(void) {
unsigned long i;
TRISA = 0;
PORTA = 0;
while(i++ <= 50000);
while(1)
PORTA.RA2 = 1;
}
long i = 0;
void main() {
TRISA = 0;
PORTA = 0;
while(1)
{
i++;
if(i >= 50000)
{
PORTA.RA2 = ~PORTA.RA2;
i = 0;
}
}
}
The FIRST should make a LED turn On after some time. But the LED just turns On immediately!
void main() //MAIN;
{
TRISA = 0x00; //SET PORTA TO BE OUTPUT;
PORTA = 0x00; //TURN OFF LEDs ON PORTA;
Delay_ms(1000); //WAIT 1S;
while(1){ //INFINITE LOOP;
PORTA = 0xFF; //SET PORTA HIGH;
}
} //END;
The SECOND should make a LED blink continuously. But the LED, after some time, turns On and just stays On forever.
void main() //MAIN;
{
TRISA = 0x00; //SET PORTA TO BE OUTPUT;
PORTA = 0x00; //TURN OFF LEDs ON PORTA;
while(1){ //INFINITE LOOP;
PORTA = ~PORTA; //INVERT STATE ON PORTA;
Delay_ms(1000); //WAIT 1S;
}
} //END;
void main(void) {
unsigned long i;
TRISA = 0;
PORTA = 0;
while(i++ <= 50000);
while(1)
PORTA.RA2 = 1;
}
andunsigned long i;
in some compiler i will automatically initialized from zero. but some might not work.. please declare and define i here.while(i++ <= 50000);
long i = 0;
void main() {
TRISA = 0;
PORTA = 0;
while(1)
{
i++;
if(i >= 50000)
{
PORTA.RA2 = ~PORTA.RA2;
i = 0;
}
}
}
Code C - [expand] 1 while(i++ <= 50000);
Code C - [expand] 1 volatile unsigned int i;
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include <htc.h> void main(void) { unsigned long i = 0; TRISA = 0; PORTA = 0; while(i++ <= 50000); while(1) RA2 = 1; }
Venkadesh: THANKS A LOT for trying it! Could you please tell me what kind of 16F PIC did you use?
long i = 0;
char toggle;
void main() {
TRISA = 0;
PORTA = 0;
while(1){
i++;
if(i >= 50000){
PORTA.RA2 = toggle;
toggle++;
i = 0;
}
}
}
It can only happen if the required LED current limiting resistor has been omitted, also exceeding PIC rated output current, Unfortunately the original poster didn't manage yet to show a circuit or answer the respective question.I think you are suffering from Read Modify Write problems - or R-M-W.
// simple LED flash code for PIC16F628A with 4MHz oscillator
// mikroC pro for PIC
unsigned long i = 0; // just a counter for delay
void main() {
CMCON = 7; // disable comparator to make ports digital
TRISA = 0; // PORTA all outputs
PORTA = 0; // PORTA all low
while(1){ // loop forever
i++;
if(i >= 50000){ // count to cause a delay
PORTA.RA2 = ~PORTA.RA2; // toggle LED on PORTA bit 2
i = 0; // reset count
}
}
}
unsigned long i=0;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?