View previous topic :: View next topic |
Author |
Message |
Johan v. Althuis
Joined: 01 Jan 2005 Posts: 54
|
Posted: Thu Feb 03, 2005 9:52 am Post subject: ERROR: ISR Already defined :S |
|
|
Dear Bascom Users,
I receive an error when using the interrupt flag URXC.
An example of my program:
Code: |
$crystal = 16000000
$baud = 4800
$regfile = "m8def.dat"
' Buffer de seriele ingang tot een lengte van 82 karakters
Config Serialin = Buffered , Size = 82
Config Lcdpin = Pin , Db4 = Pb.0 , Db5 = Pb.1 , Db6 = Pb.2 , Db7 = Pb.3 , E = Pb.4 , Rs = Pb.5
' Configureer 'Nmea' en 'Temp' als string
Dim Signaal As String * 1
Dim Nmea As String * 82
Dim Temp As String * 10
Dim Kwaliteit As Byte
' Activeer interrupts
On Urxc Test
Enable Urxc
Enable Interrupts
Config Lcd = 16 * 2
Cursor Off
Cls
Begin:
Goto Begin
Test:
Do
Signaal = Inkey()
' Wacht totdat er een karakter doorgestuurd is
If Err = 0 Then
Nmea = Nmea + Signaal
End If
Loop Until Signaal = Chr(13)
Print Nmea
Temp = Mid(nmea , 2 , 6)
If Temp = "$GPGGA" Then Gosub Kwaliteit
Nmea = ""
Return
Kwaliteit:
Cls
Temp = Mid(nmea , 44 , 1)
If Temp = "0" Then Kwaliteit = 1
If Temp = "1" Then Kwaliteit = 2
If Temp = "2" Then Kwaliteit = 3
If Temp = "3" Then Kwaliteit = 2
Temp = Mid(nmea , 46 , 1)
If Temp <= "3" Then Kwaliteit = Kwaliteit + 1
If Temp >= "6" Then Kwaliteit = Kwaliteit + 3
If Temp > "3" Then
If Temp < "6" Then Kwaliteit = Kwaliteit + 2
End If
Temp = Mid(nmea , 49 , 3)
If Temp <= "2.0" Then Kwaliteit = Kwaliteit + 3
If Temp >= "4.0" Then Kwaliteit = Kwaliteit + 1
If Temp > "2.0" Then
If Temp =< "4.0" Then Kwaliteit = Kwaliteit + 2
End If
If Kwaliteit >= 0 Then
If Kwaliteit <= 5 Then Lcd "Slecht"
End If
If Kwaliteit >= 6 Then
If Kwaliteit <= 8 Then Lcd "Normaal"
End If
If Kwaliteit > 8 Then Lcd "Goed"
Return
|
When compiling I get the error: Error: 249 Line: 16 ISR Already defined...
What is wrong in my code?
Thanks in advance,
Johan v. Althuis
Ps. Sorry for my bad englis! (i'm dutch )
Additional info:
Using bascom 1.11.7.4 |
|
Back to top |
|
|
pedrodantas
Joined: 30 Dec 2004 Posts: 22
|
Posted: Thu Feb 03, 2005 10:13 am Post subject: |
|
|
Hi,
You can not use
On Urxc Test
Enable Urxc
if you use Config Serialin = Buffered , Size = 82 (With this, bascom handle the ISR), see the bascom help.
Com os melhores cumprimentos/Best Regards,
Pedro Dantas
pedro.dantas@betronic.com |
|
Back to top |
|
|
oe9vfj
Joined: 17 Jun 2004 Posts: 269 Location: Austria, Hard
|
Posted: Thu Feb 03, 2005 10:18 am Post subject: |
|
|
Hi,
The URXC Interrupt vector-address is used by the buffered Serial in.
Every-time a character is received by the UART, an Interrupt-routine is started to save this character to the serial-In buffer.
So you can't use this interrupt a second time. _________________ regards Josef
DOS - File System for BASCOM-AVR on http://members.aon.at/voegel |
|
Back to top |
|
|
Johan v. Althuis
Joined: 01 Jan 2005 Posts: 54
|
Posted: Thu Feb 03, 2005 11:00 am Post subject: |
|
|
That's sad,
Is it possible to go to an subroutine when there is a serial signal?
Cause that was my plan by using URXC.
Thanks in advance, |
|
Back to top |
|
|
oe9vfj
Joined: 17 Jun 2004 Posts: 269 Location: Austria, Hard
|
Posted: Thu Feb 03, 2005 12:59 pm Post subject: |
|
|
I Think you want only take an action in the main part of your application, if a complete String is received.
I advise you to set a flag inside the serial buffer receiving routine.
This BASCOM-AVR ISR routine is located in MCS.LIB
Open the library MCS.LIB
search for the routine
[_GOTCHAR0]
Copy all code from [_GOTCHAR0] to next [end] to an own file, name it "CR_Check0.LIB" and save it to the LIB-Path.
Now change the code of this routine:
Insert just before the label: _gotchar_exit0
following lines:
cpi r25, 13 ; CR received?
brne _GotChar_Exit0 ; if not than no action
ldi r24, 1 ; 1 is flag for received
* sts {CR_Received}, r24 ; store to variable CR_Received
Save Lib-File and test with following program:
Code: |
$crystal = 16000000
$baud = 4800
$regfile = "m8def.dat"
' Buffer de seriele ingang tot een lengte van 82 karakters
Config Serialin = Buffered , Size = 82
Config Lcdpin = Pin , Db4 = Pb.0 , Db5 = Pb.1 , Db6 = Pb.2 , Db7 = Pb.3 , E = Pb.4 , Rs = Pb.5
' Configureer 'Nmea' en 'Temp' als string
Dim Signaal As String * 1
Dim Nmea As String * 82
Dim Temp As String * 10
Dim Kwaliteit As Byte
Dim CR_Received as Byte
$Lib "CR_Check0.LIB"
' Activeer interrupts
Enable Interrupts
Config Lcd = 16 * 2
Cursor Off
Cls
Begin:
GOSUB Test ' Test for Receiving CR and handle String
Goto Begin
Test:
Disable Interrupts ' ISR may not varable while checking it
if CR_Received <> 1 then
enable interrupts ' No CR, enable interrupt and go back
return
end if
CR_Received = 0 ' reset ISR Flag
enable interrupts
Input Nmea
Print Nmea
Temp = Mid(nmea , 2 , 6)
If Temp = "$GPGGA" Then Gosub Kwaliteit
Nmea = ""
Return
Kwaliteit:
Cls
Temp = Mid(nmea , 44 , 1)
If Temp = "0" Then Kwaliteit = 1
If Temp = "1" Then Kwaliteit = 2
If Temp = "2" Then Kwaliteit = 3
If Temp = "3" Then Kwaliteit = 2
Temp = Mid(nmea , 46 , 1)
If Temp <= "3" Then Kwaliteit = Kwaliteit + 1
If Temp >= "6" Then Kwaliteit = Kwaliteit + 3
If Temp > "3" Then
If Temp < "6" Then Kwaliteit = Kwaliteit + 2
End If
Temp = Mid(nmea , 49 , 3)
If Temp <= "2.0" Then Kwaliteit = Kwaliteit + 3
If Temp >= "4.0" Then Kwaliteit = Kwaliteit + 1
If Temp > "2.0" Then
If Temp =< "4.0" Then Kwaliteit = Kwaliteit + 2
End If
If Kwaliteit >= 0 Then
If Kwaliteit <= 5 Then Lcd "Slecht"
End If
If Kwaliteit >= 6 Then
If Kwaliteit <= 8 Then Lcd "Normaal"
End If
If Kwaliteit > 8 Then Lcd "Goed"
Return
|
As you can see, there is the new variable CR_Received, which is set to 1, if a CR is received in the ISR. The Line
$LIB "CR_Check0.LIB"
link the new routine to the program, so the compiler use it instead of that on in the MCS.LIB.
In the program there is a gosub to the test-routine, which first disables the interrupts, so ISR can not change the CR_Received during checking it.
If the Flag-Variable CR_Reiceived is 0, Interrupts are enable and test-routine is leaved.
If CR_Received is 1 (CR received), the Flag is set back to 0, Interrupts enabled and next your own routine for String-handling is done.
Always keep ISR as short as possible, set there a flag for the Main part and handle all other in the main part in a loop.
You can find more information about libraries and ASM in the help file
I have not tested this program on hardware. _________________ regards Josef
DOS - File System for BASCOM-AVR on http://members.aon.at/voegel |
|
Back to top |
|
|
Twenty
Joined: 30 Nov 2004 Posts: 50 Location: Sydney
|
Posted: Wed Jan 04, 2006 7:57 am Post subject: migrating m8 to m168 reading serial port |
|
|
oe9vfj,
Thanks for the code that you have put on the forum. I have used it in one of my projects and it is working fine on m8. However, when I tried to migrate to m168 it doesn't work at all. Somehow I think the interrupt in the m168 is not activated. The code that is working for the m8 but not for the m168 is below. Could you please perhaps give me some pointers or guidelines where to start looking for? I have Bascom 1.11.8.1
$regfile = "m168def.dat"
$crystal = 8000000
$baud = 4800
Config Serialin = Buffered , Size = 82
Dim Nmea As String * 82
Dim Cr_received As Byte
$lib "CR_Check0.LIB"
Enable Interrupts
Begin:
Gosub Test
Goto Begin
End
Test:
Disable Interrupts
If Cr_received <> 1 Then
Enable Interrupts ' No CR, enable interrupt and go back
Return
End If
Cr_received = 0 ' reset ISR Flag
Enable Interrupts
Input Nmea
Cr_received = 1
Print Nmea 'Or gosub to furhter processing of string
Nmea = ""
Return
|
|
Back to top |
|
|
Twenty
Joined: 30 Nov 2004 Posts: 50 Location: Sydney
|
Posted: Sun Jan 08, 2006 3:40 am Post subject: |
|
|
I got it working. The problem was that the fuse setting "devide by clock..." was enabled. After this setting was disabled it worked fine
Thanks |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|