PDA

View Full Version : Problems with program



Fossil
- 24th February 2004, 18:49
Hi guys again. I know I shouldn't keep asking for help but this time i really need help. Cause my progress report 2 is just next week. Not much has been done which is omg omg for me now. lolz.

I am now doing a sender and receiver device. The receiver device has a button for it to reply to the sender but it should only allow this to happen when 2 conditions are satisfied, 1-the button is pressed and 2-when the led lights up. My problem is that I have tried using the IF...THEN...ENDIF statement to check for the button and LED. For eg. PORTA.0 is the LED and PORTA.1 is the switch, so...
IF (PORTA.0 = 1) AND (PORTA.1 = 0) THEN

It doesn't work. So I assume that the IF...THEN statement treats PORTA.0 as an input and some error might occur there. Anyone has any idea how to go about this problem? Thanks in advance.

Melanie
- 24th February 2004, 20:01
If you post your program and/or schematic. we could point you in the right direction, but as it stands we don't know how your PIC is detecting the LED is lit, so it's difficult to answer.

Fossil
- 25th February 2004, 04:58
The LED is actually connected to the chip itself. When the receiver receives a data from the sender, the receiver will light up this LED. Only when this LED is on, then the user is allowed to press a button to send a reply.

The LED is connected to Port A pin 0
The button is connected to Port A pin 1
The Receive pin is Port B pin 0
The Sending pin is Port B pin 1
The carrier detect pin (from the RF transceiver which will switch to low when a signal is detected) is Port B pin 2

My program looks roughly like this:
DEFINE OSC 20
DEFINE SER2_BITS 9
REC VAR BYTE
DATA VAR BYTE
TRISA=%00000010
TRISB=%00000001
TRISC=$00

RECEIVE: IF PORTB.2=0 THEN
SERIN2 PORTB.0,8380,RECEIVE,[WAIT("TUV"),REC]
HIGH PORTA.0
ENDIF
REPLY: IF (PORTA.0 = 1) AND (PORTA.1 = 0) THEN
SEROUT2 PORTB.1,8380,["TUV",PRESS]
LOW PORTA.0
ENDIF
END

This is actually a small part of my whole program. The finished receiver should be able to take in message from 3 senders.

Melanie
- 25th February 2004, 09:06
OK, we've got something to work on now...

The problem you're having is that you've set A.0 for Output, and then performing a Read (Input) operation on it... sometimes this doesn't work and sometimes you can get away with it... to be bullet-proof try this...

LEDStatus var bit ' Add this variable

RECEIVE: IF PORTB.2=0 THEN
SERIN2 PORTB.0,8380,RECEIVE,[WAIT("TUV"),REC]
HIGH PORTA.0:LEDStatus=1
ENDIF

REPLY:
IF LEDStatus=1 THEN
IF PORTA.1 = 0 THEN
SEROUT2 PORTB.1,8380,["TUV",PRESS]
LOW PORTA.0:LEDStatus=0
ENDIF
ENDIF

If it still doesn't work then you must ask yourself...

Is PORTA.1 Low?
Have I remembered that A.1 needs a pull-up Resistor?

Melanie

Fossil
- 25th February 2004, 09:24
Ok thanks. There should be any problems with the hardware cause I have already tested it before and it works fine. I'll go tryout your solution. Thanks alot.