CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

input() function problem???
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
YulL



Joined: 29 Sep 2004
Posts: 39
Location: Paris (France)

View user's profile Send private message

PostPosted: Tue Dec 14, 2004 2:55 am     Reply with quote

I'm wrong, here is the detail with fast_io (I gived details with standard_io).

.................... while(1)
.................... {
.................... if(!input(ONOFF))
0052: BTFSC 05.4
0053: GOTO 056
.................... {
.................... output_low(REGUL);
0054: BCF 05.5
.................... }
.................... else
0055: GOTO 057
.................... {
.................... output_high(REGUL);
0056: BSF 05.5
.................... }
.................... }
0057: GOTO 052
.................... }
Ttelmah
Guest







PostPosted: Tue Dec 14, 2004 5:15 am     Reply with quote

Humberto wrote:
We doesn´t know what compiler version is using YulL

Quote:

This code is fine.
The code is switching banks. Setting the _TRIS_ bit to '1', to make the pin an input. Then switching to the bank to read the pin, and correctly testing it.


Yes but.. he defines:
#use fast_io(A) and then:
set_tris_a(0x10);

Why is setting the TRIS_BIT in the main if it was done before ?
Quote:

.................... while (input(ONOFF));
0059: BSF 03.5
005A: BSF 05.4 // !!!! ???? Why here ?
005B: BCF 03.5
005C: BTFSC 05.4
005D: GOTO 059




I agree with rnielsen proposal -just to test- his code is very clean and generate the simplest available code.

Code:

....................    while(1)
....................    {
....................     if(!input(ONOFF))
*
0019:  BTFSC  05.4
001A:  GOTO   01D
....................       {
....................        output_low(REGUL);
001B:  BCF    05.5
....................       }
....................     else
001C:  GOTO   01E
....................       {
....................        output_high(REGUL);
001D:  BSF    05.5
....................       }
....................    }
001E:  GOTO   019
.................... }
....................




Humberto
[/quote]
The reason it is setting the TRIS bit, is that if 'standard_io' is selected, it will _always_ do it.
The three 'io methods' in CCS, are:
'standard_io'. With this, tris will be changed for _every_ IO instruction, even if it was set in the past.
'fixed_io'. With this, the TRIS bits can be defined in the io statement, or using 'tris', and these wll not be altered for the individual accesses, but will be left as they were for the last set statement.
'fast_io'. With this, the compiler will not touch TRIS at all, but will leave it up to you to set/reset it.
You can play with TRIS as much as you want, but unless 'fast_io', or 'fixed_io' is selected, the compiler will still set the TRIS bit for every access...

Best Wishes
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Dec 14, 2004 7:24 am     Reply with quote

Ttelmah wrote:
Quote:

The reason it is setting the TRIS bit, is that if 'standard_io' is selected, it will _always_ do it.


NOP. This is not the case.
If you read carefully the code posted by YulL, you will see clearly that for
port_a data direction setting he used the directive
#use fast_io(A)
and for other ports he used
#use standard_io();

The inputs and outputs regarding this discusion was focused in port_A.



Humberto Very Happy
YulL



Joined: 29 Sep 2004
Posts: 39
Location: Paris (France)

View user's profile Send private message

PostPosted: Tue Dec 14, 2004 7:32 am     Reply with quote

Well the problem is that I have played with standard_io and unfortunately it is possible that I have send the code with standard_io. fast_io is a good method and it works.

I have finally found 400ns glitches in the onoff signal, that explains why the program detects a low level sometimes Confused

I have included the following code and it works now! Wink

#include "F:\...\header.h"
#org 0x0F00, 0x0FFF void loader16F874(void) {} //for the 4k 16F873/4
#define DEBOUNCE_PERIOD_IN_MS 10
#define DEBOUNCE_COUNT 8

int8 count=0, debounce=0;

#int_rtcc
void clock_isr()
{
switch (debounce)
{
case 0:
// First, wait for the button to be released.
if(input(ONOFF)) count++;
else count=0;
if(count==DEBOUNCE_COUNT) { debounce=1; count=0; }
else debounce=0;
break;

case 1:
// Now that the button is up, wait until the user presses it.
if(!input(ONOFF)) count++;
else count=0;
if(count==DEBOUNCE_COUNT) { debounce=2; count=0; }
else debounce=1;
break;

case 2:
output_low(REGUL);
break;
}
}

void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
set_tris_a(0x10);

output_high(REGUL);
output_high(LED0);
output_low(LED1);

delay_ms(2000);
output_high(LED1);

set_timer0(0);
setup_counters( RTCC_INTERNAL, RTCC_DIV_64 | RTCC_8_BIT );
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);

while(1);
}


Thanks for all your help, it is really helpful Wink
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Dec 14, 2004 12:18 pm     Reply with quote

Humberto wrote:
Ttelmah wrote:
Quote:

