DEMO BLACK BOARD
|
Device = 18F67K22 Declare Xtal = 64 Declare Watchdog = OFF Declare Warnings = Off Declare Optimiser_Level = 3 '================ TFT SCREEN ================ $define TFT_IC ST7789V $define TFT_COM SPI_1 $define TftScreenWidth 320 $define TftScreenHeight 240 $define TFT_CS PORTF.7 $define TFT_RESET PORTC.7 $define TFT_DC PORTC.2 $define TFT_MOSI PORTC.5 $define TFT_MISO PORTC.4 $define TFT_SCLK PORTC.3 $define _TFT_MOSI _PORTC.5 $define _TFT_MISO _PORTC.4 $define _TFT_SCLK _PORTC.3 '================ TFT TOUCH ================ $define TOUCH_IC XPT2046 $define TOUCH_COM SPI_SW $define Z_Threshold 600 $define TouchAveragePoints 2 $define TouchMedianDistance 8 $define T_CS PORTG.1 $define T_IRQ PORTA.5 $define T_MOSI PORTC.5 $define T_MISO PORTC.4 $define T_SCLK PORTC.3 $define _T_MOSI _PORTC.5 $define _T_MISO _PORTC.4 $define _T_SCLK _PORTC.3 '================ MCU ================ $define McuType 0 '================ SD CARD ================ $define SDCardUsed 0 $define SDCardFatUsed 0 $define SD_COM SPI_2 $define SD_CS PORTG.3 $define SD_SDO PORTD.4 $define SD_SDI PORTD.5 $define SD_CLK PORTD.6 $define _SD_SDO _PORTD.4 $define _SD_SDI _PORTD.5 $define _SD_CLK _PORTD.6 '================ MEMORY ================ $define MemoryType 2 $define MEM_COM SPI_2 $define MEM_CS PORTA.2 $define MEM_MOSI PORTD.4 $define MEM_MISO PORTD.5 $define MEM_SCLK PORTD.6 $define _MEM_MOSI _PORTD.4 $define _MEM_MISO _PORTD.5 $define _MEM_SCLK _PORTD.6 $define MEM_PAGE_SIZE 256 $define MEM_SECTOR_SIZE 4096 $define MEM_SECTOR_COUNT 2048 $define MEM_FILE_COUNT 256 $define MEM_WRITE_DELAY 5 '================ FONT ================ $define FontSmooth 0 $define FontMaxSpace 8 $define FontMaxPixels 8 Include "TftLib\Fonts\BDF\F4_BDF_Ranchers-Regular-23.inc" Include "TftLib\TFT_Graphic_Lib.inc" Dim pButtonMode As Bit Dim pBufferReset As Bit = 1 Dim wTouchToPointXOld As Word Dim wTouchToPointYOld As Word On_Hardware_Interrupt GoTo Isr GoTo Main Isr: Context Save T1CON.0 = 0 pBufferReset = 1 TMR1H = $63 : TMR1L = $C0 PIR1.0 = 0 Context Restore
Main: Clear SetCrystal() SetPins() SetTimer1() TftSetUp(0) TftResetScreen(BLACK) TftTouchCalibration(3) SetScreen() DelayMS 1000
While 1 = 1 If T_IRQ = 0 Then If TftTouchGetCoordinates(0) = 1 Then 'Check if within board area, if not check buttons If wTouchToPointY > 44 And wTouchToPointY < 235 And wTouchToPointX > 4 And wTouchToPointX < 315 Then 'Print pixel If pButtonMode = 0 Then If pBufferReset = 0 Then If Abs(wTouchToPointX - wTouchToPointXOld) < 3 Then If Abs(wTouchToPointY - wTouchToPointYOld) < 3 Then TftPixel(wTouchToPointX, wTouchToPointY, GREEN) wTouchToPointXOld = wTouchToPointX wTouchToPointYOld = wTouchToPointY T1CON.0 = 0 : TMR1H = $63 : TMR1L = $C0 : T1CON.0 = 1 EndIf EndIf Else TftPixel(wTouchToPointX, wTouchToPointY, GREEN) wTouchToPointXOld = wTouchToPointX wTouchToPointYOld = wTouchToPointY pBufferReset = 0 T1CON.0 = 1 EndIf Else 'Erase 4x4 pixel area TftRectangleSNCP(wTouchToPointX, wTouchToPointY, 4,4, BLACK) EndIf Else CheckButtons() EndIf EndIf EndIf Wend End
Proc CheckButtons() If wTouchToPointY > 6 And wTouchToPointY < 34 Then Select wTouchToPointX Case 25 To 95 TftRectangleRC(120,5, 200,35, 10, 0,BURNISHED_BROWN, 2,-1) TftRectangleRC(20,5, 100,35, 10, 0,RED, 2,-1) pButtonMode = 0 Case 125 To 195 TftRectangleRC(20,5, 100,35, 10, 0,BURNISHED_BROWN, 2,-1) TftRectangleRC(120,5, 200,35, 10, 0,RED, 2,-1) pButtonMode = 1 Case 225 To 295 TftRectangleRC(20,5, 100,35, 10, 0,BURNISHED_BROWN, 2,-1) TftRectangleRC(120,5, 200,35, 10, 0,BURNISHED_BROWN, 2,-1) TftRectangleRC(220,5, 300,35, 10, 0,RED, 2,-1) TftRectangleSNTC(3,41, 316,236, BLACK) DelayMS 200 TftRectangleRC(220,5, 300,35, 10, 0,BURNISHED_BROWN, 2,-1) TftRectangleRC(20,5, 100,35, 10, 0,RED, 2,-1) pButtonMode = 0 EndSelect EndIf EndProc Proc SetScreen() TftResetScreen(BLACK) 'Outside frame TftRectangleTCG(0,0, 319,40, AZURE, WHITE, 1) TftRectangleETTCI(0,0, 319,40, ANTIQUE_RUBY, 2) TftRectangleETTCI(0,38, 319,239, ANTIQUE_RUBY, 2) 'Print buttons TftRectangleRCG(20,5, 100,35, 10, ANTIQUE_BRASS,BRONZE, 1) TftRectangleRCG(120,5, 200,35, 10, ANTIQUE_BRASS,BRONZE, 1) TftRectangleRCG(220,5, 300,35, 10, ANTIQUE_BRASS,BRONZE, 1) TftRectangleRC(20,5, 100,35, 10, 0,BURNISHED_BROWN, 2,-1) TftRectangleRC(120,5, 200,35, 10, 0,BURNISHED_BROWN, 2,-1) TftRectangleRC(220,5, 300,35, 10, 0,BURNISHED_BROWN, 2,-1) TftSetBdfFont(4) TftPrintBdfString("Write", 34, 12, 480, 0, WARM_BLACK, WHITE, 1) TftPrintBdfString("Erase", 134, 12, 480, 0, WARM_BLACK, WHITE, 1) TftPrintBdfString("Reset", 234, 12, 480, 0, WARM_BLACK, WHITE, 1) TftRectangleRC(20,5, 100,35, 10, 0,RED, 2,-1) EndProc 'Set Fosc Proc SetCrystal() Clear OSCTUNE.6 = 1 DelayMS 100 EndProc Proc SetPins() 'Set all digital ANCON0 = 0 ANCON1 = 0 ANCON2 = 0 SSP1STAT.6 = 1 SSP1CON1 = %00100000 EndProc Proc SetTimer1() T1CON.7 = 0 : T1CON.6 = 0 'FOSC /4 T1CON.5 = 1 : T1CON.4 = 0 '1:4 Prescaler T1CON.3 = 0 'Dedicated T1 oscillator disabled T1CON.2 = 1 'Do not synchronize T1CON.1 = 0 '8-bit T1CON.0 = 0 'TMR1 ON / Off TMR1H = $63 : TMR1L = $C0 INTCON.7 = 1 : INTCON.6 = 1 : PIR1.0 = 0 : PIE1.0 = 1 EndProc Config_Start RETEN = On ;Enabled INTOSCSEL = Low ;LF-INTOSC in Low-power mode during Sleep SOSCSEL = Dig ;digital XINST = OFF ;Disabled FOSC = EC2 ;HS oscillator (High power, 16 MHz - 25 MHz) PLLCFG = On ;Enabled FCMEN = OFF ;Disabled IESO = OFF ;Disabled PWRTEN = OFF ;Disabled BOREN = OFF ;Disabled in hardware, SBOREN disabled BORV = 0 ;3.0V BORPWR = High ;BORMV set to high power level WDTEN = OFF ;WDT disabled in hardware; SWDTEN bit disabled WDTPS = 1048576 ;1:1048576 RTCOSC = SOSCREF ;RTCC uses SOSC CCP2MX = PORTBE ;RC1 MSSPMSK = MSK7 ;7 Bit address masking mode MCLRE = On ;MCLR Enabled, RG5 Disabled STVREN = On ;Enabled BBSIZ = BB2K ;2K word Boot Block size Debug = OFF ;Disabled Cp0 = OFF ;Disabled CP1 = OFF ;Disabled CP2 = OFF ;Disabled CP3 = OFF ;Disabled CP4 = OFF ;Disabled CP5 = OFF ;Disabled CP6 = OFF ;Disabled CP7 = OFF ;Disabled CPB = OFF ;Disabled CPD = OFF ;Disabled WRT0 = OFF ;Disabled WRT1 = OFF ;Disabled WRT2 = OFF ;Disabled WRT3 = OFF ;Disabled WRT4 = OFF ;Disabled WRT5 = OFF ;Disabled WRT6 = OFF ;Disabled WRT7 = OFF ;Disabled WRTC = OFF ;Disabled WRTB = OFF ;Disabled WRTD = OFF ;Disabled EBRT0 = OFF ;Disabled EBRT1 = OFF ;Disabled EBRT2 = OFF ;Disabled EBRT3 = OFF ;Disabled EBRT4 = OFF ;Disabled EBRT5 = OFF ;Disabled EBRT6 = OFF ;Disabled EBRT7 = OFF ;Disabled EBRTB = OFF ;Disabled Config_End |
Created with the Personal Edition of HelpNDoc: Easily create iPhone documentation