/******************************************************************** Funciton: void CUPLDInitialize(void) ********************************************************************/ void CPLDInitialize(void) { CPLDSetGraphicsConfiguration(CPLD_GFX_CONFIG_8BIT); CPLDSetSPIFlashConfiguration(CPLD_SPI2); PORTSetPinsDigitalOut(IOPORT_G, BIT_14 | BIT_12); PORTSetPinsDigitalOut(IOPORT_A, BIT_7 | BIT_6); }
/***************************************** * void InitializeHardware(void) *****************************************/ void InitializeHardware(void) { #if defined(__dsPIC33F__) || defined(__PIC24H__) // Configure Oscillator to operate the device at 40Mhz // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2 // Fosc= 8M*40(2*2)=80Mhz for 8M input clock PLLFBD = 38; // M=40 CLKDIVbits.PLLPOST = 0; // N1=2 CLKDIVbits.PLLPRE = 0; // N2=2 OSCTUN = 0; // Tune FRC oscillator, if FRC is used // Disable Watch Dog Timer RCONbits.SWDTEN = 0; // Clock switching to incorporate PLL __builtin_write_OSCCONH(0x03); // Initiate Clock Switch to Primary // Oscillator with PLL (NOSC=0b011) __builtin_write_OSCCONL(0x01); // Start clock switching while(OSCCONbits.COSC != 0b011); // Wait for Clock switch to occur // Wait for PLL to lock while(OSCCONbits.LOCK != 1) { }; #elif defined(__PIC32MX__) SYSTEMConfig(GetSystemClock(), SYS_CFG_ALL); #ifdef MEB_BOARD CPLDInitialize(); CPLDSetGraphicsConfiguration(GRAPHICS_HW_CONFIG); CPLDSetSPIFlashConfiguration(SPI_FLASH_CHANNEL); #endif #endif #if defined(__dsPIC33FJ128GP804__) || defined(__PIC24HJ128GP504__) AD1PCFGL = 0xffff; #endif #if defined (__PIC24FJ256GB210__) // Map UART2 __builtin_write_OSCCONL(OSCCON & 0xbf); // Configure Input Functions (Table 10-2)) // Assign U2RX To Pin RP10 RPINR19bits.U2RXR = 10; // Assign U2CTS To Pin RP32 RPINR19bits.U2CTSR = 32; // Configure Output Functions (Table 10-4) // Assign U2TX To Pin RP17 RPOR8bits.RP17R = 5; // Assign U2RTS To Pin RP31 RPOR15bits.RP31R = 6; __builtin_write_OSCCONL (OSCCON | 0x40); #endif #if ( USE_SPI_CHANNEL == 1 ) #if defined (__PIC24FJ256GB210__) __builtin_write_OSCCONL(OSCCON & 0xbf); // unlock PPS // Configure SPI1 PPS pins (ENC28J60/ENCX24J600/MRF24WB0M or other PICtail Plus cards) RPOR0bits.RP0R = 8; // Assign RP0 to SCK1 (output) RPOR7bits.RP15R = 7; // Assign RP15 to SDO1 (output) //RPOR6bits.RP13R = 9; // Assign RP15 to SDO1 (output) RPINR20bits.SDI1R = 23; // Assign RP23 to SDI1 (input) __builtin_write_OSCCONL(OSCCON | 0x40); // lock PP #endif #endif ///////////////////////////////////////////////////////////////////////////// // ADC Explorer 16 Development Board Errata (work around 2) // RB15 should be output ///////////////////////////////////////////////////////////////////////////// #ifndef MEB_BOARD LATBbits.LATB15 = 0; TRISBbits.TRISB15 = 0; #endif #if defined (EXPLORER_16) /************************************************************************ * For Explorer 16 RD12 is connected to EEPROM chip select. * To prevent a conflict between this EEPROM and SST25 flash * the chip select of the EEPROM SPI should be pulled up. ************************************************************************/ // Set IOs directions for EEPROM SPI MCHP25LC256_CS_LAT = 1; // set initial CS value to 1 (not asserted) MCHP25LC256_CS_TRIS = 0; // set CS pin to output #endif // #if defined (EXPLORER_16) //The following are PIC device specific settings for the SPI channel //used. //Set IOs directions for SST25 SPI #if defined (USE_SST25VF064) SST25_CS_LAT = 1; SST25_CS_TRIS = 0; #ifndef __PIC32MX__ SST25_SCK_TRIS = 0; SST25_SDO_TRIS = 0; SST25_SDI_TRIS = 1; #if defined(__PIC24FJ256GB210__) || defined(__dsPIC33E__) || defined(__PIC24E__) SST25_SDI_ANS = 0; #endif #endif #endif // set the peripheral pin select for the SPI channel used #if defined(__PIC24FJ256GB110__) || defined(__PIC24FJ256GA110__) || defined (__PIC24FJ256GB210__) __builtin_write_OSCCONL(OSCCON & 0xbf); // unlock PPS RPOR10bits.RP21R = 11; // assign RP21 for SCK2 RPOR9bits.RP19R = 10; // assign RP19 for SDO2 RPINR22bits.SDI2R = 26; // assign RP26 for SDI2 __builtin_write_OSCCONL(OSCCON | 0x40); // lock PPS #endif #if defined (USE_SST25VF064) SST25Init((DRV_SPI_INIT_DATA *)&SPI_Init_Data); #endif }
int main(void) { SHORT width, height; // variables to store the height and width of the 16-bit bitmap image SHORT counter; // loop control variable for each shape that controls how many shapes are printed and their scale SHORT triangle[] = {160,120,160,120,160,120,160,120}; // triangle polygon points (start triangle in center of LCD) #if defined(__dsPIC33F__) || defined(__PIC24H__) // Configure Oscillator to operate the device at 40Mhz // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2 // Fosc= 8M*40(2*2)=80Mhz for 8M input clock PLLFBD = 38; // M=40 CLKDIVbits.PLLPOST = 0; // N1=2 CLKDIVbits.PLLPRE = 0; // N2=2 OSCTUN = 0; // Tune FRC oscillator, if FRC is used // Disable Watch Dog Timer RCONbits.SWDTEN = 0; // Clock switching to incorporate PLL __builtin_write_OSCCONH(0x03); // Initiate Clock Switch to Primary // Oscillator with PLL (NOSC=0b011) __builtin_write_OSCCONL(0x01); // Start clock switching while(OSCCONbits.COSC != 0b011); // Wait for Clock switch to occur // Wait for PLL to lock while(OSCCONbits.LOCK != 1) { }; #elif defined(__PIC32MX__) INTEnableSystemMultiVectoredInt(); SYSTEMConfigPerformance(GetSystemClock()); #ifdef MULTI_MEDIA_BOARD_DM00123 CPLDInitialize(); CPLDSetGraphicsConfiguration(GRAPHICS_HW_CONFIG); CPLDSetSPIFlashConfiguration(SPI_FLASH_CHANNEL); #endif #endif #if defined (PIC24FJ256DA210_DEV_BOARD) // _ANSG8 = 0; /* S1 */ // _ANSE9 = 0; /* S2 */ // _ANSB5 = 0; /* S3 */ #else ///////////////////////////////////////////////////////////////////////////// // ADC Explorer 16 Development Board Errata (work around 2) // RB15 should be output ///////////////////////////////////////////////////////////////////////////// LATBbits.LATB15 = 0; TRISBbits.TRISB15 = 0; #endif ///////////////////////////////////////////////////////////////////////////// #if defined(__dsPIC33FJ128GP804__) || defined(__PIC24HJ128GP504__) AD1PCFGL = 0xffff; #endif InitGraph(); while(1) { /* Display the Kettering Logo bit image with the Welcome to the ECE in the center /* The image was taken from a JPEG and converted to a 16-bit bitmap in order to meet /* the display requirement of 16-bits per pixel. This can be done by resaving the /* JPEG as 16-bit bitmap in a image editing program and then converting it using /* the graphics library resource converter. The LCD only supports 4-bit, 8-bit, and /* 16-bits per pixel images */ width = GetImageWidth((void *) &kulogo); SetFont((void *) &Font25); WAIT_UNTIL_FINISH(PutImage(45, 20 , (void *) &kulogo, 1)); // image location is relative to the top left corner of the image SetColor(WHITE); Bar(45, 110, width + 45, 135); // Draw a bar over the image to place the text over. SetColor(BLUE); OutTextXY(65, 110, "WELCOME TO THE ECE"); DelayMs(DEMODELAY); // delay for 1 sec and clear the screen SetColor(BLACK); ClearDevice(); /* Display multiple circles, starting at the center and increasing in size at /* each draw until the LCD borders are met. Increasing the counter value will /* expand the shape size more quickly. */ for(counter = 0; counter < MIN(GetMaxX(), GetMaxY()) >> 1; counter += 14) { SetColor(BLACK); // refresh the screen ClearDevice(); SetColor(BRIGHTRED); SetFont((void *) &Font25); // draw the name of the shape in the center OutTextXY(135, 110, "Circle"); WAIT_UNTIL_FINISH(Circle(GetMaxX() >> 1, GetMaxY() >> 1, counter + 5)); // draw the shape DelayMs(50); // display for 50 ms } DelayMs(DEMODELAY); // delay for 1 sec and clear the screen SetColor(BLACK); ClearDevice(); /* Display multiple rectangles, starting at the center and increasing in size at /* each draw until the LCD borders are met. Increasing the counter value will /* expand the shape size more quickly. */ for(counter = 0; counter < MIN(GetMaxX() / 2, GetMaxY() / 2) >> 1; counter += 5) { SetColor(BLACK); // refresh the screen ClearDevice(); SetColor(BRIGHTBLUE); OutTextXY(120, 110, "Rectangle"); // draw the name of the shape in the center WAIT_UNTIL_FINISH ( Rectangle ( GetMaxX() / 2 - counter * 3 + 6, // x value of top left corner of rectangle GetMaxY() / 2 - counter * 2 - 8, // y value of top left corner of rectangle GetMaxX() / 2 + counter * 3 - 6, // x value of bottom right corner of rectangle GetMaxY() / 2 + counter * 2 + 8 // y value of bottom right corner of rectangle ) ); DelayMs(20); // Display for 20 ms } DelayMs(DEMODELAY); // delay for 1 sec and clear the screen SetColor(BLACK); ClearDevice(); /* Display multiple triangles, starting at the center and increasing in size at /* each draw until the LCD borders are met. Increasing the counter value will /* expand the shape size more quickly. */ int i; for(counter = 0; counter < MIN(GetMaxX() / 2, GetMaxY() / 2) >> 1; counter += 10) { SetColor(BLACK); // refresh the screen ClearDevice(); SetColor(GREEN); // draw the name of the shape at the center OutTextXY(125, 110, "Triangle"); //{160,120,160,120,160,120,160,120} start in center of screen triangle[1] = triangle[1] - counter * 2 - 20; // top point y triangle[7] = triangle[1]; // top point y (close triangle) triangle[2] = triangle[2] - counter * 2 - 58; // left corner point x triangle[3] = triangle[3] + counter * 2 + 16; // left corner point y triangle[4] = triangle[4] + counter * 2 + 58; // right corner point x triangle[5] = triangle[5] + counter * 2 + 16; // right corner point y DrawPoly(4, triangle); // draw the triangle (4 points to enclose it) // reset each of the triangle points to the center to prevent over expansion for (i = 0; i < 8; i++) if (i % 2 == 0) triangle[i] = 160; else triangle[i] = 120; DelayMs(50); // display for 50 ms } DelayMs(DEMODELAY); // delay for 1 sec and clear the screen SetColor(BLACK); ClearDevice(); } }
int main(void) { GOL_MSG msg; // GOL message structure to interact with GOL Nop(); #if defined(PIC24FJ256DA210_DEV_BOARD) _ANSG8 = 0; /* S1 */ _ANSE9 = 0; /* S2 */ _ANSB5 = 0; /* S3 */ #else ///////////////////////////////////////////////////////////////////////////// // ADC Explorer 16 Development Board Errata (work around 2) // RB15 should be output ///////////////////////////////////////////////////////////////////////////// #ifndef MULTI_MEDIA_BOARD_DM00123 LATBbits.LATB15 = 0; TRISBbits.TRISB15 = 0; #endif #endif ///////////////////////////////////////////////////////////////////////////// #if defined(__dsPIC33F__) || defined(__PIC24H__) // Configure Oscillator to operate the device at 40Mhz // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2 // Fosc= 8M*40(2*2)=80Mhz for 8M input clock PLLFBD = 38; // M=40 CLKDIVbits.PLLPOST = 0; // N1=2 CLKDIVbits.PLLPRE = 0; // N2=2 OSCTUN = 0; // Tune FRC oscillator, if FRC is used // Disable Watch Dog Timer RCONbits.SWDTEN = 0; // Clock switching to incorporate PLL __builtin_write_OSCCONH(0x03); // Initiate Clock Switch to Primary // Oscillator with PLL (NOSC=0b011) __builtin_write_OSCCONL(0x01); // Start clock switching while(OSCCONbits.COSC != 0b011); // Wait for Clock switch to occur // Wait for PLL to lock while(OSCCONbits.LOCK != 1) { }; // Set PMD0 pin functionality to digital AD1PCFGL = AD1PCFGL | 0x1000; #elif defined(__PIC32MX__) INTEnableSystemMultiVectoredInt(); SYSTEMConfigPerformance(GetSystemClock()); #ifdef MULTI_MEDIA_BOARD_DM00123 CPLDInitialize(); CPLDSetGraphicsConfiguration(GRAPHICS_HW_CONFIG); CPLDSetSPIFlashConfiguration(SPI_FLASH_CHANNEL); #endif // #ifdef MULTI_MEDIA_BOARD_DM00123 #endif // #if defined(__dsPIC33F__) || defined(__PIC24H__) GOLInit(); // initialize graphics library & // create default style scheme for GOL #if defined (GFX_PICTAIL_V1) || defined (GFX_PICTAIL_V2) EEPROMInit(); // initialize Exp.16 EEPROM SPI BeepInit(); #else #if defined (USE_SST25VF016) SST25Init(); // initialize GFX3 SST25 flash SPI #endif #endif TouchInit(); // initialize touch screen HardwareButtonInit(); // Initialize the hardware buttons // create default style scheme for GOL TickInit(); // initialize tick counter (for random number generation) // create default style scheme for GOL #if defined(__dsPIC33FJ128GP804__) || defined(__PIC24HJ128GP504__) // If S3 button on Explorer 16 board is pressed calibrate touch screen TRISAbits.TRISA9 = 1; if(PORTAbits.RA9 == 0) { TRISAbits.TRISA9 = 0; TouchCalibration(); TouchStoreCalibration(); } TRISAbits.TRISA9 = 0; #else /** * Force a touchscreen calibration by pressing the switch * Explorer 16 + GFX PICTail - S3 (8 bit PMP) * Explorer 16 + GFX PICTail - S5 (16 bit PMP) * Starter Kit + GFX PICTail - S0 (8 bit PMP) * Multimedia Expansion Board - Fire Button * DA210 Developement Board - S1 * NOTE: Starter Kit + GFX PICTail will switches are shared * with the 16 bit PMP data bus. **/ if(GetHWButtonTouchCal() == HW_BUTTON_PRESS) { TouchCalibration(); TouchStoreCalibration(); } #endif // If it's a new board (EEPROM_VERSION byte is not programed) calibrate touch screen #if defined (GFX_PICTAIL_V1) || defined (GFX_PICTAIL_V2) if(GRAPHICS_LIBRARY_VERSION != EEPROMReadWord(ADDRESS_VERSION)) { TouchCalibration(); TouchStoreCalibration(); } #else #if defined (USE_SST25VF016) if(GRAPHICS_LIBRARY_VERSION != SST25ReadWord(ADDRESS_VERSION)) { TouchCalibration(); TouchStoreCalibration(); } #elif defined (USE_SST39LF400) WORD tempArray[12], tempWord = 0x1234; SST39LF400Init(tempArray); tempWord = SST39LF400ReadWord(ADDRESS_VERSION); SST39LF400DeInit(tempArray); if(GRAPHICS_LIBRARY_VERSION != tempWord) { TouchCalibration(); TouchStoreCalibration(); } #endif #endif // Load touch screen calibration parameters from memory TouchLoadCalibration(); GDDDemoCreateFirstScreen(); while(1) { if(GOLDraw()) // Draw GOL object { TouchGetMsg(&msg); // Get message from touch screen #if (NUM_GDD_SCREENS > 1) // GDD Readme: // The following line of code allows a GDD user to touch the touchscreen // to cycle through different static screens for viewing. This is useful as a // quick way to view how each screen looks on the physical target hardware. // This line of code should eventually be commented out for actual development. // Also note that widget/object names can be found in GDD_Screens.h if(msg.uiEvent == EVENT_RELEASE) GDDDemoNextScreen(); #endif GOLMsg(&msg); // Process message } }//end while }