BMP PICTURES FROM SD CARD FAT32

Code Examples ››
Parent Previous Next

DEMO BMP PICTURES FROM SD CARD FAT32


Device = 33EP128MC504


Declare Xtal = 150

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\BDF\F0_BDF_Sail-Regular-60.inc"

Include                      "TftLib\TFT_Graphic_Lib.inc"



Main:

    Clear

    SetCrystal()

    SetPins()  

    TftSetBdfFont(0)          

    TftSetUp(0)       

    TftResetScreen(WHITE)

    TftBmpFromSD("BT1.BMP", 16,21)

    TftBmpFromSD("BT2.BMP", 71,81) 

    TftRectangleENTC(200,80, 248,128, BLUE)

    TftBmpFromSD("BT3.BMP", 201,81) 

    DelayMS 2000

    

    TftBmpFromSD("PIC001.BMP", 0,0) 

    DelayMS 1000

    TftPrintBdfString("Positron8", 30,160,319,0, NAVY_BLUE,WHITE, 1)

    TftPrintBdfString("&", 130,100,319,0, NAVY_BLUE,WHITE, 1)

    TftPrintBdfString("Positron16", 20,40,319,0, NAVY_BLUE,WHITE, 1)

    DelayMS 1000

    

    TftBmpFromSD("PIC004.BMP", 0,0) 

    DelayMS 1000

    TftPrintBdfString("Positron8", 30,160,319,0, SPRING_BUD,WHITE, 1)

    TftPrintBdfString("&", 130,100,319,0, SPRING_BUD,WHITE, 1)

    TftPrintBdfString("Positron16", 20,40,319,0, SPRING_BUD,WHITE, 1)

    DelayMS 1000

    

    TftBmpFromSD("PIC006.BMP", 0,0) 

    DelayMS 1000

    TftPrintBdfString("Positron8", 30,160,319,0, TITANIUM_YELLOW,WHITE, 1)

    TftPrintBdfString("&", 130,100,319,0, TITANIUM_YELLOW,WHITE, 1)

    TftPrintBdfString("Positron16", 20,40,319,0, TITANIUM_YELLOW,WHITE, 1)

    DelayMS 1000

    

    TftBmpFromSD("PIC009.BMP", 0,0) 

    DelayMS 1000

    TftPrintBdfString("Positron8", 30,160,319,0, RED,WHITE, 1)

    TftPrintBdfString("&", 130,100,319,0, RED,WHITE, 1)

    TftPrintBdfString("Positron16", 20,40,319,0, RED,WHITE, 1)

    DelayMS 1000

End    


'Set Fosc    

Proc SetCrystal()

    'Crystal = 16 MHz --> PLLDIV = 68 for 140MHz / PLLDIV = 73 For 150MHz

    CLKDIV = %0000000000000010 'PLLPRE = 2 ; PLLPOST = 0

    PLLFBD.Byte0 = 73 '--> 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: HelpNDoc's Project Analyzer: Incredible documentation assistant