'18lf2520 8MHz INT 5110 SPI 061017 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 'FUNCTION NOT USED 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 FLASHESFarg1 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 'DEFINE SYMBOLS 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 'SET COMMAND MODE lcd_data_command = 0 'SEND Call write_reg(ext_instuction_set) 'VOID!! PROCEDURE. This is used when only SEND as a return value is not required. Call write_reg(bias_voltage) Call write_reg(temp_coeff) Call write_reg(contrast) Call write_reg(basic_instuction_set) Call write_reg(normal_mode) 'SET DATA MODE lcd_data_command = 1 End 'y = write_2reg(ext_instuction_set, bias_voltage, temp_coeff, contrast, basic_instuction_set)'FUNCTION. is when a READ is used, and returns a value for 'Y' 'Function write_2reg(arg1 As Byte, arg2 As Byte, arg3 As Byte, arg4 As Byte, arg5 As Byte) As Byte'FUNCTION COMMENTED OUT, PROCEDURE USED INSTEAD. 'SPIPrepare 'SPICSOn 'SPISend arg1 'SPICSOff 'End Function Proc write_reg(arg1 As Byte) '5 MAX SPIPrepare SPICSOn SPISend arg1 SPICSOff End Proc