Now Reading
A minimalistic Forth laptop with discrete CPU

A minimalistic Forth laptop with discrete CPU

2023-04-01 03:00:43





Excellent news: My4TH kits will likely be out there quickly. Please go to this web site commonly, I’ll maintain you up to date!



This web page is about My4TH. My4TH (pronounced “my fourth”) is my fourth homebuilt
CPU-less laptop after MyCPU, MyNOR and TraNOR. I needed to construct the best laptop
potential, with a discrete CPU utilizing as few gates and parts as potential, operating
a Forth working system.


FORTH is an early programming language developed by Charles H. Moore within the late Sixties.
Extra developed FORTH on an IBM 1130 minicomputer, which had a 16-bit CPU and solely 8 KB of RAM.
To maintain issues easy and scale back reminiscence consumption, he carried out FORTH as a stack-based
digital machine utilizing the Reverse Polish Notation (RPN). However FORTH is far more than simply
a programming language. As a result of FORTH has a built-in interpreter, compiler and disk
I/O assist, a pc operating FORTH can be referred to as a “Forth system”. My4TH is such
a Forth system. You possibly can develop and debug your Forth applications immediately on My4TH.
You possibly can enter your supply code with the built-in textual content editor and retailer it within the on-board
EEPROM reminiscence. From there you may compile and run it immediately on the My4TH board.


My4TH is predicated on MyNOR, so it additionally has a quite simple 1-bit NOR gate “ALU”.
Due to the simplicity of the {hardware}, My4TH can’t interpret Forth code immediately.
As a substitute, it implements an interpreter written in native machine code.
To additional improve execution pace, My4TH compiles Forth code into machine code
(“Subroutine Threaded Code”) quite than into intermediate byte code.




My4TH {hardware} options:

  • 8-bit discrete logic CPU
  • 8 to 14 MHz clock frequency
  • 32 KB ROM, 32 KB RAM
  • as much as 256 KB EEPROM
  • 1-bit NOR gate “ALU”
  • 6300 8-bit additions / sec
  • 4 reminiscence chips
  • 16 CMOS logic chips
  • RS-232 with 4800 baud
  • I2C-bus for extensions
  • 6 digital inputs
  • 5 digital outputs
  • PCB measurement 10 x 10 cm




My4TH software program options:

  • 16-bit Forth system
  • Helps the Forth 2012 customary
  • Core and core extension phrases
  • Double quantity phrase set
  • Block phrase set
  • Built-in textual content editor




Is that this the Forth laptop with the fewest parts and a discrete CPU?




This laptop is totally useful, however it has no assist for the Block phrases. It consists of:
One 32 KB RAM, one 32 KB EPROM, 16 CMOS logic ICs, one oscillator,
4 100nF capacitors, one 150K resistor and two 10K resistor networks.

The wires come from a
FTDI USB->RS232 converter cable
, which additionally provides +5V to the My4TH laptop.

 








The pc is managed by a VT100 appropriate serial terminal. After switching on,
My4TH shows a welcome message and the Forth immediate. Now you may instantly begin
coming into your individual Forth program:





That is the block diagram of the My4TH laptop. As you may see, there may be
no CPU or microcontroller, simply reminiscence chips and easy CMOS logic chips:




Now take a look at the image under. You will note all of the blocks from the diagram above:




However one query stays: How does all of it work?


All of it begins with the microcode handle counter, which is one thing just like the “coronary heart”
of the pc. Every machine instruction consists of as much as 128 microinstructions, whereby
a microinstruction consists of two components: an 8-bit management phrase and an elective 8-bit information phrase.
The machine instruction (the “OP code”) to be executed is utilized to deal with strains
A8 to A14 of the EPROM, and the microcode handle counter is linked to A0 to A7.
The microcode handle counter counts by way of all microinstructions of the present OP code.



In each “even” clock cycle (when A0 is zero),
the primary a part of the microinstruction, particularly the management phrase, is saved within the management phrase latch.
5 of the 8 indicators of this management phrase are used to regulate the information movement by way of the processor by deciding on
the supply and vacation spot system. The ultimate information switch happens within the following “odd” clock
cycle when A0 is one. Since on this second clock cycle the EPROM itself also can function a knowledge supply,
it’s simple to retailer fixed values outlined by the microcode within the numerous registers and the RAM.
Nonetheless, since any handle could be enter into the EPROM on this cycle, it’s potential to carry out random learn
accesses to the EPROM in order that the appliance program (the Forth interpreter) could be executed from the EPROM.



