Hi,
I tried to adapt Hkipnik`s ST7735 code to drive it with XMEGA....
I changed hardware SPI to:
[code:1:240feb209a] Config Spie = Hard , Master = Yes , Mode = 0 , Clockdiv = Clk2 , Data_order = Msb , Ss = none
Open "SPIE" For Binary As #12
[/code:1:240feb209a]
and also the pins for DC, CS and Reset...
[code:1:240feb209a]
Config PortE.0 = Output
Config PortE.2 = Output
Config PortE.1 = Output
Lcd_cs Alias PortE.0
Lcd_dc Alias PortE.2
Lcd_reset Alias PortE.1
PortE.0 = 1
[/code:1:240feb209a]
and I changed "SPIOUT" command to "print #12" and have no luck.... With ATMEGA I had this display already running...
Has anybody an idea what I am doing wrong?
Cheers
[b:240feb209a][color=red:240feb209a](BASCOM-AVR version : 2.0.7.8 )[/b:240feb209a][/color:240feb209a]
↧
BASCOM-AVR : ST7735R with XMEGA : NEWTOPIC
↧
BASCOM-AVR Old versions : problem with delay using motion sensor : REPLY
I tried to make a 10 second delay for PIR sensor using timer0 by modifying the code in the topic "Timer Interrupts", but delay which occurred less than 3 seconds. what's wrong with the code? any one can help me? thank you
↧
↧
Share your working BASCOM-AVR code here : Fast library for ILI9325 LCD : REPLY
Updated version. Speedup:
- Line & Circle - 3 times
- Filled Circle - 6 times in 8bit, 10 times in 16bit.
Added separate sub for 18bit bmp (262k color) from SD-card.
Some small changes.
↧
BASCOM-AVR Old versions : problem with delay using motion sensor : REPLY
I use this code to give a one second tic for time keeping it runs every second so
buy incrementing variables within it you can get delays in seconds
Regards Paul
[code:1:4c78c5596e]
Config Timer0 = Timer , Prescale = 1024 'configure the timer
On Ovf0 Tim0_isr 'Define ISR handler for clock
Enable Timer0 'Enable timer 0 interrupt
Dim Bres As Long '--This is the timer value
Dim L2 As Long
Enable Interrupts 'enable global Interrupts
Tim0_isr:
Bres = Bres + 262144 '262144 = prescaler:1024 * timer0:256
If Bres > Xtal Then ' = xtal frequency
Bres = Bres - Xtal 'change to your crystal or RC frequency
'turn on clock output and measure frequency
Incr L2 ' Increment system seconds
End If
Return
[/code:1:4c78c5596e]
↧
BASCOM-AVR Old versions : problem with delay using motion sensor : REPLY
To understand mistake think "when value Bz is increased?"
I think only if Pir sensor = 1 :D
Code like this should work
[code:1:076c879fa3]$regfile = "m16def.dat"
$crystal = 8000000
$hwstack = 40
$swstack=16
$framesize=32
Config Pinb.0 = Input 'input pir1
Config Portc = Output 'relay
Dim N As Word
Dim Zs As Byte ' in interrupt for flag better to use Byte
Dim Bz As Byte
' IRQ Time = Freq(4MHz)/Prescaler(64)/Timer(256)
' 8 000 000 Hz/256/256 = 122Hz
' 1 second have 1000ms
' 1000ms / 122 = 8ms
Config Timer0 = Timer , Prescale = 256 '
Enable Timer0 : On Timer0 T0_isr
Enable Interrupts
Do
'-[this process is executed every second]-
If Zs = 1 Then ' every 1000ms if flag is set
Zs = 0 ' clear flag
If Bz > 0 Then 'only if Bz have value > 0 then
Decr Bz 'countdown every second
If Bz = 0 Then Reset Portc.1 'if value = 0 then relay Off
End If
End If
'-[ End 1s ]-
If Pinb.0 = 1 Then ' if motion detect in pir sensor1
Set Portc.1 'enable relay
Bz = 10 'set timeout delay ;)
End If
Loop
T0_isr:
Incr N
If N >= 125 Then '125x8ms=1000ms
N = 0
Zs = 1 'set flag only 1s past
End If
Return
End[/code:1:076c879fa3]
↧
↧
BASCOM-AVR Old versions : problem with delay using motion sensor : REPLY
thanks paul . but I still confused , do I have to assign a value to a variable "bres" ?
↧
BASCOM-AVR Old versions : problem with delay using motion sensor : REPLY
Yes you're right EDC, i make a mistake... is that the same way if i want to use 2 pir sensor? sorry for asking to much :)
↧
BASCOM-AVR Old versions : problem with delay using motion sensor : REPLY
If I tell you then you remmember nothing. If you try maybe you learn even more...
↧
BASCOM-AVR Old versions : problem with delay using motion sensor : REPLY
:oops: ok EDC i will try to generate 10 seconds delay for 2 pir sensors using timer... thank you
↧
↧
Share your working BASCOM-AVR code here : SSD1306 LCD SPI-mode library : REPLY
Hello Mrshilov,
Thanks for sharing. Another excellent library :D
And as usual complete with circuit, pdf, sample, bgf.
Well done!
↧
Share your working BASCOM-AVR code here : WEB Server based CLOCK with NTP SYNCH on MEGA2560 (no SD nee : REPLY
Thank you for the sample and the information.
yes sometimes these small things can have big consequences. it is good to share that info :D
↧
Share your working BASCOM-AVR code here : Fast library for ILI9325 LCD : REPLY
thanks for the update. I appreciate it.
↧
BASCOM-AVR Old versions : problem with delay using motion sensor : REPLY
it works for two sensor2 PIR.... i modified using subroutines . thanks for your help EDC
[code:1:36a418f2c1]
$regfile = "m16def.dat"
$crystal = 8000000
$hwstack = 40
$swstack=16
$framesize=32
Config Pinb.0 = Input 'input pir1
Config Pinb.2 = Input 'input pir2
Config Portc = Output 'relay
Dim N As Word
Dim Zs As Byte , Za As Byte ' in interrupt for flag better to use Byte
Dim Bz As Byte , Bz1 As Byte
Declare Sub Rules()
Declare Sub Room1()
Declare Sub Room2()
' IRQ Time = Freq(4MHz)/Prescaler(64)/Timer(256)
' 8 000 000 Hz/256/256 = 122Hz
' 1 second have 1000ms
' 1000ms / 122 = 8ms
Config Timer0 = Timer , Prescale = 256 '
Enable Timer0 : On Timer0 T0_isr
Enable Interrupts
Do
Call Room1()
Call Room2()
Call Rules()
Loop
T0_isr:
Incr N
If N >= 125 Then '125x8ms=1000ms
N = 0
Zs = 1 'set flag only 1s past
Za = 1 'set flag only 1s past
End If
Return
End
Sub Room1()
'-[this process is executed every second]-
If Zs = 1 Then ' every 1000ms if flag is set
Zs = 0 ' clear flag
If Bz > 0 Then 'only if Bz have value > 0 then
Decr Bz 'countdown every second
If Bz = 0 Then
Reset Portc.1
End If
End If
End If
'-[ End 1s ]-
If Pinb.0 = 1 Then ' if motion detect in pir sensor1
Set Portc.1 'enable relay
Bz = 10 'set timeout delay Wink
End If
End Sub
Sub Room2()
'-[this process is executed every second]-
If Za = 1 Then ' every 1000ms if flag is set
Za = 0 ' clear flag
If Bz1 > 0 Then 'only if Bz have value > 0 then
Decr Bz1 'countdown every second
If Bz1 = 0 Then
Reset Portc.3
'Print " test2 "
End If
End If
End If
'-[ End 1s ]-
If Pinb.2 = 1 Then ' if motion detect in pir sensor2
Set Portc.3 'enable relay
Bz1 = 10 'set timeout delay Wink
End If
End Sub[/code:1:36a418f2c1]
↧
↧
BASCOM-AVR Old versions : problem with delay using motion sensor : REPLY
Code should be more "readable" so even after years you can understand what`s is going on :P
Add proper aliases to the pins and names for variables is fundamental :P
[code:1:23bab91cb8]$regfile = "m16def.dat"
$crystal = 8000000
$hwstack = 40
$swstack=16
$framesize=32
Config Pinb.0 = Input : Pir_1 Alias Pinb.0 'input pir1
Config Pinb.2 = Input : Pir_2 Alias Pinb.2 'input pir2
Config Portc = Output 'relays
Relay_1 Alias Portc.1
Relay_2 Alias Portc.3
Dim Miliseconds As Byte , N As Byte , 1s As Byte
'You can simply add new room by "Dimm Timeout(3) As Byte" instead Dim below
Dim Timeout(2) As Byte 'we have two Bytes (Timeout(1) and Timeout(2)) the same name but with Index
'one constant located on the beginning of code and you don`t need to search in code in future
'and you can change timeouts for all rooms in one line
Const Timeout_time = 10
Declare Sub Sensors()
Declare Sub Control()
Config Timer0 = Timer , Prescale = 256 '
Enable Timer0 : On Timer0 T0_isr '~8ms
Enable Interrupts
Do
If 1s = 1 Then
1s = 0
Call Control() 'timeouts we check every sec only
End If
Call Sensors() 'sensors we check often (maybe even too much)
Loop
T0_isr:
Incr Miliseconds
If Miliseconds >= 125 Then '125x8ms=1000ms
Miliseconds = 0
1s = 1 'set flag only 1s past
End If
Return
End
Sub Sensors
If Pir_1 = 1 Then
Timeout(1) = Timeout_time
Set Relay_1
Elseif Pir_2 = 1 Then
Timeout(2) = Timeout_time
Set Relay_2
End If
End Sub
Sub Control
For N = 1 To 2 'loop where N have 1 and will be increased till N = 2 ;)
If Timeout(n) > 0 Then 'if N=1 then we check Timeout(1), if N=2 then we check Timeout(2)
Decr Timeout(n)
If Timeout(n) = 0 Then
Select Case N
Case 1 : Reset Relay_1 'if N=1 in this loop
Case 2 : Reset Relay_2 'if N=2 in this loop
End Select
End If
End If
Next
End Sub
'## EXAMPLE how Sub Control() will be look if you add new room
'## Watch that code not grow much ;) so that`s why using byte arrays is cool
'Sub Control
' For N = 1 To 3
' If Timeout(n) > 0 Then
' Decr Timeout(n)
' If Timeout(n) = 0 Then
' Select Case N
' Case 1 : Reset Relay_1 'if N=1 in this loop
' Case 2 : Reset Relay_2 'if N=2 in this loop
' Case 3 : Reset Relay_3
' End Select
' End If
' End If
' Next
'End Sub[/code:1:23bab91cb8]
↧
BASCOM-AVR Old versions : problem with delay using motion sensor : REPLY
i'm a newcomer in programming with bascom avr and i am glad joining MCS forum.. i learn much from this forum. thank you for suggestion and the code :D
↧
BASCOM-AVR : ATxmega128B3 : REPLY
Hi,
Thanks for your help but problem is still there.
Perhaps there is a probleme with the DAT file ?
Best regards
Georges
↧
BASCOM-AVR : using an interrupt just for wakeup : NEWTOPIC
Hi
i want to use int0 of atmega64 just for wakeing up microcontroller from powerdown mode by an external signal. also i dont want to do any instruction in interrupt isr. i want to know if i dont use "on int0 int0_isr" what will happen?
i want to dont go to any interrupt service routine and dont save any register to save time, is it possible?
Regards
[b:a26749d7ea][color=red:a26749d7ea](BASCOM-AVR version : 2.0.7.8 )[/b:a26749d7ea][/color:a26749d7ea]
↧
↧
BASCOM-AVR : using an interrupt just for wakeup : REPLY
Atmega64 is a oldboy I think.
Only Lov level on interrupt pin can wake micro from powerdown.
Maybe change to something equivalent and new will be better idea.
For example look how I`v made dimmer for stairs to truck :P
If you open the door then two stepsare slowly highlited.
I use PCINT with nosave to wake up micro.
[code:1:e3279cdbef]$regfile = "attiny13a.dat"
$crystal = 1200000
$hwstack = 10
$swstack = 9
$framesize = 9
Config Submode = New
Config Portb = &B000110 : Portb = &B001000
Sw1 Alias Pinb.3
Config Timer0 = Timer , Prescale = 8 , Compare A = Disconnect , Compare B = Disconnect , Clear Timer = 1
Enable Compare0a : On Compare0a Int0_isr Nosave : Compare0a = 180
Dim P1 As Byte
Dim P2 As Byte
Dim Licznik As Byte
Dim Speed As Byte
Dim Mark As Byte
Pcmsk = &B001000
Enable Pcint0 : On Pcint0 Pcint_isr Nosave
Enable Interrupts
Sub Calc_speed(byval Pwm As Byte)
Speed = 127 - Pwm
Shift Speed , Left , 1
End Sub
Do
If Speed = 0 Then 'if switch pressed
If Sw1 = 0 Then
If P1 < 100 Then 'if PWM LED1 <100% then
Incr P1 'slowly rise
Call Calc_speed(p1) 'calc speed for state of PWM LED1
Else 'if PWM LED1 is 100% then
If P2 < 100 Then
Incr P2 'slowly rise second LED
Call Calc_speed(p2)
End If
End If
Else 'if switch is released
'if PWM > 0 then decrase slowly
If P1 > 0 Then
Decr P1 'and if PWM is 0 then..
Else
Config Powermode = Powerdown 'go to sleep here
'** MICRO SLEEP HERE AND AFTER WAKE UP BEGIN FROM THAT POINT **
End If
If P2 > 0 Then Decr P2
Call Calc_speed(p1) 'calculate for both
End If
End If
Loop
End
Int0_isr:
$asm
PUSH R16
PUSH R20
PUSH R24
PUSH R26
!in R24, sreg
PUSH R24
$end Asm
Incr Licznik
If Licznik = 100 Then Licznik = 1
If Licznik > P1 Then Reset Portb.1 Else Set Portb.1
If Licznik > P2 Then Reset Portb.2 Else Set Portb.2
If Speed > 0 Then Decr Speed
' Tuned with NoSave Tool
$asm
POP R24
!out sreg, r24
POP R26
POP R24
POP R20
POP R16
$end Asm
Return
Pcint_isr:
'this only wake micro so no instructions here
Return
[/code:1:e3279cdbef]
↧
BASCOM-AVR : using an interrupt just for wakeup : REPLY
thank you
but, forget atmega64 and other hardware recomandation, please say me obviousely my answer.
my question:
if i use below instruction:
config int0=rising(/falling/change)
enable int0
do
loop
end
what will happen after trigering int0 pin?
Regards
↧
BASCOM-AVR : using an interrupt just for wakeup : REPLY
I think you can save a lot of time by due test yourself instead asking for direct answears on forum :P
Yes, I test it for you because it cost me 1min
[code:1:da882957ea]$regfile = "m64def.dat"
$crystal = 8000000
$hwstack = 40
$swstack = 16
$framesize = 32
Config Portd.4 = Output : Led Alias Portd.4
Portd.2 = 1 ' pullup on INT0
Config Int0 = Low Level
Enable Int0 : On Int0 Int0_isr Nosave
Enable Interrupts
Do
Config Powermode = Powerdown
Set Led
Loop
End
Int0_isr:
Return[/code:1:da882957ea]
and I can confirm that this int wake from Powerdown. Ar U satisfied ? :D
↧