uC Hangs after second serout command
Hello,
I'm using the following configuration:
1 PIC 16F876A
PIC Basic PRO 3 (demo)
Why does the uC only runs this code one time. It does not loops it:
Code:
Include "modedefs.bas"
Define OSC 20
STATUSLED VAR PORTC.4 ' Rode LED
BUZZER VAR PORTC.7 ' Buzzer
ReedContact VAr PORTC.0 ' Reed contact voor starten dot
Power_On VAR PORTC.1 ' Overname contact power
Power_XBEE VAR PORTB.0
Power_RFID VAR PORTB.3
XBEE_RX VAR PORTB.2 ' Serial data vanaf XBEE
XBEE_TX VAR PORTB.1 ' Serial data naar XBEE
RFID_RX VAR PORTB.4 ' Seriele data vanaf de RFID lezer
RFID_TX VAR PORTB.5 ' Seriele data naar de RFID lezer
i VAr BYTE ' Globale teller
received_date VAR BYTE[16]
x var BYTE[20]
y VAR BYTE
CRC VAR BYTE ' CRC over RFID data
CRC_TOT VAR BYTE ' CRC over totale data
'===============================================================================
' Init
'===============================================================================
Init:
HIGH Power_On
high Power_XBEE
for x = 0 to 20
serout XBEE_TX, T9600,["X2 = ",#x,13,10] '9600 inverted
pause 500
next x
Goto Main
'*******************************************************************************
' Main:
'*******************************************************************************
Main:
HIGH STATUSLED
pause 500
Serout2 RFID_TX,16416,[$AA,$BB,$02,$20,$22] ' Read Card Command
SERIN2 RFID_RX,16416,100,Check_data,[received_date[0]] ' Receive data
Goto Main
'*******************************************************************************
' Check_Data:
' 1. Controle op gelezen data
' 2. Controle of kaart anders is dan vorige keer
' 3. Indien nieuwe kaart schrijf deze in Temp Card Data
'*******************************************************************************
Check_Data:
serout XBEE_TX, T9600,["CHECK DATA",13,10] '9600 inverted
LOW STATUSLED
pause 500
RETURN
Re: uC Hangs after second serout command
NL2TTL,
Probably the code is getting hung up somewhere in the program. You need to determine where it is getting hung up. There are several ways to do it. I would move the next line around in the program and see how far the program goes
TOGGLE STATUSLED
This is just one way to do it.
Robert
Re: uC Hangs after second serout command
Hi,
At first look I'd say you need to change the RETURN to something like GOTO Main.
/Henrik.
Re: uC Hangs after second serout command
Quote:
Why does the uC only runs this code one time. It does not loops it:
Are you stating that because the status led is always on?
If this is the case, take note that you turn off the status led only in the subroutine CHECK_DATA and there is no gosub to this sub in your code.
Cheers
Al.
Re: uC Hangs after second serout command
Hi I take notice off that.
There are more strange things:
After the:
SEROUT2 XBEE_TX,84, ["Nieuwe kaart",13,10]
The uC starts at INIT again and does not go back to the main routine.
Code:
'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 17-8-2011 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
Include "modedefs.bas"
Define OSC 20
STATUSLED VAR PORTC.4 ' Rode LED
BUZZER VAR PORTC.7 ' Buzzer
ReedContact VAr PORTC.0 ' Reed contact voor starten dot
Power_On VAR PORTC.1 ' Overname contact power
Power_XBEE VAR PORTB.0
Power_RFID VAR PORTB.3
XBEE_RX VAR PORTB.2 ' Serial data vanaf XBEE
XBEE_TX VAR PORTB.1 ' Serial data naar XBEE
RFID_RX VAR PORTB.7 ' Seriele data vanaf de RFID lezer
RFID_TX VAR PORTB.5 ' Seriele data naar de RFID lezer
Card_Temp VAR BYTE[4] ' Temp serie nummer kaart
i VAr BYTE ' Globale teller
received_date VAR BYTE[16]
read_try var byte ' Pogin tot lezen
x var BYTE[20]
y VAR BYTE
CRC VAR BYTE ' CRC over RFID data
CRC_TOT VAR BYTE ' CRC over totale data
'===============================================================================
' Init
'===============================================================================
Init:
high Power_On
high Power_XBEE
for x = 0 to 30
serout2 XBEE_TX,84,["X2 = ",#x,13,10] '9600 inverted
pause 500
next x
Goto Main
'*******************************************************************************
' Main:
'*******************************************************************************
Main:
high Power_RFID
High STATUSLED
Serout2 RFID_TX,16416,[$AA,$BB,$02,$20,$22] ' Read Card Command
SERIN2 RFID_RX,16416,100,Check_data,[received_date[0]] ' Receive data
FOR i = 1 to 8
SERIN2 RFID_RX,16416,10,Check_Data,[received_date[i]]
NEXT i
Goto Main
'*******************************************************************************
' Check_Data:
' 1. Controle op gelezen data
' 2. Controle of kaart anders is dan vorige keer
' 3. Indien nieuwe kaart schrijf deze in Temp Card Data
'*******************************************************************************
Check_Data:
CRC = received_date[2] ^ received_date[3] ^ received_date[4] ^ received_date[5] ^ received_date[6] ^ received_date[7]
If (received_date[0] = $AA) AND (received_date[1] = $BB) AND (received_date[2] = $06) AND (received_date[8] = CRC) Then
serout2 XBEE_TX,84,["Geldige kaart gelezen CRC := ", HEX2 CRC,13,10]
' Controleer of de kaart anders is dan de vorige kaart
If (received_date[4] <> Card_Temp[4]) OR (received_date[5] <> Card_Temp[5]) OR (received_date[6] <> Card_Temp[6]) OR (received_date[7] <> Card_Temp[7]) Then
SEROUT2 XBEE_TX,84, ["Nieuwe kaart",13,10]
For i = 4 to 7
Card_Temp[i] = received_date[I]
NEXT I
RETURN
ELSE
SEROUT2 XBEE_TX,84, ["Oude kaart",13,10]
RETURN
ENDIF
ELSE
serout2 XBEE_TX,84,["Ongeldige / geen kaart gelezen",13,10]
ENDIF
Goto Main
Re: uC Hangs after second serout command
In Check_Data you have RETURNs, but you're not using GOSUBs to get there, so replace the RETURNs with GOTOs to get back.
Re: uC Hangs after second serout command
Funny in 2.47 version of the compiler the timeout lable works with returns
I see that 3.00 does not accept the return.
Re: uC Hangs after second serout command
As far as I know, the timeout/label option has always used a GOTO to get to the label after the timeout period has expired. I can't say why it would have worked on an earlier version. Maybe luck...:)
Re: uC Hangs after second serout command
time out....go sit on the bench,
timeout only needed for serin !
don
amgen
Re: uC Hangs after second serout command
NL2TTL, The statement: Funny in 2.47 version of the compiler the timeout lable works with returns
I see that 3.00 does not accept the return. Only makes sense if the timeout actually happened inside of a subroutine. Otherwise, where are you returning to?
Re: uC Hangs after second serout command
could check PARITY BIT 13 in mode, manual says must=1
don