Device = 18F26J11 Declare Stack_Size=10 'On_Hardware_Interrupt GoTo Interrupt_routines Xtal 8 Config_Start WDTEN = OFF ;Disabled - Controlled by SWDTEN bit STVREN = OFF ;Disabled XINST = OFF ;Disabled Debug = OFF ;Disabled Cp0 = OFF ;Program memory is not code-protected OSC = HS ;INTOSC ;INTOSC T1DIG = OFF ;Secondary Oscillator clock source may not be selected LPT1OSC = OFF ;High-power operation FCMEN = OFF ;Disabled IESO = OFF ;Disabled WDTPS = 2048 ;1:2048 DSWDTOSC = INTOSCREF ;DSWDT uses INTRC RTCOSC = INTOSCREF ;RTCC uses INTRC DSBOREN = OFF ;Disabled DSWDTEN = OFF ;Disabled DSWDTPS = 8192 ;1:8,192 (8.5 seconds) IOL1WAY = OFF ;The IOLOCK bit (PPSCON<0>) can be set and cleared as needed MSSP7B_EN = MSK7 ;7 Bit address masking mode WPFP = PAGE_63 ;Write Protect Program Flash Page 63 WPEND = PAGE_WPFP ;Pages WPFP<5:0> to (Configuration Words page) write/erase protected WPCFG = OFF ;Configuration Words page not erase/write-protected WPDIS = OFF ;WPFP[5:0], WPEND, and WPCFG bits ignored Config_End All_Digital=On Declare I2C_Slow_Bus Off Declare I2C_Bus_SCL On TRISA=%11111111 TRISB=%11111111 TRISC=%11100111 Declare Hserial_Baud = 38400 ' Set baud rate to 9600 Declare Hserial_RCSTA = %10010000 ' Enable serial port and continuous receive Declare Hserial_TXSTA = %00100100 ' Enable transmit and asynchronous mode Declare Hserial_Clear = On All_Digital = true Dim X As Byte Dim Y As Byte Dim I As Byte Dim loop As Word loop=0 GoSub init '************************************************************* '************************************************************* MAIN: GoSub clear_all '********* draw characters 8x8. Specifically chars are: ABCD ******************** X=0:Y=0:GoSub SET_XY HBStart HBusOut $78:HBusOut $80 HBusOut $78,[$40,$7E,$11,$11,$11,$7E,$00,$7F,$49,$49,$49,$36,$00,$3E,$41,$41,$41,$22,$00,$7F,$41,$41,$22,$1C,$00,$7F,$49,$49,$49,$41,$00] HBStop '********* draw characters 12x16. Specifically char is: number 5 ******************** X=0:Y=2:GoSub SET_XY HBStart HBusOut $78 HBusOut $78,[$40,0x00 ,0x3F ,0x7F ,0x63 ,0x63 ,0x63 ,0x63 ,0x63 ,0x63 ,0xE3 ,0xC3 ,0x83] HBStop X=0:Y=3:GoSub SET_XY HBStart HBusOut $78 HBusOut $78,[$40,0x00 ,0x0C ,0x1C ,0x38 ,0x30 ,0x30 ,0x30 ,0x30 ,0x30 ,0x38 ,0x1F ,0x0F] HBStop DelayMS 1000 '********* draw characters 12x16. Specifically char is: number 1 ******************** X=20:Y=2:GoSub SET_XY HBStart HBusOut $78 HBusOut $78,[$40,0x00 ,0x00 ,0x00 ,0x0C ,0x0C ,0x0E ,0xFF ,0xFF ,0x00 ,0x00 ,0x00, 0x00] HBStop X=20:Y=3:GoSub SET_XY HBStart HBusOut $78 HBusOut $78,[$40,00x00 ,0x00 ,0x00 ,0x30 ,0x30 ,0x30 ,0x3F ,0x3F ,0x30 ,0x30 ,0x30 ,0x00] HBStop DelayMS 1000 '********* draw a solid line with width of 1 pixel ******************** X=0:Y=4 GoSub SET_XY HBStart For loop=0 To 127 HBusOut $78,[$40,$1] DelayMS 5 Next loop HBStop '********* draw a solid line with width of 8 pixels ******************** X=0:Y=5 GoSub SET_XY HBStart For loop=0 To 127 HBusOut $78,[$40,$ff] DelayMS 5 Next loop HBStop '******** make two times DelayMS 2000 HBStart HBusOut $78 HBusOut $80 HBusOut $78,[$80,$a7] DelayMS 500 HBusOut $78,[$80,$a6] DelayMS 500 HBusOut $78,[$80,$a7] DelayMS 500 HBusOut $78,[$80,$a6] DelayMS 500 HBStop GoTo MAIN '*********************************************** '*********************************************** '---------------------------------------- SET_XY: HBStart HBusOut $78 HBusOut $80 HBusOut $78,[$80,$21] HBusOut $78,[$80,X] HBusOut $78,[$80,127] HBusOut $78,[$80,$22] HBusOut $78,[$80,Y] HBusOut $78,[$80,7] HBStop Return '---------------------------------------- clear_all: HBStart HBusOut $78 HBusOut $80 For Y=0 To 7 X=0 GoSub SET_XY For loop=0 To 127 HBusOut $78,[$40,0] Next loop Next Y HBStop Return '---------------------------------------- init: DelayMS 1000 HBStart 'Send a Start condition to the I2C bus HBusOut $78 'Slave Adress HBusOut 0x80 ; HBusOut 0xae ;//--turn off oled panel HBusOut 0x80 ; HBusOut 0xd5 ;//--set display clock divide ratio/oscillator frequency HBusOut 0x80 ; HBusOut 0x80 ;//--set divide ratio HBusOut 0x80 ; HBusOut 0xa8 ;//--set multiplex ratio 1 to 64 HBusOut 0x80 ; HBusOut 0x3f ;//--1/64 duty HBusOut 0x80 ; HBusOut 0xd3 ;//-set display offset HBusOut 0x80 ; HBusOut 0x00 ;//-not offset HBusOut 0x80 ; HBusOut 0x8d ;//--set Charge Pump enable/disable HBusOut 0x80 ; HBusOut 0x14 ;//--set 0x10 disable HBusOut 0x80 ; HBusOut 0x40 ;//--set start line address HBusOut 0x80 ; HBusOut 0xa6 ;//--set normal display HBusOut 0x80 ; HBusOut 0xa4 ;//Disable Entire Display On HBusOut 0x80 ; HBusOut 0xa1 ;//--set segment re-map 128 to 0 HBusOut 0x80 ; HBusOut 0xC8 ;//--Set COM Output Scan Direction 64 to 0 HBusOut 0x80 ; HBusOut 0xda ;//--set com pins hardware configuration HBusOut 0x80 ; HBusOut 0x12 ; HBusOut 0x80 ; HBusOut 0x81 ;//--set contrast control register HBusOut 0x80 ; '-------------------------------------- HBusOut 0x8F ; 'THIS IS CONTRAST VALUE '-------------------------------------- HBusOut 0x80 ; HBusOut 0xd9 ;//--set pre-charge period HBusOut 0x80 ; HBusOut 0xf1 ; HBusOut 0x80 ; HBusOut 0xdb ;//--set vcomh HBusOut 0x80 ; HBusOut 0x40 ; HBusOut 0x80 ; HBusOut 0xaf ;//--turn on oled panel HBStop Return