'18f4520 8MHz 121017 Define CONFIG1L = 0x00 Define CONFIG1H = 0x08 'INT OSC Define CONFIG2L = 0x1e Define CONFIG2H = 0x00 Define CONFIG3L = 0x00 Define CONFIG3H = 0x80 Define CONFIG4L = 0x80 'Set for HVP 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 = 20 'SET PIN IN/OUT TRISA = %00000000 TRISB = %00000000 TRISC = %00000001 '0=button 'SET BITS ON/OFF PORTA = %00000000 'ON/OFF PORTB = %00000000 PORTC = %00000000 PORTE = %00001000 'POSS MCLR RE3 OSCCON = %01110010 'internal 8Mhz clock WaitMs 10 AllDigital 'SPI Define SPI_CS_REG = PORTA Define SPI_CS_BIT = 5 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 Symbol lcd_reset = PORTA.4 Symbol lcd_data_command = PORTC.6 '=D/C=1-DATA D/C=0-COMMAND Symbol yled = PORTC.1 'yled Dim menu0 As String Dim menu1 As String Dim menu2 As String Dim menu3 As String Dim menu4 As String Dim msg1 As String 'any msg data will be passed via this string 'test messages, your project msgs go here, more if needed menu0 = "0123 ABCDEFG" menu1 = "BBBBB" menu2 = "CCCCCC" menu3 = "DDD" menu4 = "BAD EGG" msg1 = "" Dim b As Byte Dim x As Byte Dim y As Byte Dim ascval As String 'do a lcd Reset lcd_reset = 1 lcd_reset = 0 WaitMs 10 lcd_reset = 1 'START UP LED FLASHES yled = 1 WaitMs 1000 yled = 0 WaitMs 1000 start: SPIPrepare Gosub cmd5110 'init lcd lcd_data_command = 1 'set data write mode main: 'data write to LCD block, specify required positions of X and Y Gosub lcdxy 'set lcd write at top left of screen loop1: 'write some data 'note you need to set the location of the msg start on the lcd 'I will look into the method required, Video #2? msg1 = menu0 'assign menu0 msg to msg1 Gosub msg2lcd WaitMs 1000 msg1 = menu1 Gosub msg2lcd WaitMs 1000 'msg1 = menu2 'Gosub msg2lcd 'msg1 = menu3 'Gosub msg2lcd 'msg1 = menu4 'Gosub msg2lcd loop2: Toggle PORTB.7 'dummy loop to pause data write Goto loop2 End 'gets each ASCII char in turn and writes it to lcd msg2lcd: y = Len(msg1) For x = 0 To y ascval = MidStr(msg1, x, 1) Gosub chr2lcd Next x Return 'uses Case function to get correct font pattern chr2lcd: SPICSOn Select Case ascval Case "A" SPISend 0x7e SPISend 0x11 SPISend 0x11 SPISend 0x11 SPISend 0x7e Case "B" SPISend 0x7f SPISend 0x49 SPISend 0x49 SPISend 0x49 SPISend 0x36 Case "C" SPISend 0x3c SPISend 0x41 SPISend 0x41 SPISend 0x41 SPISend 0x22 Case "D" SPISend 0x7f SPISend 0x41 SPISend 0x41 SPISend 0x22 SPISend 0x1c Case "E" SPISend 0x7f SPISend 0x49 SPISend 0x49 SPISend 0x49 SPISend 0x41 Case "F" SPISend 0x7f SPISend 0x09 SPISend 0x09 SPISend 0x09 SPISend 0x01 Case "G" SPISend 0x3e SPISend 0x41 SPISend 0x49 SPISend 0x49 SPISend 0x7a ''''''''''''''''' add the others Case "0" SPISend 0x3e SPISend 0x51 SPISend 0x49 SPISend 0x45 SPISend 0x3e Case "1" SPISend 0x00 SPISend 0x42 SPISend 0x7f SPISend 0x40 SPISend 0x00 Case "2" SPISend 0x42 SPISend 0x61 SPISend 0x51 SPISend 0x49 SPISend 0x46 Case "3" SPISend 0x21 SPISend 0x41 SPISend 0x45 SPISend 0x4b SPISend 0x31 'add more numbers and math symbols Case Else 'display a space for unrecognised ASCII SPISend 0x00 SPISend 0x00 SPISend 0x00 SPISend 0x00 SPISend 0x00 EndSelect SPISend 0x00 'one bit gap between chars on the lcd display SPICSOff Return cmd5110: lcd_reset = 0 WaitMs 100 lcd_reset = 1 'SET COMMAND MODE lcd_data_command = 0 SPICSOn SPISend 0x21 WaitUs 100 SPISend 0xb0 'contrast WaitUs 100 SPISend 0x04 WaitUs 100 SPISend 0x14 'lcd bias WaitUs 100 SPISend 0x20 WaitUs 100 SPISend 0x0c '' 09 now normal mode WaitUs 100 SPICSOff WaitMs 1 Return 'this is for setting top left of lcd and bit write direction. lcdxy: SPICSOn SPISend 0x80 WaitUs 100 SPISend 0x40 SPICSOff WaitMs 1 Return