Ik ben nu aan het testen met een 1,3"Oled display, 240 * 240 met SPI interface (IC: ST7789).
Ik heb geprobeerd om het programma van Arco om te te zetten naar een PIC16F887, maar lukt niet echt:
pic basic code:
e MikroBasic code om te testen (past nog in de demo versie van de dsPic compiler):
pic basic code:
'==================================================================================================
' Project name: Test_Oled - CONFIG1 : 0x3F7F
' MCU: PIC24FJ256GA106 - CONFIG2 : 0x92BE
' Oscillator: HS, 8.0000 MHz - CONFIG3 : 0xFFFF
'==================================================================================================
program Test_Oled
Dim SSel As sBit At LATD.9 'Display select
D_C As sBit At LATF.5 'Data/Command
const Char6x8 As Byte[570] = ( 'Character table
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ' sp
0x00, 0x00, 0x00, 0x2f, 0x00, 0x00, ' !
0x00, 0x00, 0x07, 0x00, 0x07, 0x00, ' "
0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14, ' #
0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12, ' $
0x00, 0x62, 0x64, 0x08, 0x13, 0x23, ' %
0x00, 0x36, 0x49, 0x55, 0x22, 0x50, ' &
0x00, 0x00, 0x05, 0x03, 0x00, 0x00, ' '
0x00, 0x00, 0x1c, 0x22, 0x41, 0x00, ' (
0x00, 0x00, 0x41, 0x22, 0x1c, 0x00, ' )
0x00, 0x14, 0x08, 0x3E, 0x08, 0x14, ' *
0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, ' +
0x00, 0x00, 0x00, 0xA0, 0x60, 0x00, ' ,
0x00, 0x08, 0x08, 0x08, 0x08, 0x08, ' -
0x00, 0x00, 0x60, 0x60, 0x00, 0x00, ' .
0x00, 0x20, 0x10, 0x08, 0x04, 0x02, ' /
0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, ' 0
0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, ' 1
0x00, 0x42, 0x61, 0x51, 0x49, 0x46, ' 2
0x00, 0x21, 0x41, 0x45, 0x4B, 0x31, ' 3
0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, ' 4
0x00, 0x27, 0x45, 0x45, 0x45, 0x39, ' 5
0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30, ' 6
0x00, 0x01, 0x71, 0x09, 0x05, 0x03, ' 7
0x00, 0x36, 0x49, 0x49, 0x49, 0x36, ' 8
0x00, 0x06, 0x49, 0x49, 0x29, 0x1E, ' 9
0x00, 0x00, 0x36, 0x36, 0x00, 0x00, ' :
0x00, 0x00, 0x56, 0x36, 0x00, 0x00, ' ;
0x00, 0x08, 0x14, 0x22, 0x41, 0x00, ' <
0x00, 0x14, 0x14, 0x14, 0x14, 0x14, ' =
0x00, 0x00, 0x41, 0x22, 0x14, 0x08, ' >
0x00, 0x02, 0x01, 0x51, 0x09, 0x06, ' ?
0x00, 0x32, 0x49, 0x59, 0x51, 0x3E, ' @
0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C, ' A
0x00, 0x7F, 0x49, 0x49, 0x49, 0x36, ' B
0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, ' C
0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C, ' D
0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, ' E
0x00, 0x7F, 0x09, 0x09, 0x09, 0x01, ' F
0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A, ' G
0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, ' H
0x00, 0x00, 0x41, 0x7F, 0x41, 0x00, ' I
0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, ' J
0x00, 0x7F, 0x08, 0x14, 0x22, 0x41, ' K
0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, ' L
0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F, ' M
0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F, ' N
0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, ' O
0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, ' P
0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E, ' Q
0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, ' R
0x00, 0x46, 0x49, 0x49, 0x49, 0x31, ' S
0x00, 0x01, 0x01, 0x7F, 0x01, 0x01, ' T
0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, ' U
0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F, ' V
0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F, ' W
0x00, 0x63, 0x14, 0x08, 0x14, 0x63, ' X
0x00, 0x07, 0x08, 0x70, 0x08, 0x07, ' Y
0x00, 0x61, 0x51, 0x49, 0x45, 0x43, ' Z
0x00, 0x00, 0x7F, 0x41, 0x41, 0x00, ' [
0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55, ' \
0x00, 0x00, 0x41, 0x41, 0x7F, 0x00, ' ]
0x00, 0x04, 0x02, 0x01, 0x02, 0x04, ' ^
0x00, 0x40, 0x40, 0x40, 0x40, 0x40, ' _
0x00, 0x00, 0x01, 0x02, 0x04, 0x00, ' '
0x00, 0x20, 0x54, 0x54, 0x54, 0x78, ' a
0x00, 0x7F, 0x48, 0x44, 0x44, 0x38, ' b
0x00, 0x38, 0x44, 0x44, 0x44, 0x20, ' c
0x00, 0x38, 0x44, 0x44, 0x48, 0x7F, ' d
0x00, 0x38, 0x54, 0x54, 0x54, 0x18, ' e
0x00, 0x08, 0x7E, 0x09, 0x01, 0x02, ' f
0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C, ' g
0x00, 0x7F, 0x08, 0x04, 0x04, 0x78, ' h
0x00, 0x00, 0x44, 0x7D, 0x40, 0x00, ' i
0x00, 0x40, 0x80, 0x84, 0x7D, 0x00, ' j
0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, ' k
0x00, 0x00, 0x41, 0x7F, 0x40, 0x00, ' l
0x00, 0x7C, 0x04, 0x18, 0x04, 0x78, ' m
0x00, 0x7C, 0x08, 0x04, 0x04, 0x78, ' n
0x00, 0x38, 0x44, 0x44, 0x44, 0x38, ' o
0x00, 0xFC, 0x24, 0x24, 0x24, 0x18, ' p
0x00, 0x18, 0x24, 0x24, 0x18, 0xFC, ' q
0x00, 0x7C, 0x08, 0x04, 0x04, 0x08, ' r
0x00, 0x48, 0x54, 0x54, 0x54, 0x20, ' s
0x00, 0x04, 0x3F, 0x44, 0x40, 0x20, ' t
0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C, ' u
0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C, ' v
0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C, ' w
0x00, 0x44, 0x28, 0x10, 0x28, 0x44, ' x
0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C, ' y
0x00, 0x44, 0x64, 0x54, 0x4C, 0x44, ' z
0x00, 0x10, 0x6C, 0x82, 0x00, 0x00, ' {
0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, ' |
0x00, 0x00, 0x00, 0x82, 0x6C, 0x10, ' }
0x14, 0x14, 0x14, 0x14, 0x14, 0x14) ' horiz lines
'==================================================================================================
Sub Procedure Init_App() 'Initialize pillbox
'==================================================================================================
Dim lRet As Byte
delay_ms(100)
TRISD = %0000000000001011 '
TRISF = %0000000000000000 '
LATD = %0000001000000010 '
LATF = %0000000000000000 '
Unlock_IOLock()
PPS_Mapping_NoLock( 3,_OUTPUT,_SDO1) 'RP3 (= LATD.10 pin)
PPS_Mapping_NoLock(12,_OUTPUT,_SCK1OUT) 'RP12 (= LATD.11 pin)
Lock_IOLock()
Spi1_Init_Advanced(_SPI_MASTER,
_SPI_8_BIT,
_SPI_PRESCALE_SEC_1,
_SPI_PRESCALE_PRI_16,
_SPI_SS_DISABLE,
_SPI_DATA_SAMPLE_MIDDLE,
_SPI_CLK_IDLE_HIGH,
_SPI_IDLE_2_ACTIVE)
Delay_ms(100)
End Sub
'==================================================================================================
Sub Procedure Lcd_WrCmd(Dim pCmd As Byte) 'Write command to display
'==================================================================================================
D_C = 0
Spi1_Write(pCmd)
End Sub
'==================================================================================================
Sub Procedure Lcd_WrDat(Dim pDat As Byte) 'Write data to display
'==================================================================================================
Dim lCnt As Byte
D_C = 1
Spi1_Write(pDat)
End Sub
'==================================================================================================
Sub Procedure Lcd_SetPos(Dim px, py as Byte) 'Set write position on display
'==================================================================================================
delay_us(1)
Lcd_WrCmd(0xB0 + py)
Lcd_WrCmd((px >> 4) Or 0x10)
Lcd_WrCmd((px And 0x0F))
delay_us(1)
End Sub
'==================================================================================================
Sub Procedure LCD_Fill(Dim pFill As Byte) 'Fill display with character pFill
'==================================================================================================
Dim lx, ly As Byte
For ly = 0 To 8
Lcd_WrCmd(0xB0+ly)
Lcd_WrCmd(0x01)
Lcd_WrCmd(0x10)
For lx = 0 to 131
Lcd_WrDat(pFill)
Next lx
Next ly
End Sub
'==================================================================================================
Sub Procedure Lcd_Char_6x8(Dim px, py, pchar As Byte) 'Write one character
'==================================================================================================
Dim lIndex As Word
Lcd_SetPos(px, py)
lIndex = pChar - 0x20
lIndex = (lIndex << 2) + (lIndex << 1)
Lcd_WrDat(Char6x8[lIndex+0])
Lcd_WrDat(Char6x8[lIndex+1])
Lcd_WrDat(Char6x8[lIndex+2])
Lcd_WrDat(Char6x8[lIndex+3])
Lcd_WrDat(Char6x8[lIndex+4])
Lcd_WrDat(Char6x8[lIndex+5])
End Sub
'==================================================================================================
Sub Procedure Lcd_String_6x8(Dim px, py As Byte, Dim ByRef pDisp As String) ' Write string
'==================================================================================================
Dim lLen, lCnt As Byte
lLen = Length(pDisp)
For lCnt = 0 To (lLen-1)
If px >= 124 Then px = 0 py = py+1 End If
Lcd_Char_6x8(px, py, pDisp[lCnt])
px = px + 6
Next lCnt
End Sub
'==================================================================================================
Main: 'Main program
'==================================================================================================
Init_App() 'Initialize
SSel = 0
delay_ms(500)
SSEL = 1 'Only for 0.96", for 1.3" remove it
delay_ms(500)
Lcd_WrCmd(0xAE) 'Turn OLED panel off
'--------------------------------------------------------------------------
Lcd_WrCmd(0xA8) 'Multiplex ratio set to
Lcd_WrCmd(0x3F) '63
'--------------------------------------------------------------------------
Lcd_WrCmd(0xD3) 'Display offset RAM counter
Lcd_WrCmd(0x00) 'none
'--------------------------------------------------------------------------
Lcd_WrCmd(0x40) 'Start line address
'--------------------------------------------------------------------------
Lcd_WrCmd(0xA1) 'Set segment remap rotation to left
'--------------------------------------------------------------------------
Lcd_WrCmd(0xC8) 'Common output scan direction
'--------------------------------------------------------------------------
Lcd_WrCmd(0xDA) 'Common signals pad
Lcd_WrCmd(0x12) 'value
'--------------------------------------------------------------------------
Lcd_WrCmd(0x81) 'Contrast control
Lcd_WrCmd(0xFF) 'value
'--------------------------------------------------------------------------
Lcd_WrCmd(0xA4)
'--------------------------------------------------------------------------
Lcd_WrCmd(0xA6) 'Normal display
'--------------------------------------------------------------------------
Lcd_WrCmd(0xD5) 'Clock ratio:oscillator frequency
Lcd_WrCmd(0x80) 'oooo:rrrr
'--------------------------------------------------------------------------
Lcd_WrCmd(0x8D)
Lcd_WrCmd(0x14)
'--------------------------------------------------------------------------
Lcd_WrCmd(0x00) 'Set lower column address
Lcd_WrCmd(0x10) 'Set higher column address
'--------------------------------------------------------------------------
Lcd_WrCmd(0xD9) '15 clocks, discharge 1 clock
Lcd_WrCmd(0xF1) 'dddd:pppp
'--------------------------------------------------------------------------
Lcd_WrCmd(0xDB) 'Common output voltage
Lcd_WrCmd(0x40) 'level
'--------------------------------------------------------------------------
Lcd_WrCmd(0x20) 'Addressing mode
Lcd_WrCmd(0x02) 'value
'--------------------------------------------------------------------------
' Lcd_WrCmd(0xA7)
Lcd_Fill(0x00)
Lcd_SetPos(0,0)
'--------------------------------------------------------------------------
Lcd_String_6x8(0,0,"Dit is een test van")
Lcd_String_6x8(0,1,"een 128x64 pixel gra-")
Lcd_String_6x8(0,2,"fisch OLED display.")
Lcd_String_6x8(0,3,"Met 't 6x8 pixel font")
Lcd_String_6x8(0,4,"gaat er heel wat in-")
Lcd_String_6x8(0,5,"formatie op zo'n mini")
Lcd_String_6x8(0,6,"scherm van 1.1x2.2cm")
Lcd_String_6x8(0,7,"(en toch nog scherp!)")
Lcd_WrCmd(0xAF) 'Turn OLED panel on
delay_ms(500)
SSel = 1
While True
Wend
End.
Deze routines
pic basic code:
Unlock_IOLock()
PPS_Mapping_NoLock( 3,_OUTPUT,_SDO1) 'RP3 (= LATD.10 pin)
PPS_Mapping_NoLock(12,_OUTPUT,_SCK1OUT) 'RP12 (= LATD.11 pin)
Lock_IOLock()
Spi1_Init_Advanced(_SPI_MASTER,
_SPI_8_BIT,
_SPI_PRESCALE_SEC_1,
_SPI_PRESCALE_PRI_16,
_SPI_SS_DISABLE,
_SPI_DATA_SAMPLE_MIDDLE,
_SPI_CLK_IDLE_HIGH,
_SPI_IDLE_2_ACTIVE)
lopen sowieso al niet (kunnen ws dus niet bij de 887).
Ik heb de poorten aangepast, maar zonder resultaat (display doet niks)