Define CONFIG1H = %00000010 'Oscillator mode (set just x1 crystal)
Define CONFIG2L = %00000000 'Brown out reset (disabled)
Define CONFIG2H = %00000000 'Watchdog timer (disabled)
Define CONFIG3L = %00000000 'External bus (not implemented)
Define CONFIG3H = %00000000 'External reset & EECCP controls
Define CONFIG4L = %00000000 'ISP controls
Define CONFIG5L = %11111111 'Set code protection blocks (disabled)
Define CONFIG5H = %11000000 'EEPROM protetion (disabled)
Define CONFIG6L = %11111111 'Write protection (disabled)
Define CONFIG6H = %11100000 'EEPROM write protection
Define CONFIG7L = %11111111 'Write from other block protection
Define CONFIG7H = %01000000 'Root protection
Define CLOCK_FREQUENCY = 10
WaitMs 1
WDTCON = %00000000 'Diable watchdog
INTCON = %00000000 'Interrupt control (all disabled)
INTCON2 = %00000000 'Interrupt control
INTCON3 = %00000000 'Interrupt control
PIR1 = %00000000 'Peripheral interrupt select
PIR2 = %00000000 'Peripheral interrupt select
PIR3 = %00000000 'Peripheral interrupt select
PIE1 = %00000000 'Peripheral interrupt select
PIE2 = %00000000 'Peripheral interrupt select
PIE3 = %00000000 'Peripheral interrupt select
IPR1 = %00000000 'Interrupt priority
IPR2 = %00000000 'Interrupt priority
IPR3 = %00000000 'Interrupt priority
'0= Output, 1= Input
'RA7,6 Xtal - RA5,4 Spare ports on 16W - RA3 LCD Backlight on - RA2 3v3 Volts - RA1 Line Current - RA0 Line Volts
'***** RA3 will have to be an AN, but not used **** Backlight enable will have to be linked on ************
'Symbol lcd_light = PORTA.3 'Until the touch screen is turned on, this will work
'RB7,6,5 ISP - LCD Panel, RB4 CS*, RB3 RD*, RB2 WR*, RB1 RS - RB0 Touch Interrupt
TRISB = %11100001
PORTB = %00011100
Symbol lcd_cs = PORTB.4
Symbol lcd_rd = PORTB.3
Symbol lcd_wr = PORTB.2
Symbol lcd_rs = PORTB.1
'RC7 Serial TX - RC6 Serial RX - RC5 SD Data Out - RC4 SD Data In - RC3 SD Clk - RC2 SD CS - RC1 Loopthrough - RC0 Touched
TRISC = %10110001
PORTC = %00000110
Symbol loop_th = PORTC.1
Symbol touch = PORTC.2
'RD7,6,5,4,3,2,1,0 LCD Data LS Byte
TRISD = %00000000
PORTD = %00000000
Symbol lcd_ls = PORTD
'RE7,6,5,4,3,2,1,0 LCD Data MS Byte
TRISE = %00000000
PORTE = %00000000
Symbol lcd_ms = PORTE
'RF7 NC - RF6 Touch Enable - RF5 Touch Y drive - RF4 X Drive - RF3 Y Top - RF2 X Left - RF1 Y Bottom - RF0 X Right
TRISF = %10001111
PORTF = %00000000
Symbol touch_en = PORTF.6
Symbol drive_y = PORTF.5
Symbol drive_x = PORTF.4
Symbol touch_yt = PORTF.3
Symbol touch_xl = PORTF.2
Symbol touch_yb = PORTF.1
Symbol touch_xr = PORTF.0
'RG 4,3,2 NC - RG1,0 SD Card switches
TRISG = %11111111
T0CON = %00000000 'Timer 0 off
CCP1CON = %00000000 'Disable comparitors
CCP2CON = %00000000 'Disable comparitors
CCP3CON = %00000000 'Disable comparitors
CCP4CON = %00000000 'Disable comparitors
CCP5CON = %00000000 'Disable comparitors
ADCON0 = %00000000 'ADC idle for setup
ADCON1 = %00000110 'ADC channels 0 to 8 enabled
ADCON2 = %00100110 'Set ADC Clock
Const softver = 201 'Software version
Const panelt = 3 'Panel type 800x480 KD20050 - fixed in this version
Const comim1 = 3 'compatible image type
Const comim2 = 255 'compatible image type
Const comim3 = 255 'compatible image type
Dim paneln As Byte 'Panel number in chain
Dim tmp As Byte
Dim rsin As Byte 'Serial in data
Dim colour As Byte
Dim dform As Byte
Dim cx As Byte 'counter bytes
Dim cy As Byte
Dim x As Byte
Dim y As Byte
Dim tc As Word
Dim k As Byte
'enable loop through and start serial port
loop_th = 1
Hseropen 19200
'added to make sure it's UART 1
TXSTA1 = %00100000
RCSTA1 = %10010000