The reason it is setting the TRIS bit, is that if 'standard_io' is selected, it will _always_ do it.


NOP. This is not the case.
If you read carefully the code posted by YulL, you will see clearly that for
port_a data direction setting he used the directive
#use fast_io(A)
and for other ports he used
#use standard_io();

The inputs and outputs regarding this discusion was focused in port_A.



Humberto Very Happy


NOPE, Ttelmah is right. I guess you didn't read or understand his earlier post
Quote:
I'm wrong, here is the detail with fast_io (I gived details with standard_io).

Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Dec 14, 2004 2:45 pm     Reply with quote

Mark wrote:
Quote:

NOPE, Ttelmah is right. I guess you didn't read or understand his earlier post


Mark,

I guess you didn't read or understand my earlier post.

I copied and pasted the header code posted by YulL

Quote:

here is the header :

#include <16F873A.h>
#device adc=8
#use delay(clock=7372800) //7372800
#fuses HS, NOWDT, NOPROTECT, NOLVP, NOBROWNOUT, PUT
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#use fast_io(A)
#use standard_io(B)
#use standard_io(C)

#define LED0 PIN_A0
#define LED1 PIN_A1
#define ONOFF PIN_A4
#define REGUL PIN_A5
#define DATADS PIN_C4


The inputs and outputs regarding this discusion was focused exclusivelly in port_a.

Can you see the directive #use fast_io(A) ???

'fast_io'. With this, the compiler will not touch TRIS at all.



Humberto
Ttelmah
Guest







PostPosted: Tue Dec 14, 2004 3:16 pm     Reply with quote

Humberto wrote:
Ttelmah wrote:
Quote:

The reason it is setting the TRIS bit, is that if 'standard_io' is selected, it will _always_ do it.


NOP. This is not the case.
If you read carefully the code posted by YulL, you will see clearly that for
port_a data direction setting he used the directive
#use fast_io(A)
and for other ports he used
#use standard_io();

The inputs and outputs regarding this discusion was focused in port_A.



Humberto Very Happy

I think the 'key' thing you are missing, is that _standard_io_, is _standard_.
_Unless_ fast_io, or fixed_io is selected, _standard_io_, is assumed. In fact there is no reason at all for the 'standard_io' statements in the code posted. The only time you need to use the standard_io statement, is where you have selected one of the other forms, and wish to 'change back' for a section of code.
Hence port_a, is using standard_io. As such the TRIS statement, will be overridden as soon as I/O is attempted to the port...
Hence my comments...

Best Wishes
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Dec 14, 2004 3:54 pm     Reply with quote

Now I am thoroughly confused.
Ttelmah do you mean that after:
#use fast_io(A)
#use standard_io(B)
#use standard_io(C)
the compiler will STILL set the TRIS register each time for port A, despite the #use fast_io(A) statement?

And I am used to a TRIS statement looking like:
0498: MOVLW F0
0499: TRIS 5

I don't see a TRIS in this code:
.................... if(!input(ONOFF))
0059: BSF 03.5
005A: BSF 05.4
005B: BCF 03.5
005C: BTFSC 05.4
005D: GOTO 063
It looks like the ONOFF bit itself is being set at 005A
_________________
The search for better is endless. Instead simply find very good and get the job done.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Dec 14, 2004 4:07 pm     Reply with quote

Humberto wrote:
Mark wrote:
Quote:

NOPE, Ttelmah is right. I guess you didn't read or understand his earlier post


Mark,

I guess you didn't read or understand my earlier post.

I copied and pasted the header code posted by YulL

Quote:

here is the header :

#include <16F873A.h>
#device adc=8
#use delay(clock=7372800) //7372800
#fuses HS, NOWDT, NOPROTECT, NOLVP, NOBROWNOUT, PUT
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#use fast_io(A)
#use standard_io(B)
#use standard_io(C)

#define LED0 PIN_A0
#define LED1 PIN_A1
#define ONOFF PIN_A4
#define REGUL PIN_A5
#define DATADS PIN_C4


The inputs and outputs regarding this discusion was focused exclusivelly in port_a.

Can you see the directive #use fast_io(A) ???

'fast_io'. With this, the compiler will not touch TRIS at all.



Humberto


No I understood everything. YulL posted code that used fast_io. However, his lst file was from a version where he tried standard_io and thus his comment
Quote:
I'm wrong, here is the detail with fast_io (I gived details with standard_io).


Then you went on to say that Ttelmah's comment was incorrect. But what he said was totally correct but he was referring to the lst files details where YulL used standard_io! Razz
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Dec 14, 2004 7:29 pm     Reply with quote

To be kind with the readers of this forum I suggest to stop with this
Babel Tower discution.

Anyway, I want to redeem the spirit of this forum. Exclamation Exclamation Exclamation

Ttelmah and Mark thanks for your patience. Very Happy



Humberto
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group