Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
void PutPixel(SHORT x, SHORT y)
{
CS_LAT_BIT = 0;
Write_GE_RegAddr( REG38_WINXSPOS0 );
Write_GE_RegData( (Uint8)x ); // lower byte of x start
Write_GE_RegData( (Uint8)(x>>8) ); // upper byte of x start
Write_GE_RegData( (Uint8)y ); // lower byte of y start
Write_GE_RegData( (Uint8)(y>>8) ); // upper byte of y start
Write_GE_RegData( (Uint8)x+1 ); // lower byte of x end
Write_GE_RegData( (Uint8)((x+1)>>8) ); // upper byte of x end
Write_GE_RegData( (Uint8)y+1 ); // lower byte of y end
Write_GE_RegData( (Uint8)((y+1)>>8) ); // upper byte of y end
Write_GE_SRAMData( _color.Val );
CS_LAT_BIT = 1;
}
void Bar(SHORT left, SHORT top, SHORT right, SHORT bottom)
{
Uint16 x, y;
Uint32 nbr_of_pixels;
x = left;
y = top;
nbr_of_pixels = (right - left + 1) * (bottom - top + 1);
CS_LAT_BIT = 0;
// Set register access to window X start position and write the position
// data. The register access will autoincrement until it reaches the GRAM
// data. Once GRAM is reached, just output data for each pixel until all
// pixels have been written
Write_GE_RegAddr( REG38_WINXSPOS0 );
Write_GE_RegData( (Uint8)left ); // lower byte of x start
Write_GE_RegData( (Uint8)(left>>8) ); // upper byte of x start
Write_GE_RegData( (Uint8)top ); // lower byte of y start
Write_GE_RegData( (Uint8)(top>>8) ); // upper byte of y start
Write_GE_RegData( (Uint8)right ); // lower byte of x end
Write_GE_RegData( (Uint8)(right>>8) ); // upper byte of x end
Write_GE_RegData( (Uint8)bottom ); // lower byte of y end
Write_GE_RegData( (Uint8)(bottom>>8) ); // upper byte of y end
while (nbr_of_pixels--)
{
Write_GE_SRAMData( _color.Val );
}
CS_LAT_BIT = 1;
}
//#define SetIndex(index) RS_LAT_BIT=0;PMDIN1=0;PMPWaitBusy();PMDIN1=index;PMPWaitBusy();
#define SetIndex(index) RS_LAT_BIT=0; PMDIN1=index; PMPWaitBusy();
//#define WriteData(byte1,byte0) RS_LAT_BIT=1;PMDIN1=byte1;PMPWaitBusy();PMDIN1=byte0;PMPWaitBusy();
#define WriteData(byte1,byte0) RS_LAT_BIT=1;PMDIN1=(byte1<<8 | byte0); PMPWaitBusy();
#if INVERT_DISPLAY
#define SetAddress(addr2,addr1,addr0) \
SetIndex(0x20);WriteData(0,GetMaxX()-addr0);\
SetIndex(0x21);WriteData(addr2,addr1);\
SetIndex(0x22);
#else
#define SetAddress(addr2,addr1,addr0) \
SetIndex(0x20);WriteData(0,addr0);\
SetIndex(0x21);WriteData(addr2,addr1);\
SetIndex(0x22);
#endif
void write_command(unsigned int command)
{
CLR_CD;
PMDIN1 = command;
}
void write_data(unsigned int data)
{
SET_CD;
PMDIN1 = data;
}
// ---------------------------------------
//PMP setup
//---------------------------------------
PMMODE = 0; PMAEN = 0; PMCON = 0;
PMMODEbits.MODE = 2; // Intel 80 master interface
PMMODEbits.WAITB = 0;
PMMODEbits.WAITM = 0b0001;
PMMODEbits.WAITE = 0;
PMMODEbits.MODE16 = 0; // 8-bit Mode
PMCONbits.PTRDEN = 1; // enable RD line
PMCONbits.PTWREN = 1; // enable WR line
PMCONbits.WRSP = 0; // Make WR active low
PMCONbits.RDSP = 0; // Make RD active low
PMCONbits.CSF0 = 0b10; // PMCS1 functions as chip select
//PMCONbits.CSF2 = 0b
PMCONbits.PMPEN = 1; // enable PMP
//---------------------------------------
//---------------------------------------
//Configure for 39.92MhzMIPS using FRC w/PLL
//---------------------------------------
CLKDIVbits.PLLPRE = 1; //7.37Mhz/3 = 2.457Mhz
PLLFBDbits.PLLDIV = 63; //PLLDIV+2 = 65 = VCO out:159.683Mhz
CLKDIVbits.PLLPOST = 0; //Fcy=((((Oscilator/PLLPRE)*(PLLDIV+2))/PLLPOST)/2)
// =((((7.37Mhz/3)*(65))/2)/2) = 39.92Mhz
while(!OSCCONbits.LOCK);
//---------------------------------------
#include "p33FJ128MC804.h"
#include <libpic30.h>
#include "customdelays.h"
//********Configuration Bytes********//
_FBS(RBS_NO_RAM & BSS_NO_FLASH & BWRP_WRPROTECT_OFF);
_FSS(RSS_NO_RAM & SSS_NO_FLASH & SWRP_WRPROTECT_OFF);
_FGS(GSS_OFF & GCP_OFF & GWRP_OFF);
_FOSCSEL(FNOSC_FRCPLL & IESO_OFF);
_FOSC(FCKSM_CSECME & IOL1WAY_ON & OSCIOFNC_ON & POSCMD_NONE);
_FWDT(FWDTEN_OFF & WINDIS_OFF & WDTPRE_PR128 & WDTPOST_PS32768);
_FPOR(PWMPIN_ON & HPOL_ON & LPOL_ON & ALTI2C_OFF & FPWRT_PWR128);
_FICD(JTAGEN_OFF & ICS_PGD1);
int main(void);
/* Control line pin definitions */
#define CLR_RST LATBbits.LATB2 = 0;
#define SET_RST LATBbits.LATB2 = 1;
#define CLR_CD LATCbits.LATC0 = 0;
#define SET_CD LATCbits.LATC0 = 1;
#define CLR_CS LATBbits.LATB3 = 0;
#define SET_CS LATBbits.LATB3 = 1;
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
//*********Function Prototypes*******//
void write_command(unsigned int command)
{
CLR_CS;
CLR_CD;
PMDIN1 = (command>>8);
DELAY_US(1);
PMDIN1 = (command);
DELAY_US(1);
SET_CS;
}
void write_data(unsigned int data)
{
CLR_CS;
SET_CD;
PMDIN1 = (data>>8);
DELAY_US(1);
PMDIN1 = (data);
DELAY_US(1);
SET_CS;
}
void initialization()
{
SET_CS;
SET_CD;
SET_RST;
write_data(0x00);
CLR_RST;
DELAY_MS(200);
SET_RST;
DELAY_MS(500);
write_command(0x0028); // VCOM OTP
write_data(0x0006); // Page 55-56 of SSD2119 datasheet
write_command(0x0000); // start Oscillator
write_data(0x0001); // Page 36 of SSD2119 datasheet
write_command(0x0010); // Sleep mode
write_data(0x0000); // Page 49 of SSD2119 datasheet
write_command(0x0001); // Driver Output Control
write_data(0x32EF); // Page 36-39 of SSD2119 datasheet
write_command(0x0002); // LCD Driving Waveform Control
write_data(0x0600); // Page 40-42 of SSD2119 datasheet
write_command(0x0003); // Power Control 1
write_data(0x6A38); // Page 43-44 of SSD2119 datasheet
write_command(0x0011); // Entry Mode
write_data(0x6870); // Page 50-52 of SSD2119 datasheet
write_command(0X000F); // Gate Scan Position
write_data(0x0000); // Page 49 of SSD2119 datasheet
write_command(0X000B); // Frame Cycle Control
write_data(0x5308); // Page 45 of SSD2119 datasheet
write_command(0x000C); // Power Control 2
write_data(0x0003); // Page 47 of SSD2119 datasheet
write_command(0x000D); // Power Control 3
write_data(0x000A); // Page 48 of SSD2119 datasheet
write_command(0x000E); // Power Control 4
write_data(0x2E00); // Page 48 of SSD2119 datasheet
write_command(0x001E); // Power Control 5
write_data(0x00BE); // Page 53 of SSD2119 datasheet
write_command(0x0025); // Frame Frequency Control
write_data(0x8000); // Page 53 of SSD2119 datasheet
write_command(0x0026); // Analog setting
write_data(0x7800); // Page 54 of SSD2119 datasheet
write_command(0x004E); // Ram Address Set
write_data(0x0000); // Page 58 of SSD2119 datasheet
write_command(0x004F); // Ram Address Set
write_data(0x0000); // Page 58 of SSD2119 datasheet
write_command(0x0012); // Sleep mode
write_data(0x08D9); // Page 49 of SSD2119 datasheet
// Gamma Control (R30h to R3Bh) -- Page 56 of SSD2119 datasheet
write_command(0x0030);
write_data(0x0000);
write_command(0x0031);
write_data(0x0104);
write_command(0x0032);
write_data(0x0100);
write_command(0x0033);
write_data(0x0305);
write_command(0x0034);
write_data(0x0505);
write_command(0x0035);
write_data(0x0305);
write_command(0x0036);
write_data(0x0707);
write_command(0x0037);
write_data(0x0300);
write_command(0x003A);
write_data(0x1200);
write_command(0x003B);
write_data(0x0800);
write_command(0x0007); // Display Control
write_data(0x0033); // Page 45 of SSD2119 datasheet
DELAY_MS(150);
write_command(0x0022); // RAM data write/read
}
void Display_Home()
{
write_command(0x004E); // RAM address set
write_data(0x0000); // Page 58 of SSD2119 datasheet
write_command(0x004F); // RAM address set
write_data(0x0000); // Page 58 of SSD2119 datasheet
write_command(0x0044); // Vertical RAM address position
write_data(0xEF00); // Page 57 of SSD2119 datasheet
write_command(0x0045); // Horizontal RAM address position
write_data(0x0000); // Page 57 of SSD2119 datasheet
write_command(0x0046); // Horizontal RAM address position
write_data(0x013F); // Page 57 of SSD2119 datasheet
write_command(0x0022); // RAM data write/read
}
void LCD_test()
{
unsigned int i,j;
Display_Home();
for(i=0;i<320;i++)
{
for(j=0;j<240;j++)
{
if(i>279)write_data(BLACK);
else if(i>239)write_data(BLUE);
else if(i>199)write_data(GREEN);
else if(i>159)write_data(CYAN);
else if(i>119)write_data(RED);
else if(i>79)write_data(MAGENTA);
else if(i>39)write_data(YELLOW);
else write_data(WHITE);
}
}
}
void display_rgb(unsigned int data)
{
unsigned int i,j;
Display_Home();
for(i=0;i<320;i++)
{
for(j=0;j<240;j++)
{
write_data(data);
}
}
}
int main()
{
AD1PCFGL = 0x0FFF; // Disable ADC, make AN pins Digital I/O
AD1CON2 = 0x0000; // Use AVDD and AVSS as ADC reference voltages
IC1CON = 0x0000; // Disable change notification on CN3
IC2CON = 0x0000; // Disable change notification on CN4 and all other CNs
TRISA = 0x0000; // Configure port A all as digital I/O
TRISB = 0x0000; // Configure port B all as digital I/O
TRISC = 0x0000; // Configure port C all as digital I/O
// ---------------------------------------
//PMP setup
//---------------------------------------
PMMODE = 0; PMAEN = 0; PMCON = 0;
PMMODEbits.MODE = 2; // Intel 80 master interface
PMMODEbits.WAITB = 0b0000;
PMMODEbits.WAITM = 0b0010;
PMMODEbits.WAITE = 0b0000;
PMMODEbits.MODE16 = 0; // 8-bit Mode
PMCONbits.PTRDEN = 1; // enable RD line
PMCONbits.PTWREN = 1; // enable WR line
PMCONbits.WRSP = 0; // Make WR active low
PMCONbits.RDSP = 0; // Make RD active low
PMCONbits.PMPEN = 1; // enable PMP
//---------------------------------------
//---------------------------------------
//Configure for 39.92MhzMIPS using FRC w/PLL
//---------------------------------------
CLKDIVbits.PLLPRE = 1; //7.37Mhz/3 = 2.457Mhz
PLLFBDbits.PLLDIV = 63; //PLLDIV+2 = 65 = VCO out:159.683Mhz
CLKDIVbits.PLLPOST = 0; //Fcy=((((Oscilator/PLLPRE)*(PLLDIV+2))/PLLPOST)/2)
// =((((7.37Mhz/3)*(65))/2)/2) = 39.92Mhz
while(!OSCCONbits.LOCK);
//---------------------------------------
initialization();
Display_Home();
while(1)
{
DELAY_MS(1000);
display_rgb(BLACK);
DELAY_MS(1000);
display_rgb(BLUE);
DELAY_MS(1000);
display_rgb(RED);
DELAY_MS(1000);
display_rgb(GREEN);
DELAY_MS(1000);
display_rgb(CYAN);
DELAY_MS(1000);
display_rgb(MAGENTA);
DELAY_MS(1000);
display_rgb(YELLOW);
DELAY_MS(1000);
display_rgb(WHITE);
DELAY_MS(1000);
LCD_test();
}
return 0;
}
for (x = 0; x < 255; x++)
{
SetColor( RGB565CONVERT( x, 0, 0 ) );
Bar( 0, x, 79, x );
}
for (x = 0; x < 255; x++)
{
SetColor( RGB565CONVERT( 0, x, 0 ) );
Bar( 80, x, 159, x );
}
for (x = 0; x < 255; x++)
{
SetColor( RGB565CONVERT( 0, 0, x ) );
Bar( 160, x, 239, x );
}