timerlan |
Дата: Пт, 22.04.2016, 06:21 | Сообщение # 24 |
Группа:
Проверенные
Ранг:
Понимаю
Сообщений:
94
Замечания:
±
На сайте с 18.03.2012
Статус:
Offline
|
этот экран монохром, активный-синий, молчит-черный..
для GLCD попробую поискать, спасибо за наводку!.
Добавлено (22.04.2016, 06:10) ---------------------------------------------
--------------------------------------------- Всем привет! Вот такой код выводит <HELLO WORLD> на панель:
ADCON0=0 ADCON1=7
'========================== MAIN Routine ==============================
'=================== SSD1306 ADDRESS AND CONSTANTS ======================== SSD_i_Device CON $78 ' Normally $78 SSD_i_DeviceCommand CON $00 SSD_i_DataCommand CON $40 '========================= SSD Variables ================================== SCL var PortC.3 ' I2C Clock PortC.3 move if using more than one I2C device SDA var PortC.4 ' I2C Data PortC.4 move if using more than one I2C device SSD_BUFF VAR BYTE[27] ' pass through to Display SSD_i_Byte2Send VAR BYTE ' Prepared byte to be sent to Display SSD_i_Byte2Send2 VAR BYTE ' Prepared Byte to be sent to Display
SSD_i_Column VAR BYTE' LCD Column POSITION (0 TO 127) SSD_i_Row VAR BYTE'LCD Line POSITION FOR PAGE MODE(0 TO 7)
SSD_i_CharIndex var word 'Char codes index SSD_i_CharIndexT var byte 'char codes index temp SSD_i_OffsetTemp var byte ' calculating offset into tables
SSD_i_StringWork var byte 'index for text SSD_i_Char2send var byte 'data carrier for text chars
goto SSD1306_i_Around ' this is an add-in so go around
'==================== SSD1306 initialization =============================== SSD_Init: pause 10
SSD_i_Byte2Send=$AE GOSUB SSD_i_SendCommand 'Display OFF
SSD_i_Byte2Send=$D3 SSD_i_Byte2Send2=$00 GOSUB SSD_i_SendCommand2 ' Set offset to 0
SSD_i_Byte2Send=$8D SSD_i_Byte2Send2=$14 GOSUB SSD_i_SendCommand2' Set Charge Pump Internal, usually needed
SSD_i_Byte2Send=$20 SSD_i_Byte2Send2=$10 GOSUB SSD_i_SendCommand2' Adressing mode $10=Page, $00=Horizontal
SSD_i_Byte2Send=$A1 GOSUB SSD_i_SendCommand ' set segment remap column 127 as start
SSD_i_Byte2Send=$C8 GOSUB SSD_i_SendCommand ' Com Scan Direction, Flip display vertically
SSD_i_Byte2Send=$DA SSD_i_Byte2Send2=$12 GOSUB SSD_i_SendCommand2 ' set COM pins = 128x64=$12 128x32=$02
SSD_i_Byte2Send=$81 SSD_i_Byte2Send2=$ff GOSUB SSD_i_SendCommand2 ' Set contrast to $01 to $FF ($7F is default, $01 is faint)
SSD_i_Byte2Send=$A4 GOSUB SSD_i_SendCommand ' display ON continue
SSD_i_Byte2Send=$A6 GOSUB SSD_i_SendCommand ' $A6=NORMAL MODE; $A7=INVERSE MODE
SSD_i_Byte2Send=$AF GOSUB SSD_i_SendCommand 'Display ON
GOSUB SSD_Clear return '======================Print Lines============================================== SSD_Print: SSD_i_StringWork = 0 ' set index to beginning DO while SSD_BUFF[SSD_i_StringWork] <> 0 SSD_i_Char2send = SSD_BUFF[SSD_i_StringWork] ' pull letter out of array gosub SSD_i_BuildChar ' Build char and send out SSD_i_StringWork = SSD_i_StringWork + 1 ' point to next char loop return
SSD_PrintXY: SSD_i_Column=SSD_BUFF[0] ' Column in first position SSD_i_Row=SSD_BUFF[1] ' Row in second gosub SSD_i_SetXY ' set cursor position SSD_i_StringWork = 2 ' now point to first character to print DO while SSD_BUFF[SSD_i_StringWork] <> 0 SSD_i_Char2send = SSD_BUFF[SSD_i_StringWork] gosub SSD_i_BuildChar SSD_i_StringWork = SSD_i_StringWork + 1 loop return
'===================== Send data ============================================= SSD_i_SendData: I2CWrite SDA,SCL,SSD_i_Device,[SSD_i_DataCommand,SSD_i_Byte2Send] RETURN '==================== Send Command =========================================== SSD_i_SendCommand: I2CWrite SDA,SCL,SSD_i_Device,[SSD_i_DeviceCommand,SSD_i_Byte2Send] RETURN '==================== Send Command =========================================== SSD_i_SendCommand2: I2CWrite SDA,SCL,SSD_i_Device,[SSD_i_DeviceCommand, SSD_i_Byte2Send, SSD_i_Byte2Send2] RETURN '============================== clear ======================================== SSD_Clear: SSD_i_Column=0 'SSD_i_Row=0 FOR SSD_i_Row=0 TO 7 gosub SSD_i_SetXY FOR SSD_i_OffsetTemp=0 TO 127 I2CWrite SDA,SCL,SSD_i_Device,[SSD_i_DataCommand,0] 'Send 0 to every column in every line 'GOSUB SSD_i_SendData NEXT SSD_i_OffsetTemp NEXT SSD_i_Row SSD_i_Column=0 : SSD_i_Row=0 : gosub SSD_i_SetXY ' Go Home RETURN '===========================================SET X AND Y========================= SSD_i_SetXY: SSD_i_Byte2Send=$21:GOSUB SSD_i_SendCommand SSD_i_Byte2Send=SSD_i_Column:GOSUB SSD_i_SendCommand SSD_i_Byte2Send=127:GOSUB SSD_i_SendCommand 'Above 3 lines means; Column starts at SSD_i_Column and End at 127 SSD_i_Byte2Send=$22:GOSUB SSD_i_SendCommand SSD_i_Byte2Send=SSD_i_Row:GOSUB SSD_i_SendCommand SSD_i_Byte2Send=SSD_i_Row:GOSUB SSD_i_SendCommand 'Above 3 lines means; Line starts at SSD_i_Row and end at SSD_i_Row, 'which means ; Only work on specified line! RETURN '===================== Build Character and Send===================================== SSD_i_BuildChar: ' Enter this Subroutine with printable character: SSD_i_Char2send ' SSD_i_Char2send is subtracted from " " (space char) and * by 5 to be able to index into one table ' One table is broken into 3 to avoid the 255 max. Index into table must be a byte variable.
SSD_i_OffsetTemp = SSD_i_Char2send - 32 ' Space is now at index 0 all other characters are 32 less into index SSD_i_OffsetTemp = SSD_i_OffsetTemp * 5 ' Every character is made of 5 bytes for SSD_i_CharIndex=SSD_i_OffsetTemp to SSD_i_OffsetTemp+4 IF SSD_i_Char2send < "A" then SSD_i_CharIndexT = SSD_i_CharIndex - 0 ' lookup variable must be 8 bits lookup SSD_i_CharIndexT,[$00,$00,$00,$00,$00,$00,$00,$5F,$00,$00,$00,$07,$00,$07,$00,$14,$7F,$14,$7F,$14,_ 'sp,!,",# $24,$2A,$7F,$2A,$12,$23,$13,$08,$64,$62,$36,$49,$56,$20,$50,_ '$,%,& $00,$08,$07,$03,$00,$00,$1C,$22,$41,$00,$00,$41,$22,$1C,$00,_ '',(,) $2A,$1C,$7F,$1C,$2A,$08,$08,$3E,$08,$08,$00,$00,$70,$30,$00,_ '*,+,, $08,$08,$08,$08,$08,$00,$00,$60,$60,$00,$20,$10,$08,$04,$02,_ '-,.,/ $3E,$51,$49,$45,$3E,$00,$42,$7F,$40,$00,$72,$49,$49,$49,$46,_ '0,1,2 $21,$41,$49,$4D,$33,$18,$14,$12,$7F,$10,$27,$45,$45,$45,$39,_ '3,4,5 $3C,$4A,$49,$49,$31,$41,$21,$11,$09,$07,$36,$49,$49,$49,$36,_ '6,7,8 $46,$49,$49,$29,$1E,$00,$00,$14,$00,$00,$00,$40,$34,$00,$00,_ '9,:,; $00,$08,$14,$22,$41,$14,$14,$14,$14,$14,$00,$41,$22,$14,$08,_ '<,=,> $02,$01,$59,$09,$06,$3E,$41,$5D,$59,$4E],SSD_i_Byte2Send '?,@ elseif (SSD_i_Char2send < "[") then SSD_i_CharIndexT = SSD_i_CharIndex - 165 ' subtract previous table length so "A" = zero lookup SSD_i_CharIndexT,[$7C,$12,$11,$12,$7C,_ 'A $7F,$49,$49,$49,$36,$3E,$41,$41,$41,$22,$7F,$41,$41,$41,$3E,_ 'B,C,D $7F,$49,$49,$49,$41,$7F,$09,$09,$09,$01,$3E,$41,$41,$51,$73,_ 'E,F,G $7F,$08,$08,$08,$7F,$00,$41,$7F,$41,$00,$20,$40,$41,$3F,$01,_ 'H,I,J $7F,$08,$14,$22,$41,$7F,$40,$40,$40,$40,$7F,$02,$1C,$02,$7F,_ 'K,L,M $7F,$04,$08,$10,$7F,$3E,$41,$41,$41,$3E,$7F,$09,$09,$09,$06,_ 'N,O,P $3E,$41,$51,$21,$5E,$7F,$09,$19,$29,$46,$26,$49,$49,$49,$32,_ 'Q,R,S $03,$01,$7F,$01,$03,$3F,$40,$40,$40,$3F,$1F,$20,$40,$20,$1F,_ 'T,U,V $3F,$40,$38,$40,$3F,$63,$14,$08,$14,$63,$03,$04,$78,$04,$03,_ 'W,X,Y $61,$59,$49,$4D,$43],SSD_i_Byte2Send 'Z else SSD_i_CharIndexT = SSD_i_CharIndex - 295 ' subtract previous tables length so "[" = zero lookup SSD_i_CharIndexT,[$00,$7F,$41,$41,$41,$02,$04,$08,$10,$20,_ '[,\ $00,$41,$41,$41,$7F,$04,$02,$01,$02,$04,$40,$40,$40,$40,$40,_ '],^,_ $00,$03,$07,$08,$00,$04,$fc,$90,$90,$e0,$7F,$28,$44,$44,$38,_ '`,a,b $38,$44,$44,$44,$28,$38,$44,$44,$28,$7F,$38,$54,$54,$54,$18,_ 'c,d,e $00,$08,$7E,$09,$02,$0C,$52,$52,$4A,$3C,$7F,$08,$04,$04,$78,_ 'f,g,h $00,$44,$7D,$40,$00,$20,$40,$40,$3D,$00,$7F,$10,$28,$44,$00,_ 'i,j,k $00,$41,$7F,$40,$00,$7C,$04,$78,$04,$78,$7C,$08,$04,$04,$78,_ 'l,m,n $38,$44,$44,$44,$38,$7C,$18,$24,$24,$18,$18,$24,$24,$18,$7C,_ 'o,p,q $7C,$08,$04,$04,$08,$48,$54,$54,$54,$24,$04,$04,$3F,$44,$24,_ 'r,s,t $3C,$40,$40,$20,$7C,$1C,$20,$40,$20,$1C,$3C,$40,$30,$40,$3C,_ 'u,v,w $44,$28,$10,$28,$44,$4C,$50,$50,$50,$3C,$44,$64,$54,$4C,$44,_ 'x,y,z $00,$08,$36,$41,$00,$00,$00,$77,$00,$00,$00,$41,$36,$08,$00,_ '{,|,} $02,$01,$02,$04,$02],SSD_i_Byte2Send '~ endif gosub SSD_i_SendData next SSD_i_CharIndex SSD_i_Byte2Send = $00 ' space between characters always $00 gosub SSD_i_SendData return '=============================================================================== SSD1306_i_Around:
gosub SSD_Init looper:
arraywrite SSD_BUFF,[25,4,"<HELLO WORLD>",0] : gosub SSD_PRINTXY
pause 200 GOTO looperДобавлено (22.04.2016, 06:21) --------------------------------------------- но как не бьюсь не мог увывести свой символ, например квадрат, 20х20 пикселей....
Сообщение отредактировал
timerlan - Пт, 22.04.2016, 06:20
|
|
|
|
timerlan |
Дата: Пт, 22.04.2016, 19:26 | Сообщение # 30 |
Группа:
Проверенные
Ранг:
Понимаю
Сообщений:
94
Замечания:
±
На сайте с 18.03.2012
Статус:
Offline
|
да, с этим разобрался, как вывести свой символ,хоть какого размера, вот результаты эксперимента, пока правда, на LCD 3310, так как он был у меня в Протеусе
Добавлено (22.04.2016, 18:51) --------------------------------------------- при нажатии на кнопку появляется символ... сейчас буду пробовать это перенести на SSD1306
Добавлено (22.04.2016, 19:20) --------------------------------------------- ещё вопрос интересный: хочу для примера сделатьтак,чтобы после включения отображался некий символ, который должен быть постоянно высвечен, а при нажатии кнопки появлялся ещё один символ, в другом месте, изменил свой предыдущий код вот так:
Код TRISA = 255 ADCON1 = %00000110
BUTT VAR PORTA.1 CLK VAR PORTB.3 DTA VAR PORTB.2 DC VAR PORTB.1 RST VAR PORTB.0
Chr VAR Byte PosX VAR Byte PosY VAR Byte LcdData VAR Byte
PAUSE 10 GOSUB LCD_INIT PAUSE 10 GOSUB LCD_Clear
MAIN:
PosX=45:PosY=1:GOSUB LCD_GotoXY HIGH DC SHIFTOUT DTA,CLK,1,[$3c,$3c,$3c,$3c]
if BUTT=0 then GOSUB print else gosub lcd_clear endif
goto MAIN
print:
PosX=10 PosY=1 GOSUB LCD_GotoXY HIGH DC SHIFTOUT DTA,CLK,1,[$fe,$fc,$f8,$f0,$e0,$c0,$80,$00,_ $00,$00,$00,$00,$00,$00,$00,$00,$00,$80,$c0,$e0,$f0,$f8,$fc,$fe]
'------------------------------------------------------------------------------- PosX=10 PosY=2 GOSUB LCD_GotoXY HIGH DC SHIFTOUT DTA,CLK,1,[$ff, $ff, $ff, $ff, $ff, $ff, $ff,_ $ff,$fe,$fc,$78,$30,$30,$78,$fc,$fe,$ff, $ff, $ff, $ff, $ff, $ff, $ff, $ff] '------------------------------------------------------------------------------- PosX=10 PosY=3 GOSUB LCD_GotoXY HIGH DC SHIFTOUT DTA,CLK,1,[$ff, $ff, $7f, $3f, $1f, $f, $7, $3,$1,_ $00,$00,$00,$00,$00,$00,$1,$3,$7,$f,$1f,$3f,$7f,$ff,$ff] '------------------------------------------------------------------------------- PosX=10 PosY=4 GOSUB LCD_GotoXY HIGH DC SHIFTOUT DTA,CLK,1,[$1,$00,$00,$00,$00,$00,$00,$00,$00,$00,_ $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$1]
return
LCD_Init:
LOW RST :pause 100 : HIGH RST : LOW DC ' RESET LCD
LcdData= $21: GOSUB LCD_ByteOut ' LCD EXTENDED COMMANDS LcdData= $c8: GOSUB LCD_ByteOut ' SET LCD Vop (CONTRAST) LcdData= $06: GOSUB LCD_ByteOut ' SET TEMP COEFFICENT LcdData= $13: GOSUB LCD_ByteOut ' LCD BIAS MODE LcdData= $20: GOSUB LCD_ByteOut ' LCD STANDARD COMMANDS LcdData= $0c: GOSUB LCD_ByteOut ' LCD IN NORMAL MODE RETURN
LCD_ByteOut: SHIFTOUT DTA,CLK,1, [LcdData]RETURN
LCD_Clear: PosX=0:PosY=0:GOSUB LCD_GotoXY HIGH DC FOR Chr=1 TO 252 LcdData=0:GOSUB LCD_ByteOut LcdData=0:GOSUB LCD_ByteOut NEXT Chr RETURN
LCD_GotoXY: LOW DC LcdData=%01000000 | PosY :GOSUB LCD_ByteOut LcdData=%10000000 | PosX :GOSUB LCD_ByteOut RETURN
Добавлено (22.04.2016, 19:26) --------------------------------------------- то, что должно постоянно отображаться-это PosX=45:PosY=1:GOSUB LCD_GotoXY HIGH DC SHIFTOUT DTA,CLK,1,[$3c,$3c,$3c,$3c] (маленький квадрат) но он почему-то не светится постоянно, я мигает...а при нажатии на кнопку на RA1 светится постоянно...пока кнопку не отпустишь, пробовыл выводить этот кусок отдельной подпрограммой-эффект тот же...помогите, пожалуйста, разобраться, какой же алгоритм должен быть для этого, я уверен, что это именно в алгоритме дело.
|
|
|
|