Benutzer-Werkzeuge

Webseiten-Werkzeuge


projects:mmt4ue2:mmtquellcode0

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
projects:mmt4ue2:mmtquellcode0 [2014-11-09 20:38] – v13 geladen mkaprojects:mmt4ue2:mmtquellcode0 [2014-11-19 08:45] (aktuell) mka
Zeile 1: Zeile 1:
-  \ v13-2014-11-06 +  \ MMT Source Code of Version 1.0 
      
 +  : .MMT#   \ --    print version number 
 +    ." MMT Version 1.0 2014-11-19"
 +
 +  \ ----------------------------------------------------------
   \ Mini Multi Tool  4bit I/O "MMT4"   \ Mini Multi Tool  4bit I/O "MMT4"
-  \ using 4e4th Release0.34 on TI MSP430G2553 MCU LaunchPad+  \ using 4e4th Release 0.34 on TI MSP430G2553 MCU LaunchPad
   \ started: mka, 2014_10_26   \ started: mka, 2014_10_26
   \ Idea: Juergen Pintaske and his "swiss knife"   \ Idea: Juergen Pintaske and his "swiss knife"
Zeile 12: Zeile 16:
      
   \ ----------------------------------------------------------   \ ----------------------------------------------------------
-  \ Table of Content+  \ Table of Contents
   \ Defining the I/O for this application, basic definitions   \ Defining the I/O for this application, basic definitions
     \ Device Pinout: MSP430G2553 20-Pin PDIP      \ Device Pinout: MSP430G2553 20-Pin PDIP 
Zeile 18: Zeile 22:
     \ Juggling nibbles for packing and unpacking into 16 bit      \ Juggling nibbles for packing and unpacking into 16 bit 
     \ I/O initialisation, I/O words, test switches, time delays     \ I/O initialisation, I/O words, test switches, time delays
-  \ Drivers for this MCU +  \ Utilities for this MCU 
-    \ Square wave at P1.5 using timer TA0.0+    \ Square wave at P1.5 (Pin7) using timer TA0.0
     \ Midi tones B3 to B5, 2 octaves; pitch list, play a note     \ Midi tones B3 to B5, 2 octaves; pitch list, play a note
     \ PWM of 16KHz for 8MHZ DCO using timer TA0     \ PWM of 16KHz for 8MHZ DCO using timer TA0
Zeile 25: Zeile 29:
     \ Servos - position 4 servos using digital OUT, double function     \ Servos - position 4 servos using digital OUT, double function
     \ Initialisation of MMT4     \ Initialisation of MMT4
-  \ 16 Example Programs - some with switches only, some need serial+  \ Example Programs - using switches only
     \ EX0  - Leave demo loop, run Forth     \ EX0  - Leave demo loop, run Forth
     \ EX1  - Display IN at OUT     \ EX1  - Display IN at OUT
     \ EX2  - Display IN at OUT, set PWM-LED too     \ EX2  - Display IN at OUT, set PWM-LED too
     \ EX3  - Falling edge detector (1)     \ EX3  - Falling edge detector (1)
