DEMO BMP FILES TO AND FROM FLASH MEMORY
|
Device = 33EP128MC504 Declare Xtal = 140 Declare Watchdog = OFF Declare Warnings = OFF Declare Stack_Expand = On Declare Optimiser_Level = 3 Declare Access_Upper_64K = On '================ TFT SCREEN ================ $define TFT_IC ST7789V $define TFT_COM SPI_2 $define TftScreenWidth 320 $define TftScreenHeight 240 $define TFT_CS PORTC.9 $define TFT_RESET PORTC.2 $define TFT_DC PORTC.1 $define TFT_MOSI PORTC.6 $define TFT_MISO PORTC.5 $define TFT_SCLK PORTC.7 $define _TFT_MOSI _PORTC.6 $define _TFT_MISO _PORTC.5 $define _TFT_SCLK _PORTC.7 '================ TFT TOUCH ================ $define TOUCH_IC XPT2046 $define TOUCH_COM SPI_SW $define Z_Threshold 800 $define TouchAveragePoints 2 $define TouchMedianDistance 8 $define T_CS PORTC.8 $define T_IRQ PORTA.8 $define T_MOSI PORTC.6 $define T_MISO PORTC.5 $define T_SCLK PORTC.7 $define _T_MOSI _PORTC.6 $define _T_MISO _PORTC.5 $define _T_SCLK _PORTC.7 '================ MCU ================ $define McuType 1 '================ SD CARD ================ $define SDCardUsed 1 $define SDCardFatUsed 1 $define SD_COM SPI_1 $define SD_CS PORTA.1 $define SD_SDO PORTA.4 $define SD_SDI PORTA.9 $define SD_CLK PORTC.3 $define _SD_SDO _PORTA.4 $define _SD_SDI _PORTA.9 $define _SD_CLK _PORTC.3 '================ MEMORY ================ $define MemoryType 2 $define MEM_COM SPI_1 $define MEM_CS PORTA.7 $define MEM_MOSI PORTA.4 $define MEM_MISO PORTA.9 $define MEM_SCLK PORTC.3 $define _MEM_MOSI _PORTA.4 $define _MEM_MISO _PORTA.9 $define _MEM_SCLK _PORTC.3 $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\SND\F0_SND_8x8_Basic.Inc" Include "TftLib\TFT_Graphic_Lib.inc" 'Generated with Excel table $define TickMenu_List_Front 0 $define TickMenu_List_Back 1 $define TickMenu_List_Kitchen 2 $define TickMenu_List_Porch 3 $define TickMenu_List_All 4 $define TickMenu_Mark_Empty_Front 5 $define TickMenu_Mark_Empty_Back 6 $define TickMenu_Mark_Empty_Kitchen 7 $define TickMenu_Mark_Empty_Porch 8 $define TickMenu_Mark_Empty_All 9 $define Button_Up_Set 10 $define TickMenu_List_Front_Erase 11 $define TickMenu_List_Back_Erase 12 $define TickMenu_List_Kitchen_Erase 13 $define TickMenu_List_Porch_Erase 14 $define TickMenu_List_All_Erase 15 $define TickMenu_Mark_Check_Front 16 $define TickMenu_Mark_Check_Back 17 $define TickMenu_Mark_Check_Kitchen 18 $define TickMenu_Mark_Check_Porch 19 $define TickMenu_Mark_Check_All 20 $define Button_Down_Set 21 $define Tree_TickMenu_Show 22 $define Tree_Button_Door_Show 23 $define Button_Down_Lock 24 $define Button_Down_Unlock 25 $define Button_Down_Door 26 $define Tree_TickMenu_Hide 27 $define Tree_Button_Door_Hide 28 $define Button_Up_Door 29 $define Button_Up_Lock 30 $define Button_Up_Unlock 31 $define Button_Hide_Lock 32 $define Button_Hide_Unlock 33 $define Button_Hide_Set 34 $define MainScreen 35 $define Message_Clear 36 Dim sFileName As String * 12 Dim bCounter1 As Byte Dim bCounter2 As Byte Dim wBitVariable As Word Dim ButtonDoor As wBitVariable.0 Dim ButtonLock As wBitVariable.1 = 1 Dim ButtonUnlock As wBitVariable.2 = 0 Dim ButtonSet As wBitVariable.3 Dim TickFront As wBitVariable.4 Dim TickBack As wBitVariable.5 Dim TickKitchen As wBitVariable.6 Dim TickPorch As wBitVariable.7 Dim TickAll As wBitVariable.8 Main: Clear SetCrystal() SetPins() TftBmpMemSet() TftSetSndFont(0,0) TftSetUp(0) TftResetScreen(BLACK) TransferFilesToFlash() TftTouchCalibration(3) 'Mask full screen transfer lag by switching off the screen during transfer TftDisplayOff() TftBmpFromMemIndex(MainScreen, 0, 0) TftDisplayOn()
While 1 = 1 'Touch IRQ triggered If T_IRQ = 0 Then 'if touch ADC values are within valid range If TftTouchGetCoordinates(1) = 1 Then 'check if valid menu has been selected ClickMenu(wTouchToPointX, wTouchToPointY) 'Debounce DelayMS 300 EndIf EndIf Wend End Proc TransferFilesToFlash() Dim wTemp As Dword
'Some delay to avoid accidental FLASH erasure TftPrintSndString("File transfer in ", 1, 5,13,1, GREEN,BLACK,0) For bCounter1 = 4 DownTo 0 TftPrintSndInteger(bCounter1,1, 1, 23,13,1, GREEN,BLACK,0) DelayMS 1000 Next
TftPrintSndString("Format memory start", 1, 5,13,1, GREEN,BLACK,0) TftBmpMemFormat() TftPrintSndString("Format memory done ", 1, 5,13,1, GREEN,BLACK,0) DelayMS 1000
bCounter2 = 0 'Generate file names as in SD card and transfer For bCounter1 = 0 To 36 sFileName = "P" + Str$(Dec3 bCounter1) + ".BMP" TftPrintSndString(sFileName, 1, 5,12,1, GREEN,BLACK,0) TftPrintSndString(" ", 1, 14,12,1, GREEN,BLACK,0) Inc bCounter2 Select TftBmpSdToMem(sFileName) Case 0 Dec bCounter2 Case 1 TftPrintSndString("SD NO RESPONSE ", 1, 14,12,1, GREEN,BLACK,0) DelayMS 1000 Case 2 TftPrintSndString("NO FAT16/FAT32 ", 1, 14,12,1, GREEN,BLACK,0) DelayMS 1000 Case 3 TftPrintSndString("FILE NOT FOUND ", 1, 14,12,1, GREEN,BLACK,0) DelayMS 1000 Case 4 TftPrintSndString("FILE IN USE ", 1, 14,12,1, GREEN,BLACK,0) DelayMS 1000 Case 5 TftPrintSndString("READ/WRITE ERROR", 1, 14,12,1, GREEN,BLACK,0) DelayMS 1000 Case 6 TftPrintSndString("MEMORY ERROR ", 1, 14,12,1, GREEN,BLACK,0) DelayMS 1000 Case 7 TftPrintSndString("NO FREE SPACE ", 1, 14,12,1, GREEN,BLACK,0) DelayMS 1000 Case Else TftPrintSndString("UNKNOWN ERROR ", 1, 14,12,1, GREEN,BLACK,0) DelayMS 1000 EndSelect Next TftPrintSndString("Done with " + Str$(Dec3 bCounter2) + " errors", 1, 5,11,1, GREEN,BLACK,0) DelayMS 1000 EndProc Proc ClickMenu(wPointX As Word, wPointY As Word) 'Button door If wPointX > 17 And wPointX < 106 And wPointY > 189 And wPointY < 221 Then Toggle ButtonDoor ButtonDoor_Change() ExitProc EndIf 'Button lock If wPointX > 127 And wPointX < 216 And wPointY > 189 And wPointY < 221 Then If ButtonDoor = 1 Then Toggle ButtonLock ButtonLock_Change() EndIf ExitProc EndIf
'Button unlock If wPointX > 127 And wPointX < 216 And wPointY > 145 And wPointY < 177 Then If ButtonDoor = 1 Then Toggle ButtonUnlock ButtonUnlock_Change() EndIf ExitProc EndIf
'Tick front If wPointX > 233 And wPointX < 265 And wPointY > 194 And wPointY < 219 Then If ButtonDoor = 1 Then Toggle TickFront TickFront_Change() EndIf ExitProc EndIf
'Tick back If wPointX > 233 And wPointX < 265 And wPointY > 163 And wPointY < 188 Then If ButtonDoor = 1 Then Toggle TickBack TickBack_Change() EndIf ExitProc EndIf
'Tick kitchen If wPointX > 233 And wPointX < 265 And wPointY > 134 And wPointY < 159 Then If ButtonDoor = 1 Then Toggle TickKitchen TickKitchen_Change() EndIf ExitProc EndIf
'Tick porch If wPointX > 233 And wPointX < 265 And wPointY > 104 And wPointY < 129 Then If ButtonDoor = 1 Then Toggle TickPorch TickPorch_Change() EndIf ExitProc EndIf
'Tick all If wPointX > 233 And wPointX < 265 And wPointY > 74 And wPointY < 99 Then If ButtonDoor = 1 Then Toggle TickAll TickAll_Change() EndIf ExitProc EndIf
'Button Set If wPointX > 233 And wPointX < 318 And wPointY > 12 And wPointY < 45 Then If ButtonDoor = 1 Then TickButtonSet_Change() EndIf ExitProc EndIf EndProc Proc TickButtonSet_Change() TftBmpFromMemIndex(Button_Down_Set, 233, 12) DelayMS 1000 TftBmpFromMemIndex(Button_Up_Set, 233, 12) If ButtonLock = 1 Then TftBmpFromMemIndex(Message_Clear, 59, 221) TftPrintSndString("Door LOCK ... Done", 1,10,28,1, CARDINAL, BLACK,1) Else TftBmpFromMemIndex(Message_Clear, 59, 221) TftPrintSndString("Door UNLOCK ... Done", 1,9,28,1, CARDINAL, BLACK,1) EndIf EndProc Proc TickAll_Change() If TickAll = 0 Then TftBmpFromMemIndex(TickMenu_Mark_Empty_All, 233, 74) wBitVariable = wBitVariable & %1111111100001111 TickPorch_Change() TickKitchen_Change() TickBack_Change() TickFront_Change() Else TftBmpFromMemIndex(TickMenu_Mark_Check_All, 233, 74) wBitVariable = wBitVariable | %0000000011110000 TickPorch_Change() TickKitchen_Change() TickBack_Change() TickFront_Change() EndIf EndProc Proc TickPorch_Change() If TickPorch = 0 Then TftBmpFromMemIndex(TickMenu_Mark_Empty_Porch, 233, 104) TftBmpFromMemIndex(TickMenu_Mark_Empty_All, 233, 74) TickAll = 0 Else TftBmpFromMemIndex(TickMenu_Mark_Check_Porch, 233, 104) If (wBitVariable & %0000000011110000) = %11110000 Then TftBmpFromMemIndex(TickMenu_Mark_Check_All, 233, 74) EndIf EndIf EndProc Proc TickKitchen_Change() If TickKitchen = 0 Then TftBmpFromMemIndex(TickMenu_Mark_Empty_Kitchen, 233, 134) TftBmpFromMemIndex(TickMenu_Mark_Empty_All, 233, 74) TickAll = 0 Else TftBmpFromMemIndex(TickMenu_Mark_Check_Kitchen, 233, 134) If (wBitVariable & %0000000011110000) = %11110000 Then TftBmpFromMemIndex(TickMenu_Mark_Check_All, 233, 74) EndIf EndIf EndProc Proc TickBack_Change() If TickBack = 0 Then TftBmpFromMemIndex(TickMenu_Mark_Empty_Back, 233, 163) TftBmpFromMemIndex(TickMenu_Mark_Empty_All, 233, 74) TickAll = 0 Else TftBmpFromMemIndex(TickMenu_Mark_Check_Back, 233, 163) If (wBitVariable & %0000000011110000) = %11110000 Then TftBmpFromMemIndex(TickMenu_Mark_Check_All, 233, 74) EndIf EndIf EndProc Proc TickFront_Change() If TickFront = 0 Then TftBmpFromMemIndex(TickMenu_Mark_Empty_Front, 233, 194) TftBmpFromMemIndex(TickMenu_Mark_Empty_All, 233, 74) TickAll = 0 Else TftBmpFromMemIndex(TickMenu_Mark_Check_Front, 233, 194) If (wBitVariable & %0000000011110000) = %11110000 Then TftBmpFromMemIndex(TickMenu_Mark_Check_All, 233, 74) EndIf EndIf EndProc Proc ButtonUnlock_Change() If ButtonUnlock = 0 Then ButtonLock = 1 TftBmpFromMemIndex(Button_Up_Unlock, 127, 145) TftBmpFromMemIndex(Button_Down_Lock, 127, 189)
Else ButtonLock = 0 TftBmpFromMemIndex(Button_Down_Unlock, 127, 145) TftBmpFromMemIndex(Button_Up_Lock, 127, 189) EndIf EndProc Proc ButtonLock_Change() If ButtonLock = 0 Then ButtonUnlock = 1 TftBmpFromMemIndex(Button_Down_Unlock, 127, 145) TftBmpFromMemIndex(Button_Up_Lock, 127, 189) Else ButtonUnlock = 0 TftBmpFromMemIndex(Button_Up_Unlock, 127, 145) TftBmpFromMemIndex(Button_Down_Lock, 127, 189) EndIf EndProc Proc ButtonDoor_Change() If ButtonDoor = 0 Then TftBmpFromMemIndex(Button_Hide_Set, 233, 12) TftBmpFromMemIndex(TickMenu_List_All_Erase, 233, 74) TftBmpFromMemIndex(TickMenu_List_Porch_Erase, 233, 104) TftBmpFromMemIndex(TickMenu_List_Kitchen_Erase, 233, 134) TftBmpFromMemIndex(Button_Hide_Unlock, 127, 145) TftBmpFromMemIndex(TickMenu_List_Back_Erase, 233, 163) TftBmpFromMemIndex(Tree_TickMenu_Hide, 216, 87) TftBmpFromMemIndex(Tree_Button_Door_Hide, 106, 162) TftBmpFromMemIndex(Button_Hide_Lock, 127, 189) TftBmpFromMemIndex(TickMenu_List_Front_Erase, 233, 194) TftBmpFromMemIndex(Button_Up_Door, 17, 189) TftBmpFromMemIndex(Message_Clear, 59, 221) Else TftBmpFromMemIndex(Button_Down_Door, 17, 189) TftBmpFromMemIndex(Tree_Button_Door_Show, 106, 162)
If ButtonLock = 0 Then TftBmpFromMemIndex(Button_Up_Lock, 127, 189) Else TftBmpFromMemIndex(Button_Down_Lock, 127, 189) EndIf
If ButtonUnlock = 0 Then TftBmpFromMemIndex(Button_Up_Unlock, 127, 145) Else TftBmpFromMemIndex(Button_Down_Unlock, 127, 145) EndIf
TftBmpFromMemIndex(Tree_TickMenu_Show, 216, 87)
If TickFront = 0 Then TftBmpFromMemIndex(TickMenu_Mark_Empty_Front, 233, 194) Else TftBmpFromMemIndex(TickMenu_Mark_Check_Front, 233, 194) EndIf TftBmpFromMemIndex(TickMenu_List_Front, 264, 201)
If TickBack = 0 Then TftBmpFromMemIndex(TickMenu_Mark_Empty_Back, 233, 163) Else TftBmpFromMemIndex(TickMenu_Mark_Check_Back, 233, 163) EndIf TftBmpFromMemIndex(TickMenu_List_Back, 264, 166)
If TickKitchen = 0 Then TftBmpFromMemIndex(TickMenu_Mark_Empty_Kitchen, 233, 134) Else TftBmpFromMemIndex(TickMenu_Mark_Check_Kitchen, 233, 134) EndIf TftBmpFromMemIndex(TickMenu_List_Kitchen, 264, 136)
If TickPorch = 0 Then TftBmpFromMemIndex(TickMenu_Mark_Empty_Porch, 233, 104) Else TftBmpFromMemIndex(TickMenu_Mark_Check_Porch, 233, 104) EndIf TftBmpFromMemIndex(TickMenu_List_Porch, 264, 106)
If TickAll = 0 Then TftBmpFromMemIndex(TickMenu_Mark_Empty_All, 233, 74) Else TftBmpFromMemIndex(TickMenu_Mark_Check_All, 233, 74) EndIf TftBmpFromMemIndex(TickMenu_List_All, 264, 75)
TftBmpFromMemIndex(Button_Up_Set, 233, 12) EndIf EndProc
'Set Fosc Proc SetCrystal() 'Crystal = 16 MHz --> PLLDIV = 68 for 140MHz / PLLDIV = 73 For 150MHz CLKDIV = %0000000000000010 'PLLPRE = 2 ; PLLPOST = 0 PLLFBD.Byte0 = 68 '--> 150MHz Fp 'Wait for oscillator PLL lock While OSCCON.5 = 0 : Wend DelayMS 100 EndProc Proc SetPins() 'Set all digital ANSELA = 0 ANSELB = 0 ANSELC = 0
'RP55 to SCK2 / RP54 To SDO2 / RPI53 to SDI2 RPOR5.Byte1 = %00001001 'RP55 RPOR5.Byte0 = %00001000 'RP54 RPINR22.Byte0 = %00110101 'SDI2 RPINR22.Byte1 = %00110111 'SCK2
SPI2CON1 = 0x033B '8b / SPRE[2:0] 2:1 / PPRE[1:0] 1:1 SPI2STAT = 0x8000
SPI1CON1 = 0x033B '8b / SPRE[2:0] 2:1 / PPRE[1:0] 1:1 SPI1STAT = 0x8000 EndProc Config FICD = ICS_PGD1, JTAGEN_OFF Config FPOR = ALTI2C1_OFF, ALTI2C2_OFF, WDTWIN_WIN25 Config FWDT = FWDTEN_OFF, PLLKEN_ON, WDTPOST_PS16384, WDTPRE_PR128, WINDIS_OFF Config FOSC = FCKSM_CSECMD, IOL1WAY_OFF, OSCIOFNC_OFF, POSCMD_HS Config FOSCSEL = FNOSC_PRIPLL, IESO_ON, PWMLOCK_OFF Config FGS = GCP_OFF, GWRP_OFF |
Created with the Personal Edition of HelpNDoc: Upgrade your help files and your workflow with HelpNDoc's WinHelp HLP to CHM conversion