Shop OBEX P1 Docs P2 Docs Learn Events
LCD touchscreen, A development thread - Page 2 — Parallax Forums

LCD touchscreen, A development thread

245

Comments

  • average joeaverage joe Posts: 795
    edited 2012-02-20 19:53
    Tyler,
    First thing, make sure you are using the same controller. If you are, it's most likely my code. I have had some bugs so. I changed hardware version, but the display is wired the same right now.

    CON
      _clkmode      = xtal1 + pll16x                        ' use crystal x 16
      _xinfreq      = 5_000_000
      ''PINS FOR LCD
      RS                = 16            ''PINS FOR CS - TO KEEP FROM FLOATING 
      LCD_WR            = 17                         ''and sd card defs
      DEV_SD_CLK        = 18
      DEV_SD_DI         = 19
      DEV_SD_DO         = 20    
      DEV_SPI_EN        = 21
      DEV_SPI_ADD0      = 22
      DEV_SPI_ADD1      = 23
      DEV_SPI_ADD_LE    = 24
    DEV_SPI_LCD_RES      = 0
    DEV_SPI_SDC_CS       = 1
    DEV_SPI_TSC_CS       = 2
    DEV_SPI_EXT_CS       = 3  
     DEV_SPI_EXT_POT_CS   = 0
     DEV_SPI_EXT_SW_CS    = %100                                                   
    ''LCD REGISTERS   
      REG_OSCILLATOR                = $0000                               ''Oscillator                                (R00h) (POR = 0000h)
      REG_DRIVEROUTPUTCONTROL       = $0001                               ''Driver Output Control                     (R01h) (POR = 2B3Fh)
      REG_LCDDRIVINGWAVFORM         = $0002                               ''LCD-Driving-Waveform Control              (R02h) (POR = 0000h)
      REG_POWERCONTROL1             = $0003                               ''                                          (R03H)
      REG_DISPLAYCONTROL            = $0007                               ''Display Control                           (R07h) (POR = 0000h)
      REG_FRAMECYCLECONTROL         = $000B                               ''Frame Cycle Control                       (R0Bh) (POR = 5308h)D308 BY DATASHEET
      REG_POWERCONTROL2             = $000C                               ''                                          (R0Ch) (POR = 0004)
      REG_POWERCONTROL3             = $000D                               ''                                          
      REG_POWERCONTROL4             = $000E                               ''
      REG_GATESCANPOSITION          = $000F                               ''Gate Scan Position                        (R0Fh) (POR = 0000h)
      REG_SLEEPMODE                 = $0010                               ''Sleep mode                                (R10h) (POR = 0001h)
      REG_ENTRYMODE                 = $0011                               ''Entry Mode                                (R11h) (POR = 6830h)             
      REG_HPORCH                    = $0016                               ''                                          (R16h) (POR = EF1Ch)
      REG_VPORCH                    = $0017                               ''                                          (R17h) (POR = 0003h)
      REG_POWERCONTROL5             = $001E                               ''                                          
      REG_RAMDATAWRITE              = $0022                               ''
      REG_RAMWRITEDATAMASK1         = $0023                               ''                                          (R23h) (POR = 0000h)
      REG_RAMWRITEDATAMASK2         = $0024                               ''                                          (R24h) (POR = 0000h)
      REG_VERTICALSCROLCONTROL1     = $0041                               ''                                          (R41h) (POR = 0000h)
      REG_VERTICALSCROLCONTROL2     = $0042                               ''                                          (R42h) (POR = 0000h)
      REG_HORIZONTALRAMADDRESSPOS   = $0044                               ''                                          (R44h) (POR = EF00h)
      REG_VERTICALRAMADDRESSSTART   = $0045                               ''                                          (R45h) (POR = 0000h)
      REG_VERTICALRAMADDRESSEND     = $0046                               ''                                          (R46h) (POR = 013Fh)
      REG_FIRSTWINDOWSTART          = $0048                               ''                                          (R48h) (POR = 0000h)
      REG_FIRSTWINDOWEND            = $0049                               ''                                          (R49h) (POR = 013Fh)
      REG_SECONDWINDOWSTART         = $004A                               ''                                          (R4Ah) (POR = 0000h)
      REG_SECONDWINDOWEND           = $004B                               ''                                          (R4Bh) (POR = 013Fh)
      REG_SETGDDRXADDRESSCOUNTER    = $004E                               ''                                          (R4Eh) (POR = 0000h)
      REG_SETGDDRYADDRESSCOUNTER    = $004F                               ''                                          (R4Fh) (POR = 0000h)
      
      FONT_ROM_ADDRESS              = $8000
      BGCOLOR                       = $0fff
      TXTCOLOR                      = $0000
    OBJ
        'fat :    "SD3.01_FATEngine.spin"                 ' thanks to Kye
        spi  : "SPI_ASM"                               ' thanks to Beau 
        wait : "timing"                                    ' thanks to parallax   
        pst  : "Parallax Serial Terminal"    
    VAR
         long ActiveColor, WindowX1, WindowX2,  WindowY1, WindowY2       
    PUB Bootstrap
        EnableDisplayPins
      OUTA[DEV_SPI_EN] := 0
      OUTA[DEV_SPI_ADD_LE] := 0
      'OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := 3 
      'SPI.SHIFTOUT(DEV_SD_DO, DEV_SD_CLK, 4,8,%100)
     'wait.pause1s(100)
      Init_SSD1289
         'ClearScreen
         PST_Init
         SPI.start(5,0)  
          'Init_SD         
         Repeat
          Test_Main
    PUB Init_SD  | pe                 ''broken?
      PST.CLEAR
      pst.Str(string("Testing for SD card"))        ' helpful message if card is out, better than just a blank screen 
      pst.newline       
       'pst.dec(fat.FATEngineStart(20,18,19,22,-1, 1, 1, 1,-1))
       pst.newline   
       'pst.str(string("sucess"))
       pst.newline
       pst.str(string("mounting fat"))
       pst.newline
       'pst.DEC(fat.partitionError)
       'fat.mountPartition(0)                        ' mount the sd card
       wait.pause1s(5)
       pst.str(string("mounting fat done"))
        pst.newline
    PUB TestTS  | yval, xval,x,y
      Enable_Touch       ''Old format was      OUTA[TS_CS] := 0     ' enable the touch screen
     'SPI.start(3,0)                                        ' delay,state     Already running?
      'Shiftout = data,clock,mode,bits,value
      'shiftin = data,clock,mode,bits
      'SPI read S, A2, A1, A0, Mode, SER, PD1, PD0
      '         1  0   0   1    1     0    0    0
      ' MSB first
      ' 001 is X
      ' 101 is Y
       repeat
          pst.clear
          SPI.SHIFTOUT(DEV_SD_DI, DEV_SD_CLK, 5, 8 , %1101_0000)  ' reads x from  500 to 3700  (off < 500 )
          xval := SPI.SHIFTIN(DEV_SD_DO, DEV_SD_CLK,2, 12)
          SPI.SHIFTOUT(DEV_SD_DI, DEV_SD_CLK, 5, 8 , %1001_0000)  ' reads y from 400 to 3800 (off > 3800 ) 
          yval := SPI.SHIFTIN(DEV_SD_DO,DEV_SD_CLK,2, 12)
          pst.Dec(xval)
          pst.newline
          pst.Dec(yval)
          wait.pause1ms(10)
      Disable_Touch       ''Old format was      OUTA[TS_CS] := 1     ' disable the touch screen 
    PUB Init_SSD1289                                        ''Init Display
        EnableDisplayPins                                   ''enable pins 0 to 15
        WriteHigh
        LCD_Reset                                           ''reset screen
        wait.pause1ms(5)                                       
        LCD_Reset           ''then init screen
        wait.pause1ms(5)
        Lcd_Write_Com (REG_DISPLAYCONTROL)                  ''Display Control (R07h) (POR = 0000h) 
        Lcd_Write_Data($0021)                               ''GON = 1 DTE = 0 D[1:0] = 01 
        Lcd_Write_Com (REG_OSCILLATOR)                      ''Oscillator (R00h) (POR = 0000h)
        Lcd_Write_Data($0001)                               ''Turn on oscillator
        Lcd_Write_Com (REG_DISPLAYCONTROL)                  ''Display Control (R07h) (POR = 0000h)
        Lcd_Write_Data($0023)                               ''GON = 1 DTE = 0 D[1:0] = 11
        Lcd_Write_Com (REG_SLEEPMODE)                       ''Sleep mode (R10h) (POR = 0001h)
        Lcd_Write_Data($0000)     ''                        ''exit sleep mode         
        Lcd_Write_Com (REG_DISPLAYCONTROL)                  ''Display Control (R07h) (POR = 0000h)
        Lcd_Write_Data($0033)                               ''GON = 1 DTE = 1 D[1:0] = 11
        Lcd_Write_Com (REG_ENTRYMODE)                       ''Entry Mode (R11h) (POR = 6830h)
        Lcd_Write_Data($6838)                               ''
        Lcd_Write_Com (REG_LCDDRIVINGWAVFORM)               ''LCD-Driving-Waveform Control (R02h) (POR = 0000h)($1000) 
        Lcd_Write_Data($1000)     ''                        ''
        Lcd_Write_Com (REG_GATESCANPOSITION)                ''Gate Scan Position (R0Fh) (POR = 0000h)  ($0000)
        Lcd_Write_Data($0000)     ''                        ''                                                        ''
        Lcd_Write_Com (REG_DRIVEROUTPUTCONTROL)             ''Driver Output Control (R01h) (POR = [0XXXX0X1]3Fh) 433f    ($633F) 
        Lcd_Write_Data($6B3F) ''                            ''                                                      
        Lcd_Write_Com (REG_FRAMECYCLECONTROL)               ''Frame Cycle Control (R0Bh) (POR = 5308h) ($5308)
        Lcd_Write_Data($5308)                               ''                           '
        Lcd_Write_Com (REG_DISPLAYCONTROL)                  ''Display Control (R07h) (POR = 0000h) ($0033)
        Lcd_Write_Data($0033)                               ''GON = 1 DTE = 1 D[1:0] = 11 
    PUB PST_Init  | PstCog                                       ''Starts Parallax Serial Terminal for debugging.
      PstCog := (pst.Start(115200) -1)                             '' returns the cog pst started in
      pst.Str(String("Parallax Serial Terminal started in cog "))  ''  talk to human
      pst.Dec(PstCog)                                              '' displays cog on PST                                                  ''
      wait.pause1s(5)                                              '' wait a bit
    PUB Test_Main | char, tmp
        pst.Clear
        pst.Str(String("Function Test Main Menu"))
        pst.NewLine
        pst.Str(String("1 for Font Test 1"))
        pst.NewLine
        pst.Str(String("2 for Color Test"))
        pst.Newline
        pst.Str(String("3 for Hello World"))
        pst.NewLine   
        pst.Str(String("4 for FreeRun Color Test"))
        pst.NewLine
        pst.Str(String("5 for Sd Test"))
        pst.NewLine
        pst.Str(String("6 for TS Test"))
        pst.NewLine    
        pst.Str(String("7 for External SPI Test"))
        pst.NewLine    
    char := pst.DecIn
        if (char == 1)
          FontTest
        elseif (char == 2)
          pst.newline
          pst.str(string("Select Hex Color 0000 -FFFF"))
          pst.NewLine
          char := pst.hexin
          ColorTest(char)
        elseif (char == 3)
          HelloWorld
        elseif (char == 4)
          ColorTestFreeRUN
        elseif (char == 5)
          Init_SD
        elseif (char == 6)
          TestTS
        elseif (char == 7)
          Spi_Test
         'pst.   
    return
    PUB Spi_Test  | char, address, data
      repeat
        pst.Clear
        pst.Str(String("1 for pot test"))
        Pst.NewLine
        Pst.Str(String("2 for switch test"))
        Pst.NewLine
        char := pst.DecIn
        if (char == 1)
          Pst.Clear
          Pst.Str(String("Input Pot Address 0 - 3"))
          Pst.NewLine
          address := Pst.DecIn
          Pst.NewLine
          Pst.Str(String("Input Pot Value"))
          Pst.Newline
          data := Pst.DecIn
          address <<= 8
          data := data + address
          wait.pause1s(1)
          Set_Spi_Ext_Address(0)   
          SPI.SHIFTOUT(DEV_SD_DO, DEV_SD_CLK, 5, 11, data)
          StrobeCS
          Disable_Spi_Ext
    PUB ColorTestFreeRUN | color                  
      repeat                             
        repeat color from $0000 to $FFFF step 1
           ColorTest(Color)
    PUB ColorTest(Color) | idxr, idxc
    SetWindow(0, 0, 239, 319)
    SetGAddress(0,0)
      repeat idxr from 0 to 319
        repeat idxc from 0 to 239                   
                                 
             Lcd_Write_Com(REG_RAMDATAWRITE)
             Lcd_Write_Data(Color)
    return
    PUB HelloWorld | char, row, col
        PropFont_WriteCr(72,  0, 0*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(101, 0, 1*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(108, 0, 2*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(108, 0, 3*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(111, 0, 4*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(32,  0, 5*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(87,  0, 6*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(111, 0, 7*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(114, 0, 8*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(108, 0, 9*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(100, 0, 10*16, 0, 0, BGCOLOR, TXTCOLOR)
        
    PUB FontTest | tmp, char, row, col, rbor, cbor
    pst.Clear
    pst.Str(String("Select character"))
    pst.newline
        char := pst.DecIn
    pst.Str(String("Select Row"))
    pst.newline
        row := pst.DecIn
    pst.Str(String("Select Col"))
    pst.newline
        col := pst.DecIn
    pst.Str(String("Select RBor"))
    pst.newline
        rbor := pst.DecIn
    pst.Str(String("Select CBor"))
    pst.newline
        cbor := pst.DecIn
                         PropFont_WriteCr(char, row, col, rbor, cbor, BGCOLOR, TXTCOLOR)
    return
    PUB ClearScreen | idxr, idxc
           Lcd_Write_Com (REG_SETGDDRxADDRESSCOUNTER)
           Lcd_Write_Data(0)
           Lcd_Write_Com (REG_SETGDDRyADDRESSCOUNTER)
           Lcd_Write_Data(0)
      repeat idxr from 0 to 76800
            Lcd_Write_Com(REG_RAMDATAWRITE)
            Lcd_Write_Data(BGCOLOR)
    return
    PUB PropFont_WriteCr(Character, PosR, PosC, RBorder, CBorder, BgC, TxC) | characterpointer, odd_even, bitpatern[32], idx, pxlidx, lcdidx, pxlidxdcd, x1, y1, x2, y2
      odd_even                      := character & $0001
      characterpointer              := character & $fffe
      characterpointer              >>= 1
      characterpointer              *= 32
       repeat idx from 0 to 31 
         bitpatern[idx] := long[FONT_ROM_ADDRESS][characterpointer + idx]    
      y1 :=  PosC + CBorder 
      y2 := (PosC + 15) - CBorder
      x1 :=  PosR + RBorder
      x2 := (PosR + 31) - RBorder
         SetWindow(x1, y1, x2, y2)
         SetGAddress(x1,y1)
      repeat idx from RBorder to 31 - RBorder        
         repeat pxlidx from odd_even + (CBorder*2) to (odd_even + 30) - (CBorder*2) step 2
           pxlidxdcd := |< pxlidx   
           if ((bitpatern[idx] & pxlidxdcd) == pxlidxdcd)  
             Lcd_Write_Com(REG_RAMDATAWRITE)
             Lcd_Write_Data(TxC)
           else
             Lcd_Write_Com(REG_RAMDATAWRITE)
             Lcd_Write_Data(BgC)
     SetWindow(0, 0, 239, 319)
     return        
    PUB SetWindow(x1, y1, x2, y2) | HORIZONTALRAMADDRESSPOS
     WindowX1 := x1
     WindowX2 := x2
     WindowY1 := y1
     WindowY2 := y2
        HORIZONTALRAMADDRESSPOS := x1 + (x2 << 8)      
           Lcd_Write_Com ( REG_HORIZONTALRAMADDRESSPOS)
           Lcd_Write_Data(HORIZONTALRAMADDRESSPOS)
           Lcd_Write_Com (REG_VERTICALRAMADDRESSSTART)
           Lcd_Write_Data(y1)
           Lcd_Write_Com (REG_VERTICALRAMADDRESSEND)
           Lcd_Write_Data(y2)
    PUB SetGAddress(x,y)
           Lcd_Write_Com (REG_SETGDDRxADDRESSCOUNTER) ''max %1111_1111, $FF
           Lcd_Write_Data(x)
           Lcd_Write_Com (REG_SETGDDRyADDRESSCOUNTER) ''max %1_0011_1111, $13f
           Lcd_Write_Data(y)
    return
    ''PUB ChangeOrientation(n) ' pass true = portrait or false = landscape, changes global variable orientation in this object
    ''    EnableLatchPins
    ''    orientation := n                      
    ''    if orientation
    ''     Lcd_Write_Com(REG_DRIVEROUTPUTCONTROL)        
    ''      ILIcmd($0001,$0100)                        ' set SS and SM bit 0001 0100   portrait
    ''      ILIcmd($0003,$1030)                        ' set GRAM write direction and BGR=1. $0003 $1030  
    ''    else
    ''      ILIcmd($0001,$0000)                        ' set SS and SM bit 0001 0000   landscape   
    ''      ILIcmd($0003,$1038)                        ' landscape  $1028 = original but 1038 is correct - not mirror image                                              
    PUB Enable_SDC
      OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_SDC_CS                       ' 
      OUTA[DEV_SPI_EN] := 1
    PUB Disable_SDC
      OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_SDC_CS                       ' 
      OUTA[DEV_SPI_EN] := 1
    PUB Set_Spi_Ext_Address(Ext_Spi_Address)
      OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_EXT_CS
      wait.pause1s(1)
      OUTA[DEV_SPI_ADD_LE] := 0
       wait.pause1s(1)
      SPI.SHIFTOUT(DEV_SD_DO, DEV_SD_CLK, 5, 8, Ext_Spi_Address)
      wait.pause1s(1)
      OUTA[DEV_SPI_ADD_LE] := 1
      wait.pause1s(1)
      OUTA[DEV_SPI_ADD_LE] := 0                        ' 
    PUB Disable_SPI_EXT                        ' 
      OUTA[DEV_SPI_EN] := 1
    PUB StrobeCS
       OUTA[DEV_SPI_EN] := 0
       wait.pause1ms(5)
       OUTA[DEV_SPI_EN] := 1
    '********************** private methods *********************
    PRI Enable_Touch
      OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_TSC_CS                              
      OUTA[DEV_SPI_EN] := 0                        ' 
    PRI Disable_Touch
      OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_TSC_CS                              
      OUTA[DEV_SPI_EN] := 0                        ' 
    PRI LCD_Reset 
        OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_LCD_RES                              
        outa[DEV_SPI_EN] := 0         
        wait.pause1ms(5)                                  ''wait here if necessary                           ' 
        outa[DEV_SPI_EN] := 1
    PRI LCD_Writ_Bus(V) 
        OUTA[15..0]  := V
        WriteLow                                            ' write pin low
        WriteHigh                                           ' toggle write pin
    PRI Lcd_Write_Com(V)
        RSLow
        LCD_Writ_Bus(V)
    PRI Lcd_Write_Data(V)
        RSHigh
        LCD_Writ_Bus(V)    
    PRI EnableDisplayPins
        DIRA:=%00000001_11100011_11111111_11111111 ' , Reset, WR, RS and 16 data lines active    
    PRI TristateDisplayPins ' tristate all pins -                                                 
        DIRA:=%00000001_11100010_00000000_00000000 ''
    PRI RSLow                                    
        outa[RS] := 0
    PRI RSHigh
        outa[RS] := 1                 '
    PRI WriteLow                                    
        outa[LCD_WR] := 0                             ' 
    PRI WriteHigh
        outa[LCD_WR] := 1
    Pub Deadend      'Deadend   
        repeat
         wait.pause1s(10000)
    
    
    
    
    Not everything is working yet, but this *should* display pixels if you have the same controller.

    eagletalontim, I can't work on the sd card right now, but hopefully dr A will figure this out. It would be a real bummer to find out the cage itself is bad. I hope I was doing something wrong. :D I was looking at the 5v crowd and they seem to have it working. I would THINK just removing the resistors would work, but bypassing may be key too. All I know is I tried both and I still have nothing. I'm making progress with the analog board, but still having issues. Time to RTFM... :D
  • TylerSkylerTylerSkyler Posts: 72
    edited 2012-02-20 20:00
    Thanks, for the reply i'll try that out. I have tried to get the sd card working to and no luck so far. Weird i was hoping to use it and save some space(and money).
  • average joeaverage joe Posts: 795
    edited 2012-02-20 20:14
    Try looking for the 3 resistors, take them out and bypass the supply pins. SHOULD work..
  • average joeaverage joe Posts: 795
    edited 2012-02-21 06:38
    Tyler, which controller does your display use? Which display are you using? The one thing that comes to mind is POR values. Your display MAY NOT have the same Power On Reset values even if it is the same controller.
    I am commenting code right now. I used to be in the habit of commenting as I wrote. I have been slacking off a bit.
    I still have not been able to get my analog board to work. I will be switching back to my BS2 to test the control circuitry I added. The board was working with the BS2before I added the control circuitry. I'm hoping I'm just doing something wrong.

    Found another wiring mistake. I wired DEV_SPI_ADD_LE to DEV_SPI_EN. I am correcting this now.
    Other bugs found. Fixing those as well. I will be updating the final rev of ScreenTest shortly.
  • average joeaverage joe Posts: 795
    edited 2012-02-21 09:36
    I just put together the final revision of the display test. SDO and SDI might be reversed. I can't test this with my hardware, but it should work.
    {
    '' SSD1289  LCD driver
     ''P0 - P15 Data bus pins
     ''P16 LCD_RS 
     ''P17 LCD_WR
     ''P18 SData_In
     ''P19 SData_ck
     ''P20 Sdata_out
     ''P21 TS_CS
     ''P22 SD_CS
     ''P23 LCD_RESET
     ''P24
     ''P25
     ''P26
     ''P27
     ''P28
     ''P29
    }  
    CON
      _clkmode      = xtal1 + pll16x                        ' use crystal x 16
      _xinfreq      = 5_000_000
      ''PINS FOR LCD
    
      TS_CS       = 21
      SD_CS       = 22
      DEV_LCD_RST =23
      
      RS                = 16            ''PINS FOR CS - TO KEEP FROM FLOATING 
      LCD_WR            = 17                         ''and sd card defs
      DEV_SD_CLK        = 18
      DEV_SD_DI         = 19
      DEV_SD_DO         = 20
                                                     
    ''LCD REGISTERS   
      REG_OSCILLATOR                = $0000                               ''Oscillator                                (R00h) (POR = 0000h)
      REG_DRIVEROUTPUTCONTROL       = $0001                               ''Driver Output Control                     (R01h) (POR = 2B3Fh)
      REG_LCDDRIVINGWAVFORM         = $0002                               ''LCD-Driving-Waveform Control              (R02h) (POR = 0000h)
      REG_POWERCONTROL1             = $0003                               ''                                          (R03H)
      REG_DISPLAYCONTROL            = $0007                               ''Display Control                           (R07h) (POR = 0000h)
      REG_FRAMECYCLECONTROL         = $000B                               ''Frame Cycle Control                       (R0Bh) (POR = 5308h)D308 BY DATASHEET
      REG_POWERCONTROL2             = $000C                               ''                                          (R0Ch) (POR = 0004)
      REG_POWERCONTROL3             = $000D                               ''                                          
      REG_POWERCONTROL4             = $000E                               ''
      REG_GATESCANPOSITION          = $000F                               ''Gate Scan Position                        (R0Fh) (POR = 0000h)
      REG_SLEEPMODE                 = $0010                               ''Sleep mode                                (R10h) (POR = 0001h)
      REG_ENTRYMODE                 = $0011                               ''Entry Mode                                (R11h) (POR = 6830h)             
      REG_HPORCH                    = $0016                               ''                                          (R16h) (POR = EF1Ch)
      REG_VPORCH                    = $0017                               ''                                          (R17h) (POR = 0003h)
      REG_POWERCONTROL5             = $001E                               ''                                          
      REG_RAMDATAWRITE              = $0022                               ''
      REG_RAMWRITEDATAMASK1         = $0023                               ''                                          (R23h) (POR = 0000h)
      REG_RAMWRITEDATAMASK2         = $0024                               ''                                          (R24h) (POR = 0000h)
      REG_VERTICALSCROLCONTROL1     = $0041                               ''                                          (R41h) (POR = 0000h)
      REG_VERTICALSCROLCONTROL2     = $0042                               ''                                          (R42h) (POR = 0000h)
      REG_HORIZONTALRAMADDRESSPOS   = $0044                               ''                                          (R44h) (POR = EF00h)
      REG_VERTICALRAMADDRESSSTART   = $0045                               ''                                          (R45h) (POR = 0000h)
      REG_VERTICALRAMADDRESSEND     = $0046                               ''                                          (R46h) (POR = 013Fh)
      REG_FIRSTWINDOWSTART          = $0048                               ''                                          (R48h) (POR = 0000h)
      REG_FIRSTWINDOWEND            = $0049                               ''                                          (R49h) (POR = 013Fh)
      REG_SECONDWINDOWSTART         = $004A                               ''                                          (R4Ah) (POR = 0000h)
      REG_SECONDWINDOWEND           = $004B                               ''                                          (R4Bh) (POR = 013Fh)
      REG_SETGDDRXADDRESSCOUNTER    = $004E                               ''                                          (R4Eh) (POR = 0000h)
      REG_SETGDDRYADDRESSCOUNTER    = $004F                               ''                                          (R4Fh) (POR = 0000h)
      
      FONT_ROM_ADDRESS              = $8000
      BGCOLOR                       = $0fff
      TXTCOLOR                      = $0000
    OBJ
        spi  : "SPI_ASM"                               ' thanks to Beau 
        wait : "timing"                                    ' thanks to parallax   
        pst  : "Parallax Serial Terminal"    
    VAR
         long ActiveColor, WindowX1, WindowX2,  WindowY1, WindowY2       
    PUB Bootstrap
        EnableDisplayPins
        OUTA[SD_CS] := 1
        OUTA[TS_CS] := 1
    SPI.start(3,0)
     
      Init_SSD1289
         ClearScreen
         PST_Init
         SPI.start(5,0)  
         HelloWorld         
         Repeat
          Test_Main
    PUB TestTS  | yval, xval,x,y
      OUTA[TS_CS] := 0     ' enable the touch screen
     'SPI.start(3,0)                                        ' delay,state     Already running?
      'Shiftout = data,clock,mode,bits,value
      'shiftin = data,clock,mode,bits
      'SPI read S, A2, A1, A0, Mode, SER, PD1, PD0
      '         1  0   0   1    1     0    0    0
      ' MSB first
      ' 001 is X
      ' 101 is Y
       repeat
          pst.clear
          SPI.SHIFTOUT(DEV_SD_DO, DEV_SD_CLK, 5, 8 , %1101_0000)  ' reads x from  500 to 3700  (off < 500 )
          xval := SPI.SHIFTIN(DEV_SD_DI, DEV_SD_CLK,2, 12)
          SPI.SHIFTOUT(DEV_SD_DO, DEV_SD_CLK, 5, 8 , %1001_0000)  ' reads y from 400 to 3800 (off > 3800 ) 
          yval := SPI.SHIFTIN(DEV_SD_DI,DEV_SD_CLK,2, 12)
          pst.Dec(xval)
          pst.newline
          pst.Dec(yval)
          wait.pause1ms(100)
      OUTA[TS_CS] := 1     ' disable the touch screen 
    PUB Init_SSD1289                                        ''Init Display
        EnableDisplayPins                                   ''enable pins 0 to 15
        WriteHigh
        LCD_Reset                                           ''reset screen
        wait.pause1ms(5)                                       
        LCD_Reset           ''then init screen
        wait.pause1ms(5)
        Lcd_Write_Com (REG_DISPLAYCONTROL)                  ''Display Control (R07h) (POR = 0000h) 
        Lcd_Write_Data($0021)                               ''GON = 1 DTE = 0 D[1:0] = 01 
        Lcd_Write_Com (REG_OSCILLATOR)                      ''Oscillator (R00h) (POR = 0000h)
        Lcd_Write_Data($0001)                               ''Turn on oscillator
        Lcd_Write_Com (REG_DISPLAYCONTROL)                  ''Display Control (R07h) (POR = 0000h)
        Lcd_Write_Data($0023)                               ''GON = 1 DTE = 0 D[1:0] = 11
        Lcd_Write_Com (REG_SLEEPMODE)                       ''Sleep mode (R10h) (POR = 0001h)
        Lcd_Write_Data($0000)     ''                        ''exit sleep mode         
        Lcd_Write_Com (REG_DISPLAYCONTROL)                  ''Display Control (R07h) (POR = 0000h)
        Lcd_Write_Data($0033)                               ''GON = 1 DTE = 1 D[1:0] = 11
        Lcd_Write_Com (REG_ENTRYMODE)                       ''Entry Mode (R11h) (POR = 6830h)
        Lcd_Write_Data($6838)                               ''
        Lcd_Write_Com (REG_LCDDRIVINGWAVFORM)               ''LCD-Driving-Waveform Control (R02h) (POR = 0000h)($1000) 
        Lcd_Write_Data($1000)     ''                        ''
        Lcd_Write_Com (REG_GATESCANPOSITION)                ''Gate Scan Position (R0Fh) (POR = 0000h)  ($0000)
        Lcd_Write_Data($0000)     ''                        ''                                                        ''
        Lcd_Write_Com (REG_DRIVEROUTPUTCONTROL)             ''Driver Output Control (R01h) (POR = [0XXXX0X1]3Fh) 433f    ($633F) 
        Lcd_Write_Data($6B3F) ''                            ''                                                      
        Lcd_Write_Com (REG_FRAMECYCLECONTROL)               ''Frame Cycle Control (R0Bh) (POR = 5308h) ($5308)
        Lcd_Write_Data($5308)                               ''                           '
        Lcd_Write_Com (REG_DISPLAYCONTROL)                  ''Display Control (R07h) (POR = 0000h) ($0033)
        Lcd_Write_Data($0033)                               ''GON = 1 DTE = 1 D[1:0] = 11 
    PUB PST_Init  | PstCog                                       ''Starts Parallax Serial Terminal for debugging.
      PstCog := (pst.Start(115200) -1)                             '' returns the cog pst started in
      pst.Str(String("Parallax Serial Terminal started in cog "))  ''  talk to human
      pst.Dec(PstCog)                                              '' displays cog on PST                                                  ''
      wait.pause1s(5)                                              '' wait a bit
    PUB Test_Main | char, tmp
        pst.Clear
        pst.Str(String("Function Test Main Menu"))
        pst.NewLine
        pst.Str(String("1 for Font Test 1"))
        pst.NewLine
        pst.Str(String("2 for Color Test"))
        pst.Newline
        pst.Str(String("3 for Hello World"))
        pst.NewLine   
        pst.Str(String("4 for FreeRun Color Test"))
        pst.NewLine
        pst.Str(String("5 for TouchScreen Test"))
        pst.NewLine
                
    char := pst.DecIn
        if (char == 1)
          FontTest
        elseif (char == 2)
          pst.newline
          pst.str(string("Select Hex Color 0000 -FFFF"))
          pst.NewLine
          char := pst.hexin
          ColorTest(char)
        elseif (char == 3)
          HelloWorld
        elseif (char == 4)
          ColorTestFreeRUN
        elseif (char == 5)
          TestTS
            
          
    PUB ColorTestFreeRUN | color                  
      repeat                             
        repeat color from $0000 to $FFFF step 1
           ColorTest(Color)
    PUB ColorTest(Color) | idxr, idxc
    SetWindow(0, 0, 239, 319)
    SetGAddress(0,0)
      repeat idxr from 0 to 319
        repeat idxc from 0 to 239                   
                                 
             Lcd_Write_Com(REG_RAMDATAWRITE)
             Lcd_Write_Data(Color)
    return
    PUB HelloWorld | char, row, col
        PropFont_WriteCr(72,  0, 0*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(101, 0, 1*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(108, 0, 2*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(108, 0, 3*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(111, 0, 4*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(32,  0, 5*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(87,  0, 6*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(111, 0, 7*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(114, 0, 8*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(108, 0, 9*16, 0, 0, BGCOLOR, TXTCOLOR)
        PropFont_WriteCr(100, 0, 10*16, 0, 0, BGCOLOR, TXTCOLOR)
        
    PUB FontTest | tmp, char, row, col, rbor, cbor                                      
    pst.Clear
    pst.Str(String("Select character"))
    pst.newline
        char := pst.DecIn
    pst.Str(String("Select Row"))
    pst.newline
        row := pst.DecIn
    pst.Str(String("Select Col"))
    pst.newline
        col := pst.DecIn
    pst.Str(String("Select RBor"))
    pst.newline
        rbor := pst.DecIn
    pst.Str(String("Select CBor"))
    pst.newline
        cbor := pst.DecIn
                         PropFont_WriteCr(char, row, col, rbor, cbor, BGCOLOR, TXTCOLOR)
    return
    PUB ClearScreen | idxr, idxc
           Lcd_Write_Com (REG_SETGDDRxADDRESSCOUNTER)
           Lcd_Write_Data(0)
           Lcd_Write_Com (REG_SETGDDRyADDRESSCOUNTER)
           Lcd_Write_Data(0)
      repeat idxr from 0 to 76800
            Lcd_Write_Com(REG_RAMDATAWRITE)
            Lcd_Write_Data(BGCOLOR)
    return
    PUB PropFont_WriteCr(Character, PosR, PosC, RBorder, CBorder, BgC, TxC) | characterpointer, odd_even, bitpatern[32], idx, pxlidx, lcdidx, pxlidxdcd, x1, y1, x2, y2
      odd_even                      := character & $0001
      characterpointer              := character & $fffe
      characterpointer              >>= 1
      characterpointer              *= 32
       repeat idx from 0 to 31 
         bitpatern[idx] := long[FONT_ROM_ADDRESS][characterpointer + idx]    
      y1 :=  PosC + CBorder 
      y2 := (PosC + 15) - CBorder
      x1 :=  PosR + RBorder
      x2 := (PosR + 31) - RBorder
         SetWindow(x1, y1, x2, y2)
         SetGAddress(x1,y1)
      repeat idx from RBorder to 31 - RBorder        
         repeat pxlidx from odd_even + (CBorder*2) to (odd_even + 30) - (CBorder*2) step 2
           pxlidxdcd := |< pxlidx   
           if ((bitpatern[idx] & pxlidxdcd) == pxlidxdcd)  
             Lcd_Write_Com(REG_RAMDATAWRITE)
             Lcd_Write_Data(TxC)
           else
             Lcd_Write_Com(REG_RAMDATAWRITE)
             Lcd_Write_Data(BgC)
     SetWindow(0, 0, 239, 319)
     return        
    PUB SetWindow(x1, y1, x2, y2) | HORIZONTALRAMADDRESSPOS
     WindowX1 := x1
     WindowX2 := x2
     WindowY1 := y1
     WindowY2 := y2
        HORIZONTALRAMADDRESSPOS := x1 + (x2 << 8)      
           Lcd_Write_Com ( REG_HORIZONTALRAMADDRESSPOS)
           Lcd_Write_Data(HORIZONTALRAMADDRESSPOS)
           Lcd_Write_Com (REG_VERTICALRAMADDRESSSTART)
           Lcd_Write_Data(y1)
           Lcd_Write_Com (REG_VERTICALRAMADDRESSEND)
           Lcd_Write_Data(y2)
    PUB SetGAddress(x,y)
           Lcd_Write_Com (REG_SETGDDRxADDRESSCOUNTER) ''max %1111_1111, $FF
           Lcd_Write_Data(x)
           Lcd_Write_Com (REG_SETGDDRyADDRESSCOUNTER) ''max %1_0011_1111, $13f
           Lcd_Write_Data(y)
    return
    
    '********************** private methods *********************
    PRI LCD_Reset                               
        outa[DEV_LCD_RST] := 0         
        wait.pause1ms(5)                                  ''wait here if necessary                           ' 
        outa[DEV_LCD_RST] := 1
    PRI LCD_Writ_Bus(V) 
        OUTA[15..0]  := V
        WriteLow                                            ' write pin low
        WriteHigh                                           ' toggle write pin
    PRI Lcd_Write_Com(V)
        RSLow
        LCD_Writ_Bus(V)
    PRI Lcd_Write_Data(V)
        RSHigh
        LCD_Writ_Bus(V)    
    PRI EnableDisplayPins
        DIRA:=%00000000_11100011_11111111_11111111 ' , Reset, WR, RS and 16 data lines active    
    PRI TristateDisplayPins ' tristate all pins -                                                 
        DIRA:=%00000000_11100010_00000000_00000000 ''
    PRI RSLow                                    
        outa[RS] := 0
    PRI RSHigh
        outa[RS] := 1                 '
    PRI WriteLow                                    
        outa[LCD_WR] := 0                             ' 
    PRI WriteHigh
        outa[LCD_WR] := 1
    
  • TylerSkylerTylerSkyler Posts: 72
    edited 2012-02-21 10:01
    Thanks for the commented code i'll look at that later today when I have time. I hope Dr. A can firgure out the sd card, i can't. I read on a gadget gangstar forum that when not using PSM Sd Card reader your must put the Cs first instead of Do. As in:

    ...mount_explicit(CS, DI, CLK, DO) 'Gives me -100

    instead of:

    ...mount_explicit(DO, CLK, DI, CS) 'Gives me -1

    But unfortunately it doesn't seem to work, but mabye switching the order will provide a fix for this pesky sd card reader.

    Cheers,

    Tyler
  • average joeaverage joe Posts: 795
    edited 2012-02-21 11:01
    I hope Dr. A can firgure out the sd card, i can't. I read on a gadget gangstar forum that when not using PSM Sd Card reader your must put the Cs first instead of Do. As in:

    ...mount_explicit(CS, DI, CLK, DO) 'Gives me -100

    instead of:

    ...mount_explicit(DO, CLK, DI, CS) 'Gives me -1

    But unfortunately it doesn't seem to work, but mabye switching the order will provide a fix for this pesky sd card reader.

    Cheers,

    Tyler
    I will have to look into this. I have most of my hardware revisions done. I think I will leave multiplexing the parallel bus for later when I need it. I have one more chip to mount and connect on my analog board, which is fully working now. Hopefully all will go well with this.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2012-02-21 18:12
    Just got my screens in today :) I ordered 2 and got 4. Guess it is an error in my favor. I will continue to follow this thread for updates on the SD card reading. Just have to get mine to turn on, then display a pixel... the fun begins!
  • average joeaverage joe Posts: 795
    edited 2012-02-21 18:27
    @ eagle, Awesome! I want to order 4 more of these things. I'm about ready to start working on the sd card, although I don't think I need it yet. I've been writing and drawing a GUI. I still haven't bound anything yet, but it's getting close. I'm getting excited at the potential. I'm still using spin drivers to write the display which is slow. I will be converting to ASM shortly. Drawing a screen is not horrible, but takes about 12 seconds. This is single threaded still, but I will be implementing multi-threading as soon as I get the drivers working. I hate to have to write my own text based gui, but I couldn't find anything that fit my needs close enough. I want font scaling because the simple borders control I have is not enough. Hats off to the guys at parallax for programming this font on the rom. It looks great.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-02-21 19:36
    I ordered 2 and got 4.

    Hey, bonus. Tempting to order 2000 and see what happens.

    6 hours to go before work stops and soldering time starts :)
  • TylerSkylerTylerSkyler Posts: 72
    edited 2012-02-21 19:59
    Tyler, which controller does your display use? Which display are you using? The one thing that comes to mind is POR values. Your display MAY NOT have the same Power On Reset values even if it is the same controller.
    I am commenting code right now. I used to be in the habit of commenting as I wrote. I have been slacking off a bit.
    I still have not been able to get my analog board to work. I will be switching back to my BS2 to test the control circuitry I added. The board was working with the BS2before I added the control circuitry. I'm hoping I'm just doing something wrong.

    Found another wiring mistake. I wired DEV_SPI_ADD_LE to DEV_SPI_EN. I am correcting this now.
    Other bugs found. Fixing those as well. I will be updating the final rev of ScreenTest shortly.

    Hey, thanks for the help! I have tried your latest test and still miserable failure. You mentioned that my displays may not have the same Power on and Reset values as yours(I believe we are using the same exact touchscreen module). How do I find out these values for my board and how do I adapt the code to address this? I think this may solve my troubles(My display doesn't seem to turn on or Reset :smile:).

    Thanks Again,

    Tyler
  • average joeaverage joe Posts: 795
    edited 2012-02-21 20:50
    I mentioned those PORs because I am not setting every register on power on. You might want to try setting all the registers. I don't know enough to advise the correct values. With how forgiving these displays are, I wonder if you have a hardware issue. Did you connect Vcc to a good +5v? LCD Chip Select to ground and Write to +3.3? Does the backlight come on? Make sure LCD reset is 3v after power on. I have not needed reset, or used it other than making it high in the bootstrap.
  • TylerSkylerTylerSkyler Posts: 72
    edited 2012-02-21 21:18
    I mentioned those PORs because I am not setting every register on power on. You might want to try setting all the registers. I don't know enough to advise the correct values. With how forgiving these displays are, I wonder if you have a hardware issue. Did you connect Vcc to a good +5v? LCD Chip Select to ground and Write to +3.3? Does the backlight come on? Make sure LCD reset is 3v after power on. I have not needed reset, or used it other than making it high in the bootstrap.

    Thanks for your patience. Yes I am using a good 5 volt for the VCC. I have put LCD CS to gnd and Write to 3.3 volt. Yes the Backlight turns in. But the LCD reset isn't 3V(tested with multimeter and got mere millivolts). My problem is that when I load the demo the backlight stays on but nothing comes up on the screen, don't know what to make of this though.

    Thanks,

    Tyler
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-02-22 02:21
    Success with the SD card!!

    I sacrificed one of the displays by completely removing the SD socket and connecting wires to my own. Started with my own socket with lots of bypass caps and running the SD card off the propeller's 3V supply. First socket kept shorting the supply - who knows why but that one ended up in the bin. New socket. Moved the supply over to the local regulator. Removed first the 470uF, then the 22uF then the 0.1uF. No difference.

    And then finally the answer. Bypassed the three 2k resistors.

    So that is all you need to do. Remove those three resistors and replace with little wire links. Mine are not beautiful but they work fine. See attached photo. 10k pullups on the 4 lines. Oh and don't forget the card goes in upside down.
    1024 x 768 - 128K
    1024 x 768 - 93K
  • average joeaverage joe Posts: 795
    edited 2012-02-22 05:51
    Tyler, your problem is the reset line. It must be high for the display to work. Otherwise the screen will just sit blank. You may be able to tie directly to 3v supply. I do not seem to need it, but results may vary.

    Dr.A, I'm glad you got the card working. I will try again now that the rest of the hardware works.
  • TylerSkylerTylerSkyler Posts: 72
    edited 2012-02-22 09:36
    Victory! Your were right joe my problem was the reset. I put it straight to the 3V just as you suggested and it worked perfectly. Now i'll move on to wiring touch recognition(hopefully it will take me less than a week :smile:). Thanks for your help Joe and Dr. Acula(over on his thread).

    @Dr. A im glad you solved the mystery of the sd card i'll definintly modify my board as you suggested and see if it works.


    Thanks,

    Tyler
  • average joeaverage joe Posts: 795
    edited 2012-02-22 12:06
    Awesome! I'm glad I could help. The touch input is very simple. DI, DO, Ck and CS. Write a byte, read 12. X-Y decoding looks to be decently easy.I will play with this in a couple days.

    I have been thinking about freeing up the reset line since the screen doesn't seem to need it. I need to hook the CS line for the sd card back up and do some more tests. The sd cards I'm using (tried 3) might be the culprit. Now that everything else is working, it would be nice to have. I hope to have my sd breakout today or tomorrow, so that will give me something to test against as well.
    I'm currently working out a couple aspects of the future menu design. I like using the propeller ROM font. It looks nice and has a comprehensive character set. I still need to write a few methods for the PropFont object, but this is what I have so far.
    This is my PropFont object.
    CON
    
      RS                = 16            ''PINS FOR CS - TO KEEP FROM FLOATING 
      LCD_WR            = 17
    
      
    ''LCD REGISTERS   
      REG_OSCILLATOR                = $0000                               ''Oscillator                                (R00h) (POR = 0000h)
      REG_DRIVEROUTPUTCONTROL       = $0001                               ''Driver Output Control                     (R01h) (POR = 2B3Fh)
      REG_LCDDRIVINGWAVFORM         = $0002                               ''LCD-Driving-Waveform Control              (R02h) (POR = 0000h)
      REG_POWERCONTROL1             = $0003                               ''                                          (R03H)
      REG_DISPLAYCONTROL            = $0007                               ''Display Control                           (R07h) (POR = 0000h)
      REG_FRAMECYCLECONTROL         = $000B                               ''Frame Cycle Control                       (R0Bh) (POR = 5308h)D308 BY DATASHEET
      REG_POWERCONTROL2             = $000C                               ''                                          (R0Ch) (POR = 0004)
      REG_POWERCONTROL3             = $000D                               ''                                          
      REG_POWERCONTROL4             = $000E                               ''
      REG_GATESCANPOSITION          = $000F                               ''Gate Scan Position                        (R0Fh) (POR = 0000h)
      REG_SLEEPMODE                 = $0010                               ''Sleep mode                                (R10h) (POR = 0001h)
      REG_ENTRYMODE                 = $0011                               ''Entry Mode                                (R11h) (POR = 6830h)             
      REG_HPORCH                    = $0016                               ''                                          (R16h) (POR = EF1Ch)
      REG_VPORCH                    = $0017                               ''                                          (R17h) (POR = 0003h)
      REG_POWERCONTROL5             = $001E                               ''                                          
      REG_RAMDATAWRITE              = $0022                               ''
      REG_RAMWRITEDATAMASK1         = $0023                               ''                                          (R23h) (POR = 0000h)
      REG_RAMWRITEDATAMASK2         = $0024                               ''                                          (R24h) (POR = 0000h)
      REG_VERTICALSCROLCONTROL1     = $0041                               ''                                          (R41h) (POR = 0000h)
      REG_VERTICALSCROLCONTROL2     = $0042                               ''                                          (R42h) (POR = 0000h)
      REG_HORIZONTALRAMADDRESSPOS   = $0044                               ''                                          (R44h) (POR = EF00h)
      REG_VERTICALRAMADDRESSSTART   = $0045                               ''                                          (R45h) (POR = 0000h)
      REG_VERTICALRAMADDRESSEND     = $0046                               ''                                          (R46h) (POR = 013Fh)
      REG_FIRSTWINDOWSTART          = $0048                               ''                                          (R48h) (POR = 0000h)
      REG_FIRSTWINDOWEND            = $0049                               ''                                          (R49h) (POR = 013Fh)
      REG_SECONDWINDOWSTART         = $004A                               ''                                          (R4Ah) (POR = 0000h)
      REG_SECONDWINDOWEND           = $004B                               ''                                          (R4Bh) (POR = 013Fh)
      REG_SETGDDRXADDRESSCOUNTER    = $004E                               ''                                          (R4Eh) (POR = 0000h)
      REG_SETGDDRYADDRESSCOUNTER    = $004F                               ''                                          (R4Fh) (POR = 0000h)
      
    
      FONT_ROM_ADDRESS              = $8000
    
    VAR
    long BackgroundColor,ActiveColor, ActiveTextColor, InactiveTextColor, Row, Col, RowBorder,ColBorder, WindowX1, WindowX2, WindowY1, WindowY2
    'long
    obj wait : "timing"
    PUB Init_SSD1289                                        ''Init Display
        EnableDisplayPins                                   ''enable pins 0 to 15
        WriteHigh
        'LCD_Reset                                          ''reset screen
        'wait.pause1ms(5)                                      
        'LCD_Reset          ''then init screen
        'wait.pause1ms(5)
        Lcd_Write_Com (REG_DISPLAYCONTROL)                  ''Display Control (R07h) (POR = 0000h) 
        Lcd_Write_Data($0021)                               ''GON = 1 DTE = 0 D[1:0] = 01 
        Lcd_Write_Com (REG_OSCILLATOR)                      ''Oscillator (R00h) (POR = 0000h)
        Lcd_Write_Data($0001)                               ''Turn on oscillator
        Lcd_Write_Com (REG_DISPLAYCONTROL)                  ''Display Control (R07h) (POR = 0000h)
        Lcd_Write_Data($0023)                               ''GON = 1 DTE = 0 D[1:0] = 11
        Lcd_Write_Com (REG_SLEEPMODE)                       ''Sleep mode (R10h) (POR = 0001h)
        Lcd_Write_Data($0000)     ''                        ''exit sleep mode         
        Lcd_Write_Com (REG_DISPLAYCONTROL)                  ''Display Control (R07h) (POR = 0000h)
        Lcd_Write_Data($0033)                               ''GON = 1 DTE = 1 D[1:0] = 11
        Lcd_Write_Com (REG_ENTRYMODE)                       ''Entry Mode (R11h) (POR = 6830h)
        Lcd_Write_Data($6838)                               ''
        Lcd_Write_Com (REG_LCDDRIVINGWAVFORM)               ''LCD-Driving-Waveform Control (R02h) (POR = 0000h)($1000) 
        Lcd_Write_Data($1000)     ''                        ''
        Lcd_Write_Com (REG_GATESCANPOSITION)                ''Gate Scan Position (R0Fh) (POR = 0000h)  ($0000)
        Lcd_Write_Data($0000)     ''                        ''                                                        ''
        Lcd_Write_Com (REG_DRIVEROUTPUTCONTROL)             ''Driver Output Control (R01h) (POR = [0XXXX0X1]3Fh) 433f    ($633F) 
        Lcd_Write_Data($6B3F) ''                            ''                                                      
        Lcd_Write_Com (REG_FRAMECYCLECONTROL)               ''Frame Cycle Control (R0Bh) (POR = 5308h) ($5308)
        Lcd_Write_Data($5308)                               ''                           '
        Lcd_Write_Com (REG_DISPLAYCONTROL)                  ''Display Control (R07h) (POR = 0000h) ($0033)
        Lcd_Write_Data($0033)                               ''GON = 1 DTE = 1 D[1:0] = 11 
    
    PUB WriteNextActiveCr(Character) | characterpointer, odd_even, bitpatern[32], idx, pxlidx, lcdidx, pxlidxdcd, x1, y1, x2, y2
      odd_even                      := character & $0001
      characterpointer              := character & $fffe
      characterpointer              >>= 1
      characterpointer              *= 32
       repeat idx from 0 to 31 
         bitpatern[idx] := long[FONT_ROM_ADDRESS][characterpointer + idx]
    
           
      y1 :=  Col + ColBorder 
      y2 := (Col + 15) - ColBorder
      x1 :=  Row + RowBorder
      x2 := (Row + 31) - RowBorder
    
      
         SetWindow(x1, y1, x2, y2)
         SetGAddress(x1,y1)
      repeat idx from RowBorder to 31 - RowBorder        
         repeat pxlidx from odd_even + (ColBorder*2) to (odd_even + 30) - (ColBorder*2) step 2
           pxlidxdcd := |< pxlidx   
           if ((bitpatern[idx] & pxlidxdcd) == pxlidxdcd)  
             Lcd_Write_Com(REG_RAMDATAWRITE)
             Lcd_Write_Data(ActiveTextColor)
           else
             Lcd_Write_Com(REG_RAMDATAWRITE)
             Lcd_Write_Data(BackgroundColor)
    
      if (((Col + 16) >  319 ) and  ((Row + 32) > 223))
        Row := 0
        Col := 0
      elseif (((Col + 16) >  319 ) and  ((Row + 32) < 223)) 
        Row := Row + 32
        Col := 0
      else
        Col := Col + 16
             
     SetWindow(0, 0, 239, 319)
    PUB WriteActiveCr(Character, PosR, PosC, RBorder, CBorder, BgC, TxC) | characterpointer, odd_even, bitpatern[32], idx, pxlidx, lcdidx, pxlidxdcd, x1, y1, x2, y2
      odd_even                      := character & $0001
      characterpointer              := character & $fffe
      characterpointer              >>= 1
      characterpointer              *= 32
       repeat idx from 0 to 31 
         bitpatern[idx] := long[FONT_ROM_ADDRESS][characterpointer + idx]
         
       Row              := PosR      
       Col              := PosC
       RowBorder        := RBorder
       ColBorder        := CBorder
       BackgroundColor  := BgC
       ActiveTextColor  := Txc
    
      y1 :=  PosC + CBorder 
      y2 := (PosC + 15) - CBorder
      x1 :=  PosR + RBorder
      x2 := (PosR + 31) - RBorder
      
         SetWindow(x1, y1, x2, y2)
         SetGAddress(x1,y1)
      repeat idx from RBorder to 31 - RBorder        
         repeat pxlidx from odd_even + (CBorder*2) to (odd_even + 30) - (CBorder*2) step 2
           pxlidxdcd := |< pxlidx   
           if ((bitpatern[idx] & pxlidxdcd) == pxlidxdcd)  
             Lcd_Write_Com(REG_RAMDATAWRITE)
             Lcd_Write_Data(TxC)
           else
             Lcd_Write_Com(REG_RAMDATAWRITE)
             Lcd_Write_Data(BgC)
             
      if (((Col + 16) >  319 ) and  ((Row + 32) > 223))
        Row := 0
        Col := 0
      elseif (((Col + 16) >  319 ) and  ((Row + 32) < 223)) 
        Row := Row + 32
        Col := 0
      else
        Col := Col + 16
              
     SetWindow(0, 0, 239, 319)
     return
    
    PUB SetWindow(x1, y1, x2, y2) | HORIZONTALRAMADDRESSPOS
     WindowX1 := x1
     WindowX2 := x2
     WindowY1 := y1
     WindowY2 := y2
        HORIZONTALRAMADDRESSPOS := x1 + (x2 << 8)      
           Lcd_Write_Com ( REG_HORIZONTALRAMADDRESSPOS)
           Lcd_Write_Data(HORIZONTALRAMADDRESSPOS)
           Lcd_Write_Com (REG_VERTICALRAMADDRESSSTART)
           Lcd_Write_Data(y1)
           Lcd_Write_Com (REG_VERTICALRAMADDRESSEND)
           Lcd_Write_Data(y2)
    PUB SetGAddress(x,y)
           Lcd_Write_Com (REG_SETGDDRxADDRESSCOUNTER) ''max %1111_1111, $FF
           Lcd_Write_Data(x)
           Lcd_Write_Com (REG_SETGDDRyADDRESSCOUNTER) ''max %1_0011_1111, $13f
           Lcd_Write_Data(y)
    
    PUB ClearScreen(color) | idxr, idxc
           Lcd_Write_Com (REG_SETGDDRxADDRESSCOUNTER)
           Lcd_Write_Data(0)
           Lcd_Write_Com (REG_SETGDDRyADDRESSCOUNTER)
           Lcd_Write_Data(0)
      repeat idxr from 0 to 76800
            Lcd_Write_Com(REG_RAMDATAWRITE)
            Lcd_Write_Data(Color)
    Row              := 0      
    Col              := 0
    
    PUB FillScreen(Color) | idxr, idxc
           Lcd_Write_Com (REG_SETGDDRxADDRESSCOUNTER)
           Lcd_Write_Data(0)
           Lcd_Write_Com (REG_SETGDDRyADDRESSCOUNTER)
           Lcd_Write_Data(0)
      repeat idxr from 0 to 76800
            Lcd_Write_Com(REG_RAMDATAWRITE)
            Lcd_Write_Data(Color)
    Row              := 0      
    Col              := 0          
    
    PUB SetBG(Color)
    PUB SetFG(Color)
    PUB SetActive(Color)
    PUB SetInActive(Color)
    PUB SetRow(NewRow)
    PUB SetCol(NewCol)
                
    PUB EnableDisplayPins
        DIRA:=%00000001_11100011_11111111_11111111 ' , Reset, WR, RS and 16 data lines active    
    PUB TristateDisplayPins ' tristate all pins -                                                 
        DIRA:=%00000001_11100010_00000000_00000000 ''
        
    PRI LCD_Writ_Bus(V) 
        OUTA[15..0]  := V
        WriteLow                                            ' write pin low
        WriteHigh                                           ' toggle write pin
    PRI Lcd_Write_Com(V)
        RSLow
        LCD_Writ_Bus(V)
    PRI Lcd_Write_Data(V)
        RSHigh
        LCD_Writ_Bus(V)  
    
    
    PRI RSLow                                        
        outa[RS] := 0
    PRI RSHigh
        outa[RS] := 1                 '
    PRI WriteLow                                    
        outa[LCD_WR] := 0                             ' 
    PRI WriteHigh
        outa[LCD_WR] := 1
    
    I'm sorry that I have not commented this code yet. I need to finish abstraction as well. It seems to run ok, other than being a bit slow. I have some ideas for optimization, but have not started working it out. I am convinced that using 2 cogs running Pasm will speed up display writes significantly. Before I can work on asm I need to finish the spin code. This includes a working character based gui. The current top object looks something like this.
    CON
      _clkmode      = xtal1 + pll16x                        ' use crystal x 16
      _xinfreq      = 5_000_000
      ''PINS FOR LCD
                                                     ''and sd card defs
      DEV_SD_CLK        = 18
      DEV_SD_DI         = 19
      DEV_SD_DO         = 20    
      DEV_SPI_EN        = 21
      DEV_SPI_ADD0      = 22
      DEV_SPI_ADD1      = 23
      DEV_SPI_ADD_LE    = 24
      
    DEV_SPI_LCD_RES      = 0
    DEV_SPI_SDC_CS       = 1
    DEV_SPI_TSC_CS       = 2
    DEV_SPI_EXT_CS       = 3  
     DEV_SPI_EXT_POT_CS   = 0
     DEV_SPI_EXT_SW_CS    = 1                                                   
    
      BGCOLOR                       = $ffff
      TXTCOLOR                      = $0000
      NotPressedBGC                 = $ffff
      NotPressedATC                 = $0000
      PressedBGC                    = $0000
      PressedATC                    = $ffff
      Pressed                       = 1
      NotPressed                    = 0    
      
    
    OBJ
        pfw : "PropFont"
         'fat : "SD3.01_FATEngine.spin"                  ' thanks to Kye
        spi  : "SPI_ASM"                               ' thanks to Beau 
        wait : "timing"                                    ' thanks to parallax   
        pst  : "Parallax Serial Terminal"    
    VAR
          long stringptr[65], BackgroundColor, ActiveTextColor
            BYTE Fader0[3], Fader1[3], Fader2[3], Fader3[3], faderOrentation, faderpos, faderval, oldfader, ButtonName 'Fader POS, New Fader Value, Old Fader Value, FaderOrentation holds 0 for landscape, portrait not enabled
                word Button0[3], Button1[3], Button2[3], Button3[3], Button4[3], Button5[3], ButtonGroup, ButtonX, ButtonY, ButtonState
                
    PUB Bootstrap | f
    BackgroundColor := $ffff
    ActiveTextColor := %0000
    
        pfw.EnableDisplayPins
      OUTA[DEV_SPI_EN] := 1
      OUTA[DEV_SPI_ADD_LE] := 0
        SPI.start(3,0)
      
      pfw.Init_SSD1289
         pfw.ClearScreen(BackgroundColor)
         FaderTest
         ButtonTest
         deadend
          PST_Init
    
    PUB FaderTest | F
    Fader0[0] :=255
    Fader0[1] := 0
    Fader0[2] := 2
    
    Fader1[0] := 0
    Fader1[1] := 0
    Fader1[2] := 54
    
    Fader2[0] := 126
    Fader2[1] := 0
    Fader2[2] := 106
    
    Fader3[0] := 192
    Fader3[1] := 0
    Fader3[2] := 161
    
     REPEAT f from 0 to 3
         SetFader(F)
         DrawFader
    'Repeat
     REPEAT f from 0 to 3
       SetFader(F)
       UpdateFader
     Fader0[1] := Fader0[0]
     Fader0[0] -= 1
    
    PUB ButtonTest | b
    Button0[0] := 1
    Button0[1] := 206
    Button0[2] := 78
    
    Button1[0] := 54
    Button1[1] := 206
    Button1[2] := 66
    
    Button2[0] := 108
    Button2[1] := 206
    Button2[2] := 209
    
    Button3[0] := 161
    Button3[1] := 206
    Button3[2] := 209  
    
    Button4[0] := 216
    Button4[1] := 206
    Button4[2] := 66  
    
    Button5[0] := 271
    Button5[1] := 206
    Button5[2] := 78  
    
     REPEAT b from 0 to 5
         SetButton(b)
         Drawbutton(b)  
    PUB SetFader(FaderNumber)
     case FaderNumber
        0: faderval :=  Fader0[0]
           oldfader :=  Fader0[1]
           faderpos :=  Fader0[2]
           
        1: faderval :=  Fader1[0]
           oldfader :=  Fader1[1]
           faderpos :=  Fader1[2]
           
        2: faderval :=  Fader2[0]
           oldfader :=  Fader2[1]
           faderpos :=  Fader2[2]
           
        3: faderval :=  Fader3[0]
           oldfader :=  Fader3[1]
           faderpos :=  Fader3[2]
          
         
    PUB UpdateFader 'layer 2               
       
      pfw.WriteActiveCr(6, faderpos, 2, 7, 0, BackgroundColor, ActiveTextColor)
      pfw.WriteActiveCr(7, faderpos, 301, 7, 0, BackgroundColor, ActiveTextColor)
    
      pfw.WriteActiveCr(32, faderpos, oldfader + 31, 4, 2, BackgroundColor, ActiveTextColor)
      pfw.WriteActiveCr(14, faderpos, faderval + 24, 4, 3, BackgroundColor, ActiveTextColor)
      
    PUB DrawFader |index                'layer 1
      
      pfw.WriteActiveCr(1, faderpos, 0, 0, 0, BackgroundColor, ActiveTextColor)
      pfw.WriteActiveCr(9, faderpos, 7, 0, 0, BackgroundColor, ActiveTextColor)
       
       REPEAT 18
        pfw.WriteNextActiveCr(13)
        
      pfw.WriteActiveCr(1, faderpos, 297, 0, 0, BackgroundColor, ActiveTextColor)
      pfw.WriteActiveCr(9, faderpos, 304, 0, 0, BackgroundColor, ActiveTextColor)
    
    PUB SetButton(Button)  
      case Button
        0: ButtonX     := Button0[0]
           ButtonY     := Button0[1]
           ButtonName  := Button0[2]
           ButtonState := ButtonGroup & $01
           
        1: ButtonX     := Button1[0]
           ButtonY     := Button1[1]
           ButtonName  := Button1[2]
           ButtonState := ButtonGroup & $02
           
        2: ButtonX     := Button2[0]
           ButtonY     := Button2[1]
           ButtonName  := Button2[2]
           ButtonState := ButtonGroup & $04
           
        3: ButtonX     := Button3[0]
           ButtonY     := Button3[1]
           ButtonName  := Button3[2]
           ButtonState := ButtonGroup & $08
           
        4: ButtonX     := Button4[0]
           ButtonY     := Button4[1]
           ButtonName  := Button4[2]
           ButtonState := ButtonGroup & $10
           
        5: ButtonX     := Button5[0]
           ButtonY     := Button5[1]
           ButtonName  := Button5[2]
           ButtonState := ButtonGroup & 20
           
           
    PUB DrawButton(Button) | x, y
     if ButtonState == Pressed
      pfw.WriteActiveCr(1, ButtonY, ButtonX, 0, 0, PressedBGC, PressedATC)
        pfw.WriteNextActiveCr(ButtonName)
      pfw.WriteNextActiveCr(9)
     else
      pfw.WriteActiveCr(1, ButtonY, ButtonX, 0, 0, NotPressedBGC, NotPressedATC)
        pfw.WriteNextActiveCr(ButtonName)
      pfw.WriteNextActiveCr(9)
    
    
    That's the main portion of the code, some helper methods in the top object are
    PUB Enable_SDC
      OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_SDC_CS                       ' 
      OUTA[DEV_SPI_EN] := 1
    PUB Disable_SDC
      OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_SDC_CS                       ' 
      OUTA[DEV_SPI_EN] := 1
    
    PUB Set_Spi_Ext_Address(Ext_Spi_Address)
      OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_EXT_CS
      wait.pause1ms(1)
      OUTA[DEV_SPI_ADD_LE] := 0
       wait.pause1ms(1)
      SPI.SHIFTOUT(DEV_SD_DO, DEV_SD_CLK, 5, 3, Ext_Spi_Address)
      wait.pause1ms(1)
      OUTA[DEV_SPI_ADD_LE] := 1
      wait.pause1ms(1)
      'OUTA[DEV_SPI_ADD_LE] := 0
                              ' 
    PUB Disable_SPI_EXT                        ' 
      OUTA[DEV_SPI_EN] := 1
    PUB StrobeCS
       OUTA[DEV_SPI_EN] := 0
       wait.pause1ms(10)
       OUTA[DEV_SPI_EN] := 1
    
    
    PUB TestTS  | yval, xval,x,y
      Enable_Touch       ''Old format was      OUTA[TS_CS] := 0     ' enable the touch screen
     'SPI.start(3,0)                                        ' delay,state     Already running?
      'Shiftout = data,clock,mode,bits,value
      'shiftin = data,clock,mode,bits
      'SPI read S, A2, A1, A0, Mode, SER, PD1, PD0
      '         1  0   0   1    1     0    0    0
      ' MSB first
      ' 001 is X
      ' 101 is Y
       repeat
          pst.clear
          SPI.SHIFTOUT(DEV_SD_DI, DEV_SD_CLK, 5, 8 , %1101_0000)  ' reads x from  500 to 3700  (off < 500 )
          xval := SPI.SHIFTIN(DEV_SD_DO, DEV_SD_CLK,2, 12)
          SPI.SHIFTOUT(DEV_SD_DI, DEV_SD_CLK, 5, 8 , %1001_0000)  ' reads y from 400 to 3800 (off > 3800 ) 
          yval := SPI.SHIFTIN(DEV_SD_DO,DEV_SD_CLK,2, 12)
          pst.Dec(xval)
          pst.newline
          pst.Dec(yval)
          wait.pause1ms(10)
      Disable_Touch       ''Old format was      OUTA[TS_CS] := 1     ' disable the touch screen 
    
    PUB PST_Init  | PstCog                                       ''Starts Parallax Serial Terminal for debugging.
      PstCog := (pst.Start(115200) -1)                             '' returns the cog pst started in
      pst.Str(String("Parallax Serial Terminal started in cog "))  ''  talk to human
      pst.Dec(PstCog)                                              '' displays cog on PST                                                  ''
      wait.pause1s(2) 
    '********************** private methods *********************
    PRI Enable_Touch
      OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_TSC_CS                              
      OUTA[DEV_SPI_EN] := 0                        ' 
    PRI Disable_Touch
      OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_TSC_CS                              
      OUTA[DEV_SPI_EN] := 0
    
    PRI LCD_Reset  
        OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_LCD_RES                              
        outa[DEV_SPI_EN] := 0         
        wait.pause1ms(5)                                  ''wait here if necessary                           ' 
        outa[DEV_SPI_EN] := 1
    
    These are the basics. Once I get propfont finished, I'll re-write in asm which should speed up the display quite a bit. 12 seconds to display a blank screen is a bit too slow IMO. 4 sounds WAY more reasonable.
  • average joeaverage joe Posts: 795
    edited 2012-02-22 14:05
    I've been working on the assembly program and had a lightbulb go off. I can save several instructions by adding a 10k pullup to the LCD write line. Instead of adding lcdwriteline to the data to be sent out, making pins = data, then pulling the write line low and back high again, flow will go make pins=data, mux lcdwrite*DIR* out, then back to input. I will be updating my hardware to this soon, but I'm writing without the update so I can test the difference this makes.

    I will also be using a pullup on RS. This will save some code too.
    edit,
    Made hardware changes. I'm obviously doing something wrong in my ASM test. I don't know what now, I'll have to come back to this in a bit. Maybe someone can find my mistake, I'm burnt out at this point.
    CON
      _clkmode      = xtal1 + pll16x                        ' use crystal x 16
      _xinfreq      = 5_000_000
    DEV_SPI_EN        = 21 
    PUB BOOT      'bootstrap
       dirA[DEV_SPI_EN] := 1
      OUTA[DEV_SPI_EN] := 1
    
      cognew(@entry, 0)
       repeat
          wait.pause1s(5)
    
    
    
    DAT
                   org 0                                                                                   
    entry             mov dira, DirsEnabled               'initalize pins
                      mov outa, PinsInit                  'and set write high
                                        'then initalize display
                      mov LCD_Data,asmREG_DISPLAYCONTROL                  ''Display Control (R07h) (POR = 0000h)
                      call #writecmd
                      mov LCD_Data,DISPLAYCONTROL0                                                 '' GON = 1 DTE = 0 D[1:0] = 01
                      call #writedat
                      mov LCD_Data,asmREG_OSCILLATOR                      ''Oscillator (R00h) (POR = 0000h)
                      call #writecmd
                      mov LCD_Data,OSCILLATOR                                                ''Turn on oscillator
                      call #writedat
                      mov LCD_Data,asmREG_DISPLAYCONTROL                  ''Display Control (R07h) (POR = 0000h)
                      call #writecmd
                      mov LCD_Data,DISPLAYCONTROL1                              ''GON = 1 DTE = 0 D[1:0] = 11
                      call #writedat
                      mov LCD_Data,asmREG_SLEEPMODE                       ''Sleep mode (R10h) (POR = 0001h)
                      call #writecmd
                      mov LCD_Data,SLEEPMODE     ''                        ''exit sleep mode
                      call #writedat
                      mov LCD_Data,asmREG_DISPLAYCONTROL                  ''Display Control (R07h) (POR = 0000h)
                      call #writecmd
                      mov LCD_Data,DISPLAYCONTROL2                             ''GON = 1 DTE = 1 D[1:0] = 11
                      call #writedat
                      mov LCD_Data,asmREG_ENTRYMODE                       ''Entry Mode (R11h) (POR = 6830h)
                      call #writecmd
                      mov LCD_Data,ENTRYMODE                              ''
                      call #writedat
                      mov LCD_Data,asmREG_LCDDRIVINGWAVFORM               ''LCD-Driving-Waveform Control (R02h) (POR = 0000h)($1000)
                      call #writecmd
                      mov LCD_Data,DRIVINGWAVEFORM  ''                        ''
                      call #writedat
                      mov LCD_Data,asmREG_GATESCANPOSITION                ''Gate Scan Position (R0Fh) (POR = 0000h)  ($0000)
                      call #writecmd
                      mov LCD_Data,GATESCANPOSITION                         ''
                      call #writedat
                      mov LCD_Data,asmREG_DRIVEROUTPUTCONTROL             ''Driver Output Control (R01h) (POR = [0XXXX0X1]3Fh) 433f    ($633F)
                      call #writecmd
                      mov LCD_Data,DRIVEROUTPUT                    ''
                      call #writedat
                      mov LCD_Data,asmREG_FRAMECYCLECONTROL               ''Frame Cycle Control (R0Bh) (POR = 5308h) ($5308)
                      call #writecmd
                      mov LCD_Data,FRAMECYCLE                               ''
                      call #writedat
                      mov LCD_Data,asmREG_DISPLAYCONTROL                  ''Display Control (R07h) (POR = 0000h) ($0033)
                      call #writecmd
                      mov LCD_Data,DISPLAYCONTROL2                               ''GON = 1 DTE = 1 D[1:0] = 11
                      call #writedat
    
    
                      mov LCD_Data,asmREG_DISPLAYCONTROL                  ''Display Control (R07h) (POR = 0000h) ($0033)
                      call #writecmd
                      mov LCD_Data,DISPLAYCONTROL2                               ''GON = 1 DTE = 1 D[1:0] = 11
                      call #writedat
    
    
                      mov LCD_Data,asmREG_HORIZONTALRAMADDRESSPOS
                      call #writecmd
                      mov LCD_Data,asmHORIZONTALRAMADDRESSPOS
                      call #writedat
                      
                      mov LCD_Data,asmREG_VERTICALRAMADDRESSSTART
                      call #writecmd
                      mov LCD_Data,#0
                      call #writedat
    
                      mov LCD_Data,asmREG_VERTICALRAMADDRESSEND
                      call #writecmd
                      mov LCD_Data,239
                      call #writedat
    
                      
    loop              mov LCD_Data,asmREG_RAMDATAWRITE 
                      call #writecmd 
                      mov LCD_Data,asmColor
                      call #writedat
    
                      jmp #loop
    
                                                                                                 
    writecmd                  
                             mov outa, LCD_Data             wc
                             nop
                             muxc   dira,RSpin
                             nop
                             muxnc  dira,WritePin
                             nop
                             muxc   dira,WritePin
                             nop
                             muxnc  dira,RSpin
                             nop
    writecmd_ret
    
    writedat
                             mov    outa, LCD_Data           wc
                             nop
                             muxnc  dira,WritePin
                             nop
                             muxc   dira,WritePin
                             nop
    writedat_ret
    
    
    
    asmColor                        long  $0000
    
            
    PinsInit                          long   %00000000_00000000_00000000_00000000
    DirsDisabled                      long   %00000000_00000000_11111111_11111111
    DirsEnabled                       long   %00000000_00000000_11111111_11111111
    BackgroundColorASM                long   $ffff
    ActiveColorASM                    long   $0000
    
    WritePin                          long %00000000_00000010_00000000_00000000
    RSPin                             long %00000000_00000001_00000000_00000000
    
      GATESCANPOSITION                long $0000_0000
      SLEEPMODE                       long $0000_0000
      OSCILLATOR                      long $0000_0001
      DISPLAYCONTROL0                 long $0000_0021
      DISPLAYCONTROL1                 long $0000_0023
      DISPLAYCONTROL2                 long $0000_0033
      
      FRAMECYCLE                      long $0000_5308
      DRIVEROUTPUT                    long $0000_6B3F
      DRIVINGWAVEFORM                 long $0000_1000                               
      ENTRYMODE                       long $0000_6838
    
      asmXADDRESSCOUNTER              long $0000_0000
      asmHORIZONTALRAMADDRESSPOS      long $0001_3F00
     
      asmREG_OSCILLATOR               long $0000_0000                          ''Oscillator                                (R00h) (POR = 0000h)
      asmREG_DRIVEROUTPUTCONTROL      long $0000_0001                          ''Driver Output Control                     (R01h) (POR = 2B3Fh)
      asmREG_LCDDRIVINGWAVFORM        long $0000_0002                          ''LCD-Driving-Waveform Control              (R02h) (POR = 0000h)
      asmREG_POWERCONTROL1            long $0000_0003                          ''                                          (R03H)
      asmREG_DISPLAYCONTROL           long $0000_0007                          ''Display Control                           (R07h) (POR = 0000h)
      asmREG_FRAMECYCLECONTROL        long $0000_000B                          ''Frame Cycle Control                       (R0Bh) (POR = 5308h)D308 BY DATASHEET
      asmREG_POWERCONTROL2            long $0000_000C                          ''                                          (R0Ch) (POR = 0004)
      asmREG_POWERCONTROL3            long $0000_000D                          ''                                          
      asmREG_POWERCONTROL4            long $0000_000E                          ''
      asmREG_GATESCANPOSITION         long $0000_000F                          ''Gate Scan Position                        (R0Fh) (POR = 0000h)
      asmREG_SLEEPMODE                long $0000_0010                          ''Sleep mode                                (R10h) (POR = 0001h)
      asmREG_ENTRYMODE                long $0000_0011                          ''Entry Mode                                (R11h) (POR = 6830h)             
      asmREG_HPORCH                   long $0000_0016                          ''                                          (R16h) (POR = EF1Ch)
      asmREG_VPORCH                   long $0000_0017                          ''                                          (R17h) (POR = 0003h)
      asmREG_POWERCONTROL5            long $0000_001E                          ''                                          
      asmREG_RAMDATAWRITE             long $0000_0022                          ''
      asmREG_RAMWRITEDATAMASK1        long $0000_0023                          ''                                          (R23h) (POR = 0000h)
      asmREG_RAMWRITEDATAMASK2        long $0000_0024                          ''                                          (R24h) (POR = 0000h)
      asmREG_VERTICALSCROLCONTROL1    long $0000_0041                          ''                                          (R41h) (POR = 0000h)
      asmREG_VERTICALSCROLCONTROL2    long $0000_0042                          ''                                          (R42h) (POR = 0000h)
      asmREG_HORIZONTALRAMADDRESSPOS  long $0000_0044                          ''                                          (R44h) (POR = EF00h)
      asmREG_VERTICALRAMADDRESSSTART  long $0000_0045                          ''                                          (R45h) (POR = 0000h)
      asmREG_VERTICALRAMADDRESSEND    long $0000_0046                          ''                                          (R46h) (POR = 013Fh)
      asmREG_FIRSTWINDOWSTART         long $0000_0048                          ''                                          (R48h) (POR = 0000h)
      asmREG_FIRSTWINDOWEND           long $0000_0049                          ''                                          (R49h) (POR = 013Fh)
      asmREG_SECONDWINDOWSTART        long $0000_004A                          ''                                          (R4Ah) (POR = 0000h)
      asmREG_SECONDWINDOWEND          long $0000_004B                          ''                                          (R4Bh) (POR = 013Fh)
      asmREG_SETGDDRXADDRESSCOUNTER   long $0000_004E                          ''                                          (R4Eh) (POR = 0000h)
      asmREG_SETGDDRYADDRESSCOUNTER   long $0000_004F                          ''                                          (R4Fh) (POR = 0000h)
    
    LCD_data                res 1
    
  • average joeaverage joe Posts: 795
    edited 2012-02-22 18:57
    Still no luck. I decided to try and get simple writes working. Here's where I'm at.
    'init display in spin, tristate pins, and pass to ASM
      cognew(@entry, 0)
       repeat
         wait.pause1s(5)
    
    DAT
                   org 0
    entry             mov outa, PinsInit                 
                      mov dira, DirsEnabled    
    
    :loop             mov LCD_Data,#$22
                             add zero,#0                                      wz
                             nop
                             muxz   dira,RSpin              nr
                             nop
                             muxnz  outa,RSpin              nr
                             nop
                             mov    outa,LCD_Data           nr
                             nop                        
                             muxz   dira,WritePin           nr
                             nop                         
                             muxnz  dira,WritePin           nr
                             nop
                             muxnz  dira,RSpin              nr
                             nop
    
                      mov LCD_Data,#$22
                             add zero,#0                                      wz
                             nop
                             muxnz  dira,RSpin               nr
                             nop
                             mov    outa, #LCD_Data          nr
                             nop
                             muxz   dira,WritePin            nr
                             nop
                             muxnz  dira,WritePin            nr
                             nop
    
    
                      jmp #:loop
    
    Should write characters. Maybe it's running too fast? I don't know ASM very well at all. Any help would be appreciated!
  • kuronekokuroneko Posts: 3,623
    edited 2012-02-22 19:03
    What you're doing here is running a huge loop full of nops. The nr modifier at the tail of your instructions stands for no result meaning the destination isn't affected. I don't think that's the idea here. So just remove them and let the insns do their default behaviour.
  • TylerSkylerTylerSkyler Posts: 72
    edited 2012-02-22 19:33
    Hey Joe! I have just a quick question.What would the 4-bit code for A white background be? I tried $255255255255, but its over 32bits.
  • average joeaverage joe Posts: 795
    edited 2012-02-22 19:40
    @Tyler, hex would be $FFFF. remember $ is Hex and hex is base 16. 0 - 9 and A thru F.
    Thanks Kuroneko, I'll try again. Not very good @asm.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-02-22 20:43
    @Tyler, the colors are two bytes RRRRRGGG_GGGBBBBB so you get 5 levels for red and blue, and 6 levels for green. White is 11111111_11111111 which is hex FFFF
  • TylerSkylerTylerSkyler Posts: 72
    edited 2012-02-22 21:35
    @Tyler, hex would be $FFFF. remember $ is Hex and hex is base 16. 0 - 9 and A thru F.
    Thanks Kuroneko, I'll try again. Not very good @asm.

    Thanks Joe! It worked perfectly(i need to read up on HEX im not familiar with it).

    @Dr. Acula I bypassed the 2K resistors and the SD Card still didn't work. I tested my links they seemed fine, but my program still returned "Failed to Mount"(-1). Are there any other issues that may cause the sd not to work? I have formatted it to FAT-16 and it's a Lexar SDHC 4GB Sd card(if that helps with the diagnosis).

    Thanks for your help,

    Tyler
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-02-22 22:06
    it's SDHC
    There's your problem. SDHC and SD are different protocols. Get a 2GB or smaller SD card, and it'll work.
  • average joeaverage joe Posts: 795
    edited 2012-02-22 22:43
    I have a working dat block. It writes a blank screen in a flash. I hope I can squeeze the character read and decode into the clock cycles wasted by the write loop. Very promising results. I'm glad I took the jump from spin to ASM. ASM is not that much harder, it's just it requires that much more though to making things work.
    DAT
                   org 0
    entry             mov outa, PinsInit 'and set write high        
                      mov dira, DirsEnabled    
    
    WrCmd                   mov outa,#$22
                            add    zero,#0                                   wz                      
                             muxz   dira,RSpin
    '                         add    pntr, #2           
    ':wait1                   djnz   pntr, :wait1                            
                             muxz   dira,WritePin
                            add    pntr, #16
    :wait2                   djnz   pntr, :wait2                                                
                             muxnz  dira,WritePin
                             add    pntr, #5           
    :wait3                   djnz   pntr, :wait3                         
                             muxnz  dira,RSpin
    
    
    WrDat                  
                           mov outa,asmColor
                             add    zero,#0                               wz
                             add    pntr, #4           
    :wait1                   djnz   pntr, :wait1
                             muxz   dira,WritePin
                             add    pntr, #16
                                
    :wait3                   djnz   pntr, :wait3
                             muxnz  dira,WritePin
                            add    pntr, #5
    :wait2                   djnz   pntr, :wait2                         '
                             'sub   asmColor,#1
                             'max    asmColor, BackgroundColorASM
    '                         add    pntr,waittime
    ':wait5                   djnz   pntr, :wait5                         
                      jmp #WrCmd
    
    I hooked the sd card on my screen back up, but I haven't tested it yet. Now that spin code works, I'm going to investigate again. The hardware mods work great. Getting ASM working was top priority, now on to sd card!
    *edit*
    the question I have now is on cognew formatting..
    is it?
    cognew(@entry, @buffer)
    or?
    cognew(@entry,@@buffer)
  • average joeaverage joe Posts: 795
    edited 2012-02-23 15:43
    Ok, now I'm really curious. I got things working, but it takes about 50something? seconds? to launch a new cog? Or am I really doing something wrong?
    PUB BOOT |cr  'bootstrap   
      dirA[DEV_SPI_ADD0]   := 1
      dirA[DEV_SPI_ADD1]   := 1
      dirA[DEV_SPI_EN]     := 1
      OUTA[LCD_WR]         := 0
      OUTA[RS]             := 0
      OUTA[DEV_SPI_EN]     := 1
      OUTA[DEV_SPI_ADD_LE] := 0
          PST_Init
       Init_SSD1289
       pst.str(string("init done, clearing screen"))
       pst.newline
      EnableDisplayPins
       FillScreen($0000)
      pst.str(string("clear, tri-stating pins"))
      pst.newline  
      TristateDisplayPins
      pst.str(string("tri-stated pins, starting cog with screen buffer address"))
      pst.newline
      pst.dec(@screenbuffer)
      pst.newline
      pst.dec(@@screenbuffer)   
       cr := (cognew(@entry,@long[screenbuffer])+ 1)
        pst.dec(cr)
        pst.newline
        pst.str(string("waiting"))
        pst.newline
        'StartAsm
        repeat
          
          repeat while (long[screenbuffer] <> 0)
            pst.str(string("waiting"))
            pst.newline
            wait.pause1s(1)
         pst.str(string("done"))
    
    PUB PST_Init  | PstCog                                       ''Starts Parallax Serial Terminal for debugging.
      PstCog := (pst.Start(115200) -1)                             '' returns the cog pst started in
      pst.Str(String("Parallax Serial Terminal started in cog "))  ''  talk to human
      pst.Dec(PstCog)                                              '' displays cog on PST                                                  ''
      wait.pause1s(1)
    PUB SetWindow(x1, y1, x2, y2) | HORIZONTALRAMADDRESSPOS
     WindowX1 := x1
     WindowX2 := x2
     WindowY1 := y1
     WindowY2 := y2
        HORIZONTALRAMADDRESSPOS := x1 + (x2 << 8)      
           Lcd_Write_Com (REG_HORIZONTALRAMADDRESSPOS)
           Lcd_Write_Data(HORIZONTALRAMADDRESSPOS)
           Lcd_Write_Com (REG_VERTICALRAMADDRESSSTART)
           Lcd_Write_Data(y1)
           Lcd_Write_Com (REG_VERTICALRAMADDRESSEND)
           Lcd_Write_Data(y2)
    PUB SetGAddress(x,y)
           Lcd_Write_Com (REG_SETGDDRxADDRESSCOUNTER) ''max %1111_1111, $FF
           Lcd_Write_Data(x)
           Lcd_Write_Com (REG_SETGDDRyADDRESSCOUNTER) ''max %1_0011_1111, $13f
           Lcd_Write_Data(y)
    PUB ClearScreen(color) | idxr, idxc
      SetWindow(0, 0, 239, 319)
      SetGAddress(0,0)
      repeat idxr from 0 to 76240
            Lcd_Write_Com(REG_RAMDATAWRITE)
            Lcd_Write_Data(Color)
    Row              := 0      
    Col              := 0
    
    PUB FillScreen(Color) | idxr, idxc
     SetWindow(0, 0, 239, 319)
     SetGAddress(0,0)
      repeat idxr from 0 to 76240
            Lcd_Write_Com(asmREG_RAMDATAWRITE)
            Lcd_Write_Data(Color)
    Row              := 0      
    Col              := 0 
    
    PUB EnableDisplayPins
        DIRA:=%00000001_11100000_11111111_11111111 ' , Reset, WR, RS and 16 data lines active    
    PUB TristateDisplayPins ' tristate all pins -                                                 
        DIRA:=%00000001_11100000_00000000_00000000 ''
    
    PRI Lcd_Write_Asm(V)                                   'handler for asm writes
        long[screenbuffer] := V                             'makes screen buffer = v
    
    
        
    PRI LCD_Writ_Bus(V) 
        OUTA[15..0]  := V
        WriteLow                                            ' write pin low
        WriteHigh                                           ' toggle write pin
    PRI Lcd_Write_Com(V)
        RSLow
        LCD_Writ_Bus(V)
    PRI Lcd_Write_Data(V)
        RSHigh
        LCD_Writ_Bus(V)  
    PRI RSLow                                        
        dira[RS] := 1
    PRI RSHigh
        dira[RS] := 0                 '
    PRI WriteLow                                    
        dira[LCD_WR] := 1                             ' 
    PRI WriteHigh
        dira[LCD_WR] := 0
    
    pub deadend
    repeat
       wait.pause1s(1)
    PUB EnableDisplayPins
        DIRA:=%00000001_11100000_11111111_11111111 ' , Reset, WR, RS and 16 data lines active    
    PUB TristateDisplayPins ' tristate all pins -                                                 
        DIRA:=%00000001_11100000_00000000_00000000 ''
    
    PRI Lcd_Write_Asm(V)                                   'handler for asm writes
        long[screenbuffer] := V                             'makes screen buffer = v
    
    
        
    PRI LCD_Writ_Bus(V) 
        OUTA[15..0]  := V
        WriteLow                                            ' write pin low
        WriteHigh                                           ' toggle write pin
    PRI Lcd_Write_Com(V)
        RSLow
        LCD_Writ_Bus(V)
    PRI Lcd_Write_Data(V)
        RSHigh
        LCD_Writ_Bus(V)  
    PRI RSLow                                        
        dira[RS] := 1
    PRI RSHigh
        dira[RS] := 0                 '
    PRI WriteLow                                    
        dira[LCD_WR] := 1                             ' 
    PRI WriteHigh
        dira[LCD_WR] := 0
    
    pub deadend
    repeat
       wait.pause1s(1)
    PUB Init_SSD1289                                        ''Init Display
        EnableDisplayPins                                   ''enable pins 0 to 15
        ' WriteHigh
        
        'LCD_Reset                                          ''reset screen
        'wait.pause1ms(5)                                      
        'LCD_Reset          ''then init screen
        'wait.pause1ms(5)
        Lcd_Write_Com (REG_DISPLAYCONTROL)                  ''Display Control (R07h) (POR = 0000h) 
        Lcd_Write_Data($0021)                               ''GON = 1 DTE = 0 D[1:0] = 01
        
        Lcd_Write_Com (REG_OSCILLATOR)                      ''Oscillator (R00h) (POR = 0000h)
        Lcd_Write_Data($0001)                               ''Turn on oscillator
        
        Lcd_Write_Com (REG_DISPLAYCONTROL)                  ''Display Control (R07h) (POR = 0000h)
        Lcd_Write_Data($0023)                               ''GON = 1 DTE = 0 D[1:0] = 11
                
        Lcd_Write_Com (REG_SLEEPMODE)                       ''Sleep mode (R10h) (POR = 0001h)
        Lcd_Write_Data($0000)     ''                        ''exit sleep mode
        
        Lcd_Write_Com (REG_DISPLAYCONTROL)                  ''Display Control (R07h) (POR = 0000h)
        Lcd_Write_Data($0033)                               ''GON = 1 DTE = 1 D[1:0] = 11
        
        Lcd_Write_Com (REG_ENTRYMODE)                       ''Entry Mode (R11h) (POR = 6830h)
        Lcd_Write_Data($6838)                               ''
        
        Lcd_Write_Com (REG_LCDDRIVINGWAVFORM)               ''LCD-Driving-Waveform Control (R02h) (POR = 0000h)($1000) 
        Lcd_Write_Data($1000)     ''                        ''
        
        Lcd_Write_Com (REG_GATESCANPOSITION)                ''Gate Scan Position (R0Fh) (POR = 0000h)  ($0000)
        Lcd_Write_Data($0000)     ''                        ''
                                            ''
        Lcd_Write_Com (REG_DRIVEROUTPUTCONTROL)             ''Driver Output Control (R01h) (POR = [0XXXX0X1]3Fh) 433f    ($633F) 
        Lcd_Write_Data($6B3F) ''                            ''
                                        
        Lcd_Write_Com (REG_FRAMECYCLECONTROL)               ''Frame Cycle Control (R0Bh) (POR = 5308h) ($5308)
        Lcd_Write_Data($5308)                               ''
                '
        Lcd_Write_Com (REG_DISPLAYCONTROL)                  ''Display Control (R07h) (POR = 0000h) ($0033)
        Lcd_Write_Data($0033)                               ''GON = 1 DTE = 1 D[1:0] = 11 
    
        'TristateDisplayPins
       'deadend
    DAT                                             'init
                   org 0
    entry             mov outa, PinsInit                          'set pins to inital state       
                      mov dira, DirsEnabled                       'enables p0 - p15
                      mov bufferaddress, par                      'store par in bufferaddress, par is screen buffer address at startup 
                      'wrlong zero, bufferaddress                                  'set par to zero to confirm load done
    
                      
                                                   'get write command from buffer, and check if it's 0
                                                   
    'Get                     rdlong LCD_cmd, bufferaddress            'get long from main memory and put it in ldc command, msW = LCD cmd, LSw = LCD data
    '                        cmp    Lcd_cmd, #0                 wz    'and check if it's 0
    'if_z                    jmp #get                                 'if it is, try again.
    
    
                                                   'if not, prepare transfer
                                                   
    '                        mov LCD_Data, LCD_cmd                    'copy lcd command to lcd data
    '                        and LCD_Data, lowWordMask                'mask off High word of Lcd_Data
    
    '                        shr LCD_cmd,  #16                        'move lcd command 16 bit to the right if not gddr write
    '                        cmp LCD_cmd, #22                   wz    'check to see if this is a gddr write  
    'if_nz                   jmp WRcmd         
                                            'optimized write to display, for gddr transfer
    
    
    
    
     WrCmdfix                   mov outa,#$22
                            add    zero,#0                                   wz                      
                             muxz   dira,RSpin
                             add    pntr, #6           
    :wait1                   djnz   pntr, :wait1                            
                             muxz   dira,WritePin
                            add    pntr, #16
    :wait2                   djnz   pntr, :wait2                                                
                             muxnz  dira,WritePin
                             add    pntr, #5          
    :wait3                   djnz   pntr, :wait3                         
                             muxnz  dira,RSpin
    
    
    WrDatafix                  
                           mov outa,#$1ff
                             add    zero,#0                               wz
                             add    pntr, #6           
    :wait1                   djnz   pntr, :wait1
                             muxz   dira,WritePin
                             add    pntr, #16
                                
    :wait3                   djnz   pntr, :wait3
                             muxnz  dira,WritePin
                            add    pntr, #5
    :wait2                   djnz   pntr, :wait2                         '
                             'sub   asmColor,#1
                            ' max    asmColor, BackgroundColorASM
                             add    pntr,#16
    :wait5                   djnz   pntr, :wait5
                             wrlong zero, bufferaddress                        
                      jmp #WrCmdfix
    
    zero                              long $0
    waittime                          long $6  
    asmColor                          long  $0000_ffff
                                              
    PinsInit                          long   %00000000_00000000_00000000_00000000
    DirsDisabled                      long   %00000000_00000000_00000000_00000000
    DirsEnabled                       long   %00000000_00000000_11111111_11111111
    BackgroundColorASM                long   $0000_ffff
    ActiveColorASM                    long   $0000
    
    WritePin                          long %00000000_00000010_00000000_00000000
    RSPin                             long %00000000_00000001_00000000_00000000
    
    lowWordMask                       long $0000_ffff              
    
    
      GATESCANPOSITION                long $0000_0000
      SLEEPMODE                       long $0000_0000
      OSCILLATOR                      long $0000_0001
      FRAMECYCLE                      long $0000_5308
      DRIVEROUTPUT                    long $0000_6B3F
      DRIVINGWAVEFORM                 long $0000_1000                               
      ENTRYMODE                       long $0000_6838
      
      DISPLAYCONTROL0                 long $0000_0021
      DISPLAYCONTROL1                 long $0000_0023
      DISPLAYCONTROL2                 long $0000_0033
       
      asmXADDRESSCOUNTER              long $0000_0000
      asmHORIZONTALRAMADDRESSPOS      long $0001_3F00
     
      asmREG_OSCILLATOR               long $0000_0000                          ''Oscillator                                (R00h) (POR = 0000h)
      asmREG_DRIVEROUTPUTCONTROL      long $0000_0001                          ''Driver Output Control                     (R01h) (POR = 2B3Fh)
      asmREG_LCDDRIVINGWAVFORM        long $0000_0002                          ''LCD-Driving-Waveform Control              (R02h) (POR = 0000h)
      asmREG_POWERCONTROL1            long $0000_0003                          ''                                          (R03H)
      asmREG_DISPLAYCONTROL           long $0000_0007                          ''Display Control                           (R07h) (POR = 0000h)
      asmREG_FRAMECYCLECONTROL        long $0000_000B                          ''Frame Cycle Control                       (R0Bh) (POR = 5308h)D308 BY DATASHEET
      asmREG_POWERCONTROL2            long $0000_000C                          ''                                          (R0Ch) (POR = 0004)
      asmREG_POWERCONTROL3            long $0000_000D                          ''                                          
      asmREG_POWERCONTROL4            long $0000_000E                          ''
      asmREG_GATESCANPOSITION         long $0000_000F                          ''Gate Scan Position                        (R0Fh) (POR = 0000h)
      asmREG_SLEEPMODE                long $0000_0010                          ''Sleep mode                                (R10h) (POR = 0001h)
      asmREG_ENTRYMODE                long $0000_0011                          ''Entry Mode                                (R11h) (POR = 6830h)             
      asmREG_HPORCH                   long $0000_0016                          ''                                          (R16h) (POR = EF1Ch)
      asmREG_VPORCH                   long $0000_0017                          ''                                          (R17h) (POR = 0003h)
      asmREG_POWERCONTROL5            long $0000_001E                          ''                                          
      asmREG_RAMDATAWRITE             long $0000_0022                          ''
      asmREG_RAMWRITEDATAMASK1        long $0000_0023                          ''                                          (R23h) (POR = 0000h)
      asmREG_RAMWRITEDATAMASK2        long $0000_0024                          ''                                          (R24h) (POR = 0000h)
      asmREG_VERTICALSCROLCONTROL1    long $0000_0041                          ''                                          (R41h) (POR = 0000h)
      asmREG_VERTICALSCROLCONTROL2    long $0000_0042                          ''                                          (R42h) (POR = 0000h)
      asmREG_HORIZONTALRAMADDRESSPOS  long $0000_0044                          ''                                          (R44h) (POR = EF00h)
      asmREG_VERTICALRAMADDRESSSTART  long $0000_0045                          ''                                          (R45h) (POR = 0000h)
      asmREG_VERTICALRAMADDRESSEND    long $0000_0046                          ''                                          (R46h) (POR = 013Fh)
      asmREG_FIRSTWINDOWSTART         long $0000_0048                          ''                                          (R48h) (POR = 0000h)
      asmREG_FIRSTWINDOWEND           long $0000_0049                          ''                                          (R49h) (POR = 013Fh)
      asmREG_SECONDWINDOWSTART        long $0000_004A                          ''                                          (R4Ah) (POR = 0000h)
      asmREG_SECONDWINDOWEND          long $0000_004B                          ''                                          (R4Bh) (POR = 013Fh)
      asmREG_SETGDDRXADDRESSCOUNTER   long $0000_004E                          ''                                          (R4Eh) (POR = 0000h)
      asmREG_SETGDDRYADDRESSCOUNTER   long $0000_004F                          ''                                          (R4Fh) (POR = 0000h)
    
    currentwait             res 1
    bufferaddress           res 1
    Longin                  res 1
    LCD_cmd                 res 1
    LCD_data                res 1
     Pntr                   res 1
     c res 1
    
    it runs. screen clears slowly, then displays wait for 50 +seconds. Then draws, and done? is there some way to start a cog faster?

    *edit* PST displays this
    clear, tri-stating pins
    tri-stated pins, starting cog with screen buff
    er address
    3292
    163
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    waiting
    donedonedonedonedonedonedonedonedonedonedonedo
  • kuronekokuroneko Posts: 3,623
    edited 2012-02-23 15:48
    A 50sec delay is usually an indicator that waitcnt just missed its target and is now waiting for a full wrap-around. Can you figure out where in your code it blocks (delay could be in an object)?
  • average joeaverage joe Posts: 795
    edited 2012-02-23 16:16
    the only objects are Parallax Serial Terminal, and timing. It SEEMS to get stuck between the code, and never displays cr?
     pst.dec(@@screenbuffer)
      cr := (cognew(@entry,@long[screenbuffer])+ 1)
        pst.dec(cr)
    
    init done, clearing screen
    clear, tri-stating pins
    tri-stated pins, starting cog with screen buff
    er address
    3292
    163
    waiting * 52 times then..
    donedonedonedonedonedonedonedonedonedonedon

    *edit* Fixed it..
    I can be so dumb sometimes. Changed first wait to
                             add    pntr, #6           
    :wait1                   djnz   pntr, :wait1 
    
    to the RIGHT one
                             mov   pntr, #6           
    :wait1                 djnz   pntr, :wait1 
    
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-02-24 05:51
    This is a little bit of code for those that can print a pixel but can't get an SD card working in order to display a font. Uses the internal propeller font which is inside the propeller chip.
    PUB Propfont  ' use propeller font in the rom for bootup messages when debugging sd cards
        curx := 0                               ' set cursor to top left of screen (common variable)
        cury := 0
        Propfont_string(string("Loading SD"))   ' string to send
        Propfont_string(string("Loading Font"))
    
    PUB Propfont_string(stringptr)                          'print at curx,cury
      repeat strsize(stringptr)
        ILI9325.draw(curx,cury,curx+15,cury+31)             ' location to start drawing    
        Propfont_out(byte[stringptr++])   
        curx +=16
      curx := 0
      cury += 32                                            ' new line at end of string
    
    PUB Propfont_out(ascii) | address,pixels
        address := $8000 + (ascii >> 1) << 7                ' get rom address
        repeat 32                                           ' 32 rows per character, split in two parts
          pixels := long[address]                           ' get rom font data
          pixels := pixels >> (ascii & 1)                    ' shift for odd characters
          repeat 16 ' 16 columns
            if pixels & 1
              ILI9325.pixel(%00000111_11100000)             ' foreground color RRRRRGGG_GGGBBBBB
            else
              ILI9325.pixel(%00000000_00000000)             ' background color 
            pixels := pixels >> 2                           ' alternate pixels interleaved so shift 2
          address += 4                                      'increment address by 4 bytes
    
    320 x 200 - 13K
Sign In or Register to comment.