avr.device = atmega328p
avr.clock = 16000000
avr.stack = 32
uart.Baud = 9600
uart.send.enable
#define LED1 as portB.5 'LED1 is defined as label for portB.5
LED1.mode = output,low 'the port is configured as output and set to low
dim count as byte
do
LED1 = 1 'LED1 on
waitms 500 'wait for 500ms
LED1 = 0 'LED1 off
waitms 500 'wait for 500ms
print "Count="; str( count )
count++
loop
avr.device = atmega328p
avr.clock = 16000000
avr.stack = 32
uart.Baud = 9600
uart.send.enable
#define LED1 as portB.5 'LED1 is defined as label for portB.5
LED1.mode = output,low 'the port is configured as output and set to low
dim count as byte
' main routin
do
led_on()
waitms 500 'wait for 500ms
led_off()
waitms 500 'wait for 500ms
print "Count="; str( count )
count++loop
' 関数、サブルーチン群は必ずメインルーチンの下に書く。
procedure led_on()
LED1 = 1 'LED1 on
endprocprocedure led_off()
LED1 = 0 'LED1 off
endproc
' Manchester codec for LunaAvr
' Made by audin 2014/12
' Refered to
' http://www.sfcompiler.co.uk/wiki/pmwiki.php?n=SwordfishUser.Comparison
' http://www.sfcompiler.co.uk/wiki/pmwiki.php?n=SwordfishUser.ManchesterCode
'
' For ATMega328p
avr.device = atmega328p
avr.clock = 16000000
avr.stack = 32
#define LED1 as portB.5 'LED1 is defined as label for portB.0
LED1.mode = output,low 'the port is configured as output and set to low
' Global defs
Dim Index As Byte
Dim bOrgval As Byte
Dim wEncval As Word
Dim bDecval As Byte
Dim bRes As Byte
' main routine
Do
For bOrgval = 0 To 255
wEncval = Encode( bOrgval )
bRes = Decode( wEncval , bDecval )
If bOrgval <> bDecval Then
Call Led_blink(1)
End If
Next
Call Led_blink(0)
Loop
' 関数、サブルーチン群は必ずメインルーチンの下に書く。
procedure Led_blink( byval state As Byte )
Do
If state = 1 Then
LED1 = 1
Waitms 500
LED1 = 0
Waitms 500
Else
LED1 = 1
End If
Loop
Endproc
'Encode...
Function Encode( byval bValue As Byte) As Word
dim Encode as word
Encode = 0
For Index = 0 To 7
If bValue.0 = 0 Then
Encode.14 = 1
Else
Encode.15 = 1
End If
If Index < 7 Then
Encode >>= 2
End If
bValue >>= 1
Next
return Encode
Endfunc
' Decode...
Function Decode( byval bEncodedValue As Word , byref pbDecodedValue As Byte) As Byte
dim Decode as byte
Decode = 1
For Index = 0 To 7
If bEncodedValue.1 = 0 And bEncodedValue.0 = 1 Then
pbDecodedValue.7 = 0
Elseif bEncodedValue.1 = 1 And bEncodedValue.0 = 0 Then
pbDecodedValue.7 = 1
Else
Decode = 0
break
End If
bEncodedValue >>= 2
If Index < 7 Then
pbDecodedValue >>= 1
End If
Next
return Decode
Endfunc
' Manchester codec for LunaAvr with Encodings module
' Made by audin 2014/12
' Danke forum guys.
' Refered to
' http://forum.myluna.de/viewtopic.php?f=8&t=808
'
' Refered to
' http://www.sfcompiler.co.uk/wiki/pmwiki.php?n=SwordfishUser.Comparison
' http://www.sfcompiler.co.uk/wiki/pmwiki.php?n=SwordfishUser.ManchesterCode
'
' For ATMega328p
avr.device = atmega328p
avr.clock = 16000000
avr.stack = 32
#library "Library/Encodings.module"
#define LED1 as portB.5 'LED1 is defined as label for portB.0
LED1.mode = output,low 'the port is configured as output and set to low
Dim bOrgval As Byte
Dim wEncval As Word
Dim bDecval As Byte
Dim bRes As Byte
' main routine
Do
For bOrgval = 0 To 255
wEncval = ManchesterEncode( bOrgval )
bRes = ManchesterDecode( wEncval , bDecval )
If bOrgval <> bDecval Then
Call Led_blink(1)
End If
Next
Call Led_blink(0)
Loop
' 関数、サブルーチン群は必ずメインルーチンの下に書く。
procedure Led_blink( byval state As Byte )
Do
If state = 1 Then
LED1 = 1
Waitms 500
LED1 = 0
Waitms 500
Else
LED1 = 1
End If
Loop
Endproc