'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 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 Dim data As Byte Dim addr As Byte 'DEFINE SYMBOLS Const ext_instruction_set = 0x21 Const bias_voltage = 0x13 Const temp_coeff = 0x07 Const contrast = 0xc0 Const basic_instuction_set = 0x20 Const normal_mode = 0x0c 'START UP LED FLASHESFarg1 yled = 1 WaitMs 1000 yled = 0 WaitMs 1000 start: 'initialisation lcd_reset = 0 WaitMs 100 lcd_reset = 1 'SET COMMAND MODE lcd_data_command = 0 SPIPrepare 'SEND addr = 1 loop: ''Call write_reg(addr, ext_instruction_set) data = read_reg(addr, ext_instruction_set) addr = addr + 1 Goto loop 'SET DATA MODE lcd_data_command = 1 End Function read_reg(arg1 As Byte, arg2 As Byte) As Byte SPICSOn SPISend arg1 SPIReceive arg2 SPICSOff End Function Proc write_reg(arg1 As Byte, arg2 As Byte) SPICSOn SPISend arg1 SPISend arg2 SPICSOff End Proc