/*
******************************************************************************
* Date: 11st July 2008
*
* This demonstration for QA example for the hardware platform
* PIC18LF4550-Eval-Rev4a + TY280T-240320-BO Rev 1B
* Important: It is necessary to enable JP6 on LCD module to select
* the latch device 74HC573D to make this demo work!
*
* Microchip Graphics Library port to PIC18. 
* Only Primitive functions ported with Font supported.
*
* FileName:        MainDemo.c
* Dependencies:    includes.h
* Processor:       PIC18LF4550
* Compiler:        MPLAB C18 student version, MPLAB v8.02
* Programmer : 	   John Leung (www.TechToys.com.hk)
* Note:		       Please refer to the original Software License Agreement
*				   from Microchip for details concerning Copyright
******************************************************************************
*/

/*
******************************************************************************
* Date: 24th Apr 2008
* A revised Primitive.c and Primitive.h employed for font support
* This demonstration for QA example for the hardware platform
* PIC18LF4550-Eval-Rev4a + TY320T-240320-BO Rev 2C
* Important: It is necessary to enable JP2 on LCD module to select
* the latch device 74HC573D to make this demo work!
*
* Microchip Graphics Library port to PIC18. 
* Only Primitive functions ported with Font supported.
*
* FileName:        MainDemo.c
* Dependencies:    includes.h
* Processor:       PIC18LF4550
* Compiler:        MPLAB C18 student version, MPLAB v8.02
* Programmer : 	   John Leung (www.TechToys.com.hk)
* Note:		       Please refer to the original Software License Agreement
*				   from Microchip for details concerning Copyright
******************************************************************************
*/

/*
******************************************************************************
* Date: 17th April 2008
* This demonstration for QA example for the hardware platform
* PIC18LF4550-Eval-Rev4a + TY320T-240320-BO Rev 2C
* Important: It is necessary to enable JP2 on LCD module to select
* the latch device 74HC573D to make this demo work!
*
* Microchip Graphics Library port to PIC18. Only Primitive functions ported
* with Font and Picture Drawn function removed just now.
*
* FileName:        MainDemo.c
* Dependencies:    MainDemo.h
* Processor:       PIC18LF4550
* Compiler:        MPLAB C18 student version
* Programmer : 	   John Leung (www.TechToys.com.hk)
* Note:		       Please refer to the original Software License Agreement
*				   from Microchip for details concerning Copyright
******************************************************************************
*/


/*****************************************************************************
 * Microchip Graphics Library Demo Application
 * This program shows how to use the Graphics Primitives Layer.
 *****************************************************************************
 * FileName:        MainDemo.c
 * Dependencies:    MainDemo.h
 * Processor:       PIC24
 * Compiler:       	MPLAB C30
 * Linker:          MPLAB LINK30
 * Company:         Microchip Technology Incorporated
 *
 * Software License Agreement
 *
 * Copyright ?2007 Microchip Technology Inc.  All rights reserved.
 * Microchip licenses to you the right to use, modify, copy and distribute
 * Software only when embedded on a Microchip microcontroller or digital
 * signal controller, which is integrated into your product or third party
 * product (pursuant to the sublicense terms in the accompanying license
 * agreement).  
 *
 * You should refer to the license agreement accompanying this Software
 * for additional information regarding your rights and obligations.
 *
 * SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS?WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY
 * OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR
 * PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR
 * OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION,
 * BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT
 * DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL,
 * INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
 * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY
 * CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF),
 * OR OTHER SIMILAR COSTS.
 *
 * Author               Date        Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Anton Alkhimenok		30/05/07	...
 *****************************************************************************/


#include "includes.h"

/*
********************************************************************************************************************
*												Pragma Section
*
* Configuration bits under MPLAB v7.60 subject to changes on every little change on project settings.
* So #pragma config statments used for configuration bits instead of using Configuration bits tab in MPLAB
* Refer to pdf document "mcc18\doc\MPLAB-C18-Addendum.pdf" under mcc18 installation directory for config
* variables available
********************************************************************************************************************
*/
#pragma config PLLDIV = 5			// 20Mhz crystal input, the PLL divider has to be 5 for a fixed 4MHz input to PLL
#pragma config FOSC   = HSPLL_HS	// HS oscillator, PLL sourced
#pragma config CPUDIV = OSC1_PLL2	// Since it is now PLL sourced, the CPU clock = 96MHz PLL/2 => 48MHz
									// From specification the max. clock is around 20MHz for Vdd=3.3V
									// This scenario is like a bit over-clocking the microcontroller!
