'18lf2520 8MHz INT 5110 SPI 051017 0900 Define SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC Define CLOCK_FREQUENCY = 8 Define SINGLE_DECIMAL_PLACES = 2 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 '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 initialise_chip: OSCCON = %01110010 'internal 8Mhz clock WaitMs 10 AllDigital 'SPI Dim y As Byte 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 'Define SPI_SDI_BIT = 4 Define SPI_SDO_REG = PORTC Define SPI_SDO_BIT = 5 'Define SPICLOCK_INVERT = 1 'Reverse signal 'Define SPICLOCK_STRETCH = 20 'Make the SPI signals slower Symbol lcd_reset = PORTA.4 Symbol lcd_cs = PORTA.5 'LCD Symbol lcd_data_command = PORTC.6 '=D/C=1-DATA D/C=0-COMMAND Symbol lcd_sck = PORTC.3 Symbol lcd_sdo = PORTC.5 '= MOSI/SDO Symbol yled = PORTC.1 'yled 'START UP LED FLASHES yled = 1 WaitMs 1000 yled = 0 WaitMs 1000 definitions: 'Define STRING_MAX_LENGTH = 30?????????????????????????????? Dim spi_write_func As Byte Dim write_reg_spi As Byte start: 'initialisation lcd_reset = 0 WaitMs 100 lcd_reset = 1 'SET COMMAND MODE lcd_data_command = 0 'SEND Dim ext_instuction_set As Byte ext_instuction_set = 0x21 'use extended instruction set Dim bias_voltage As Byte bias_voltage = 0x13 'select bias voltage Dim temp_coeff As Byte temp_coeff = 0x07 Dim contrast As Byte contrast = 0xc0 Dim basic_instuction_set As Byte basic_instuction_set = 0x20 Dim normal_mode As Byte normal_mode = 0x0c y = write_2reg(ext_instuction_set, bias_voltage, temp_coeff, contrast, basic_instuction_set) Call write_reg(0x21, 0x13, 0x07, 0xc0, 0x20) End Function write_2reg(arg1 As Byte, arg2 As Byte, arg3 As Byte, arg4 As Byte, arg5 As Byte) As Byte SPIPrepare SPICSOn SPISend arg1 SPICSOff End Function Proc write_reg(arg1 As Byte, arg2 As Byte, arg3 As Byte, arg4 As Byte, arg5 As Byte) '5 MAX SPIPrepare SPICSOn SPISend arg1 SPICSOff End Proc