Home  |  Contents 
Microcontroller and PC projects
  Forum Index : Microcontroller and PC projects         Section
Subject Topic: Pi-cromite Version 5.04.16 Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
matherp
Guru
Guru


Joined: 11 December 2012
Location: United Kingdom
Online Status: Offline
Posts: 1896
Posted: 12 January 2018 at 7:27pm | IP Logged Quote matherp

Please find attached V5.04.16

for Stretch

2018-01-12_224620_mmbasicstretch.zip

and for Jessie

2018-01-12_224632_mmbasicjessie.zip

Manual

2018-01-13_192334_Pi-cromite_Manual.pdf

This fixes a bug in the PEEK command and also implements the USER display driver capability of Geoff's version 5.4.09. In addition it includes a new font #7 which is a small 6x8 font ideal for smaller displays. NB the Pi-cromite does not support loadable fonts.

This is a huge advantage on the Pi-cromite where we can't have CFunctions. MMBasic is very fast on the Pi-cromite and drivers in Basic perform well





The picture shows an ST7920 based 128x64 display (QC12864B) being driven by a SPI user driver on a Pi Zero-W. The code is attached below and will also work unchanged on any of the Micromites (other than adjusting the pin numbers)

userdisplayinit
Line 0,0,MM.HRes-1,MM.VRes-1
Line MM.HRes-1,0,0,MM.VRes-1
Box 0,0,MM.HRes,MM.VRes
Text MM.HRes/2,MM.VRes/2,"Hello World",CM
End
'
Sub userdisplayinit
  Option explicit
  Option default none
  On error skip
 'if OPTION is already set then ignore the error
  Option LCDPANEL USER, 128,64
  On error skip
 'don't error if Global variables not yet defined
  Erase S$(), tmaskarray(), bmaskarray(), LCD_RESET, LCD_CD, LCD_CMD, LCD_DATA
  Dim S$(MM.VRes-1) length MM.HRes\4
  Dim integer tmaskarray(3)=(240,112,48,16)
  Dim integer bmaskarray(3)=(128,192,224,240)
  Dim INTEGER LCD_RESET=22 ' pin for chip select
  Dim INTEGER LCD_CD=24 ' pin for Reset
  Dim INTEGER LCD_CMD=&B11111000
  Dim INTEGER LCD_DATA=&B11111010
  Local i%
  On error skip
 'don't error if SPI already open
  SPI open 100000,3,8
  Pin(LCD_RESET)=1
  Pin(LCD_CD)=1
  SetPin LCD_RESET,dout
  SetPin LCD_CD,dout
  Pin(LCD_RESET)=0
  Pause 200
  Pin(LCD_RESET)=1
  Pause 200
  Pin(LCD_CD)=1
 ' continuous enable for the moment
  LCD.CMD(1) 'DISPLAY CLEAR
  LCD.CMD(&B00001100) 'display on
  LCD.CMD(1) 'DISPLAY CLEAR
  LCD.CMD(&B00100110) 'graphic mode
  For i% = 0 To MM.VRes-1
    s$(i%)=String$(MM.HRes\4,Chr$(&H0))
  Next i%
  update 0, 0, ((MM.HRes-1)\16), MM.VRes-1
End Sub
'
Sub MM.USER_RECTANGLE(x1%, y1%, x2%, y2%, fcol%)
  If x1%=0 And y1%=0 And x2%=MM.HRes-1 And y2%=MM.VRes-1 Then
    Local b$, i%
    If fcol% Then
      b$=String$(MM.HRes\4,Chr$(&HF0))
    Else
      b$=String$(MM.HRes\4,Chr$(0))
    EndIf
    For i% = 0 To MM.VRes-1
      s$(i%)=b$
    Next i%
  Else
    Local integer i, j, k, l, t, left_x,right_x, mask,emask
    Local b$
    'print "userrectangle ", x1%, y1%, x2%, y2%, fcol%
    If x2% <= x1% Then
      t = x1%
      x1% = x2%
      x2% = t
    EndIf
    If y2% <= y1% Then
      t = y1%
      y1% = y2%
      y2% = t
    EndIf
    If x1% < 0 Then x1% = 0
    If x1% >= MM.HRes Then x1% = MM.HRes - 1
    If x2% < 0 Then x2% = 0
    If x2% >= MM.HRes Then x2% = MM.HRes - 1
    If y1% < 0 Then  y1% = 0
    If y1% >= MM.VRes Then y1% = MM.VRes - 1
    If y2% < 0 Then y2% = 0
    If y2% >= MM.VRes Then y2% = MM.VRes - 1
    left_x=x1%\4
    right_x=x2%\4
    If left_x=right_x Then
      If (fcol%) Then
        mask =(tmaskarray(x1% Mod 4) And bmaskarray(x2% Mod 4))
      Else
        mask = notmask%(tmaskarray(x1% Mod 4) And bmaskarray(x2% Mod 4))
      EndIf
      For t=y1% To y2%
        l= Peek(var S$(t),left_x+1)
        If (fcol%) Then
          l=l Or mask
        Else
          l=l And mask
        EndIf
        Poke var S$(t),left_x+1, l
      Next t
    Else
      If (fcol%) Then
        mask =tmaskarray(x1% Mod 4)
        emask=bmaskarray(x2% Mod 4)
      Else
        mask = notmask%(tmaskarray(x1% Mod 4))
        emask= notmask%(bmaskarray(x2% Mod 4))
      EndIf
      For t=y1% To y2%
        If fcol% Then
          l=Peek(var S$(t),left_x+1)
          l=l Or mask
          Poke var S$(t),left_x+1, l
          l=Peek(var S$(t),right_x+1)
          l=l Or emask
          Poke var S$(t),right_x+1, l
        Else
          l=Peek(var S$(t),left_x+1)
          l=l And mask
          Poke var S$(t),left_x+1, l
          l=Peek(var S$(t),right_x+1)
          l=l And emask
          Poke var S$(t),right_x+1, l
        EndIf
      Next t
      If left_x+1<=right_x-1 Then
        If fcol% Then
          b$=String$(right_x-left_x-1, Chr$(240))
        Else
          b$=String$(right_x-left_x-1, Chr$(0))
        EndIf
        For t=y1% To y2%
          s$(t)=Left$(s$(t),left_x+1)+b$+Right$(s$(t),32-right_x)
        Next t
      EndIf
    EndIf
  EndIf
  update x1%\16, y1%, x2%\16, y2%
