View previous topic :: View next topic |
Author |
Message |
cmussoni
Joined: 21 Aug 2010 Posts: 7
|
output_high() in a "for(;;)" cycle |
Posted: Sat Aug 21, 2010 8:02 am |
|
|
Hello to all,
I've this stupid doubt. In this code:
Code: |
void main(){
...
set_tris_c(0b00000000);
...
for(;;){
delay_ms(1000);
output_high(PIN_C0);
delay_ms(1000);
}
}
|
PIN_C0 is blinking with a 1 second rate. Why?
Why in this for-cycle the PIN_C0 turns off?
(I don't write "output_low(PIN_C0)" )
Thanks a lot to all.
Claudio |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Aug 21, 2010 8:21 am |
|
|
May be a case of the well-known RMW problem. Increase the load resistor connected to the output to achieve a legal logic "1" level at the pin.
Or did you enable the watchdog timer? |
|
|
cmussoni
Joined: 21 Aug 2010 Posts: 7
|
output_high() in a "for(;;)" cicle |
Posted: Sat Aug 21, 2010 10:25 am |
|
|
Hello,
I've no WDog (#fuses XT, NOWDT...). I don't try to change the output load but when I bring out the code :
Code: |
delay_ms(1000);
output_high(PIN_C0);
delay_ms(1000);
|
from the infinite loop for(;;) the output blinks no more.
Any other idea ?
Thanks a lot
Claudio |
|
|
cmussoni
Joined: 21 Aug 2010 Posts: 7
|
output_high() in a "for(;;)" cicle |
Posted: Sat Aug 21, 2010 10:28 am |
|
|
...ooops... I remind I' m working with a PIC16F876A.
Bye. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Sat Aug 21, 2010 10:52 am |
|
|
Why don't you post the entire (compilable) program so we can test it rather than play guessing games? _________________ Google and Forum Search are some of your best tools!!!! |
|
|
cmussoni
Joined: 21 Aug 2010 Posts: 7
|
|
Posted: Sat Aug 21, 2010 11:08 am |
|
|
Ok there it is :
Code: |
#include <16F876A.h>
#fuses XT, NOWDT, NOPROTECT, NOPUT, NOBROWNOUT, NOLVP
#use delay (clock=4000000)
#define TX232 PIN_A2
#define RX232 PIN_A5
#define INTSP PIN_A4
#use rs232(baud=9600, xmit=TX232, rcv=RX232)
BYTE int_count;
#define INTS_PER_2_SECOND 20
#INT_TIMER0
int FLAGOK=0;
int timeout=0;
int DATOIN=0;
int current_b=0;
int current_c=0;
void READDATA(){
FLAGOK=0;
delay_us(100);
timeout=0;
while(!kbhit() && (++timeout<5000)){ // 0,05 second
delay_us(10);
}
if(kbhit()){
DATOIN=getc();
FLAGOK=1;
}
else {
FLAGOK=0;
}
}
void main(){
set_tris_a(0b00110010);
set_tris_b(0b11111111);
set_tris_c(0b00000000);
port_b_pullups(TRUE);
delay_ms(100);
for(;;){
READDATA();
delay_ms(200);
output_high(PIN_C0);
delay_ms(1000);
}
}
|
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Aug 21, 2010 11:19 am |
|
|
And the CCS version, please. |
|
|
cmussoni
Joined: 21 Aug 2010 Posts: 7
|
|
Posted: Sat Aug 21, 2010 11:41 am |
|
|
IDE 4.093
PCB 4.093
PCM 4.093
PCH 4.093
PCD 4.093
|
|
|
cmussoni
Joined: 21 Aug 2010 Posts: 7
|
|
Posted: Sat Aug 21, 2010 11:52 am |
|
|
Sorry, sorry. The complete for-cycle is the sequence:
Code: |
for(;;){
current_b=input_b();
delay_us(100);
current_c=input_c();
delay_us(100);
READDATO();
delay_ms(200);
output_high(PIN_C0);
delay_ms(1000);
} |
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Aug 21, 2010 1:17 pm |
|
|
Quote: | Sorry, sorry. The complete for-cycle is the sequence: |
O.K. input_c() sets all port c pins to tri-state, because default #USE STANDARD_IO is in effect. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Sat Aug 21, 2010 2:57 pm |
|
|
OK.
Several problems.
You have a #int declaration, without interrupt handler code after it. Either get rid of this declaration, or put a handler there...
You have a timeout counter, going to 5000, declared as an integer. An int, in CCS, can hold 255 max. This will never timeout.
This is why you don't get a blink.
Then, if the timeout was working, your delay here will be several instructions more than 10uSec. In fact the time will probably be nearly twice this.
You do realise that using a software UART, you _must_ poll the pin at intervals no longer than 0.5 a bit time. Any data that arrives in the 1200mSec comprising the rest of your loop, _will_ be lost. The actual 'odds' of seeing a serial character, are extremely poor indeed.
Best Wishes |
|
|
cmussoni
Joined: 21 Aug 2010 Posts: 7
|
|
Posted: Sun Aug 22, 2010 1:26 am |
|
|
FvM...THAAANKS for the solutions: input_c() set PORTC to input !!!
Thank also Ttelmah for all the other my oversights.
Bye
Claudio |
|
|
|