'**************************************************************** '* Name : LOOKUP problem example, on PIC18F14K22.BAS * '* Author : Alan Oxenbould 27-Aug-2011 * '**************************************************************** Optimiser_Level = 0 'new compiler feature 16-Oct-2009 (adjust LATER, don't want to SLOW compilation) Dead_Code_Remove = OFF 'JIC (try later, don't want to SLOW compilation) '================================================================ Device = 18F14K22 Declare Xtal = 4 'Set configuration: 12-Jun-2011 'below extracted & modified from "18F14K22.PPI" file @Config_Req @__config config1H, FOSC_IRC_1 & PLLEN_OFF_1 & PCLKEN_ON_1 & IESO_ON_1 @__config config2L, PWRTEN_ON_2 & BOREN_OFF_2 & BOREN_SBORDIS_2 & BORV_30_2 @__config config2H, WDTEN_OFF_2 & WDTPS_1024_2 @__config config3H, MCLRE_OFF_3 & HFOFST_OFF_3 @__config config4L, STVREN_OFF_4 & LVP_OFF_4 & BBSIZ_OFF_4 & XINST_OFF_4 @__config config5L, CP0_ON_5 & CP1_ON_5 @__config config5H, CPB_ON_5 & CPD_OFF_5 @__config config6L, WRT0_OFF_6 & WRT1_OFF_6 @__config config6H, WRTB_OFF_6 & WRTC_OFF_6 & WRTD_OFF_6 @__config config7L, EBTR0_OFF_7 & EBTR1_OFF_7 @__config config7H, EBTRB_OFF_7 '--------------------------------------------------------------------------------------- Symbol Sym_TRISA = %11011000 'for ATO modified 'F14K22 wiring (RA7,RA6 = n/f; RA4= AN3; RA3 = I/P); RA1= OD O/P) {UART S/W is separate config} Symbol Sym_TRISB = %00011111 'for ATO modified 'F14K22 wiring (RB4/SDI = I/P; RB3-0 = n/f) {UART S/W is separate config} Symbol Sym_TRISC = %01000000 'for ATO modified 'F14K22 wiring (RC6 = AN8) '----- Analogue Port control (else digital READ is WRONG) ------------------------------- Symbol Sym_ANSEL = %00001000 'AN3 [ 7-0] active as A/D channel (Data sheet PAGE 94) Symbol Sym_ANSELH = %00000001 'AN8 [11-8] active as A/D channel (Data sheet PAGE 95) Symbol Sym_ANSELH2 = %00001001 'AN11 & 8 [11-8] active as A/D channel (Data sheet PAGE 95) Symbol LCD_DataS = PORTC.0 'start pin for LCD data ie ports C 0,1,2,3. Symbol LCD_DataP = PORTC 'data pin port Symbol LCD_E = PORTB.7 'LCD Enable signal port 'moved AGAIN to provide H/W UART Tx signal on front panel connector. OXXRT Symbol LCD_RS = PORTB.5 'LCD RS signal (register select) 'moved AGAINto provide H/W UART Rx signal on front panel connector. OXXRT Symbol LCD_Data_Nibble = 30 'uses lower 4 bits 'LCD DISPLAY DEFINITIONS Declare LCD_Interface 4 'only 4 bit bus ATO 07 Oct 2007 Declare LCD_DTPin LCD_DataS 'start pin for LCD data 'from H/W file definition Declare LCD_DTPort LCD_DataP 'data pins on port b p302 'from H/W file definition Declare LCD_ENPin LCD_E 'enable pin position 'from H/W file definition Declare LCD_RSPin LCD_RS 'rs pin position Port 1(register select) 'from H/W file definition SLRCON = %00000111 ;all ports [C,B,A] at MAXimum slew rate (data sheet page 96) '==================================================================================================== 'DEFINE VARIABLES '======================================================== Dim temp_byte_0a As Byte Dim temp_byte_0b As Byte Dim temp_byte_0c As Byte '=================== START EXECUTABLES ============================================= Main_Init: ' PORT CONFIGURATION TRISA = Sym_TRISA 'port A tri-state register TRISB = Sym_TRISB 'port B tri-state register TRISC = Sym_TRISC 'port C tri-state register ANSEL = Sym_ANSEL 'AN3 [ 7-0] active as A/D channel (Data sheet PAGE 94) (else diital READ is WRONG) ANSELH = Sym_ANSELH 'AN8 [11-8] active as A/D channel (Data sheet PAGE 95) Clear 'clear ALL RAM (incl. Flags) 'INITIALISE ---------------------------------------- temp_byte_0a = 0 'MAIN **** TEST **** PROGRAM LOOP STARTS HERE >>>>>>>>>>>>>>>>>> Main_Repeat_TEST: @Clrwdt temp_byte_0b = LookUp temp_byte_0a,[100,101,102,103,104] Print At 1,1, "index = ", Dec2 temp_byte_0a Print At 2,1, "value = ", Dec3 temp_byte_0b temp_byte_0a = temp_byte_0a + 1 If temp_byte_0a = 5 Then temp_byte_0a = 0 DelayMS 300 ;1000 GoTo Main_Repeat_TEST '************* end of *** TEST *** MAIN loop-repeat controlling code section **************** '========================= end of file ====================