#pragma config PWRT   = ON			// PowerUp timer ON
#pragma config WDT    = OFF			// watchdog timer off
#pragma config LVP    = OFF			// low level voltage progamming OFF
#pragma config BOR    = OFF			// brown out detect off
#pragma config DEBUG  = ON			// Debug ON
#pragma config PBADEN = OFF 		// PORTB<4:0> as digital IO on reset
#pragma config STVREN = ON  		// Stack overflow reset ON
#pragma config VREGEN = OFF			// Disable internal 3.3V regulator!

///////////////////////////////// FONTS ///////////////////////////////////////
extern FONT_FLASH Font25;
extern FONT_FLASH Font35;
///////////////////////////////// FONTS ///////////////////////////////////////

char s[] = "TECHTOYS CO.";
char c[] = "www.TechToys.com.hk";

void main(void){

SHORT width, height;
SHORT counter;
const SHORT polyPoints[] = {
160,60,
240,120,
160,180,
80,120,
160,60,
};

    InitGraph();

	while(1)
	{
	
		SetColor(LIGHTGRAY);

        for(counter=0; counter<GetMaxX(); counter+=20){
            Line(counter,0,GetMaxX()-1-counter,GetMaxY()-1);
        }

        SetFont(&Font25);
        SetColor(BRIGHTGREEN);
        width = GetTextWidth(&c[0],&Font25);
        height = GetTextHeight(&Font25);
        OutTextXY( (GetMaxX()-width)>>1,(GetMaxY()-height)>>1,&c[0]);

        SetFont(&Font35);
        SetColor(BRIGHTRED);
        width = GetTextWidth(&s[0],&Font35);
        height = GetTextHeight(&Font35);
        OutTextXY( (GetMaxX()-width)>>1,100,&s[0]);	

        DelayMs(2000);  

        SetColor(BRIGHTRED);

        for(counter=10; counter<GetMaxY()>>1; counter+=10){
            Circle(GetMaxX()>>1,GetMaxY()>>1,counter);
        }

        DelayMs(2000);  

        SetColor(BRIGHTBLUE);
        FillCircle(GetMaxX()>>1,GetMaxY()>>1,60);
        SetColor(BRIGHTGREEN);
        FillCircle(GetMaxX()>>1,GetMaxY()>>1,40);
        SetColor(BRIGHTRED);
        FillCircle(GetMaxX()>>1,GetMaxY()>>1,20);

        DelayMs(2000);  

        SetColor(BLACK);
        ClearDevice();

        SetColor(BRIGHTBLUE);
        Bevel((GetMaxX()>>1)-60,(GetMaxY()>>1)-60,(GetMaxX()>>1)+60,(GetMaxY()>>1)+60,30);
        SetColor(BRIGHTGREEN);
        Bevel((GetMaxX()>>1)-40,(GetMaxY()>>1)-40,(GetMaxX()>>1)+40,(GetMaxY()>>1)+40,30);
        SetColor(BRIGHTRED);
        Bevel((GetMaxX()>>1)-20,(GetMaxY()>>1)-20,(GetMaxX()>>1)+20,(GetMaxY()>>1)+20,30);

        DelayMs(2000);  

        SetColor(BLACK);
        ClearDevice();

        SetColor(BRIGHTBLUE);
        Arc((GetMaxX()>>1)-60,(GetMaxY()>>1)-60,(GetMaxX()>>1)+60,(GetMaxY()>>1)+60,20,30,0xFF);
        SetColor(BRIGHTGREEN);
        Arc((GetMaxX()>>1)-40,(GetMaxY()>>1)-40,(GetMaxX()>>1)+40,(GetMaxY()>>1)+40,20,30,0xFF);
        SetColor(BRIGHTRED);
        Arc((GetMaxX()>>1)-20,(GetMaxY()>>1)-20,(GetMaxX()>>1)+20,(GetMaxY()>>1)+20,20,30,0xFF);

        DelayMs(2000);  

        SetColor(BRIGHTBLUE);
        FillBevel((GetMaxX()>>1)-60,(GetMaxY()>>1)-60,(GetMaxX()>>1)+60,(GetMaxY()>>1)+60,30);
        SetColor(BRIGHTGREEN);
        FillBevel((GetMaxX()>>1)-40,(GetMaxY()>>1)-40,(GetMaxX()>>1)+40,(GetMaxY()>>1)+40,30);
        SetColor(BRIGHTRED);
        FillBevel((GetMaxX()>>1)-20,(GetMaxY()>>1)-20,(GetMaxX()>>1)+20,(GetMaxY()>>1)+20,30);

        DelayMs(2000);  

        SetColor(BLACK);
        ClearDevice();

        SetColor(BRIGHTBLUE);
        Arc((GetMaxX()>>1),(GetMaxY()>>1)-50,(GetMaxX()>>1),(GetMaxY()>>1)+50,50,60,0x11);
        SetColor(BRIGHTGREEN);
        Arc((GetMaxX()>>1),(GetMaxY()>>1)-50,(GetMaxX()>>1),(GetMaxY()>>1)+50,50,60,0x22);
        SetColor(BRIGHTRED);
        Arc((GetMaxX()>>1),(GetMaxY()>>1)-50,(GetMaxX()>>1),(GetMaxY()>>1)+50,50,60,0x44);
        SetColor(BRIGHTYELLOW);
        Arc((GetMaxX()>>1),(GetMaxY()>>1)-50,(GetMaxX()>>1),(GetMaxY()>>1)+50,50,60,0x88);

        SetColor(BRIGHTBLUE);
        Arc((GetMaxX()>>1),(GetMaxY()>>1)-30,(GetMaxX()>>1),(GetMaxY()>>1)+30,35,45,0x11);
        SetColor(BRIGHTGREEN);
        Arc((GetMaxX()>>1),(GetMaxY()>>1)-30,(GetMaxX()>>1),(GetMaxY()>>1)+30,35,45,0x22);
        SetColor(BRIGHTRED);
        Arc((GetMaxX()>>1),(GetMaxY()>>1)-30,(GetMaxX()>>1),(GetMaxY()>>1)+30,35,45,0x44);
        SetColor(BRIGHTYELLOW);
        Arc((GetMaxX()>>1),(GetMaxY()>>1)-30,(GetMaxX()>>1),(GetMaxY()>>1)+30,35,45,0x88);

        SetColor(BRIGHTBLUE);
        Arc((GetMaxX()>>1),(GetMaxY()>>1),(GetMaxX()>>1),(GetMaxY()>>1),20,30,0x11);
        SetColor(BRIGHTGREEN);
        Arc((GetMaxX()>>1),(GetMaxY()>>1),(GetMaxX()>>1),(GetMaxY()>>1),20,30,0x22);
        SetColor(BRIGHTRED);
        Arc((GetMaxX()>>1),(GetMaxY()>>1),(GetMaxX()>>1),(GetMaxY()>>1),20,30,0x44);
        SetColor(BRIGHTYELLOW);
        Arc((GetMaxX()>>1),(GetMaxY()>>1),(GetMaxX()>>1),(GetMaxY()>>1),20,30,0x88);

        DelayMs(2000);  

        SetColor(BLACK);
        ClearDevice();

        SetColor(BRIGHTBLUE);

        for(counter=0; counter<GetMaxY()>>1; counter+=20){
            Rectangle(GetMaxX()/2-counter,
                      GetMaxY()/2-counter,
                      GetMaxX()/2+counter,
                      GetMaxY()/2+counter);
        }

        DelayMs(2000);  

        SetColor(BRIGHTBLUE);
        Bar(GetMaxX()/2-80,GetMaxY()/2-80,
            GetMaxX()/2+80,GetMaxY()/2+80);
        SetColor(BRIGHTGREEN);
        Bar(GetMaxX()/2-60,GetMaxY()/2-60,
            GetMaxX()/2+60,GetMaxY()/2+60);
        SetColor(BRIGHTRED);
        Bar(GetMaxX()/2-40,GetMaxY()/2-40,
            GetMaxX()/2+40,GetMaxY()/2+40);


        DelayMs(2000);  
        SetColor(BLACK);
        ClearDevice();

        SetColor(WHITE);
        DrawPoly(5,(SHORT*)polyPoints);

        DelayMs(2000);  
        SetColor(BLACK);
        ClearDevice();
		}
}
