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 support@ccsinfo.com

problem with switch on picdem DBoard

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest
Guest







problem with switch on picdem DBoard
PostPosted: Sat Feb 04, 2006 11:40 am     Reply with quote

I have PU switch and i use PIN A4. The MCU is 16F84A.

If i run my code :
Code:


#define P_0    PORTA,4
#define TRISP_0 TRISA,4


int tipkaPRESSED()
    {
    static int1 laststate=0;
    if (!bit_test(* P_0) ) {       
        delay_ms(50);           
        if (laststate) {
            laststate = 0;
            return(1);
        }
    } else
        laststate=1;
    return (0);
}


i get compiler error :
1.) Condition always FALSE PORTA
2.) Undefined identifier

He ??
Ports are defined and pointed to A4.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Feb 04, 2006 1:35 pm     Reply with quote

Port i/o is easier if you use the CCS functions such as:

input()
output_low()
output_high()

If you use the CCS "standard i/o" mode (which is the default mode of
the compiler) then you don't have to set the TRIS for these functions.
The compiler will do it for you automatically.

I've changed your program to use the input() function.
See the lines shown in bold below:

Quote:
#define P_0 PIN_A4

int tipkaPRESSED()
{
static int1 laststate=0;
if (!input(P_0)) {
delay_ms(50);
if (laststate) {
laststate = 0;
return(1);
}
} else
laststate=1;
return (0);
}
Guest








PostPosted: Sun Feb 05, 2006 5:06 am     Reply with quote

Thank you, it partly is working.

1.) If i want to use "my way", can i define this in compiler ?

2.) Im asking this becuse, then i have to change parts where im using ASM:
(is there any function in CCS so i can avoid ASM ? ).

Code:
void START_tipka() {
#asm
    BSF _RP0
    BSF TRISP_0
#endasm
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 05, 2006 5:27 am     Reply with quote

You can use a #byte statement to declare PortA to be a variable
at memory address 0x05. Then you can use PortA as a parameter
in the bit_test() function. Example:

Quote:

#byte PortA = 5

int tipkaPRESSED()
{
static int1 laststate=0;
if (!bit_test(PortA, 4) ) {
delay_ms(50);
if (laststate) {
laststate = 0;
return(1);
}
} else
laststate=1;
return (0);
}


If you want to set the TRIS, then use the set_tris_a() function.
Though, you could also use a #byte statement to declare the
address of the TRISA register, and then access it directly.
Guest








PostPosted: Sun Feb 05, 2006 6:14 am     Reply with quote

Code:
#define TRISP_0 TRISA,4


void START_tipka()
    {
#asm
    BSF _RP0
    BSF TRISP_0
#endasm


Please explain me this part... As far as i know, CCS supports ASM parts.
But when i want to run the initialisation part for button then i get compiler message: Undefined identifier TRISA

I saw that you have written :
Quote:
If you want to set the TRIS, then use the set_tris_a() function.


Is this a MUST or can i use ASM for such jobs...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 05, 2006 2:17 pm     Reply with quote

You shouldn't mix ASM and C in the way that you're doing it.

Also, it looks to me like you came from a different PIC C compiler.
You were previously using one that doesn't have all the capabilities
of CCS, perhaps, so you're trying to do all sorts of low level coding
that you believe must be done.

You don't have to do that with CCS. You don't have to set RP0,
or the bank select registers. You don't have to manually assign
memory addresses or banks to your variables. It's all done
automatically for you. This is one of the reasons why people use CCS.

With regard to your specific question, CCS doesn't have a predefined
header file with all the register addresses. You either have to do it
yourself or find one of the register header files that have been posted
around the forum, usually in the Code Library forum.

The following program will show you how to use the #bit directive
to declare the address of a bit.

Quote:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)

#bit TRISP_0 = 0x85.4

//=========================
void main()
{

#asm
BSF TRISP_0
#endasm


while(1);
}


The CCS Assembler has several limitations, and these are discussed
on here fairly often by Ttelmah. It's not the same as MPASM. If you
want to use CCS as a "shell" to do assembler, it's not the best idea.
Guest








PostPosted: Tue Feb 07, 2006 6:50 am     Reply with quote

Code:

#byte PortA = 5
#bit TRISP_0 = 0x85.4

int tipkaPRESSED()
{
   static int1 laststate=0;
   if (!bit_test(PortA, 4) )  {
   delay_ms(50);
      if (laststate) {
      laststate = 0;
      return(1);
      }
   } else
      laststate=1;
return (0);
}
//-------------------------------------
void STARTtipka() // initialisation
{
   #asm
     BSF TRISP_0
   #endasm
}

main()
{
  STARTtipka();
  if ( tipkaPRESSED())
  output_high(PIN_B0);
}


Before i get further please explain me this: this is the code that should trigger the button state and i think that i write it OK. Wenn i run the code, press the switch,nothing happens. There is no compiler errors.
This has nothing to do with ASM ? ( just to be sure before i start changes :-))
Guest








PostPosted: Tue Feb 07, 2006 6:52 am     Reply with quote

Code:

#byte PortA = 5
#bit TRISP_0 = 0x85.4

int tipkaPRESSED()
{
   static int1 laststate=0;
   if (!bit_test(PortA, 4) )  {
   delay_ms(50);
      if (laststate) {
      laststate = 0;
      return(1);
      }
   } else
      laststate=1;
return (0);
}
//-------------------------------------
void STARTtipka() // initialisation
{
   #asm
     BSF TRISP_0
   #endasm
}

main()
{
  STARTtipka();
  if ( tipkaPRESSED())
  output_high(PIN_B0);
}


Before i get further please explain me this: this is the code that should trigger the button state and i think that i write it OK. Wenn i run the code, press the switch,nothing happens. There is no compiler errors.
This has nothing to do with ASM ? ( just to be sure before i start changes :-))
Guest








PostPosted: Tue Feb 07, 2006 7:10 am     Reply with quote

Code:

main()
{
  while(){
  STARTtipka();
  if ( tipkaPRESSED())
  output_high(PIN_B0);
  }
}


My mistake. Sorry!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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