USING TACHYON V4.5 PERIPHERALS

WS2812 RGB LED

22 LEDPIN ( sets the WS2812 pin )

red LED ( 0-7 values are written as quick ANSI colors )

$400020 LED ( light magenta )

<myarray> 64 LEDS ( output myarray to 64 WS2812s)

DHT22 (or DHT11) HUMIDITY SENSOR

21 DHT ( read back relative humidity and temperature from DHT11/22 )

PING SENSOR

20 PING ( read back microseconds from ping sensor )

20 DISTANCE ( read back millimeters from ping sensor )

BLINK LED

1 BLINK ( blink an LED on P1 twice a second, use HZ to change)

TONES & FREQUENCY

23 SPKR ( set speaker/audio to P23 )

3 BEEPS 1 s BIP 1 s SIREN 500 ms 3 RINGS 1 HZ 3 s MUTE  ( combination of sound effects )  

B 2 APIN 1 MHZ ( 1MHz signal on pin 2 using CTRB )

RC ANALOG OUT

2.540 0 VOLTS ( Output a voltage of 2.54V through an RC filter on pin 0 )

SIMPLE SERIAL I/O

9600 SERBAUD         Set default baudrate for this cog

'?' 3 SEROUT        Send a question mark out at 9600 baud on pin 3

3 SERIAL PRINT" Hello World"        Print serial data to pin 3

4 SERIN        Wait for serial data on pin 4

FULL DUPLEX SERIAL I/O

<mypars> 4 " UART    " LOADCOG        Startup full-duplex in cog 4 using parameters

RTC

Tachyon maintains a soft RTC while interfacing and synchronizing to common hardware RTCs if available. The soft RTC is synchronized to the hardware RTC on boot and at midnight so reading the RTC is much faster (88us) as it only needs to convert milliseconds to time of day while the date itself is a variable and takes around 5us. Most I2C RTCs are slight variations of each other of which the DS3231 is used as the basis but the MCP7941x variety are also supported.

Any of these I2C RTCs are detected on boot and used accordingly.

..  lsi2c *** I2C ***

$A0 EEPROM

$AE RTC EEPROM

$DE MCP7941x RTC ok

..  .DT Sun, 02 Oct 2017 13:52:22 AEST

 

KEYPAD

Common 4x4 keypads can be scanned automatically using Tachyon's background timer and buffered. An optional beeper can be specified or use alternative methods. The keypad port pins are assumed to be contiguous pins for row and column from a starting pin.

16 !KEYPAD ( set P16..23 for 4x4 keypad )

5 BEEPER ( set simple key beeper up on P5 - use >31 to disable)

KEYPAD@ ( reads a decoded debounced key from the buffer else returns null )

KEYPAD ( use the keypad as the console KEY input device )

" DCBA#9630852*741" KEYCODE! ( change keypad decode table )

CHARACTER LCD

Common character LCDs which normally come as 16x1, 16x2, or 20x4 and based on HD44780 compatible controllers can be driven directly. The R/W pin should be tied low as it is not used and the contrast pin can be driven from an RC for optional electronic contrast control. The backlight pin is also selectable.

This particular driver uses all 8 data lines but also shares this with an optional keypad using 4 series resistors to prevent contention. An option is being added to specify 4-bit data. Since there is no need to check the busy flag which in most cases would take longer than it does to complete all operations bar one, the LCD is operated in write only mode and since the LCD signals are TTL compatible where >2V is a logic high then there is no need for any 5V interfacing.

Although the internal methods are always directly accessible it is normally accessed as a character output device which responds to numerous control characters just like a terminal. To control the backlight a small NPN is all that is needed, I normally used small sot-23 digital npns.

&27.9.8.0 !LCD ( setup P0..P7 as the data lines, P8 as EN, P9 as backlite, P27 as RC contrast - use >31 to disable unused pins )

LCD $0C EMIT  4 FOR PRINT" Hello World" CR NEXT ( clear screen and print 4 lines directly to the LCD )

SPI

SPI operations are coded as fast PASM instructions which execute in 2.6us or less.

Once SPI masks are set then SPI reads and writes are normally handled in 8-bits at a time with auto chip select. Use SPICE to release the CE manually.

$12 SPIWRB         Write byte to SPI bus

$12345678 4 FOR SPIWR NEXT SPICE        Write 4 bytes from long to SPI bus starting from MSB and then release SPI CE.

 

I2C

I2C100        Set bus speed to 100kHz

I2C400        Set bus speed to 400kHz

All kinds of functions to access the bus are available.        

EEPROM

All kinds of functions to read/write data or arrays or even dump memory

i.e. time a write to a long of the CLKFREQ and read it back as well - no write delay if EEPROM is not busy

..  CLKFREQ $8010 LAP E! LAP .LAP 30080 cycles at 96MHz = 313.333us  ok

..  $8010 E@ . 96000000 ok