Problems with program


Closed Thread
Results 1 to 5 of 5
  1. #1
    Fossil's Avatar
    Fossil Guest

    Unhappy Problems with program

    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.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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.

  3. #3
    Fossil's Avatar
    Fossil Guest


    Did you find this post helpful? Yes | No

    Default

    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.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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

  5. #5
    Fossil's Avatar
    Fossil Guest


    Did you find this post helpful? Yes | No

    Default

    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.

Similar Threads

  1. Replies: 1
    Last Post: - 23rd May 2009, 09:22
  2. Problems programming
    By Lionheart in forum General
    Replies: 4
    Last Post: - 7th December 2008, 16:51
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. IC2 pic 18f452 program problems
    By MrSafe in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 20th September 2007, 18:55
  5. PIC16F684 Program question
    By Nicholas in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th December 2006, 14:30

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts