roboforum.ruТехнический форум по робототехнике. |
|
|
SP-FORTH - ANS FORTH 94 for Win95/98/Me/NT/2k/XP/Vista
Open source project at http://spf.sf.net
Russian FIG at http://www.forth.org.ru ; Started by A.Cherezov
Version 4.20 Build 001 at 21.Jan.2009
>S" d:\ucontrollers\amforth\amforth-4.2\amforth-4.2_uploader.spf" INCLUDED
Ok
>commopen
CommPort handle= 2A8
Ok
>S" D:\uControllers\amforth\amforth-4.2\lib\my\" setdir!
Ok
>S" tttt1.frt" setfile!
Ok
>getfile
source file:
D:\uControllers\amforth\amforth-4.2\lib\my\tttt1.frt
428 loaded: 1113 okay Ok
>download
\
\ tttt1.frt - timer1 tools for timing tests
\ 21:06 09.10.2010 *chu*
\ =============================================================
\
marker -tttt1-
forth only also assembler
decimal
$2F constant tccr1a
$2E constant tccr1b
\ stop timer1
code t1>
tccr1b R2 out,
end-code
\ start timer1 @ normal mode, prescaler=8 ( 1us counter @8MHz )
code <t1
R17 2 ldi,
tccr1a R2 out,
tccr1b R17 out,
end-code
code delay \ : delay ( n -- ) begin 1- dup 0= until drop ;
label>
R24 1 sbiw,
<radr brne,
R24 Y+ ld,
R25 Y+ ld,
end-code
forth only
\ stop timer1 & zero counter
: <t1> t1> 0 dup TCNT1H c! TCNT1L c! ;
\ show t1 counter
: .t1
TCNT1L c@ TCNT1H c@ 8 lshift + dup
." (0x" .x ." )" bl emit u. ." us"
TIFR dup c@ $4 and dup \ test TOV1 flag
if bl emit ." overrun"
over c@ or swap c! \ clear TOV1 by writing'1'
else drop drop then cr
;
\ timing test using timer1, xt - executable address
: ?us <t1> <t1 execute t1> .t1 ; ( *x xt -- *y )
\
\ =============================================================
\
Ok
>closefile CommClose
Ok
>
amforth 4.2 ATmega32
> words
?us delay <t1 t1> tccr1b tccr1a -tttt1- run park park park stm2 stm1 .x .rotate
stm? stopoff wave! normal! half! reverse rotate step idx- idx+ init_stm! motor@
stepper: /stepper motor res1 total steps direction dly ststate shft sequence
idx -- normal wave half-step phase -stepper help help-wl -help .base calc-baudrate
.res .( erase -misc twi.scan twi.ping? twi.status? twi.status twi.rxn twi.rx twi.tx
twi.action twi.stop twi.start twi.wait -twi twi.default +twi -spi -spi2x +spi2x +spi
spi.f/128 spi.f/64 spi.f/16 spi.f/4 spi.mode3 spi.mode2 spi.mode1 spi.mode0
spi.MASTER spi.MSB spi.SPE _spi_ ftgl fclr? fset? fclr fset bv flag: pin_pullup_on
pin_highZ toggle pin@ pin_low? pin_high? pin_input pin_output pin! is_high? is_low?
pulse low high bitmask: portpin: tlist alsotask onlytask multi single task activate
cell- task-awake task-sleep stop multitaskpause wake pass follower status dump edump
idump dump> <dump trimm .addr .rcells .ecells .icells ? e? i? .item u.r endcase endof
of case assembler vocabulary Rdefer Rdefer! Rdefer@ Udefer Udefer! Udefer@ Edefer
Edefer! Edefer@ action-of anew possibly move blank nip tuck ? xt>nfa >body chars
char+ c, aligned align restore-input save-input source-id postpone fm/mod sm/rem dabs
?negate ?dnegate dnegate u*/mod sqrt -math m+ 2variable 2constant 2! 2@ 2tuck 2nip
2rot 2swap 2over 2dup 2drop marker i@ (i!) i! e@ e! not s>d up! up@ >< cmove> unloop
i sp! sp@ rp! rp@ +! rshift lshift 1- 1+ xor or and 2* 2/ invert um* um/mod m* + -
log2 d< d> 0> u> u< true 0 0< > < 0<> 0= = <> r@ >r r> rot drop over swap ?dup dup c@
c! ! @ execute exit -int +int UDR UCSRB UCSRA UBRRL UBRRH TWSR TWDR TWCR TWBR TWAR
TCNT2 TCCR2 OCR2 ASSR TCNT1L TCNT1H TCCR1B TCCR1A OCR1BL OCR1BH OCR1AL OCR1AH ICR1L
ICR1H TIMSK TIFR TCNT0 TCCR0 OCR0 SPSR SPDR SPCR PORTD PIND DDRD PORTC PINC DDRC
PORTB PINB DDRB PORTA PINA DDRA GIFR GICR EEDR EECR EEARL EEARH SREG SPL SPH OSCCAL
MCUCSR MCUCR SPMCR ACSR SFIOR ADMUX ADCSRA ADCL ADCH ms 1ms ewords fill #int int@
show-wordlist b> >b b!- b!+ nb! b! b@- b@+ nb@ b@ a> >a a!- a!+ na! a! a@- a@+ na@ a@
wordlist forth definitions previous also forth-wordlist only set-order set-current
spirw sleep wdr -wdt -jtag +usart baud tx? tx rx? rx order get-order get-current
environment? environment end-code code abort abort" [char] immediate recurse user
constant variable [ ] ; :noname : does> create ?do leave +loop loop do again until
repeat while begin then else if literal int! applturnkey is Rdefer Edefer words s" ."
.s u. dinvert d- d+ d2* init-user ee>ram ee-user tib d2/ cmove dnegate dabs d>s j *
defer@ defer! icompare find search-wordlist to value unused noop ver ?stack interpret
depth rp0 sp sp0 cold pause quit place word /string source cscan parse 2swap >number
number char refill accept cskip throw catch handler ' type count spaces space cr
icount itype s, digit? ud/mod ud.r ud. . d. .r d.r sign #> #s # <# hold hld within
max min abs mod / negate u/mod */ /mod */mod turnkey bl hex decimal bin ['] , compile
( \ allot here edp dp /key key? key emit? emit pad #tib >in cell+ cells base state
f_cpu ok
> .res
amforth 4.2 ATmega32 running at 8000 kHz
free FLASH cells 5357
free RAM bytes 1712
used EEPROM bytes 68
used data stack cells 0
used return stack cells 5
free return stack cells 35
ok
>
> ' noop ?us
(0x9 ) 9 us
ok
>
> ' 1ms ?us
( 0x3DD ) 989 us
ok
> 1 ' ms ?us
( 0x3F5 ) 1013 us
ok
> 10 ' ms ?us
( 0x26C5 ) 9925 us
ok
> 60 ' ms ?us
( 0xE82E ) 59438 us
ok
> 66 ' ms ?us
( 0xFF64 ) 65380 us
ok
> 67 ' ms ?us
( 0x342 ) 834 us overrun
ok
>
> : delayf begin 1- dup 0= until drop ;
ok
> 1 ' delay ?us
( 0xA ) 10 us
ok
> 1 ' delayf ?us
( 0x21 ) 33 us
ok
> 10 ' delay ?us
( 0xE ) 14 us
ok
> 10 ' delayf ?us
( 0xB6 ) 182 us
ok
> 100 ' delay ?us
( 0x3C ) 60 us
ok
> 100 ' delayf ?us
( 0x683 ) 1667 us
ok
> 1000 ' delay ?us
( 0x1FD ) 509 us
ok
> 1000 ' delayf ?us
( 0x4084 ) 16516 us
ok
> 0 ' delay ?us
( 0x800A ) 32778 us
ok
> 0 ' delayf ?us
( 0x8010 ) 32784 us overrun
ok
>
\
\ ps/2 mouse interface
\
\ chu 22:08 07.11.2010 last version
\ chu 10:13 03.10.2010
\
\ =============================================================
\
marker -ps/2-
forth only also assembler decimal
code (portbit#)
R16 R25 mov,
R25 clr,
-Y R25 st,
-Y R16 st,
end-code
: portbit#:
create 8 lshift swap $20 - or ,
does> i@ (portbit#)
;
PORTB 1 portbit#: ps/2_clk
PORTB 0 portbit#: ps/2_data
code +ps/2_clk
ps/2_clk
over over 1 -
swap cbi, \ set input
swap sbi, \ and pull-up
end-code
code +ps/2_data
ps/2_data
over over 1 -
swap cbi, \ set input
swap sbi, \ and pull-up
end-code
code -ps/2_clk
ps/2_clk
over over 1 -
swap sbi, \ set output
swap cbi, \ and low
end-code
code -ps/2_data
ps/2_data
over over 1 -
swap sbi, \ set output
swap cbi, \ and low
end-code
code ?ps/2_clk+ \ begin ps/2_clk pin_high? until
label>
ps/2_clk 2 - swap sbis,
<radr rjmp,
end-code
code ?ps/2_clk- \ begin ps/2_clk pin_low? until
label>
ps/2_clk 2 - swap sbic,
<radr rjmp,
end-code
code ?ps/2_data- \ begin ps/2_data pin_low? until
label>
ps/2_data 2 - swap sbic,
<radr rjmp,
end-code
code ?ps/2_data+ \ begin ps/2_data pin_high? until
label>
ps/2_data 2 - swap sbis,
<radr rjmp,
end-code
code ps/2_bit ( p c )
R16 1 ldi,
R16 R24 and, \ get current bit
R17 Y+ ld, \ get parity bit
R17 R16 eor, \ check parity
-Y R17 st, \ save parity bit
R24 lsr, \ next data bit
-Y R25 st,
-Y R24 st,
R24 R16 mov, \ current data bit
end-code ( p' c' b )
code ps/2_bit@ \ 1 rshift ps/2_data pin_high? if 0x80 or then
R24 lsr,
ps/2_data 2 - swap sbic,
R24 $80 ori,
end-code
forth only
1 constant odd \ пижонство, ага
: ps/2! ( c -- ) \ ps/2 write byte
odd swap ( p c )
+ps/2_clk
+ps/2_data 600 delay \ idle state
-ps/2_clk 600 delay \
-ps/2_data 18 delay \ start
+ps/2_clk \ bit
8 0 do
?ps/2_clk- ( p' c' )
ps/2_bit if
+ps/2_data else
-ps/2_data then
?ps/2_clk+
loop drop ( p )
\ parity
?ps/2_clk- if
+ps/2_data else
-ps/2_data then
?ps/2_clk+
\ stop bit
?ps/2_clk-
+ps/2_data
?ps/2_clk+
\ ack bit
?ps/2_clk-
?ps/2_data-
?ps/2_clk+
?ps/2_data+
-ps/2_clk \ inhibit transmission
;
: ps/2@ ( -- c ) \ ps/2 read byte
0 \ room for incoming byte
+ps/2_data
+ps/2_clk 80 delay \ idle ~50us ( хз зачем, где-то вычитал...)
?ps/2_clk- \
?ps/2_data- \ start bit
?ps/2_clk+ \
8 0 do
?ps/2_clk-
20 delay ps/2_bit@
?ps/2_clk+
loop
\ parity bit
?ps/2_clk-
?ps/2_clk+ \ ignored
\ stop bit
?ps/2_clk-
?ps/2_data+
?ps/2_clk+
\ hold incoming data
-ps/2_clk
;
\
\ =========================================================
\
marker -mice-
$FA constant mice_ack \ мышкины ответы
$FF constant mice_reset ( 1 + 2 )
$F2 constant mice_id ( 1 + 1 )
$F0 constant mice_remote ( 1 )
$EB constant mice_read ( 1 + 3 )
$E9 constant mice_status ( 1 + 3 )
$80 constant y-ovflw
$40 constant x-ovflw
$20 constant y-sign
$10 constant x-sign
$4 constant m-btn
$2 constant r-btn
$1 constant l-btn
\ =========================================================
\ mouse test words
: m!@ ( n c -- ) ps/2! 0 ?do ps/2@ .x bl emit loop cr ;
: m0 3 mice_reset m!@ 300 delay 1 mice_remote m!@ 180 delay ;
: m@ 4 mice_read m!@ ;
> amforth 4.2 ATmega32
> -polar-
ok
>
> polar-go!
FA AA 0
FA
ok
> stm1 stm0 stm? stm?
port.............3B
mask.............F
.................
idx..............0
sequence.........1
delay............2
direction........0
steps to rotate..0
total steps......0
motor status.....0
port.............3B
mask.............F0
.................
idx..............0
sequence.........1
delay............5
direction........-1
steps to rotate..0
total steps......0
motor status.....0
ok
> .res
amforth 4.2 ATmega32 running at 8000 kHz
free FLASH cells 4484
free RAM bytes 1356
used EEPROM bytes 72
used data stack cells 0
used return stack cells 5
free return stack cells 35
ok
> words
polar-go! task-stm? task-azimuth task-altitude task-control polar-stm? polar-azimuth
polar-altitude polar-control azimuth altitude stm_control ?action park? park! run
stm+! steps! stm1 stm0 -polar- m? workout mflags m@ !m m!@ l-btn r-btn m-btn x-sign
y-sign x-ovflw y-ovflw mice_status mice_read mice_remote mice_id mice_reset mice_ack
-mice- ps/2@ ps/2! odd ps/2_bit@ ps/2_bit ?ps/2_data+ ?ps/2_data- ?ps/2_clk-
?ps/2_clk+ -ps/2_data -ps/2_clk +ps/2_data +ps/2_clk ps/2_data ps/2_clk portbit#:
(portbit#) -rot -ps/2- stm? stm_unlock stm_lock stm_lock? lock_stm park stopoff wave!
normal! half! reverse direction! rotate step total- total+ idx- idx+ init_stm! motor@
stepper: motor! /stepper motor res1 total steps direction dly ststate shft sequence
idx -- normal wave half-step phase -stepper- ?us .t1 <t1> delay <t1 t1> tccr1b tccr1a
-tttt1- .x help help-wl -help .base calc-baudrate .res .( erase -misc twi.scan
twi.ping? twi.status? twi.status twi.rxn twi.rx twi.tx twi.action twi.stop twi.start
twi.wait -twi twi.default +twi -spi -spi2x +spi2x +spi spi.f/128 spi.f/64 spi.f/16
spi.f/4 spi.mode3 spi.mode2 spi.mode1 spi.mode0 spi.MASTER spi.MSB spi.SPE _spi_ ftgl
fclr? fset? fclr fset bv flag: pin_pullup_on pin_highZ toggle pin@ pin_low? pin_high?
pin_input pin_output pin! is_high? is_low? pulse low high bitmask: portpin: tlist
alsotask onlytask multi single task activate cell- task-awake task-sleep stop
multitaskpause wake pass follower status dump edump idump dump> <dump trimm .addr
.rcells .ecells .icells ? e? i? .item u.r endcase endof of case assembler vocabulary
Rdefer Rdefer! Rdefer@ Udefer Udefer! Udefer@ Edefer Edefer! Edefer@ action-of anew
possibly move blank nip tuck ? xt>nfa >body chars char+ c, aligned align
restore-input save-input source-id postpone fm/mod sm/rem dabs ?negate ?dnegate
dnegate u*/mod sqrt -math m+ 2variable 2constant 2! 2@ 2tuck 2nip 2rot 2swap 2over
2dup 2drop marker i@ (i!) i! e@ e! not s>d up! up@ >< cmove> unloop i sp! sp@ rp! rp@
+! rshift lshift 1- 1+ xor or and 2* 2/ invert um* um/mod m* + - log2 d< d> 0> u> u<
true 0 0< > < 0<> 0= = <> r@ >r r> rot drop over swap ?dup dup c@ c! ! @ execute exit
-int +int UDR UCSRB UCSRA UBRRL UBRRH TWSR TWDR TWCR TWBR TWAR TCNT2 TCCR2 OCR2 ASSR
TCNT1L TCNT1H TCCR1B TCCR1A OCR1BL OCR1BH OCR1AL OCR1AH ICR1L ICR1H TIMSK TIFR TCNT0
TCCR0 OCR0 SPSR SPDR SPCR PORTD PIND DDRD PORTC PINC DDRC PORTB PINB DDRB PORTA PINA
DDRA GIFR GICR EEDR EECR EEARL EEARH SREG SPL SPH OSCCAL MCUCSR MCUCR SPMCR ACSR
SFIOR ADMUX ADCSRA ADCL ADCH ms 1ms ewords fill #int int@ show-wordlist b> >b b!- b!+
nb! b! b@- b@+ nb@ b@ a> >a a!- a!+ na! a! a@- a@+ na@ a@ wordlist forth definitions
previous also forth-wordlist only set-order set-current spirw sleep wdr -wdt -jtag
+usart baud tx? tx rx? rx order get-order get-current environment? environment
end-code code abort abort" [char] immediate recurse user constant variable [ ] ;
:noname : does> create ?do leave +loop loop do again until repeat while begin then
else if literal int! applturnkey is Rdefer Edefer words s" ." .s u. dinvert d- d+ d2*
init-user ee>ram ee-user tib d2/ cmove dnegate dabs d>s j * defer@ defer! icompare
find search-wordlist to value unused noop ver ?stack interpret depth rp0 sp sp0 cold
pause quit place word /string source cscan parse 2swap >number number char refill
accept cskip throw catch handler ' type count spaces space cr icount itype s, digit?
ud/mod ud.r ud. . d. .r d.r sign #> #s # <# hold hld within max min abs mod / negate
u/mod */ /mod */mod turnkey bl hex decimal bin ['] , compile ( \ allot here edp dp
/key key? key emit? emit pad #tib >in cell+ ceЃ&s base state f_cpu ok
> stm1 stm0 stm? stm?
port.............3B
mask.............F
.................
idx..............4
sequence.........1
delay............2
direction........0
steps to rotate..0
total steps......-996
motor status.....0
port.............3B
mask.............F0
.................
idx..............2
sequence.........1
delay............5
direction........0
steps to rotate..0
total steps......162
motor status.....0
ok
> stm1 stn m0 stm? stm?
port.............3B
mask.............F
.................
idx..............7
sequence.........1
delay............2
direction........0
steps to rotate..0
total steps......-641
motor status.....0
port.............3B
mask.............F0
.................
idx..............5
sequence.........1
delay............5
direction........0
steps to rotate..0
total steps......589
motor status.....0
ok
> stm1 stm0 stm? stm?
port.............3B
mask.............F
.................
idx..............0
sequence.........1
delay............2
direction........0
steps to rotate..0
total steps......0
motor status.....0
port.............3B
mask.............F0
.................
idx..............0
sequence.........1
delay............5
direction........-1
steps to rotate..0
total steps......0
motor status.....0
ok
> stm1 stm0 stopoff stopoff
ok
>
\
\ portbit#: required
\
marker =senseled=
forth only also assembler
PORTC 7 portbit#: -led \ cathode
PORTC 6 portbit#: +led \ anode
code -led+
-led over over 1-
swap sbi, \ set output
swap sbi, \ and high
end-code
code -led-
-led over over 1-
swap cbi, \ set input
swap cbi, \ and low
end-code
code +led-
+led over over 1-
swap sbi, \ set output
swap cbi, \ and low
end-code
code ?led ( -- d )
R16 clr,
R17 clr,
label>
clc,
R24 1 adiw,
R16 R2 adc,
R17 R2 adc,
-led 2 - swap sbic,
<radr rjmp,
-Y R25 st,
-Y R24 st,
R24 R16 movw,
end-code
forth only
\ замерить однократно
: senseled -led+ +led- 0 delay 0 -led- ?led ; ( -- d )
\ замерять и выводить на консоль до нажатия любой клавиши
: sled begin senseled 11 ud.r cr key? until ;
\
\ 1-wire
\
\ *chu* 20:41 07.12.2010*
\ 20:30 12.12.2010* last
\ =============================================================
\
marker =1-wire=
\
\ базовые примитивы:
\ 1w-presence? 1w-bit@ 1w-bit0! 1w-bit1! 1w-c! 1w-c@
\ delay_A = 6 us
\ delay_B = 64 us
\ delay_C = 60 us
\ delay_D = 10 us
\ delay_E = 9 us
\ delay_F = 55 us
\ delay_G = 0
\ delay_H = 480 us
\ delay_I = 70 us
\ delay_J = 410 us
PORTC 5 portbit#: dq \ assembler name
PORTC 5 portpin: DQ \ highlevel name
-jtag
forth only also assembler decimal
code int-restore ( sreg -- )
SREG $20 - R24 out,
R24 Y+ ld,
R25 Y+ ld,
end-code
code dq+
dq over over 1 -
swap cbi, \ set input
swap sbi, \ and pull-up
end-code
code dq-
dq over over 1-
swap sbi, \ set output
swap cbi, \ and low
end-code
code (1w-bit@) \ 1 rshift DQ pin@ if $80 or then
R24 lsr,
dq $2 - swap sbic,
R24 $80 ori,
end-code
forth only
: 1w-reset
dq+ -int
dq- 940 delay ( H )
int-restore
;
: 1w-presence? ( -- f ) \ is anybody alive on 1-wire?
dq+ -int
dq- 940 delay ( H )
DQ
dq+ 70 delay ( I )
pin@ 0=
swap int-restore
;
: 1w-bit@ ( c -- c' )
dq+ -int swap
dq- noop ( A )
dq+ noop noop ( E )
(1w-bit@)
85 delay ( F )
swap int-restore
;
: 1w-0bit!
dq+ -int
dq- 101 delay ( C )
dq+ 1 delay ( D )
int-restore
;
: 1w-1bit!
dq+ -int
dq- noop ( A )
dq+ 110 delay ( B )
int-restore
;
\ byte transmission functions
: 1w-c! ( c -- )
8 0 do
dup 1 and if
1w-1bit! else
1w-0bit! then
1 rshift
loop drop
;
: 1w-c@ ( -- c )
0 8 0 do 1w-bit@ loop
;
\ block transmission functions
: 1w! ( addr n -- )
over + swap
do i c@ 1w-c! loop
;
: 1w@ ( addr n -- )
over + swap
do 1w-c@ i c! loop
;
\
\ =============================================================
\
\ ds1822 Econo 1-Wire® Digital Thermometer
\
marker =ds1822=
$01 constant DS2401_ID \ Silicon Serial Number
$10 constant DS18S20_ID \ 1-Wire Parasite-Power Digital Thermometer
$28 constant DS18B20_ID \
$22 constant DS1822_ID \ Programmable Resolution 1-Wire Digital Thermometer
\ DS1820/DS1822 ROM COMMANDS
$F0 constant SEARCH_ROM
$33 constant READ_ROM
$55 constant MATCH_ROM
$CC constant SKIP_ROM
$EC constant ALARM_SEARCH
\ DS1820/DS1822 FUNCTION COMMANDS
$44 constant CONVERT_T
$4E constant WRITE_SCRATCHPAD
$BE constant READ_SCRATCHPAD
$48 constant COPY_SCRATCHPAD
$B8 constant RECALL_E2
$B4 constant READ_POWER_SUPPLY
\ структуры памяти ds1822
0 \ rom
1 -- 1w_family
6 -- 1w_ident
1 -- 1w_crc
constant /1w_rom
0 \ scratchpad
1 -- thermo.templ
1 -- thermo.temph
1 -- thermo.threg
1 -- thermo.tlreg
1 -- thermo.config
1 -- thermo.res$FF
1 -- thermo.res$0C
1 -- thermo.res$10
1 -- thermo.crc
constant /scratchpad
here dup /1w_rom dup allot erase value ds1822
here dup /scratchpad dup allot erase value scratchpad
Я установил AVR Studio, но откомпилировать не смог. постоянно ошибки не найден файл.
И второй вопрос: на ATMega168 запустится?
Alex-chin писал(а):Ага все получилось!
Alex-chin писал(а):а слово .res это откуда?
S" русское слово из трех буков?" ANSI>OEM TYPE CR
amforth 4.2 ATmega168
> hex
ok
> 1 24 !
ok
> 1 25 !
ok
> 0 25 !
ok
>
Вернуться в МиниБот — национальный класс роботов
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 3