End Sub
'
'
Sub MM.USER_BITMAP(x1%, y1%, width%, height%, scale%, fcol%, bcol%, bitmap%)'bitmap is in string bitmap$
'  print  "userbitmap ", x1%, y1%, width%, height%, scale%, fcol%, bcol%
  Local INTEGER i, j, k, mask, m, l, ll, t, tt, vCd, hCd, x, y, a%=height% * width%, ln%, c2%, c3%, c4%
  vCd = y1%
  If y1% < 0  Then y1% = 0                                 ' the y coord is above the top of the screen
  For i = 0 To  height%-1                              ' step thru the font scan line by line
    ln%=i * width%
    For j = 0 To scale%-1                         ' repeat lines to scale the font
      vCd=vCd+1
      If vCd >= 0 Then  ' we are above the top of the screen
        y=vCd - 1
        If vCd > MM.VRes  Then GoTo D_UP                          ' we have extended beyond the bottom of the screen
        hCd = x1%
        For k = 0 To width%-1                         ' step through each bit in a scan line
          c2%=ln% + k
          c4%=(a% - c2% - 1) Mod 8
          t=Peek(BYTE bitmap% + c2%\8)
          tt = (t >> c4%) And 1 'we now know if the pixel is on or off
          For m = 0 To  scale% -1                      ' repeat pixels to scale in the x axis
            hCd = hCd +1' we have not reached the left margin
            If hCd >= 0 Then
              If hCd <= MM.HRes  Then                 ' check are we beyond the right margin
                x=hCd -1
                mask=1<<(7-(x Mod 4))
                c3%=notmask%(mask)
                ll= Peek(var S$(y),x\4+1)
                If tt Then
                  If fcol% Then
                    ll = ll Or mask
                  Else
                    ll = ll And c3%
                  EndIf
                Else
                  If bcol%<>-1 Then 'transparent text
                    If bcol% Then
                      ll = ll Or mask
                    Else
                      ll = ll And c3%
                    EndIf
                  EndIf
                EndIf
                Poke var S$(y), x\4+1, ll
              EndIf
            EndIf
          Next m
        Next k
      EndIf
    Next j
  Next i
D_UP:
  update x1%\16, y1%, x\16, y
End Sub
'
Sub LCD.CMD(databyte As integer)
  Local integer i,J
  SPI write 3,LCD_CMD, DATABYTE And &HF0, (DATABYTE And &H0F)<<4
  Pause 2
End Sub
'
Sub SetXY(x As integer, y As integer)
  Local integer xx=x<<4,yy=y
  If yy>31 Then
    xx=xx+128
    yy=yy-32
  EndIf
  SPI write 5, LCD_CMD, (yy And &H10) Or &H80, yy<<4, &H80, xx
  Pause 1
End Sub
'
Sub update(x1%, y1%, x2%, y2%)
  Local b$, i%
    Pin(LCD_CD)=1 ' enable
    For i% = y1% To y2%
      If i%<MM.VRes Then
        SetXY(x1%,i%)
        b$=Chr$(LCD_DATA)+Mid$(s$(i%),x1%*4 +1, (x2%-x1%+1)*4)
        SPI WRITE Len(b$),b$
      EndIf
    Next i%
    Pin(LCD_CD)=0 ' disable
End Sub
'
Function notmask%(x%)
  notmask% = (-1 Xor x%) And &HFF
End Function






Edited by matherp on 13 January 2018 at 7:23pm



Back to Top View matherp's Profile Search for other posts by matherp
 


If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Search the forums using Google.
In the news...
 
Post ReplyPost New Topic
Printable version Printable version
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum

Powered by Web Wiz Forums version 7.8
Copyright ©2001-2004 Web Wiz Guide

This page was generated in 0.1484 seconds.
Privacy Policy     Process times : 0.05, 0, 0, 0.1