View previous topic :: View next topic |
Author |
Message |
Guest
|
depend on pin |
Posted: Thu Apr 09, 2009 6:37 pm |
|
|
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. and display "Hello world" on LCD.
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
|
|
Posted: Thu Apr 09, 2009 11:25 pm |
|
|
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
|
|
Posted: Thu Apr 09, 2009 11:37 pm |
|
|
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
|
|
Posted: Fri Apr 10, 2009 12:55 am |
|
|
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
|
|
Posted: Fri Apr 10, 2009 1:21 am |
|
|
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
|
|
Posted: Fri Apr 10, 2009 5:47 am |
|
|
I think it just like a push button and blinkin LED. If the push button is high, then control your output. |
|
|
Guest
|
|
Posted: Wed Apr 15, 2009 9:13 pm |
|
|
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
|
|
Posted: Thu Apr 16, 2009 2:23 am |
|
|
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: 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: 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
|
|
Posted: Fri Apr 17, 2009 2:30 am |
|
|
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. |
|
|
|