As you may see, the principle function of all of the logic is to switch information from the varied sources to the
numerous locations underneath the management of the microcode. The CPU registers corresponding to PC, SP, Accu, and so forth. are all
saved in RAM. The programme counter is incremented through a look-up desk within the EPROM.



Information manipulation is finished through a single NOR gate on the D0 information line. You could already know that
actually any logical perform could be derived from the NOR perform, even complicated capabilities like
addition and subtraction. However to course of all of the bits of a byte, My4TH should loop over all of the
information bits and course of little by little. The required information shift perform can be carried out as a
look-up desk within the EPROM.



Conditional jumps are solely potential throughout the 128 microcode positions of an OP code. When the
microcode must carry out a conditional soar, it first masses the goal handle (which ranges
from 0 to 127) into the decrease 8 bits of the 16-bit handle latch. A management sign coming from the
management phrase latch then permits the conditional loading of the brand new handle into the
microinstruction counter relying on the worth of D0 throughout the odd clock cycle.



If you’re extra within the microcode, I like to recommend to check the doc
“The MyNOR ADD instruction”
the place I describe how
I carried out the ADD instruction within the microcode for the MyNOR laptop. Since MyNOR and
My4TH are very comparable, the microcode of the ADD perform works precisely the identical on My4TH.
However to extend efficiency, I cheated a bit of on the My4TH by implementing the one-bit adder
through a small look-up desk within the EPROM.



Now we get all the way down to enterprise: The schematic. Click on on the picture to obtain it as a greater readable PDF file.








Invoice of fabric:








Reference Worth   Reference Worth
C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 100 nF   U1 74HC 74
D1 BAT41   U2 U3 74HC 161
J1 D-SUB-09 male connector   U4 74HC 541
J2 Header 1×8 pin, 2.54mm   U5 U6 U7 U10 U17 U18 74HC 574
J3 Header 2×10 pin, 2.54mm   U8 74HC 14
J4 USB kind B mini connector   U9 74HC 08
Q1 BC547B   U11 74HC 02
Q2 BS170   U12 74HC 273
R1 R2 8x 10 kOhm array   U13 74HC 138
R3 2.2 kOhm   U14 74HC 139
R4 R5 10 kOhm   U15 AT27C256-70 (EPROM)
R6 150 kOhm   U16 AS6C62256-55 (SRAM)
SW1 push button   U19 U20 24LC1026-I/P (EEPROM)
X1 Oscillator 8.000 MHz   Socket PDIP-28 for U15







Need to construct your individual? Every little thing you want is right here:


Downloads











Beginning up My4TH and rising the clock frequency

When you have got completed assembling your individual My4TH laptop board, you may carry out a primary take a look at.
For this take a look at join a LED to pins 2(+) and 5(-) of the RS-232 socket and join the contacts
SCL and RXD of J2 with a wire jumper. After making use of the provision voltage, the LED ought to blink.
The blinking frequency of the LED is 1 Hz when My4TH is clocked by an 8 MHz oscillator.



Be aware: This LED blinking take a look at could be very helpful if you wish to take a look at the utmost clock
frequency My4TH can nonetheless work with. For instance, when you have programmed the EPROM with the
picture for 8 MHz operation, you won’t be able to determine a RS-232 connection when you clock
My4TH with 10 MHz, as a result of the baud charge has the bizarre worth of 6000 baud. On this case the
LED may give you a primary trace if My4TH could be operated with this larger frequency.
As a second step, now you can burn an EPROM with the picture supposed for 10 MHz operation.

You probably have entry to My4TH through the serial terminal, you should use the next one-liner
to check if My4TH works stably with the brand new frequency. The road outputs a easy maze
consisting of random / and characters:


: take a look at start 2 random if 47 else 92 then emit once more ; take a look at







Applied Forth Phrases

My4TH tries to comply with the Forth 2012 standard.
Right here is an summary of Forth phrases carried out within the EPROM:


