Here is my version, using only mov as first stepping stone with mostly indirect numbers.
Code:
CON
_clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz
_xinfreq = 5_000_000
PUB main
cognew(@entry,0)
DAT
entry mov dira,#%11 'pin p0 and p1 as output
mov time,#5 'first time we only want to wait 0 clock(+ 5 for the overhead)
add time,cnt 'add current counter value to time
loop waitcnt time, delay 'wait until counter matches time, when done add delay to time
mov outa,#%01 'set pin p0 high, p1 low
waitcnt time, delay 'wait, time had 15million added to it from above waitcnt opcode
mov outa,#%10 'set pin p0 low, p1 high
jmp #loop 'jmp to loop, don't forget the # sign
delay long 15_000_000 '15 million clock cycles, underscores is just for easy reading by human eyes.
time res 1
2nd updated version, that shows better programming style.
Code:
CON
_clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz
_xinfreq = 5_000_000
PUB main
cognew(@entry,0)
DAT
entry mov dira,output 'set outputs
mov time,#5 'first time we only want to wait 0 clock(+ 5 for the overhead)
add time,cnt 'add current counter value to time
loop waitcnt time, delay 'wait until counter matches time, when done add delay to time.
or outa, pin1 'set pin1 high
andn outa,pin2 'set pin2 low
waitcnt time, delay 'wait, time had 15million added to it from above waitcnt opcode.
andn outa,pin1 'set pin1 low
or outa, pin2 'set pin2 high
jmp #loop 'jmp to loop, don't forget the # sign.
delay long 15_000_000 '15 million clock cycles
pin1 long 1<<0 '1 shifted zero(p0) steps up = 1 (= %00000001)
pin2 long 1<<1 '1 shifted one(p1) step up = 2 (= %00000010)
output long 1<<0 | 1<<1 '| =or, so ora the pins we want as output
time res 1
3rd way with xor, and declaring values in CON sections.
Code:
CON
_clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz
_xinfreq = 5_000_000
pin1= 0 'p0 (use a value between 0 and 31)
pin2= 1 'p1 (though 28-31 is sometimes reserved)
PUB main
cognew(@entry,0)
DAT
entry mov dira,output 'set outputs
or outa,led1 'set pin1 high
mov time,#5 'first time we only want to wait 0 clock(+ 5 for the overhead)
add time,cnt 'add current counter, don't add code between this and next line
' without adding at least 4 to the #5 above for each line added.
:loop waitcnt time, delay 'wait until counter matches time, when done add delay to time.
xor outa, output 'bit invert all output pins.
jmp #:loop 'jmp to :loop, don't forget the # sign.
delay long 15_000_000 '15 million clock cycles
led1 long 1<<pin1 '1 shifted steps up
led2 long 1<<pin2 '1 shifted steps up
output long 1<<pin1 | 1<<pin2 '| =or, so ora the pins we want as output
time res 1 'hint: time can be replaced with cnt, yes cnt the shadow register.
Bookmarks