Hello fellow BASCOM users.
I having one of those "am I going crazy days", actually it has been more than a day....
I'm having trouble with something very simple, but I just cannot work out what I'm doing wrong. I have narrowed down the code to just the bare essentials to prove what is causing the problem.
What happens is that the timing of the pin toggle is not regular when the code is compiled with the line "bit_1 = bit_2" in the sub routine. It seems that the bit "tick" is corrupted. With the line removed the timing of the pin toggle is perfect.
BASCOM version is 2.0.7.5
Are bit operations not allowed with subroutines? I'm not aware of any rules that say so, I think I have used them like this before without a problem.
Here is the code:
'define chip to use
$regfile = "m328def.dat"
'define used crystal
$crystal = 1000000
Ddrb = &B00111110
Ddrc = &B0011111
Ddrd = &B00001110
$hwstack = 120 'defualt use 32
$swstack = 120 'default use 10
$framesize = 200 'default use 40
Config Submode = New
Config Timer1 = Timer , Prescale = 1 , Clear Timer = 1 'clear timer 1 upon compare A match
Timer1 = 0
Compare1a = 46874 'every 3 seconds
On Compare1a Timer_tick 'Nosave
Enable Compare1a
Enable Interrupts
'************************************
'Global variables
Dim Tick As Bit
Dim Bit_1 As Bit
Dim Bit_2 As Bit
'*************************************
Sub Bit_operation()
Bit_1 = Bit_2
End Sub
'*************************************
Do
While Tick = 1
Reset Tick
Toggle Portc.2
Wend
Bit_operation
Loop
'*************************************
Timer_tick:
'without NOSAVE around 30 registers are saved and recalled.
'We only need to save the SREG and the registers used inside the isr
'using Bascom 2.0.7.5 only R23 is used to set the bit
'push r23 'save R23
'in r23,sreg 'Put the contents of the status register into R23
'push r23 'now save it
Set Tick
'pop r23 'pop R23 which is a copy of the status register from before
'!Out Sreg , R23 'put it back into the status register
'pop r23 'put R23 back to how it was before.
Return
End
[b:1f493b8214][color=red:1f493b8214](BASCOM-AVR version : 2.0.7.5 , Latest : 2.0.7.6 )[/b:1f493b8214][/color:1f493b8214]
↧