Core Phrases


  !              1+             ?DUP           CHARS          HERE           OR             TYPE    
  #              1-             @              CONSTANT       HOLD           OVER           U.      
  #>             2!             ABORT          COUNT          I              POSTPONE       U             UM/MOD  
  (              2@             ACCEPT         DECIMAL        INVERT         R@             UNLOOP  
  *              2DROP          ALIGN          DEPTH          J              RECURSE        UNTIL   
  */             2DUP           ALIGNED        DO             Okay              REPEAT         VARIABLE
  */MOD          2OVER          ALLOT          DOES>          KEY            ROT            WHILE   
  +              2SWAP          AND            DROP           L              RSHIFT         WORD    
  +!             :              BASE           DUP            LEAVE          S"             XOR     
  +LOOP          ;              BEGIN          ELSE           LITERAL        S>D            [       
  ,                            C@             EXECUTE        MAX            SPACE         
  /              >BODY          CELL+          EXIT           MIN            SPACES        
  /MOD           >IN            CELLS          FILL           MOD            STATE         
  0NUMBER        CHAR           FIND           MOVE           SWAP          
  0=             >R             CHAR+          FM/MOD         NEGATE         THEN          


Core Extension Words


  .(             :NONAME        CASE           ERASE          OF             S"            UNUSED   
  .R                          COMPILE,       FALSE          PAD            SOURCE-ID      VALUE    
  0            ?DO            DEFER          HEX            PARSE          TO             WITHIN   
  0>             ACTION-OF      DEFER!         HOLDS          PARSE-NAME     TRUE           [COMPILE]
  2>R            AGAIN          DEFER@         IS             PICK           TUCK                   
  2R>            BUFFER:        ENDCASE        MARKER         REFILL         U.R            
  2R@            C"             ENDOF          NIP            ROLL           U>             



Block Phrases


  BLK            BUFFER         FLUSH          LOAD           SAVE-BUFFERS   THRU
  BLOCK          EMPTY-BUFFERS  LIST           REFILL         SCR            UPDATE



Double-Quantity Phrases


  2CONSTANT      2VARIABLE      D.R            D2/            DABS           DUS            DNEGATE        



Miscellaneous Phrases


  ?              DUMP           WORDS          KEY?           >=             MS             RDROP 
  .S             FORGET         AT-XY          PAGE           


Particular My4TH Phrases

For an entire description of non-standard phrases, please learn the Forth Glossary for My4TH (pdf).


  I2C-START      I2C-RECV       RINP           RUN-IMAGE      SX             EDIT           
  I2C-STOP       WOUT           SAVE-IMAGE     BLOAD          SY             RANDOM         
  I2C-SEND       ROUT           LOAD-IMAGE     LCD            TERMINAL       SYSV           



Forth Extension Modules


My4TH Forth implements the customized phrase BLOAD. With this phrase you may load binary
extension modules from the EEPROM into the RAM. Binary extension modules can,
for instance, develop the Forth phrase set.
These Forth extensions are at present out there:


String Phrases  (m4-strings.bin)


  BLANK          CMOVE>         /STRING        -TRAILING      SEARCH         SLITERAL
  CMOVE          COMPARE


Facility Extension Phrases  (m4-facility.bin)


  +FIELD         EKEY>CHAR      Okay-UP           Okay-INSERT       Okay-F3           Okay-F8
  FIELD:         EKEY>FKEY      Okay-LEFT         Okay-NEXT         Okay-F4           BEGIN-STRUCTURE
  CFIELD:        EMIT?          Okay-RIGHT        Okay-PRIOR        Okay-F5           END-STRUCTURE
  EKEY           Okay-DELETE       Okay-END          Okay-F1           Okay-F6
  EKEY?          Okay-DOWN         Okay-HOME         Okay-F2           Okay-F7






Utilizing Forth

If you have not performed it but, please learn the tutorial
"Starting Forth" by Leo Brodie
first. The tutorial comprises many examples that you could check out on My4TH.
One other actually good introduction to Forth is the Forth Primer
And so Forth...
by Hans Bezemer. This primer can be a group of very helpful Forth code snippets.
And that is one other excellent primer, particularly for newcomers:

A Beginner's Guide to Forth


Listed below are two examples of straightforward Forth applications that you could enter and run on My4TH:


The sq. root of an unsigned integer could be calculated this manner:


: sqrt dup start 2dup / over + 2/ swap over - abs 2 

The road above implements the Heron's technique for locating the sq. root of a quantity. The main colon tells Forth to compile the brand new phrase "sqrt", which is constructed from all the next phrases. The trailing semicolon tells Forth to exit compile mode once more. After you have got entered the road, Forth will reply with "OK". Once you now enter

49 sqrt .

you'll get the proper end result 7.

Right here is one other instance. This system under attracts the Pascal's triangle:


: triangle cr dup 0 ?do 1 over 1- i - 2* areas i 1+ 0 
  ?do dup 4 .r j i - * i 1+ / loop cr drop loop drop ;

Be aware that the road is simply too lengthy and doesn't match into 80 characters. This isn't an issue
as a result of you may cut up the road in half. Forth doesn't go away compile mode till it sees the
terminating semicolon. Forth acknowledges the primary line with "compiled"
and the second line with "OK".

To inform My4TH to print the primary 10 strains of the triangle, you merely have to enter


10 triangle

and you'll get this stunning triangle:


                     1
                   1   1
                 1   2   1
               1   3   3   1
             1   4   6   4   1
           1   5  10  10   5   1
         1   6  15  20  15   6   1
       1   7  21  35  35  21   7   1
     1   8  28  56  70  56  28   8   1
   1   9  36  84 126 126  84  36   9   1
 okay




Helpful Forth hyperlinks


Listed below are a number of hyperlinks to different Forth associated websites which may be of curiosity to you:







Forth Implementation


My Forth implementation for My4TH deviates from the usual as a result of I modified the reminiscence structure
of the “phrases” a bit to extend the pace. The phrases are saved in a easy linked checklist within the
dictionary. The unique implementation developed by Charles H. Moore is depicted under:



And that is the implementation on My4TH:



Every “phrase” is supplied with a header containing the phrase identify and a pointer to the following phrase
in reminiscence. It’s typical for Forth that the identify is just not represented as a null-terminated string, however as
size plus string. The string size is saved in a byte that precedes the string.
The sphere referred to as “payload” comprises the precise program code. This code can include machine code,
or an inventory of 16-bit address-pointers pointing to different phrases, which in flip are referred to as like subroutines.
The implementation on My4TH now deviates in {that a} phrase in reminiscence doesn’t start with its identify however with the
pointer to the following phrase. This massively hurries up the search of the thesaurus (the “dictionary”),
since no gradual addition instruction is required (in any other case, to get the pointer to the following phrase, one would have
so as to add the string size byte to the beginning handle of the phrase to get a pointer to the pointer to the following phrase).

Additionally, My4TH doesn’t use the basic “Direct Threaded Code” (DTC) mannequin, which solely comprises
perform pointers within the payload subject. As a substitute, I selected the “Subroutine Threaded Code” (STC)
method for My4TH for pace causes. Right here the code subject of a phrase all the time comprises solely pure
machine code, and calling sub-words is definitely performed with a JSR name. This technique sadly results in
about 30% larger reminiscence utilization per phrase, since along with the 16-bit goal handle for a sub-word the
JSR instruction (8-bit) should even be saved. In case you wish to delve deeper into this matter, I like to recommend
studying
Bradford J. Rodriguez, “Moving Forth”
.

To additional improve the execution pace of Forth on My4TH, many Forth phrases are already saved in
extremely optimized machine code in ROM. Thus, the Forth already has a good measurement of 13 KB in ROM.
In distinction to the ROM, the RAM continues to be virtually empty, in order that the consumer nonetheless has 30 KB of free reminiscence
out there for self-defined phrases and applications composed of them. The structure of the RAM seems like this:



 

Historically, Forth works with two stacks: a knowledge stack and a name stack. For causes of pace the
two stacks share a standard reminiscence space on the My4TH laptop, particularly the processor stack. The decision stack
occupies the higher half of the processor stack space from 8180h to 81FFh, and the information stack occupies
the decrease half from 8100h to 817Fh. Each stacks are addressed with the same old quick stack directions
PSH and POP.
Moreover, two extra stacks are carried out in My4TH Forth: The “Movement Management Stack”,
which is required by the compiler for the decision of nested IF / ELSE / THEN’s, and the
“Loop Management Stack”, which is required throughout runtime for loop variables (index and increment).
These two stacks might have been merged with the conventional information stack, however separating the stacks has two
benefits: First, the restricted cupboard space on the information stack is reserved for the precise information.
Second, the Loop Management Stack makes it simpler for the Forth-newbie to program loops, since there
isn’t any want to contemplate the loop parameters when accessing information on the stack. In reality, it may be fairly
complicated when you can’t entry information as standard on the information stack from inside a loop that was positioned
on the stack earlier than you entered the loop. By the best way, the movement management stack permits a nesting depth
of as much as 32 IF / ELSE / THEN’s, and the loop management stack permits as much as 16 nested loops.


Okay, that is solely half the reality. In my Forth implementation, there are literally two different stacks:
first, the prolonged return stack, which is accessed with the Forth phrases >r and r>, and the system
information stack, which is used for inner working system capabilities. Separating these stacks from the
processor’s return stack has two main benefits: Firstly, the out there soar depth is elevated by
liberating up the processor stack, and secondly, programming “screens” is way simpler for
the newbie, who doesn’t have to fret about display block boundaries, because the Forth information and
return stacks nonetheless comprise constant information after the transition from one display to the following,
and no management information is inserted by the system for housekeeping capabilities.




Helpful issues to learn about Forth on My4TH

Constructed-in Editor


My4TH has a built-in editor that lets you edit screens immediately on the My4TH laptop. To entry
the editor, merely enter the variety of the display you want to edit, adopted by the phrase “EDIT”.


Display 0 is for documentation solely


In line with the Forth customary, display quantity 0 can’t be used to retailer code. I like to recommend
to make use of display 0 for documentation functions solely. For instance, display 0 can be utilized to keep up
a desk of contents for the blocks at present in use.


Autostart mechanism after energy on


You possibly can configure a display to be loaded robotically after My4TH is switched on. To do that, merely
write the display quantity (decimal quantity) in the beginning of the primary line in display 0.


The RUN phrase


To standardize the best way applications are began, I launched the RUN phrase. It’s best to add your individual
RUN phrase to the top of your program, which acts as an entry level into your program
(just like the “fundamental” perform in C). For instance, after you have compiled your program
and saved it as a binary picture in EEPROM, you may merely kind “RUN-IMAGE” to load
and run your program with a single command.


Save binary program pictures


To hurry up program loading, you may retailer precompiled binary pictures in EEPROM. When you have got
fully entered your Forth program (or loaded and compiled all of the screens you want),
you should use the phrase SAVE-IMAGE to retailer a binary RAM picture in EEPROM. Binary screens can
then be loaded or loaded and run utilizing the phrases LOAD-IMAGE and RUN-IMAGE.


My4TH Forth for the MyNOR laptop


You probably have already constructed a MyNOR laptop and need to attempt My4TH Forth, you may obtain the
My4TH software program package deal. The package deal comprises the My4TH EPROM picture information in addition to an EPROM
picture file particularly for MyNOR. For full compatibility with the my4th information switch software,
it is best to clock your MyNOR at 8 MHz, in any other case the serial baud charge will likely be too low.
My4TH Forth for MyNOR has restricted performance. It doesn’t assist the MyNOR enlargement boards
(no LCD and keyboard assist), and the out there RAM is restricted to eight KB. To assist all three
output ports of MyNOR, this particular Forth variant implements the extra phrases
WOP1/WOP2/WOP3 and ROP1/ROP2/ROP3.


Information switch between My4TH and a PC


I’ve written a software referred to as “my4th” which simplifies the information switch between the
My4TH board and a PC. With this software you may switch the so referred to as Forth “screens”
from a PC to the on-board EEPROM and vice versa. This makes growing your individual Forth applications
a lot simpler, since you should use your favourite textual content editor on the PC to edit the screens.
The my4th software additionally has a particular characteristic that lets you load unformatted supply code
(“spaghetti code”) into the EEPROM. Nonetheless, my favourite technique for testing
Forth code on the goal platform is the “execute” mode of the my4th software: On this particular
mode, the software sends your Forth supply code line by line to the My4TH board for execution.
And as a bonus, if you’re utilizing Linux, the software lets you keep linked to My4TH through
its built-in terminal emulation mode. So you may add your code to My4TH in step one,
after which run and debug the code on the terminal console (with out having to launch a separate
terminal emulator like putty). That is my favourite my4th command:


$ my4th exec /dev/ttyS0 file myforthprogram.txt -t


One other tip: The my4th software makes use of the baud charge 4800 baud by default. In case you clock your board
decrease (e.g. with 4 MHz as a substitute of 8 MHz), you may instruct my4th to attach with 2400 baud by
including the -l choice after the serial port identify:


$ my4th exec /dev/ttyS0 -l file myforthprogram.txt -t


For an in depth description of the my4th switch software, please learn this doc:
My4TH_Data_Exchange.pdf


Be aware:


You could find much more helpful data within the
FAQ at the bottom of this page.




See Also



Assist for Adafruit STEMMA QT and SparkFun Qwiic boards

My4TH supplies an I2C interface for connecting exterior gadgets. I made a decision to assist the
Adafruit STEMMA QT and SparkFun Qwiic interface requirements as a result of the STEMMA QT boards are
designed to function at 5V and plenty of SparkFun Qwiic boards are additionally appropriate for 5V operation.




As you may see on the image, there’s a very simple option to equip the My4TH
board with the STEMMA QT / Qwiic connectors.
In case you take a more in-depth take a look at J2, you’ll acknowledge the STEMMA QT and Qwiic pin order:
SCL, SDA, +5V and GND. This makes it simple to attach the

SparkFun Qwiic Adapter Board
.





Driver Screens for Adafruit STEMMA QT Boards


Driver for the

Adafruit PCF8523 RTC board
:


----[001]-------------------------------------------------------
 Driver for the Adafruit PCF8523 RTC board:
   Use SETTIME / GETTIME to set or get the time.
   Use SETDATE / GETDATE to set or get the date.
   Use .TIME / .DATE to print out the time and date.
 This driver defines additionally the TIME&DATE phrase, which is a part of
 the elective Facility phrase set of the Forth 2012 customary.
base @ hex
: RTCA ( ack -- )
  0= if area ." RTC Error" cr give up then ;
: RTCW ( n-bytes depend -- )
  D0 i2c-start RTCA 0 do i2c-send drop loop i2c-stop ;
: RTCR ( depend addr -- n-bytes )
  D0 i2c-start RTCA i2c-send drop i2c-stop D1 i2c-start drop
  1 do 0 i2c-recv loop 1 i2c-recv i2c-stop ;
: 2BCD ( dec -- bcd )
  0 start over 9 > whereas 10 + swap A - swap repeat + ;
----[002]-------------------------------------------------------
: BCD2 ( bcd -- dec )
  0 start over 9 > whereas A + swap 10 - swap repeat + ;
: SETTIME ( hour min sec -- )
  rot 2BCD rot 2BCD rot 2BCD 0 0 0 0 7 RTCW ;
: GETTIME ( -- sec min hour )
  3 3 RTCR rot BCD2 rot BCD2 rot BCD2 ;
: SETDATE ( 12 months month day -- )
  rot 64 mod 2BCD rot 2BCD rot 2BCD 0 swap 6 5 RTCW ;
: GETDATE ( -- 12 months month day )
  4 6 RTCR rot drop BCD2 rot BCD2 rot BCD2 rot 7D0 + ;
: TIME&DATE ( -- sec min hour day month 12 months )
  GETTIME GETDATE ROT SWAP -ROT ;
: U2. s>d  kind ;  : U4. s>d  kind ;
: .TIME GETTIME U2. [char] : emit U2. [char] . emit U2. area ;
: .DATE GETDATE U4. [char] - emit U2. [char] - emit U2. area ;
base !
----[EOF]-------------------------------------------------------


Driver for the

Adafruit HTU31D Temperature & Humidity Sensor Board
:


----[001]-------------------------------------------------------
 Driver for the Adafruit HTU31 sensor board.

 Use the phrase HTU31 to learn the sensor. The phrase HTU31
 pushes two integer values onto the stack:
   - humidity with decision 0.1 %
   - temperature with decision 0.1 deg.C

base @ hex
: HTU31 ( -- humidity temperature )  ( returns values * 10 )
  80 i2c-start drop 40 i2c-send drop i2c-stop 2 msec
  80 i2c-start drop 0 i2c-send drop i2c-stop
  81 i2c-start if 0 i2c-recv 8 lshift 0 i2c-recv or
   0 i2c-recv drop 0 i2c-recv 8 lshift 1 i2c-recv or i2c-stop
   1 rshift 3E8 7FFF */ swap 2/ 2/ 4 + 672 3FFF */ 190 - 
   else i2c-stop 0 0 then ;
base !
----[EOF]-------------------------------------------------------


Driver for the

Adafruit LPS25 Pressure Sensor Board
:


----[001]-------------------------------------------------------
 Driver for the Adafruit LPS25 sensor board.
 Use the phrase LPS25 to learn the sensor.

base @ hex  0 worth vLPSi  0 worth vLPSt  0 worth vLPSp
: LPSW ( addrDataWord -- )    BA i2c-start drop dup
  8 rshift i2c-send drop i2c-send drop i2c-stop ;
: LPSR ( addr -- worth ack )  BA i2c-start drop i2c-send drop
  i2c-stop BB i2c-start 1 i2c-recv i2c-stop swap ;
: LPSI ( -- )  vLPSi 0= if 2094 dup LPSW LPSW 1 to vLPSi then ;
: LPS25 ( -- preasure temp ) ( decision 0.1 hPa / 0.1 deg.C )
  LPSI 27 LPSR if 3 and three = else drop 0 to vLPSi 0 to vLPSt
  0 to vLPSp false then if
  29 LPSR drop 2A LPSR drop 8 lshift or A ten */ dup to vLPSp
  2B LPSR drop 2C LPSR drop 8 lshift or 30 / 1A9 + dup to vLPSt
  else vLPSp vLPSt then ;
base !
----[EOF]-------------------------------------------------------


Driver for
I2C-driven LCD shows (16×2 characters with PCF8574):


----[001]-------------------------------------------------------
 Driver for 16x2 I2C LCD show
 lcda: show handle (4E) lcdl: show mild (8 on | 0 off)
 lcd-cmd to ship LCD command
 lcd-??d-p/p1/p2 to ship a personality --p1/p2 first/second line?
base @ hex 4e worth lcda 8 worth lcdl
: i2c-w lcda i2c-start drop lcdl or i2c-send drop i2c-stop ;
: lcd-w or dup i2c-w dup 4 or i2c-w FB and i2c-w ;
: lcd-cmd ( byte -- )
 dup F0 and 0 lcd-w 4 lshift F0 and 0 lcd-w ;
: lcd-ch   ( byte -- )
 dup F0 and 1 lcd-w 4 lshift F0 and 1 lcd-w ;
6 1 C 28 2 3 3 3 0 i2c-w : init 8 0 do lcd-cmd loop ; init
: lcd-on 8 to lcdl 0 lcd-cmd ; : lcd-off 0 to lcdl 0 lcd-cmd ;
: lcd-p 1 - start swap dup c@ lcd-ch 1+  swap 1- dup 0



FAQ

What are the principle variations between MyNOR and My4TH?

My4TH is smaller (smaller measurement, much less parts), sooner (as much as 14 MHz), and has extra reminiscence (32 KB RAM and 256 KB EEPROM) than MyNOR. Moreover, My4TH is designed particularly for FORTH programming.

Is MyNOR's FORTH implementation relevant for "actual world" purposes?

No, MyNOR's FORTH implementation has a number of identified bugs and is taken into account a proof of idea. My4TH goals to supply a extra secure and full FORTH implementation.

Can My4TH be used with MyNOR {hardware}?

Sure, there's a particular model of My4TH Forth out there for the MyNOR {hardware}, however with some limitations on account of MyNOR's 8 KB SRAM. My4TH Forth for MyNOR has additionally no assist for the MyNOR extension boards.

What's the distinction in file alternate between MyNOR and My4TH?

My4TH makes use of a command-line software for importing and downloading particular person screens or full FORTH supply code as a substitute of copying textual content information into the terminal window as in MyNOR.

Can I delete Forth phrases from reminiscence?

Sadly, the Forth structure doesn't permit sure phrases to be deleted from reminiscence. Nonetheless, you should use FORGET and MARKER phrases to delete all phrases compiled after a sure level.

How can I repair bugs and replace the My4TH-ROM?

Because the venture is open supply, you may repair the errors within the supply code. Then it's a must to create a brand new EPROM picture file with the myca cross compiler. Nonetheless, it isn't advisable to repair the error your self. As a substitute, please report it to me in order that I can repair it in an up to date firmware model.

How can I reset My4TH from the software program itself?

You possibly can create a easy phrase to execute a {hardware} reset routine. To do that, compile the next code in My4TH:

hex : reset 2D00 execute ;


Once you enter the command RESET, My4TH will execute the instruction at handle 0x2D00, which is a soar to the
{hardware} reset routine.


How can I save variables within the EEPROM utilizing My4TH?


You need to use the phrases BLOCK, UPDATE, and SAVE-BUFFERS in My4TH Forth. Use BLOCK
to load a block from EEPROM into RAM, which returns a pointer to the block.
You possibly can then copy your variables out and in of the block (deal with the buffer
as a big binary information construction). Use UPDATE to mark the block as modified
after altering a variable, and SAVE-BUFFERS to put in writing the modified block
again to EEPROM.


Why do I lose 1024 bytes of reminiscence when utilizing the BLOCK and BUFFER instructions?


The reminiscence loss is because of the block buffer being allotted by the BUFFER command. As soon as allotted, it isn't launched.
You possibly can work round this difficulty by setting a marker earlier than utilizing the instructions after which releasing the reminiscence after you are performed.


How can I clear all beforehand outlined phrases and reset reminiscence just like the "new" command in MyNOR's proof-of-concept implementation?


You possibly can create a customized NEW phrase primarily based on the instance from the unique MyNOR-Forth editor:


: execnew s" overlook new  : new execnew ;" consider ;
: new execnew ;


Enter these two strains after restarting the pc, after which you should use the "NEW" command as desired.


Why does my program crash after a sure period of time?


The issue could also be on account of the truth that the information stack turns into full.
My4TH Forth doesn't verify for stack overflows. If the information stack overflows,
the return stack is overwritten and this system crashes.


How can I debug the information stack?


You need to use the .S command to show the present contents of the information stack. This may be very useful for debugging functions.


Why does the KEY? phrase watch for a key stroke?


In case you use My4TH through a serial terminal, My4TH should ballot the RS-232 interface within the software program.
Subsequently, so as to not miss any keyboard occasion, it is very important ballot the serial port
as quick as potential. Because of this it isn't potential to implement a non-blocking keyboard
learn on My4TH. In case you want non-blocking interplay together with your program, you may join
extra exterior keys to the I/Os and browse them with RINP.


How can I create a non-blocking option to interrupt a operating program?


You need to use the RINP command to learn the RXD pin immediately. This is an instance:


: take a look at 0 start rinp 1 and whereas 1 + dup . repeat cr ." break, a key was pressed" ;


Understand that you might want to carry the important thing down for a second to make sure this system interrupts correctly.


How can I change the editor with a brand new one loaded from EEPROM?


You possibly can outline a brand new phrase "EDIT" that implements the brand new editor.
The outdated editor will then be "overloaded". For instance, you may
outline the phrase ' : EDIT ." I'm not an editor!" ; ' and name EDIT.
In case you enter FORGET EDIT, the impact will likely be gone, and EDIT will perform as standard.


What does the UP phrase return?


The UP phrase returns the handle of a pointer that factors to the start of a
256-byte reminiscence space that can be utilized freely by the consumer. To get the handle
of the start of this reminiscence space, you will need to enter "UP @".


How does My4TH map the out there reminiscence of I2C EEPROMs?


My4TH Forth maps the out there reminiscence of I2C EEPROMs to the out there 1K-blocks, no matter their addresses.
For instance, when you set up two 24LC512 EEPROMs with any I2C addresses, you'll have screens 0 to 127 out there.
Nonetheless, on the MyNOR board it isn't totally clear wherein EEPROM a particular display will likely be saved.


What occurs on MyNOR if I add one other EEPROM to an current configuration?


Including one other EEPROM to an current configuration on the MyNOR board might trigger issues
finding the beforehand saved screens. The brand new EEPROM may very well be assigned to screens numbers
that had been beforehand assigned to a different EEPROM. It is suggested that you don't add extra
EEPROMs after you have a working configuration to keep away from dropping entry to your saved screens.


Can I take advantage of different EEPROM configurations with MyNOR/My4TH, corresponding to 1x 24LC1026 and 2x 24LC512?


Sure, different configurations are potential. Nonetheless, the utmost reminiscence enlargement of 512 KB
can solely be achieved with eight 24LC512, or two 24LC1026 and 4 24LC512, or 4 24LC1026.
It's also possible to use 4 24LC1025 as a substitute of 4 24LC1026, and 24LCxxx could be changed by 24AAxxx sorts.
At all times verify the information sheet to make sure the proper pin configuration and to keep away from handle conflicts.
However the sockets on the My4th board can solely be populated with 24LC512 or 24LC1026 EEPROMs.


Can I take advantage of 24LC1025 EEPROMs with MyNOR/My4TH ?


24LC1025 EEPROMs are a bit unusual - the handle choose pin A2 have to be pulled excessive,
in any other case the EEPROM is not going to work correctly. Sadly on the sockets on the My4TH
and likewise on the MyNOR board the pin A2 is linked to GND. Nonetheless, it's nonetheless potential
to make use of 24LC1025 EEPROMs on each platforms when you join pin 3 (A2) of the EEPROM to
pin 8 (+5V). However ensure that pin 3 should not be plugged into the socket on the board
(simply bend the pin away from the EEPROM housing).


Can I take advantage of the EPROM simulator on the web site with My4TH?


No, the EPROM emulator can't be used with the My4TH board. My4TH makes use of pin 20 of the EPROM,
which is sadly wrongly linked on the emulator board.


Can I change the EPROM with a Flash reminiscence for My4TH?


Sadly, it isn't potential to exchange the EPROM with a Flash reminiscence, as a result of Flash chips
are sometimes a lot slower than EPROMs. For My4TH you want an EPROM with a most entry time of
120ns if you wish to run it at 8MHz. The quickest flash chips out there right this moment have an entry
time of 150ns, which suggests you may solely run MyNOR at 1/150ns = 6.7 MHz. Additionally, flash reminiscence chips
have a barely totally different pinout, so the socket on the My4TH board must be rewired.
One-Time Programmable (OTP) EPROMs can be found with entry occasions all the way down to 45ns.
Moreover EPROMs are extra "retro" and due to this fact higher fitted to this venture.






License Info


The cross assembler “myca” is licensed underneath the
GNU General Public License, Version 3.






Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top