-    \ EX4  - Falling edge detector with tone(2) +    \ EX4  - Falling edge detector with tone (2) 
-    \ EX5  - Toggle OUT bits manually +    \ EX5  - Dance of 4 servos (test servos
-    \ EX6  - Dance of 4 servos (test) +    \ EX6  - Servo follows analog input on pin ADC4 
-    \ EX7  - Servo follows analog input pin (ADC4) +    \ EX7  - Get analog input from ADC channel 4 
-    \ EX8  - Get analog input from ADC channel 4 +    EX8  - Audio visual display of ADC4 value 
-      EX9  - tbd +    \ EX9 - Play demo song 
-      \ EX10 - tbd +    \ DEMOLOOP - Select an example programm by its nummber. 
-    \ EX11 - Set 4 servos manually +  More Example Programs - using serial interface to PC 
-    \ EX12 - Pressing S2 increments OUT +    \ EX11 - Echo any key 
-    \ EX13 - Echo any key +    \ EX12 - Toggle OUT bits manually 
-    \ EX14 - Audio visual display of ADC4 value +  
-    \ EX15 - Play demo song +
-  \ DEMOLOOP - Select an example programm by its  +
-    nummer using S2 and S3. EXIT demoloop by selecting EX0.+
   \ ----------------------------------------------------------   \ ----------------------------------------------------------
  
  
  
-  \ History: +  \ History:  
-  \ Made duration of notes selectable. (9.11.2014)+  \ 20141117: We are ready for a release - V10  
 +  \ Added help lines to PC examples.  
 +  \ Made MMT4 images.  
 +  \ Split examples in MMT and PC part. 
 +  \ 20141109: Made duration of notes selectable. 
   \ Use TONE@ TON+ now instead of NOTE in soem EXs.    \ Use TONE@ TON+ now instead of NOTE in soem EXs. 
   \ Better EX8, wait after output, not before.   \ Better EX8, wait after output, not before.
Zeile 55: Zeile 60:
   \ Better EX2, no delay any more.   \ Better EX2, no delay any more.
   \ Renamed file to mmt4ue2.4th because this name was unique   \ Renamed file to mmt4ue2.4th because this name was unique
-  \ while "swiss knife" and its abrev. was not.+  \ while "swiss knife" and its abreviations are not.
   \ Renamed S1 to S3 since S1=reset on MSP-LaunchPad.   \ Renamed S1 to S3 since S1=reset on MSP-LaunchPad.
-  \ Added: DEMOLOOP to select examples with S2 and S3 switches. +  \ Added: DEMOLOOP to select examples using S2 and S3 switches. 
-  \ Cleaning up examples, added EX12 (3.11.2014) +  \ 20141103: Cleaning up examples, added another example
-  \ Added2 servo examples (02.11.2014) +  \ 20141102: Added 2 servo examples. 
-  \ Addedservo pulses to OUT (30.10.2014 22:47)  +  \ 20141030: Added pulses for servos to OUT.   
-  \ Renamed demos to EXx (29.10.2014 21:19) +  \ 20141029: Renamed demos to EXn
-  \ Added: some demos Px (29.10.2014 13:05) +  \ Made some demos Pn
-  \ Added: ADC (29.10.2014 00:02) +  \ Added: ADC  
-  \ First test today (26.10.2014 23:49)+  \ 20141026: First test today.
   \   Compiles in target without errors.   \   Compiles in target without errors.
   \   blocks with mk0 mark = tested ok on first glance ...   \   blocks with mk0 mark = tested ok on first glance ...
-    ... functioning, stack ok.+  \   ... functioning, stack ok.
   \   MYBONNIE is playing, no stack error - ok   \   MYBONNIE is playing, no stack error - ok
   \   PWM running, SWEEP is ok.    \   PWM running, SWEEP is ok. 
   \   I/O and nibbels working on variables.   \   I/O and nibbels working on variables.
-  \   mem u. 6703 (plenty flash left)  
      
   \ Issues:   \ Issues:
Zeile 81: Zeile 85:
  
   \ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   \ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-   
   \ Start of Program MMT4 programmed in Forth    \ Start of Program MMT4 programmed in Forth 
 +  \ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      
   \ This program uses some routines planned to help Learning    \ This program uses some routines planned to help Learning 
Zeile 93: Zeile 97:
   \ using this program running on top of Forth    \ using this program running on top of Forth 
   \ either interfaced to a PC or some parts independent of the PC   \ either interfaced to a PC or some parts independent of the PC
-  \ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
      
      
Zeile 124: Zeile 127:
   \      one of 16 frequencies with defined length   \      one of 16 frequencies with defined length
   \ P1.6 Output, later on as Pulse Width Modulation output   \ P1.6 Output, later on as Pulse Width Modulation output
-  \      – like a simple D/A Output+  \      just like a simple D/A Output
   \ P1.7 Input S3, internal pull-up resistor enabled   \ P1.7 Input S3, internal pull-up resistor enabled
      
Zeile 149: Zeile 152:
   \ into 4x4 nibbles to be one Variable (16Bit cell).   \ into 4x4 nibbles to be one Variable (16Bit cell).
   \ This will save on RAM used.   \ This will save on RAM used.
 +  
 +  
      
   \ Source code start ----------------------------------------   \ Source code start ----------------------------------------
Zeile 156: Zeile 161:
   \ A   4 bit A register   \ A   4 bit A register
   \ B   4 bit B register   \ B   4 bit B register
-  variable IFAB  \ define variable with these 4 nibbles in+  variable IFAB  \ define one variable with these 4 nibbles in it
      
   \ W   4 bit W variable   \ W   4 bit W variable
Zeile 162: Zeile 167:
   \ Y   4 bit Y variable   \ Y   4 bit Y variable
   \ Z   4 bit Z variable   \ Z   4 bit Z variable
-  variable WXYZ  \ define variable with these 4 nibbles in+  variable WXYZ  \ define one variable with these 4 nibbles in it
      
   \ A1  4 bit analog in channel 1   \ A1  4 bit analog in channel 1
Zeile 168: Zeile 173:
   \ P   4 bit pulse width modulated output    \ P   4 bit pulse width modulated output 
   \ O   4 bit output register   \ O   4 bit output register
-  variable 12PO  \ define variable with these 4 nibbles in+  variable 12PO  \ define one variable with these 4 nibbles in it
      
-  : INITSV \ -- \ init scrach variables+  : INITSV \ -- \ init these 3 scratch variables to 0
     0 IFAB !    0 WXYZ !    0 12PO ! ;        0 IFAB !    0 WXYZ !    0 12PO ! ;   
   initsv    initsv 
Zeile 181: Zeile 186:
   \ juggling nibbles     \ juggling nibbles  
   HEX    HEX 
-  : 0! \ n adr -- \ store nibble 0 to variable at address +  : n0! \ n adr -- \ store nibble 0 to variable at address 
     >r r@ @ FFF0 and swap F and + r> ! ;      >r r@ @ FFF0 and swap F and + r> ! ; 
-  : 1! \ n adr -- \ store nibble 1 to variable at address +   
 +  n1! \ n adr -- \ store nibble 1 to variable at address 
     >r r@ @ FF0F and swap F and 4 lshift + r> ! ;      >r r@ @ FF0F and swap F and 4 lshift + r> ! ; 
-  : 2! \ n adr -- \ store nibble 2 to variable at address +   
 +  n2! \ n adr -- \ store nibble 2 to variable at address 
     >r r@ @ F0FF and swap F and 8 lshift + r> ! ;      >r r@ @ F0FF and swap F and 8 lshift + r> ! ; 
-  : 3! \ n adr -- \ store nibble 3 to variable at address +   
 +  n3! \ n adr -- \ store nibble 3 to variable at address 
     >r r@ @ 0FFF and swap F and C lshift + r> ! ;      >r r@ @ 0FFF and swap F and C lshift + r> ! ; 
      
-  : 0@ \ adr - n \ fetch nibble 0 of variable at address +  : n0@ \ adr - n \ fetch nibble 0 of variable at address 
     @ 000F and ;      @ 000F and ; 
-  : 1@ \ adr - n \ fetch nibble 1 of variable at address +   
 +  n1@ \ adr - n \ fetch nibble 1 of variable at address 
     @ 00F0 and 0004 rshift ;      @ 00F0 and 0004 rshift ; 
-  : 2@ \ adr - n \ fetch nibble 2 of variable at address +   
 +  n2@ \ adr - n \ fetch nibble 2 of variable at address 
     @ 0F00 and 0008 rshift ;      @ 0F00 and 0008 rshift ; 
-  : 3@ \ adr - n \ fetch nibble 3 of variable at address +   
 +  n3@ \ adr - n \ fetch nibble 3 of variable at address 
     @ F000 and 000C rshift ;      @ F000 and 000C rshift ; 
      
Zeile 208: Zeile 219:
   \ so in the beginning we will test as Input and Output only,    \ so in the beginning we will test as Input and Output only, 
   \ see separate Forth Code   \ see separate Forth Code
-  \ for details, see 1 http://www.ti.com/product/msp430g2553+  \ for details,  
 +  \ see 1 http://www.ti.com/product/msp430g2553
   \ and 2 http://www.ti.com/product/MSP430G2553/technicaldocuments   \ and 2 http://www.ti.com/product/MSP430G2553/technicaldocuments
   \ and 3 http://www.ti.com/lit/ds/symlink/msp430g2553.pdf our reference   \ and 3 http://www.ti.com/lit/ds/symlink/msp430g2553.pdf our reference
-  \ we plan to show page numbers, here document 3 page 18 onwards+  \ we plan to show page numbers, here in document 3 page 18 onwards
      
      
   \ In 4e4th, P1 and P2 are already predefined 2constants.   \ In 4e4th, P1 and P2 are already predefined 2constants.
   HEX    HEX 
-  : INITIO \ -- \ I/O initialisation of JPS4 ports   mk0+  : INITIO \ -- \ I/O initialisation of MMT ports   mk0
   \ mask adr op    \ mask adr op 
   \       76543210    \       76543210 
Zeile 243: Zeile 255:
      
   : OUT>  \ --   \ copy O to OUT!   : OUT>  \ --   \ copy O to OUT!
-    12PO 0@ out! ;  +    12PO n0@ out! ;  
      
   : OUT   \ n --   \ save n to O-nibble and do OUT! too.   : OUT   \ n --   \ save n to O-nibble and do OUT! too.
-    12PO 0! out> ; +    12PO n0! out> ; 
      
   : IN@ \ -- n \ read digital input pins, lower nibble of P2.    : IN@ \ -- n \ read digital input pins, lower nibble of P2. 
Zeile 253: Zeile 265:
   : IN  \ -- n  \ do IN, save n to I-nibble too.   : IN  \ -- n  \ do IN, save n to I-nibble too.
     in@      in@ 
-    dup IFAB 3! ; \ copy to I-nibble of IFAB+    dup IFAB n3! ; \ copy to I-nibble of IFAB
      
      
      
-  \ helper to output a nibble to terminal+  \ output a nibble to terminal
   HEX   HEX
-  : 4#  \ n --  \ display 4 digits unsigned with leading zeros +  : 4#  \ n --  \ display 4 digits unsigned  
-    <#  zero # # # #   #> TYPE SPACE ;  +    <#  00 # # # #   #> TYPE SPACE ;  
-  : 2#  \ n --  \ display 2 digits unsigned with leading zeros +  : 2#  \ n --  \ display 2 digits unsigned  
-    <#  zero # #    #> TYPE SPACE ; +    <#  00 # #    #> TYPE SPACE ;  
 +   
 +  
      
   \ test falling edge at switch S3 and S2      mk0   \ test falling edge at switch S3 and S2      mk0
Zeile 275: Zeile 289:
   \ Delays    mk0   \ Delays    mk0
   \ 1MS is predefined in 4e4th. Its an empty loop,   \ 1MS is predefined in 4e4th. Its an empty loop,
-  \ predefined for MCU running with 8Mhz DCO = default.+  \ predefined for MCUs running with 8Mhz DCO = default.
   \ Use Forth word MS to make any ms delay.    \ Use Forth word MS to make any ms delay. 
   \ Example:    \ Example: 
Zeile 290: Zeile 304:
      
   \ ----------------------------------------------------------   \ ----------------------------------------------------------
-  \ Drivers for this MCU+  \ Utilities for this MCU
   \ ----------------------------------------------------------   \ ----------------------------------------------------------
      
Zeile 297: Zeile 311:
      
   HEX   HEX
-  \ Output square wave at P1.5 using timer TA0.0      mk0+  \ Output square wave at P1.5 (pin 7) using timer TA0.0      mk0
      
   \ Use P1.5 as timer TA0.0 ouput.   \ Use P1.5 as timer TA0.0 ouput.
Zeile 309: Zeile 323:
     020 dup p1 1+ cset  026 cset ;        020 dup p1 1+ cset  026 cset ;   
      
-  : P15IO     \ set back P1.5 to its GPIO+  : P15IO     \ set back P1.5 to its general GPIO function
     020 026 cclr  020 041 cclr ;        020 026 cclr  020 041 cclr ;   
      
   : TON-  \ --    \ Tone off.   : TON-  \ --    \ Tone off.
-    zero 0160 !   \ stop timer+    00 0160 !   \ stop timer
     p15io         \ P1.5 back to I/O      p15io         \ P1.5 back to I/O 
     20 p1 cclr  ; \ shut down current through speaker.     20 p1 cclr  ; \ shut down current through speaker.
Zeile 325: Zeile 339:
     ;     ;
      
-  \ midi tones B3 to B5, 2 octaves; pitch list for TON+   mk0+  \ Midi tones B3 to B5, 2 octaves; pitch list for TON+   mk0
   DECIMAL     DECIMAL  
   IHERE     IHERE  
Zeile 349: Zeile 363:
   : TONE@   \ i -- n   \ get pitch using index i    : TONE@   \ i -- n   \ get pitch using index i 
     cells tonelist + @ ;     cells tonelist + @ ;
 +  
   : NOTE   \ i d --   \ play note i of duration d   : NOTE   \ i d --   \ play note i of duration d
     swap   tone@ ton+   ms ton-  ;     swap   tone@ ton+   ms ton-  ;
 +  
   : PAUSE  \ q --   \ play pause (quiet) of duration q   : PAUSE  \ q --   \ play pause (quiet) of duration q
     ton-  ms ;  \      ton-  ms ;  \ 
Zeile 373: Zeile 389:
      
   : PWM-      : PWM-   
-    zero 160 !  \ TA0CTL   stop timer +    00 160 !  \ TA0CTL   stop timer 
     p16io 0040 0021 cclr ; \ set p1.6 I/O and clear p1.6     p16io 0040 0021 cclr ; \ set p1.6 I/O and clear p1.6
      
Zeile 379: Zeile 395:
     01F4 0172 !   \ TA0CCR0    set period 16KHz at 8MHZ DCO     01F4 0172 !   \ TA0CCR0    set period 16KHz at 8MHZ DCO
     00E0 0164 !   \ TA0CCTL1   set output mode      00E0 0164 !   \ TA0CCTL1   set output mode 
-         0174 !   \ TA0CCR1    set pulsewidth  +         0174 !   \ TA0CCR1    set pulse width  
-    0210 0160 !   \ TA0CTL     set timer mode and run +    0210 0160 !   \ TA0CTL     set to timer mode and run 
     ;     ;
        
Zeile 416: Zeile 432:
      
   : ADCOFF   \ --  \ stop ADC10 ...   : ADCOFF   \ --  \ stop ADC10 ...
-    zero 01B0 ! ;   \ ... can be modified only when ENC = 0  +    00 01B0 ! ;   \ ... can be modified only when ENC = 0  
      
   : ADCON    \ --  \ start ADC10   : ADCON    \ --  \ start ADC10
Zeile 449: Zeile 465:
   \ Connect servo-GND to MCU-GND.   \ Connect servo-GND to MCU-GND.
   \ Connect servo control lines to OUTx.    \ Connect servo control lines to OUTx. 
-  \ Control line needs pulse between 1..2ms pulse, +  \ Control line needs pulse between 1..2ms pulse, 
   \ 1ms left end, 1,5ms middle, 2ms right end.    \ 1ms left end, 1,5ms middle, 2ms right end. 
   \ Minimum pulse repetition rate is every 20ms, ~$40x,    \ Minimum pulse repetition rate is every 20ms, ~$40x, 
Zeile 467: Zeile 483:
     500 dup dup dup ldx ;      500 dup dup dup ldx ; 
     initx     initx
 +  
 +  \ linit x to &480 ... &1700 (Range is ~1200 steps)
 +   480 constant sermin 
 +  1700 constant sermax
 +  : limit \ x -- x' \ linit x to servo minimum an maximum
 +    sermin max sermax min ;
 +  
   HEX   HEX
   : x?     \ -- \  print all X   : x?     \ -- \  print all X
Zeile 514: Zeile 537:
      
      
 +  \ --> up to here the image is saved as file
 +  \     4e4th+mmt4-V10.txt in TI format
 +  
 +  
 +
   \ ----------------------------------------------------------   \ ----------------------------------------------------------
-  \ Example Programs +  \ Example Programs made for MiniTool  
-  \ there is the option for 16 example programs,  +  \ You need 3 switches S1 S2 S3, and 5 LED  + 470Ohm at OUT and PWM.
-  \ some need PC, some just use the 3 switches +
-  \ (PC) = serial connection to PC via terminal required. +
-  \ (solo) = works with its switches, without PC connection.+
   \ ----------------------------------------------------------   \ ----------------------------------------------------------
-   +  \ Note: (solo) means no PC connection needed.
-  ---------------------------------------------------------- +
-  \ Example 0 - leave demo loop, run forth. (PC+
-  : EX0  +
-    cr .ver +
-    cr ." forth - command me." abort ; +
-   +
-   +
-  +
   \ ----------------------------------------------------------   \ ----------------------------------------------------------
   \ Example 1 - display IN. (solo)   \ Example 1 - display IN. (solo)
Zeile 547: Zeile 564:
     initio in drop     initio in drop
     BEGIN      BEGIN 
-    in@                \ get IN +    in@                \ get INex5 
-    ifab 3@ <>+    ifab n3@ <>
       IF in dup out pwm THEN \ store IN to OUT and PWM       IF in dup out pwm THEN \ store IN to OUT and PWM
     key? UNTIL   \ leave loop, clean up     key? UNTIL   \ leave loop, clean up
Zeile 556: Zeile 573:
      
   \ ----------------------------------------------------------   \ ----------------------------------------------------------
-  \ Example 3 - faling edge detector (1) (solo)+  \ Example 3 - falling edge detector (1) (solo)
   HEX   HEX
-  : EX3  \ -- \   faling edge detector S2 to OUT,+  : EX3  \ -- \   falling edge detector S2 to OUT,
               \   reset with S3.               \   reset with S3.
     initio   \ init system      initio   \ init system 
Zeile 572: Zeile 589:
      
   \ ----------------------------------------------------------   \ ----------------------------------------------------------
-  \ Example 4 - faling edge detector (2) (solo)+  \ Example 4 - falling edge detector (2) (solo)
   HEX   HEX
-  : EX4  \ -- \   faling edge detector S2, play note too.+  : EX4  \ -- \   falling edge detector S2, play note too.
     initio   \ init system      initio   \ init system 
     s2- s3-  \ and reset edge detection     s2- s3-  \ and reset edge detection
Zeile 584: Zeile 601:
     key? UNTIL  \ leave loop     key? UNTIL  \ leave loop
     key drop    \ clean up     key drop    \ clean up
-    zero out +    00 out 
     ton- ;            ton- ;       
      
Zeile 590: Zeile 607:
      
   \ ----------------------------------------------------------   \ ----------------------------------------------------------
-  \ Example 5 - toggle OUT bits manually. (PC) +  \ Example 5 - dance of 4 servos. To test the 4 servos (solo) 
-  HEX +
-  : tout \ c -- c \  +
-    dup [char] 1 = IF 01 12po ctoggle out> exit THEN  +
-    dup [char] 2 = IF 02 12po ctoggle out> exit  THEN  +
-    dup [char] 3 = IF 04 12po ctoggle out> exit  THEN  +
-    dup [char] 4 = IF 08 12po ctoggle out> exit  THEN  +
-    dup [char] 0 = IF zero out exit THEN  +
-    dup [char] f = IF 0f out exit  THEN  ; +
-   +
-  : EX5 \ -- \  press 1 2 3 4 to toggel OUT bits, +
-            \ 0 to clear all, F to set all. +
-    initio zero out +
-    BEGIN  +
-    key tout  +
-    1B ( esc ) = UNTIL  +
-    ; \ exit on esc-character +
-   +
-   +
-   +
-  \ ---------------------------------------------------------- +
-  \ Example 6 - dance of 4 servos. (solo)+
   DECIMAL   DECIMAL
   0480 constant SL   0480 constant SL
Zeile 640: Zeile 636:
     1 rows +LOOP ;      \ advance one row     1 rows +LOOP ;      \ advance one row
      
-  : EX6 \ --  \ dance until key is pressed+  : EX5 \ --  \ dance until key is pressed
     initio     initio
     BEGIN        BEGIN   
Zeile 649: Zeile 645:
      
   \ ----------------------------------------------------------   \ ----------------------------------------------------------
-  \ Example - servo follows analog input pin (ADC4) (solo)+  \ Example - servo follows analog input pin (ADC4) (solo)
      
   \ ADC@ is 0 .. $3FF    \ ADC@ is 0 .. $3FF 
Zeile 658: Zeile 654:
     480 + ;     480 + ;
      
-  : EX7 \ --  \ Position of servo2 given by potentiometer+  : EX6 \ --  \ Position of servo2 given by potentiometer
     initio       \ init ports,     initio       \ init ports,
     adc4 adcon   \ init ADC     adc4 adcon   \ init ADC
Zeile 669: Zeile 665:
      
   \ ----------------------------------------------------------   \ ----------------------------------------------------------
-  \ Example - get analog input from ADC channel 4. (solo)+  \ Example - get analog input from ADC channel 4. (solo)
   HEX   HEX
-  : EX8 \ -- \ ADC to OUT and terminal                 mk0+  : EX7 \ -- \ ADC to OUT and terminal                 mk0
     initio adc4 adcon  \ init all modules     initio adc4 adcon  \ init all modules
 +    s2-
     BEGIN      BEGIN 
     adc@ 44 /          \ scale 10Bit value, 3FF..0 --> F...0     adc@ 44 /          \ scale 10Bit value, 3FF..0 --> F...0
     dup out            \ display scaled value     dup out            \ display scaled value
-    dup tone@ ton+     \ play apropriate tone 
     . 1sec             \ print to terminal, wait 1 second     . 1sec             \ print to terminal, wait 1 second
     key? UNTIL         \ leave loop, clean up     key? UNTIL         \ leave loop, clean up
Zeile 684: Zeile 680:
      
   \ ----------------------------------------------------------   \ ----------------------------------------------------------
-  \ Example 9 - tbd +  \ Example - audio visual display of ADC. (solo)
-  : EX9 ; +
-   +
-   +
-   +
-  \ ---------------------------------------------------------- +
-  \ Example 10 - tbd +
-  : EX10 ; +
-   +
-   +
-   +
-  \ ---------------------------------------------------------- +
-  \ Example 11 - Set 4 servos manually (PC) +
-   +
-  \ linit x to &480 ... &1700 (Range is ~1200 steps) +
-  DECIMAL +
-   480 constant sermin  +
-  1700 constant sermax +
-  : limit \ x -- x' \ linit x  +
-    sermin max sermax min ; +
-   +
-  : left \ adr -- \ increment variable +
-    >r  r@ @ 10 + limit  r> ! ; +
-  : right \ adr -- \ decrement variable +
-    >r  r@ @ 10 - limit  r> ! ; +
-   +
-  : SETSERVO \ c -- \ evaluate character c to set a servo. +
-    DUP [char] q = IF x0 left  THEN +
-    DUP [char] e = IF x0 right THEN +
-    DUP [char] a = IF x1 left  THEN +
-    DUP [char] d = IF x1 right THEN +
-    DUP [char] u = IF x2 left  THEN +
-    DUP [char] o = IF x2 right THEN +
-    DUP [char] j = IF x3 left  THEN +
-    DUP [char] l = IF x3 right THEN +
-    drop ; +
-   +
-  HEX +
-  : EX11 \ --  \ press keys Q E A D and U O J L to turn servos. +
-               \ exit on Esc  +
-    initio initx +
-    BEGIN key? +
-      IF key  +
-        ( dup emit )  \ uncomment to test keys +
-        dup setservo  +
-        dup 1B ( esc ) = IF drop exit THEN +
-        drop +
-      THEN  +
-     serve AGAIN ;    +
-   +
-   +
-   +
-  \ ---------------------------------------------------------- +
-  \ Example 12 - pressing S2 increments OUT. (solo) +
-  HEX +
-  : EX12  \ -- \   faling edge detector S2, counting up OUT +
-    initio s2-  \ init system and reset edge detection +
-    F OUT       \ initial OUT value +
-    BEGIN +
-    s2? IF  +
-        12po 0@ 1+ F and 12po 0! \ increment OUT nibble +
-        out>                     \ display it +
-        100 ms s2-     \ wait, then reset S2 +
-        THEN   +
-    key? UNTIL         \ leave loop, clean up +
-    key drop  ;        +
-   +
-   +
-   +
-  \ ---------------------------------------------------------- +
-  \ Example 13 - echo any key. (PC) +
-  : EX13 \ -- \   terminal KEY to OUT with echo  +
-    base @  hex  \ save number base on stack, set hex output +
-    initio zero out  +
-    cr ." press any key to start - press Esc-key to exit" +
-    cr  \ new line +
-    BEGIN  +
-    key       \ get key  +
-    dup over 20 < IF  +
-      5E emit 40 + emit   \ echo control character +
-      ELSE emit THEN      \ echo character +
-    dup space 2# space    \ print character value +
-    dup out   \ send lower nibble to OUT +
-    1B ( esc ) = UNTIL  +
-    base !  +
-    ; \ exit on esc-character +
-   +
-   +
-   +
-  \ ---------------------------------------------------------- +
-  \ Example 14 - audio visual display of ADC. (solo)+
   HEX   HEX
-  : EX14  \ -- \  ADC to OUT and play note       mk0+  : EX8  \ -- \  ADC to OUT and play note       mk0
     initio adc4 adcon  \ init all modules     initio adc4 adcon  \ init all modules
     BEGIN      BEGIN 
Zeile 788: Zeile 694:
      
   \ ----------------------------------------------------------   \ ----------------------------------------------------------
-  \ Example 15 - play demo song. (solo) +  \ Example - play demo song. (solo) 
-  \ Connect speaker between P1.5 and GND.+  \ Connect speaker between P1.5 (pin 7) and GND.
      
   variable BEAT      \ holds delay time in ms   variable BEAT      \ holds delay time in ms
Zeile 813: Zeile 719:
      
      
-  : EX15 \ -- \ play MYBONNIE once  +  : EX9 \ -- \ play MYBONNIE once  
     500 beat !       500 beat !  
     06 n4  \ G4      06 n4  \ G4 
Zeile 837: Zeile 743:
      
   \ ----------------------------------------------------------   \ ----------------------------------------------------------
-  \ DEMOLOOP - Select an example program by it' +  \ Example 0 leave demo loop, run forth.  
-    \ number using S2 and S3. EXIT demoloop by selecting EX0.+  : EX0  
 +    cr .ver 
 +    cr ." forth - command me." abort ; 
 +   
 +   
 +   
 +  \ ---------------------------------------------------------- 
 +  \ DEMOLOOP is the main programm starting at power up or reset. 
 +    \ Select an example program by it's number using S2
 +    \ Press S3 to run it 
 +    \ Select and run Example 11 to enter forth.
        
   : DEMOLOOP \ --    : DEMOLOOP \ -- 
     initio s2- S3- \ init system and reset edge detection     initio s2- S3- \ init system and reset edge detection
-    OUT       \ initial OUT value+    0000 OUT       \ initial OUT value 
 +    000F out!      \ indicate 'ready', turn all LEDs on
     BEGIN     BEGIN
-      s2? IF      \ select demo with S2 +      s2? IF       \ select demo with S2 
-        12po 0@ 1+ F and 12po 0! \ increment OUT nibble +        12po n0@ 1+ F and 12po n0! \ increment OUT nibble 
-        out>                     \ display it +        out>       \ display it 
-        100 ms s2-     \ wait, then reset S2+        100 ms s2- \ wait, then reset S2
         THEN           THEN  
-      S3? IF      \ run demo with S3 +      S3? IF       \ run demo with S3 
-        12po 0@+        12po n0@
        dup  0 = IF EX0  THEN \ run example ...        dup  0 = IF EX0  THEN \ run example ...
        dup  1 = IF EX1  THEN        dup  1 = IF EX1  THEN
Zeile 861: Zeile 778:
        dup  8 = IF EX8  THEN        dup  8 = IF EX8  THEN
        dup  9 = IF EX9  THEN        dup  9 = IF EX9  THEN
-       dup  A = IF EX10 THEN +       drop S3-  \ clean up stack, reset S3 
-       dup  B = IF EX11 THEN +       00 out    \ back to start value
-       dup  C = IF EX12 THEN +
-       dup  D = IF EX13 THEN +
-       dup  E = IF EX14 THEN +
-       dup  F = IF EX15 THEN +
-       drop S3-     \ clean up stack, reset S3 +
-       out        \ back to start value+
       THEN       THEN
     AGAIN ;     AGAIN ;
      
-  \ save  
      
-  \ --> MMT4-0x.txt  \ save image to text file using TI format.+  \ --> up to here the image is saved as file 
 +  \ --> 4e4th+mmt4+ex-V10.txt in TI format 
 +   
 +   
 + 
 +  \ ---------------------------------------------------------- 
 +  \ More example programs made for terminal interaction.  
 +  \ You need a serial PC connection to the MSP430 MCU. 
 +  \ How to do that is shown in the documentation of MMT4.   
 +  \ ---------------------------------------------------------- 
 +   
 +  \ ---------------------------------------------------------- 
 +  \ Example 11 - echo any key. (PC) 
 +  HEX 
 +  : EX11 \ --    \ terminal KEY to OUT with echo  
 +    base @  hex  \ save number base on stack, set hex output 
 +    initio   0000 out  
 +    cr ." press any key to start, " 
 +    cr ." Esc to quit ... " 
 +    cr  \ new line 
 +    BEGIN  
 +    key                   \ get key  
 +    dup over 20 < IF  
 +      5E emit 40 + emit   \ echo control character 
 +      ELSE emit THEN      \ echo character 
 +    dup space 2# space    \ print character value 
 +    dup out               \ send lower nibble to OUT 
 +    1B ( esc ) = UNTIL  
 +    base !  
 +    ; \ exit on esc-character 
 +   
 +   
 +   
 +  \ ---------------------------------------------------------- 
 +  \ Example 12 - toggle OUT bits manually. (PC) 
 +  HEX 
 +  : tout \ c -- c \  
 +    dup [char] 1 = IF 01 12po ctoggle out> exit THEN  
 +    dup [char] 2 = IF 02 12po ctoggle out> exit  THEN  
 +    dup [char] 3 = IF 04 12po ctoggle out> exit  THEN  
 +    dup [char] 4 = IF 08 12po ctoggle out> exit  THEN  
 +    dup [char] 0 = IF 00 out exit THEN  
 +    dup [char] f = IF 0f out exit  THEN  ; 
 +   
 +  : EX12 \ -- \  press 1 2 3 4 to toggel OUT bits, 
 +            \ 0 to clear all, F to set all. 
 +    initio 00 out 
 +    cr ." press 1 2 3 4 " 
 +    cr ." Esc to quit ... " 
 +    cr  \ new line 
 +    BEGIN  
 +    key tout  
 +    1B ( esc ) = UNTIL  
 +    ; \ exit on esc-character 
 +   
 +  \ --> up to here the image is saved as file 
 +  \ --> 4e4th+mmt4+ex+pcex-V10.txt in TI format 
 + 
 +  \ Add your own examples here. 
 +  \ SAVE when compiled. 
 +  
  
  
Zeile 880: Zeile 850:
   \ ----------------------------------------------------------   \ ----------------------------------------------------------
   \ todo ***   \ todo ***
-  \ ausgang via taster statt key? +  
-  \ EXn umsortieren: Mit und ohne keyboard betrieb. +
   decimal    decimal 
   unused u. \ RAM   unused u. \ RAM
Zeile 889: Zeile 857:
   ( finis )   ( finis )
      
- 
projects/mmt4ue2/mmtquellcode0.1415561882.txt.gz · Zuletzt geändert: 2014-11-09 20:38 von mka