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

depend on pin

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








depend on pin
PostPosted: Thu Apr 09, 2009 6:37 pm     Reply with quote

Hai!! All

I really new in PIC and not expert in C. I just buy the kits and try the program in this forum.

Right now I succeed to blinking a LED. Laughing and display "Hello world" on LCD. Laughing

Thanks a lot dear all forum members.

My third lesson is to communicate with hardware RS232. This is very tough for me but I know the basic is use putc() and getc() to send communication and get the respond respectively.

My problem is :

Before I send communication using putc(), I have to make sure the hardware Rs232 is ready. The ready status can be known by check the voltage status on hardware RS232. 5V not ready and 0V is ready. This status pin I connect to PIN_A5.

Can any one give me an advice or the way to do this?


Thanks a lot for any help.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 09, 2009 11:25 pm     Reply with quote

Quote:

Before I send communication using putc(), I have to make sure the
hardware Rs232 is ready.

Why do you believe this is necessary ?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Apr 09, 2009 11:37 pm     Reply with quote

Code:
while (input(PIN_A2)==1); // waits forever, if unready!
putc('A');

The online help has examples how to use built-in functions like input().
Guest








PostPosted: Fri Apr 10, 2009 12:55 am     Reply with quote

PCM programmer wrote:
Quote:

Before I send communication using putc(), I have to make sure the
hardware Rs232 is ready.

Why do you believe this is necessary ?


Because this hardware rs232 only ready to communicate when it detect something. If this hardware not detect anything, it won't work.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 10, 2009 1:21 am     Reply with quote

You can use the kbhit() function to detect if a character has been
received by the hardware UART. If you're using a software UART,
kbhit will detect if the Rx pin has a start bit on it (i.e., it's at a 0v level).
Guest








PostPosted: Fri Apr 10, 2009 5:47 am     Reply with quote

I think it just like a push button and blinkin LED. If the push button is high, then control your output.
Guest








PostPosted: Wed Apr 15, 2009 9:13 pm     Reply with quote

Hai!! All.

I have a hardware to detect Tag. If the Tag out of a range the hardware output pin is 5V. If the Tag in the range the hardware output pin is 0V. This hardware output pin I connect direct to PIN_B5 on 16F877A.

Here is my programme:
Code:
#define (__PCM__)
#include<16f877A.h>

#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#include<flex_lcd.c>

#define cardSta PIN_B5

void main()
{
lcd_init();

lcd_putc("\ftestpinB5");
delay_ms(1000);

   if(input(cardSta)) {      // Read the switch pin.
 
      lcd_putc("\ftag far!!"); // If tag far, display tag far!!
   }
   else {
      lcd_putc("\fB5=tag near!!"); // if tag near, display tag near!!
  }
  while(1);
}


when I switch on a circuit the LCD display testpinB5 and then tag faR!!. When I put the Tag near to the hardware but nothing change. I try the other way… Now I put a resistor 10K to PIN_B5 the same thing happen. I try the other way… put one end to a ground, the same thing happen but if I switch off the circuit and switch on LCD will display testpinB5 and tag near!! Either Tag near or far this PIN_B5 not do nothing.

plz help
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Apr 16, 2009 2:23 am     Reply with quote

You have to put a while-loop around the code that you want repeated. Now the program starts at the beginning, performs all actions once and then stops at the line:
Code:
while(1);
This line is just an empty loop doing nothing, and doing that forever. Note the ';' after the while, this is an 'empty statement'. For easier understanding you can think of the while-line above as the equivalent of:
Code:
while(1)
{
  // do nothing
};


Note:
Code:
#define (__PCM__)
Remove this line from your program, this is a compiler internal definition from the CCS header files and not supposed to be set in your code.
Guest








PostPosted: Fri Apr 17, 2009 2:30 am     Reply with quote

Thanks a lot!!

Now I the problem solve. This is the code after your advice:
Code:
#include<16f877A.h>

#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#include<flex_lcd.c>

#define cardSta PIN_B5
#define LED1 PIN_B4
#define LED2 PIN_B3

void main() {



lcd_init();
lcd_putc("\fhai!!");
delay_ms(3000);

while(1){

   if(input(cardSta)==0) {

   lcd_putc("\fyes==0!!");
      //output_high(LED1);

   }

   else {

   lcd_putc("\fno!=0!!");
      //output_high(LED2);

   }

}
}


After this I will go to next lesson: transmit and receive data with UART.

Thanks a lot again.
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