'18LF4520 5110 GPS BMP280 HC12 150418 1100 Define CONFIG1L = 0x00 Define CONFIG1H = 0x08 'INT OSC Define CONFIG2L = 0x1e Define CONFIG2H = 0x00 Define CONFIG3L = 0x00 Define CONFIG3H = 0x80 'Set for HVP Define CONFIG4L = 0x80 Define CONFIG4H = 0x00 Define CONFIG5L = 0x0f Define CONFIG5H = 0xc0 Define CONFIG6L = 0x0f Define CONFIG6H = 0xe0 Define CONFIG7L = 0x0f Define CONFIG7H = 0x40 'Define SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC Define CLOCK_FREQUENCY = 8 Define SINGLE_DECIMAL_PLACES = 2 Define STRING_MAX_LENGTH = 40 'Needs raising to fit the whole NMEA sentence for transmit>>>>>>>>>> AllDigital 'SET PIN IN/OUT TRISA = %00000001 TRISB = %00000000 TRISC = %10010000 '7=RX=1 4=SDI=1 1=RST=0 TRISD = %00000000 '7=compss c/s=0 5=altmtr c/s=0 4=lcd5110 c/s=0 TRISE = %00000001 '1=Button 'SET BITS ON/OFF PORTA = %00000000 'ON/OFF PORTB = %00000000 PORTC = %00000000 PORTD = %01110000 'ALL C/S HIGH PORTE = %00000000 'POSS MCLR RE3 ADCON0 = 0x03 'AN0-1-2-3 Can be used as Analogue inputs. ADCON1 = 0x0e ADCON2 = %10100100 PIR1 = 0 PIR2 = 0 PIE1 = 0 PIE2 = 0 PIE1.RCIE = 1 'rxd Intr , used for GPS serial input work IPR1 = 0 IPR2 = 0 RCON.IPEN = 1 'This MUST be included when using Interrupts OSCCON = %01110010 'internal 8Mhz clock 'OSCTUNE.pllen = 1 '*4 PLL enabled so Fosc = 32MHZ WaitMs 10 '--------------------------------------------------------------------------------------- 'SPI Define SPI_CS_REG = PORTD Define SPI_CS_BIT = 4 Define SPI_SCK_REG = PORTC Define SPI_SCK_BIT = 3 Define SPI_SDI_REG = PORTC 'not used, but left in so OSH does not burp Define SPI_SDI_BIT = 4 Define SPI_SDO_REG = PORTC Define SPI_SDO_BIT = 5 'Define SPICLOCK_STRETCH = 20 '?????????????????????????????????????? Symbol lcd_reset = PORTC.1 Symbol lcd_mode = PORTC.0 '1=DATA ,0=COMMAND Symbol yled = PORTA.4 'yled Symbol rled = PORTA.5 'rled Symbol lcd5110 = PORTD.4 'CS 25110 LCD Symbol altmtr = PORTD.5 'CS BAROMETER/TEMP Symbol compss = PORTD.6 'CS HMC5983 '--------------------------------------------------------------------------------------- Dim msg1 As String 'any msg data will be passed via this string Dim ascval As String Dim x As Byte '?????????????????????????????????????????????????????????? Dim y As Byte 'Dim row As Byte 'lcd row pointer Dim xp As Byte 'normal font horiz Dim yp As Byte 'vert lcd location 'GPS Dim str1(80) As Byte 'GPGGA STR1 ARRAY Dim strchr As String 'GPGGA msg Dim csv As Byte 'COMMA POSITION in GPS msg Dim sinlat As Single Dim sinlong As Single Dim strtim As String Dim strlat As String Dim strlong As String Dim char As Byte Dim rxi As Byte Dim txi As Byte 'BMP280 CALC Dim var1 As Single Dim var2 As Single Dim b(24) As Byte Dim data As Byte Dim t_fine As Single Dim t_raw As Long Dim p_raw As Long Dim adc_t As Single Dim adc_p As Single Dim tp As Single 'TEMP result in CALC Dim pr As Single 'PRESS result in CALC Dim strtp As String Dim strpr As String Dim i As Byte Dim adr As Byte 'ADDRESS FOR BMP280 Dim t1 As Word 'Compensation parameters Dim t2 As Word Dim t3 As Word Dim p1 As Word Dim p2 As Word Dim p3 As Word Dim p4 As Word Dim p5 As Word Dim p6 As Word Dim p7 As Word Dim p8 As Word Dim p9 As Word Dim dig_t1 As Single 'Compensation parameters Dim dig_t2 As Single Dim dig_t3 As Single Dim dig_p1 As Single Dim dig_p2 As Single Dim dig_p3 As Single Dim dig_p4 As Single Dim dig_p5 As Single Dim dig_p6 As Single Dim dig_p7 As Single Dim dig_p8 As Single Dim dig_p9 As Single '--------------------------------------------------------------------- 'COMPASS 'Dim id_raw As Byte 'COMPASS ID 'Dim id As Single 'TEMP result in CALC'###################### 'Dim strid As String 'Dim rega_raw As Byte 'COMPASS REGA 'Dim strrega As String 'Dim regb_raw As Byte 'COMPASS REGB 'Dim strregb As String 'READ COMPASS X Dim x_raw As Word Dim ax As Single '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Dim x1 As Byte '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Dim x2 As Byte '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Dim strx1 As String '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Dim strx2 As String '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 'Dim strxhb As String '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 'Dim strxlb As String '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 'Dim strxword As String 'READ COMPASS Y Dim y_raw As Word Dim ay As Single '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Dim y1 As Byte '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Dim y2 As Byte '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Dim stry1 As String '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Dim stry2 As String '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 'Dim stryhb As String '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 'Dim strylb As String '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 'Dim stryword As String 'READ COMPASS Z Dim z_raw As Word Dim az As Single '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Dim z1 As Byte '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Dim z2 As Byte '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Dim strz1 As String '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Dim strz2 As String '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 'Dim strzhb As String '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 'Dim strzlb As String '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 'Dim strzword As String 'Dim mode_raw As Byte 'COMPASS MODE 'Dim strmode As String 'Dim rdy As Byte 'FOR STATUS RDY 'Dim sttus_raw As Byte 'COMPASS STATUS 'Dim strsttus As String Dim azi As Single 'word Dim strazimuth As String Dim picalc As Single '????????????????????????????????????????????????????????????????? Const pi = 3.14159 picalc = 180 / pi Dim addr As Byte 'ADDRESS FOR COMPASS '----------------------------------------------------------------------------------- 'SET HC-12 TX 'TO CHANGE SETTINGS PRESS BUTTON!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Dim freq As Byte '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Dim strfreq As String '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> freq = 50 strfreq = #freq '############################################################################### Disable High Disable Low Include "fontsml.bas" 'This 'FONT' file nust be in the same folder as this program code msg1 = "" Hseropen 9600 Hserout "Ready!", CrLf start: 'do a lcd Reset Gosub rst_lcd '5110 states very early RESET is important SPIPrepare Gosub cmd5110 'init lcd WaitMs 10 Call clear() 'BMP280 INITIALISATION 'Compensation parameters SPICSOn For i = 0 To 23 altmtr = 0 'CHIP SELECT BMP280 ON adr = 0x88 + i SPISend adr SPIReceive data b(i) = data altmtr = 1 'CHIP SELECT BMP280 OFF Next i SPICSOff 'Temp coefficents t1.LB = b(0) t1.HB = b(1) t2.LB = b(2) t2.HB = b(3) t3.LB = b(4) t3.HB = b(5) 'pressure coefficients p1.LB = b(6) p1.HB = b(7) p2.LB = b(8) p2.HB = b(9) p3.LB = b(10) p3.HB = b(11) p4.LB = b(12) p4.HB = b(13) p5.LB = b(14) p5.HB = b(15) p6.LB = b(16) p6.HB = b(17) p7.LB = b(18) p7.HB = b(19) p8.LB = b(20) p8.HB = b(21) p9.LB = b(22) p9.HB = b(23) 'convert to singles with sign dig_t1 = t1 dig_t2 = t2 If dig_t2 > 32767 Then dig_t2 = dig_t2 - 65536 Endif dig_t3 = t3 If dig_t3 > 32767 Then dig_t3 = dig_t3 - 65536 Endif dig_p1 = p1 dig_p2 = p2 If dig_p2 > 32767 Then dig_p2 = dig_p2 - 65536 Endif dig_p3 = p3 If dig_p3 > 32767 Then dig_p3 = dig_p3 - 65536 Endif dig_p4 = p4 If dig_p4 > 32767 Then dig_p4 = dig_p4 - 65536 Endif dig_p5 = p5 If dig_p5 > 32767 Then dig_p5 = dig_p5 - 65536 Endif dig_p6 = p6 If dig_p6 > 32767 Then dig_p6 = dig_p6 - 65536 Endif dig_p7 = p7 If dig_p7 > 32767 Then dig_p7 = dig_p7 - 65536 Endif dig_p8 = p8 If dig_p8 > 32767 Then dig_p8 = dig_p8 - 65536 Endif dig_p9 = p9 If dig_p9 > 32767 Then dig_p9 = dig_p9 - 65536 Endif 'BMP280 INITIALISATION SPICSOn altmtr = 0 'CHIP SELECT BMP280 ON SPISend 0x60 'WRITE 0xe0 RESET ADDR [Is this needed?] SPISend 0xb6 '%10110110 RESET TO 0x00 altmtr = 1 'CHIP SELECT BMP280 OFF altmtr = 0 'CHIP SELECT BMP280 ON SPISend 0x74 'WRITE 0xF4 Control CTRL_MEAS reg addr SPISend 0x5f '%01011111 T/ON P/ON 't_x2 px16 Normal Mode altmtr = 1 'CHIP SELECT BMP280 OFF altmtr = 0 'CHIP SELECT BMP280 ON SPISend 0x75 'WRITE 0xF5 Control CONFIG reg addr SPISend 0x1c '%00011100 osrs_t 0.5ms Table 11-11R filter x16 table 6 altmtr = 1 'CHIP SELECT BMP280 OFF SPICSOff 'COMPASS INITIALISATION SPICSOn compss = 0 'CHIP SELECT COMPASS ON SPISend 0x00 'CONFIG REGA WRITE ADDR 0X00 SPISend 0xd0 'WRITE CONFIG REGA [TEMP_ON, SAMPX4, X4, 15HZ, NORM ] DEFAULT %00100000 compss = 1 'CHIP SELECT COMPASS OFF compss = 0 'CHIP SELECT COMPASS ON SPISend 0x01 'CONFIG REGB WRITE ADDR 0X01 SPISend %00000000 'WRITE CONFIG REGB [GAIN_1370] DEFAULT %00100000 compss = 1 'CHIP SELECT COMPASS OFF compss = 0 'CHIP SELECT COMPASS ON SPISend 0x02 'CONFIG MODE WRITE ADDR 0X02 SPISend 0x00 'WRITE CONFIG MODE [CONT MEASURE, ] DEFAULT %00000001 compss = 1 'CHIP SELECT COMPASS OFF SPICSOff WaitMs 67 yled = 1 'HC-12 INITIALISATION 'PRESS BUTTON FOR CHANGES 'Hserout "AT+C063", CrLf '458.200MHz 'Hserout "AT+C064", CrLf '458.600MHz 'Hserout "AT+C065", CrLf '459.000MHz Hserout "AT+C066", CrLf '459.400 MHz 'Hserin g main: '\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ Toggle yled Toggle rled 'READ BMP280 TEMP and PRESS values ADC 20 bit SPICSOn For i = 0 To 2 altmtr = 0 'CHIP SELECT BMP280 ON adr = 0xfa + i SPISend adr SPIReceive data b(i) = data altmtr = 1 'CHIP SELECT BMP280 OFF Next i t_raw.LB = b(2) t_raw.HB = b(1) t_raw.3B = b(0) t_raw = ShiftRight(t_raw, 4) adc_t = t_raw For i = 0 To 2 altmtr = 0 'CHIP SELECT BMP280 ON adr = 0xf7 + i SPISend adr SPIReceive data b(i) = data altmtr = 1 'CHIP SELECT BMP280 OFF Next i SPICSOff p_raw.LB = b(2) p_raw.HB = b(1) p_raw.3B = b(0) p_raw = ShiftRight(p_raw, 4) adc_p = p_raw Gosub calc strtp = #tp 'From CALC strpr = #pr 'From CALC '[[[[[[[[[[[[[[[[[[[[[[[[[[[ COMPASS NOTES [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ 'you calculate angle in radians from x, y coordinates. 'Angle in degrees = radians × 180 / Pi ~ radians × 57.3 'oshonsoft has Arctan Function For y / x < 1 'You have To calculate in eight octants ( 45 degrees ) 'Octants can be found from signs of x And y And from 'value of y / x If it is less Or greater than one. 'For example, If North is 0 degrees And clockwise direction: '0 - 45 degrees x / y < 1 And x > 0, y > 0 'angle = Arctan( x / y ) × 57.3 '45 - 90 degrees x/y > 1 x >0 y>0 'angle = 90 - Arctan( y / x ) × 57.3 'etc ... '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 'If x / y < 1 can be written If x < y 'The first example 0-45 degrees. 'x, y And angle are floating point variables '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] COMPASS NOTES ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] '###################################################################################### 'READ COMPASS XZY REGISTER SPICSOn For i = 0 To 5 'READ XZY Xx2 Zx2 Yx2 compss = 0 'CHIP SELECT COMPASS ON addr = 0x83 + i SPISend addr SPIReceive data b(i) = data compss = 1 'CHIP SELECT COMPASS OFF Next i SPICSOff x_raw.HB = b(0) x_raw.LB = b(1) z_raw.HB = b(2) z_raw.LB = b(3) y_raw.HB = b(4) y_raw.LB = b(5) x1 = x_raw.HB '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> y1 = y_raw.HB '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> z1 = z_raw.HB '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> x2 = x_raw.LB '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> y2 = y_raw.LB '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> z2 = z_raw.LB '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVV 2'S COMPLIMENT CALC VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV If ax > 32767 Then ax = 65535 - ax ax = ax + 1 Endif If ay > 32767 Then ay = 65535 - ay ay = ay + 1 Endif 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA 2'S COMPLIMENT CALC AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA If ax < ay Then If ax > 0 And ay > 0 Then azi = arctn(ax, ay) Endif Endif 'strazimuth = #azi 'FOR 5110 SCREEN strx1 = #x1 stry1 = #y1 strz1 = #z1 strx2 = #x2 stry2 = #y2 strz2 = #z2 'strxword = #ax 'stryword = #ay 'GPS 'Gosub get_neo 'Reads NMEA DATA<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Hserout "PRESS ", strpr, CrLf '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Gosub print '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Goto main End '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 'Function arctn(..... 'arctn= x/y/( 1+0.28125*( x/y )^2)*180/pi 'End Function '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 'Azimuth CALC Function Function arctn(ax As Single, ay As Single) As Single '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> arctn = ax / ay / (1 + 0.28125 * ((ax / ay) * (ax / ay))) * picalc '180/PI 'arctn = ay / ax / (1 + 0.28125 * ((ay / ax) * (ay / ax))) * picalc '180/PI End Function 'Await NEO GPS RXD (PIN1) get_neo: ''$GPGGA,123459.00,5001.00000,N,00059.00000,W,1,04,1.80,1.2,M,47.7,M,,*7F? rxi = 0 If RCSTA.OERR = 1 Then 'RCSTA BIT1-if over run error then flush RXD buffer RCSTA.CREN = 0 RCSTA.CREN = 1 char = RCREG PIR1.RCIF = 0 Endif sync1: 'wait for a $ start of string If PIR1.RCIF = 0 Then Goto sync1 char = RCREG If char <> 0x24 Then Goto sync1 '$' str1(1) = char 'STR1 ARRAY rxi = 2 get_msg: 'read and save GPGGA msg If PIR1.RCIF = 0 Then Goto get_msg char = RCREG str1(rxi) = char 'STR1 ARRAY rxi = rxi + 1 If rxi > 79 Then Goto get_neo 'msg bfr over run If char = 0x0a Or char = 0x3f Then Goto msg_end 'tests for either LF or ? Goto get_msg If rxi < 60 Then 'invalid msg msg1 = "" Goto get_neo Endif msg_end: If str1(5) = 0x47 Then 'G' csv = 0 For txi = 1 To 73 char = str1(txi) strchr = Chr(char) If strchr <> "," Then msg1 = msg1 + strchr Else csv = csv + 1 Gosub get_val Endif Next txi Else msg1 = "" Goto get_neo Endif Return 'This subr extracts the main values from the GPS string, into named value messages 'also converts the string to a named numeric value, for maths 'NOTE: hserouts for demo test only get_val: Select Case csv 'COMMA POSITION VALUES Case 1 Case 2 strtim = LeftStr(msg1, 2) + ":" + MidStr(msg1, 3, 2) + ":" + MidStr(msg1, 5, 2) Case 3 strlat = LeftStr(msg1, 10) sinlat = StrValS(strlat) Case 5 strlong = RightStr(msg1, 11) sinlong = StrValS(strlong) Case 12 Case Else EndSelect msg1 = "" Return calc: 'BMP280 'Calculate temperature var1 = ((adc_t / 16384 - (dig_t1 / 1024))) * dig_t2 var2 = (((adc_t) / 131072 - (dig_t1) / 8192) * (adc_t / 131072 - dig_t1 / 8192) * dig_t3) t_fine = var1 + var2 tp = (var1 + var2) / 5120 'Calculate pressure var1 = t_fine / 2 - 64000 var2 = var1 * var1 * dig_p6 / 32768 var2 = var2 + var1 * dig_p5 * 2 var2 = var2 / 4 + dig_p4 * 65536 var1 = ((dig_p3) * var1 * var1 / 524288 + dig_p2 * var1) / 524288 var1 = (1 + var1 / 32768) * dig_p1 pr = 1048576 - adc_p pr = (pr - (var2 / 4096)) * 6250 / var1 var1 = dig_p9 * pr * pr / 2147483648 var2 = pr * dig_p8 / 32768 pr = pr + (var1 + var2 + dig_p7) / 16 Return print: '?????????????? CHECK ALL PRINT ROUTINES ?????????????????????????????????????????????????????? Call clear() '################################################## msg1 = "AZI=" + strx1 Call wr_msg(0, 0, msg1) 'Hserout "AZI=", strazimuth, "XWORD=", strxword, "XH=", strxhb, "XL=", strxlb, "YWORD=", stryword, "YH=", stryhb, "YL=", strylb, CrLf 'Hserout x1, y1, z1, CrLf 'Hserout strx1, ",", stry1, ",", strz1, CrLf WaitMs 100 '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 'Hserout strx2, ",", stry2, ",", strz2, CrLf WaitMs 100 '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 'strazimuth = "" 'strxword = "" 'strxhb = "" 'strxlb = "" 'stryword = "" 'stryhb = "" 'strylb = "" msg1 = "" Return ''Writes the msg To the lcd at xp [column] And yp {row] [WRITES SMALL DIGITS] Proc wr_msg(xp As Byte, yp As Byte, msg1 As String) lcd_mode = 0 'cmd xp = xp * 6 xp = 0x80 Or xp yp = 0x40 Or yp SPICSOn lcd5110 = 0 '5110 LCD ON SPISend xp SPISend yp lcd5110 = 1 '5110 LCD OFF SPICSOff lcd_mode = 1 'data y = Len(msg1) For x = 1 To y ascval = MidStr(msg1, x, 1) Gosub chr2lcd 'in fontsml.bas Next x End Proc Proc clear() For yp = 0 To 5 Call clr_row(yp) Next yp End Proc 'Clears all normal font row xp Proc clr_row(yp As Byte) xp = 0 lcd_mode = 0 xp = xp * 6 xp = 0x80 Or xp yp = 0x40 Or yp SPICSOn lcd5110 = 0 '5110 LCD ON[[[[C/S DOESN'T MAKE ANY DIFFERENCE?????]]] SPISend xp SPISend yp lcd5110 = 1 '5110 LCD OFF SPICSOff lcd_mode = 1 SPICSOn lcd5110 = 0 '5110 LCD ON For x = 0 To 83 'all pixels across SPISend 0x00 Next x lcd5110 = 1 '5110 LCD OFF SPICSOff End Proc 'Initialise 5110 and set lcd writing direction cmd5110: lcd_reset = 0 WaitMs 100 lcd_reset = 1 WaitMs 10 lcd_mode = 0 'cmd mode WaitMs 10 SPICSOn lcd5110 = 0 '5110 LCD ON SPISend 0x21 WaitUs 100 SPISend 0xb1 'b8 contrast was b0Set LCD Vop 0xB0 for 5V, 0XB1 for 3.3v, 0XBF if screen too dark] WaitUs 100 SPISend 0x04 WaitUs 100 SPISend 0x14 'lcd bias WaitUs 100 SPISend 0x20 WaitUs 100 SPISend 0x0c '' 09 now normal data write mode WaitUs 100 lcd5110 = 1 '5110 LCD OFF SPICSOff 'this is for setting top left of lcd and bit write direction. lcd_mode = 0 xp = xp * 6 xp = 0x80 Or xp yp = 0x40 Or yp SPICSOn lcd5110 = 0 '5110 LCD ON SPISend xp SPISend yp lcd5110 = 1 '5110 LCD OFF SPICSOff WaitMs 5 ''' Return 'Reset the lcd rst_lcd: lcd_reset = 1 WaitMs 10 lcd_reset = 0 WaitMs 10 lcd_reset = 1 Return