View previous topic :: View next topic |
Author |
Message |
Future Guest
|
Inverting the state of an output pin |
Posted: Thu May 13, 2004 10:16 pm |
|
|
Hi, I moved from Basic to C and I'm having a little trouble...
I have this code:
Code: | #int_TIMER0
TIMER0_isr() {
if(mms=10) {
ms++;
mms=0;
read_adc(ADC_START_ONLY);
if(ms=10) {
tenth++;
ms=0;
if(tenth=10) {
sec++;
tenth=0;
if(!input(PIN_C4)) output_high(PIN_C4);
else output_low(PIN_C4);
}
}
}
} |
I want it to invert the state of portc.4 every second, but it is always on.
Does someone can help me?
Thank you. |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Thu May 13, 2004 11:06 pm |
|
|
The equality check in C is ==, so change your 'if' statements to
if(mms==10)
and so forth. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri May 14, 2004 12:14 am |
|
|
and more efficient is to use the function output_toggle(PIN_C4). |
|
|
Guest
|
|
Posted: Fri May 14, 2004 4:43 am |
|
|
very weird if I put if(mms==10) it doesn't light at all.
with if(mms=10) it takes one second to light but stays always on. |
|
|
Guest
|
|
Posted: Fri May 14, 2004 5:00 am |
|
|
Hmm the problem was mine..
TIMER0_isr() {
if(mms=10) {
ms++;
mms=0;
has to be
TIMER0_isr() {
mms++;
if(mms=10) {
ms++;
mms=0;
good to see the fast replies. thank you very much. |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Fri May 14, 2004 5:04 am |
|
|
Anonymous wrote: | Hmm the problem was mine..
TIMER0_isr() {
if(mms=10) {
ms++;
mms=0;
has to be
TIMER0_isr() {
mms++;
if(mms=10) {
ms++;
mms=0;
good to see the fast replies. thank you very much. |
You are still using a single = for equality check. That 'if' statement has no effect. |
|
|
Guest
|
|
Posted: Fri May 14, 2004 7:36 am |
|
|
Just a single copy/paste from the forum. In my code it is already fixed.
Thank you. |
|
|
|