Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20563

Share your working BASCOM-AVR code here : OLED Display using SSD1306 with i2c. Char Mode 16x4 : REPLY

$
0
0
Hello Madf, I changed the code, the display get this. [img:e3be69b0cc]http://img822.imageshack.us/img822/5153/oleddisplay.jpg[/img:e3be69b0cc] I´m programing on Proton Compiler is a bit similar to Bascom my code is: The Slave adrees is 0x78 or $78. I'm modifying the code to work with Proton Compiler. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' CODE ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Device = 18F4550 'Selecciono PIC Declare Xtal 20 'Fija el Cristal a 12Mhz Dim Oled_Data As Byte Dim A As Byte Dim B As Byte Dim C As String * 1 Dim Oled_txt_byte [16] As Byte Dim Char As String * 16 Dim Pag As Byte Dim Column As Byte Dim Rowsfixed As Byte Dim Rowsscroll As Byte Dim Scrollstep As Byte Dim Stepdelay As Byte Dim Lr As Byte Dim Spage As Byte Dim Epage As Byte Dim Frames As Byte Dim Scolumn As Byte Dim Ecolumn As Byte Dim Filldata As Byte Symbol Rset = PORTE.0 'Res# Port oled Symbol CS = PORTE.1 'CS# Port Oled Symbol OLED_DataCommand = 64 Symbol Oled_address = 0x78 Symbol Write_cmd = $01 Symbol Oled_reset = $03 Symbol Oled_8x16str = $52 '$10 Symbol Disp_area = $11 Symbol Fill_area = $61 '$12 Symbol Set_scrohor = $62 '$13 Symbol Set_scrover = $63 '$14 Symbol Set_scroverhor = $64'$15 Symbol Scroll_up = $01 Symbol Scroll_down = $00 Symbol Scroll_right = $26 'ok Symbol Scroll_left = $27 'ok Symbol Scroll_vr = $29 'ok Symbol Scroll_vl = $2A 'ok Symbol Scrollstop = $2E 'ok GoSub Oled_Setup DelayMS 10 GoSub Resetdisplay I2cinit: Char = "Hello World!" Pag = 0 ' line number/position (which displays the text, X (0-7)) Column = 1 ' position of the column (which displays the text, Y (0-127)) GoSub Oled_Text DelayMS 3 GoTo I2cinit Fillarea: '(Dim Spage As Byte , Dim Epage As Byte , Dim Scolumn As Byte , Dim Ecolumn As Byte , Dim Filldata As Byte) HBStart HBusOut Oled_address HBusOut Fill_area HBusOut Spage HBusOut Epage HBusOut Scolumn HBusOut Ecolumn HBusOut Filldata HBStop Return Deactivatescroll: HBStart HBusOut Oled_address HBusOut Write_cmd HBusOut Scrollstop HBStop Return Scrollinghorizontal:'(Dim Lr As Byte , Dim Spage As Byte , Dim Epage As Byte , Dim Frames As Byte) HBStart HBusOut Oled_address HBusOut Set_scrohor HBusOut Lr HBusOut Spage HBusOut Epage HBusOut Frames HBStop Return Scrollingvertical:'(Dim Rowsfixed As Byte , Dim Rowsscroll As Byte , Dim Scrollstep As Byte , Dim Stepdelay As Byte) HBStart HBusOut Oled_address HBusOut Set_scrover HBusOut Scroll_up HBusOut Rowsfixed HBusOut Rowsscroll HBusOut Scrollstep HBusOut Stepdelay HBStop Return Display8x16str:'(Dim Pag As Byte , Dim Column As Byte , Dim Char As String * 16) HBStart HBusOut Oled_address HBusOut Oled_8x16str HBusOut Pag HBusOut Column For A = 1 To 16 C = Mid$(Char , A , 1) B = Val(C, Dec) HBusOut B Next HBStop Return Oled_Text: HBStart HBusOut Oled_address HBusOut Oled_8x16str HBusOut Pag ' Page HBusOut Column ' Column For A = 1 To 16 HBusOut Oled_txt_byte [A] Next HBStop Return Resetdisplay: HBStart HBusOut Oled_address HBusOut 0x20 'Vertical addressing mode HBusOut 0x01 HBusOut 0x21 'Start en eind kolom instellen HBusOut 0x00 HBusOut 0x5F HBusOut 0x22 'Start en eind page instellen HBusOut 0x00 HBusOut 0x01 HBStop Return ''''OLED initialitation *********************************************************** Oled_Setup: DelayMS 500 High Rset 'Reset diplay DelayMS 1 High CS Low Rset DelayMS 10 Low CS High Rset DelayMS 10 HBStart HBusOut Oled_address HBusOut 0xAE '10101110 Display off HBusOut 0x00 '00000000 Set lower column start address for page addressing mode at 0 HBusOut 0x10 '00010000 Set higher column start address for page addressing mode at 0 * HBusOut 0x20 'Vertical addressing mode HBusOut 0x01 HBusOut 0x21 'Set start and end Column HBusOut 0x00 HBusOut 0x5F HBusOut 0x22 'Set Start and end page HBusOut 0x00 HBusOut 0x01 HBusOut 0xB0 'Set page start address HBusOut 0x40 '01000000 Set display start line at 0 HBusOut 0x81 '10000001 Set contrast HBusOut 0x7F '01111111 at AFh = 175d anders HBusOut 0xA1 'Column address is mapped to SEG0 * HBusOut 0xA6 '10100100 Normal display, A7 = inversed HBusOut 0xA8 'Set multiplex ratio * HBusOut 0x0F 'at 0F = 15 * HBusOut 0xD3 'Set display offset HBusOut 0x00 'at 00 = 0 HBusOut 0xD5 'Set display clock divide ratio/oscillator frequency HBusOut 0xF0 'at 80 = 128 anders HBusOut 0xD9 'set precharge period HBusOut 0x22 'at F1 = 241 anders HBusOut 0xDA 'Set COM pins hardware configuration * HBusOut 0x02 'at 02 = 2 * HBusOut 0xDB 'Set Vcomm deselect level at 0.77 x Vcc HBusOut 0x20 'at 20 = 32 HBusOut 0xC8 'Set COM output scan direction in reverse anders HBusOut 0xA4 '10100100 Display follows the RAM content anders HBusOut 0x8D 'enable charge pump * moet HBusOut 0x14 'at 14h = 20d * moet HBusOut 0xAF '10101111 Display on in normal mode * moet HBStop 'Clear display ***************************************************************** ClearDisplay: HBStart HBusOut Oled_address HBusOut OLED_DataCommand For A = 0 To 191 HBusOut 0 Next Return

Viewing all articles
Browse latest Browse all 20563

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>