Help PLEASE - Stuck on a project! 16F877A


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Is it ok to put things in loop like I have done?
    The code in the ISR still looks a bit long. Maybe put that stuff in the START label being you are looping back to it. Have a GOSUB in there to TOGGLE FAST.
    In the end I think the only thing you want in the ISR is the serial receive.


    From the PicMultiCalc program the copy defines is what you want at the beginning of your code for this.

    Your HESER statement is not quite right. Look at SERIN2/SEROUT2 for examples on the syntax, it is the same as HSERin/out. Basically you need [ ] at the beginning and end.

    Now I am going to suggest that you leave your code for a bit and and work on some simple test codes to make sure you have everything working. I am sure you did that at the beginning of this project but several things are changing now, adding new "stuff" and restructuring the code.

    RF is difficult at best so start with wires. Do the HSERIN in the ISR and just simply have it do one thing, light an LED. Then work on feed back from the receiver.

    Which brings up another thing. If I am following this correctly the RF is two way. ZUnless you have a two way module you will want to kill the power to the transmitter when you are receiving. I do not see this in the code but maybe it is there.
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    The code in the ISR still looks a bit long. Maybe put that stuff in the START label being you are looping back to it. Have a GOSUB in there to TOGGLE FAST.
    In the end I think the only thing you want in the ISR is the serial receive.
    I didn't knew about this. I just want to confirm again, that I can put gosub kind of statements in the ISR, where it can point to labels outside the ISR?
    Which brings up another thing. If I am following this correctly the RF is two way. ZUnless you have a two way module you will want to kill the power to the transmitter when you are receiving. I do not see this in the code but maybe it is there.
    I have tried to give enough pause to the TX before transmitting, so that Rx can finish listening to the code.

    One more question for now, any advise as to why this stament in the code (MCroom) is not working when code received is 1:
    Code:
    	for x=1 to 4
    		if code=x then
    			High PortC[x+3] : Y=1 : buzzer[x]=1: goto snd
    		endif
    Port C.4 should get high when code is 1, but it is not.

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I didn't knew about this. I just want to confirm again, that I can put gosub kind of statements in the ISR, where it can point to labels outside the ISR?
    That is not what I was trying to say.
    Your code loops back to START: regularly, have a GOSUB in there that will take you to the routine that WAS in the ISR. Looks like that routine is for setting the LEDs and I bet your code will run fast enough that if the LEDs are set/changed through every loop it will be fine.

    Some of the transmitters are transmitting a carrier wave all of the time when they are powered up. Could be "jamming" the receiver.


    High PortC[x+3]
    That is interesting... never tried that but I do not think it will work.
    Maybe if the . is put in after C ???
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    Back to scratch now. Just trying to do it for one machine with new approach. MCH reports the problem, LED goes high at MCroom, along with the buzzer, Ackn... signal is sent and led blinks at MCH as well.
    BUT only for few seconds and then it goes off. I also put a statement High BUzz: pause 100 : low buzz to see if valid signal comes, it does keeps comming at mcroom.
    Looking at my new code will explain better what I am trying to do. Any advise?
    Attached Files Attached Files

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Any advise?
    Re-read post 4 and 9 ???
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default Hserin & Hserout

    Quote Originally Posted by mackrackit View Post
    Re-read post 4 and 9 ???
    Hi, I have arranged my hardware accordingly to use USART, trying to understand and blink an LED first.
    My Rx code is :
    Code:
    DEFINE OSC 4
    Include "modedefs.bas"
    INCLUDE "DT_INTS-14.bas"     ; Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ; Include if using PBP interrupts
     
    @ __Config _XT_OSC & _WDT_ON & _PWRTE_ON & _BODEN_ON & _LVP_OFF & _CP_ALL & _CPD_ON
     
    Pause 50
    '-------variables declared-------------------------------------
    
    code1 var byte
    code2 var byte
    a var bit
    b var bit
    c var bit
    d var bit
    e var bit
    f var bit
    g var bit
    h var bit
    a=0 : b=0 : c=0 : d=0 : e=0 : f=0 : g=0 : h=0
    '-------------------------FUSES SET----------------------------
    PAUSE 50
    ADCON1=7
    CMCON=7
    CCP1CON=0
    OPTION_REG=%10000000
    TRISA=0 : PORTA=0
    TRISE=0 : PORTE=0
    TRISB=0 : PORTB=0
    TRISC=%10000000 : PORTC=0
    TRISD=0 : PORTD=0
    @ ERRORLEVEL -306
    
    ;-----------HSERIN & OUT------------------
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 12  ' 4800 Baud @ 0.17%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $20 ' Enable transmit, BRGH = 0
    SPBRG = 12  ' 4800 Baud @ 0.17%
    
    '------INTERRUPT DECLARED--------------------------------------------------------------
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
           INT_Handler    TMR1_INT,  _ToggleFast,   PBP,  yes
           INT_Handler    RX_INT,  _RX,   PBP,  yes	   
       endm
      INT_CREATE               ; Creates the interrupt processor
    ENDASM
    T1CON=%00110001
     
    @   INT_ENABLE   TMR1_INT
    @   INT_ENABLE   RX_INT
    
    ;------MAIN PROGRAM START-----------
    start:
    	HIGH PORTB.7
    	PAUSE 50
    	LOW PORTB.7
    	PAUSE 100
    Goto start
    
    
    '---[INT - interrupt handler]---------------------------------
    ToggleFast:
    	Toggle PortB.6
    @ INT_RETURN
    
    
    RX:
    		TOGGLE PortB.5
    		HSERIN 100,close,[WAIT("MT3"),code1,code2]
    	close:
    
    @ INT_RETURN
    
    '---------end--------------------
    Nothing is comming from Tx currently because I wanted to see first if both interrupts are working fine.
    This is what happens:
    LEDs are connected to PortB.7,6 & 5. When power is applied, PortB.7 blinks, PortB.6 blinks but when PortB.5 blinks, normally PIC hangs for few seconds and then normal erratic behaviour happens because of the interrupts, then again PIC hangs for few seconds.
    My TX module connected to PIN25 is also getting very hot, even though I am not using it in the above code. Is this overall behaviour normal, I am using this feature for the first time, am I doing it right?

Members who have read this thread : 0

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