⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 嵌入式系统
💻 C
字号:
#include <ctype.h>		/* to declare isprint() */
#include <stdio.h>
#include <stdlib.h>
#include "timer.h"
#include "kb.h"
#include "u_load.h"

/* *************************************
   LCDC Parametera (Video Memory Area)
   ************************************* */


#include "lcd.h"
#include "pio.h"
#include "intc.h"
#include "JN00_bmp.h"
#include <stdarg.h>
#include <rt_misc.h>

//#ifndef APD_LCD_SYS_DEF
#include "lcd_sys_def.h"
//#endif
//#ifndef TYPE_DEF
#include "type_def.h"
//#endif
//#ifndef APD_LCD_DEF
#include "lcd_def.h"
//#endif
//#ifndef LCD_PARAM
#include "lcd_param.h"
//#endif
//#ifndef DEV_DEF_H
#include "dev_def.h"
//#endif
//#include "Pff32.h"
//#include "L_slam16.h"
//#include "Pbnw32.h"
#ifndef NULL
#define NULL 0
#endif
/* ************************
   Misc Macro for debugging
   ************************ */
unsigned int OSTick;
unsigned int keycode=0;

/* ************************
   Misc Macro for debugging
   ************************ */
static unsigned int outer_delay;
static unsigned int delay;
#define SLIDE_DELAY()	for (outer_delay = 0; outer_delay < 10; outer_delay++) {for(delay = 0; delay < 60000; delay++);}
#define ANI_DELAY()		for (outer_delay = 0; outer_delay < 4; outer_delay++) {for(delay = 0; delay < 60000; delay++);}
unsigned long *SDRamStartAdr=(unsigned long*)0x40000000;
/**********************************************************************
**  Function      : Retarget function __user_initial_stackheap
**  Info          : Setup Heap Memory just above ZI section 
**  Input         : \
**  Output        : \
**  Returns       : configure data
**********************************************************************/
extern char Image$$RO$$Limit[];
extern char Image$$RW$$Base[];
extern unsigned int Image$$ZI$$Limit; // Base address of ZI section
__value_in_regs struct __initial_stackheap __user_initial_stackheap(
        unsigned R0, unsigned SP, unsigned R2, unsigned SL)
{
    struct __initial_stackheap config;
    
    config.heap_base = (unsigned int)&Image$$ZI$$Limit;  // set Heap just above ZI area 
    config.stack_base = SP;
    // set limit
    config.heap_limit = SL;
    config.stack_limit = SL;
    return config;
}

/*******************************************************************
********************************************************************/
int count;
void COUNTDATA (void)
{
	count++;
}
/******************************************************************
	make a "B" sound
******************************************************************/
void beep(void)
{
	unsigned int i,j;
	for(j=0;j<=10;j++)
	{
		apd_PIOSetBit(APD_PIOB,16);
		for( i=0; i<1000000; i++ );
		apd_PIOClrBit(APD_PIOB,16);
		for( i=0; i<1000000; i++ );
		i=0;
	}
}




void CheckSDRAM(void)
{
	unsigned long* pulPtr
		=(unsigned long *)0x41010000;
	unsigned long i;
	APD_LCD_POINT 	point;
	APD_LCD_COLOR	color;
	
	point.x=10;
	point.y=30;
	color=0x3df;
	apd_ClearLcd();
	apd_LCDDrawStr(&point,"writing......",color);
	for(i=0;i<=0x3f0000;i++)
	{
		*pulPtr=0x00;	//55555555;
		pulPtr++;
	}
	
	pulPtr=(unsigned long *)0x41010000;
	for(i=0;i<0x3f0000;i++)
	{
		*pulPtr |= 0xaaaaaaaa;
		pulPtr++;
	}
	point.x=10;
	point.y=30;
	color=0x3df;
	apd_ClearLcd();
	apd_LCDDrawStr(&point,"Reading......",color);
	pulPtr=(unsigned long*)0x41010000;
	for(i=0;i<0x3f0000;i++)
	{ 	//7fc180
		if(*pulPtr!=0xffffffff)
			{
			point.x=10;
			point.y=30;
			color=0x3df;
//			apd_ClearLcd();
//			apd_LCDDrawStr(&point,"Error......",color);
			while(1);
			}
		pulPtr++;

	}
	
}



/******************************************************************
	c language entrance
*******************************************************************/

//void C_Entry(void)

int main(void)

{
	unsigned int x,y;
	unsigned char  *buffer;
	APD_LCD_POINT point,dim1;
	APD_LCD_DIM dim;
	volatile unsigned int  reg;
	unsigned long           index;
	unsigned int x1,y1;	
	int i,j;
	unsigned char value;
	APD_LCD_COLOR color;
	APD_UART_INIT_TYPE uart_init;
	APD_TIMER_INIT_TYPE tinit;
	char *str="Hello!World!Test!";


	
/************************* initial area *********/	

	apd_INTCConfigure();
/**** timer init ****/
	tinit.enablebit   = APD_TIMER_DISABLE;
	tinit.modebit     = APD_TIMER_PERIODIC;
	tinit.clearbit    = APD_TIMER_NORM_OP;
	tinit.clockbit    = APD_TIMER_INT_SYS_CLK;
	tinit.prescalebit = APD_TIMER_PRESCALE_4;
	tinit.carrybit    = APD_TIMER_DISABLE_CARRY;
	apd_TIMERInit(APD_TIMER0, tinit,13000);
/**** PIO init ****/	
	apd_PIOInit();
/**** LCD init ****/	
	apd_LCDInit(); 
/**** key init ****/
	KeyInit();
	
/**** UART init ****/
	uart_init.rate=9600;
	uart_init.format=APD_UART_8W_NOXSTOP_NOPARITY;
	uart_init.intmask=0x0;
	apd_UARTInit (APD_UART_CH0,uart_init);
	apd_INTCDisableIRQ(APD_INTC_UART0);
	apd_UARTDisable(APD_UART_CH0);
	apd_UARTEnableFIFO(APD_UART_CH0);
	apd_SIOOpen(APD_UART_CH0,APD_INTC_UART0);

/******************  init end ******************/

	apd_StartTimer(APD_TIMER0,APD_INTC_TIMER0);
	count=0;
	apd_LCDSetRasterOperation(APD_LCD_ROP_S);

wait00:
	point.x=20;
	point.y=30;
	apd_ClearLcd();
	apd_LCDDrawStr(&point,"Press KB_ROT key to continue!!!",0x3df);
//	apd_LCDDrawStr(&point,"Please enter key",0x3df);
	while( GetKey()!=KB_ROT);
	apd_ClearLcd();
	apd_LCDDrawStr(&point,"Press KB_U_MARK key to continue!!!",0x3df);
	while( GetKey()!=KB_U_MARK);
	apd_ClearLcd();
	apd_LCDDrawStr(&point,"Press KB_BRT key to continue!!!",0x3df);
	while( GetKey()!=KB_BRT);
	apd_ClearLcd();
	apd_LCDDrawStr(&point,"Press KB_SHOW key to continue!!!",0x3df);
	while( GetKey()!=KB_SHOW);
	apd_ClearLcd();
	apd_LCDDrawStr(&point,"Press KB_DEL key to continue!!!",0x3df);
	while( GetKey()!=KB_DEL);
	apd_ClearLcd();
	apd_LCDDrawStr(&point,"Press KB_UP key to continue!!!",0x3df);
	while( GetKey()!=KB_UP);
	apd_ClearLcd();
	apd_LCDDrawStr(&point,"Press KB_DOWN key to continue!!!",0x3df);
	while( GetKey()!=KB_DOWN);
	apd_ClearLcd();
	apd_LCDDrawStr(&point,"OK!!! Flash LED Now!!!",0x3df);
	//for (i=0;i<=2000000;i++);	
	//apd_ClearLcd();
	
/*
	switch(GetKey())
		{ case KB_ROT:
				apd_ClearLcd();
				apd_LCDDrawStr(&point,"enter key : KB_ROT!!!",0x3df);
				break;
		case KB_U_MARK:
				apd_ClearLcd();
				apd_LCDDrawStr(&point,"enter key : KB_U_MARK!!!",0x3df);
				break;
		case KB_BRT:
				apd_ClearLcd();
				apd_LCDDrawStr(&point,"enter key : KB_BRT!!!",0x3df);
				break;
		case KB_SHOW:
				apd_ClearLcd();
				apd_LCDDrawStr(&point,"enter key : KB_SHOW!!!",0x3df);
				break;
		case KB_DEL:
				apd_ClearLcd();
				apd_LCDDrawStr(&point,"enter key : KB_DEL!!!",0x3df);
				break;
		case KB_UP:
				apd_ClearLcd();
				apd_LCDDrawStr(&point,"enter key : KB_UP!!!",0x3df);
				break;
		case KB_DOWN:
				apd_ClearLcd();
				apd_LCDDrawStr(&point,"enter key : KB_DOWN!!!",0x3df);
				break;
		default:
				break;
		}
		
goto wait00;
	
*/
	//beep();
	point.y=point.x=0;
	dim.width=320;
	dim.height=240;
	apd_LCDDrawImage(&point,&dim,(unsigned char*)JN00_320x240_Bmp);
	while(1);
	apd_ClearLcd();
	i=0xffffffff;
	apd_LCDFillScr(i);
	apd_LCDDrawStr(&point,"this is a test for project JN00_098:",0x00);
	while(1);
	
	color=0x1f;
	for (i=0;i<29;i++)
	{
		point.x=1;
		point.y=i*8;
		apd_LCDDrawStr(&point,"this is a test for project pn00_098:",color);
	}
	point.x=242;
	point.y=220;
	apd_LCDDrawNum(&point,count,0x03df);
	
	//while(1);	
	for (i=0;i<=2000000;i++);	
	apd_ClearLcd();

	i=0xffff;
	apd_LCDFillScr(i);

	apd_LCDSetColor(0x1e);	
	point.x=0;
	point.y=0;
	dim.width=319;
	dim.height=238;
	apd_LCDDrawRect(&point,&dim);
	

	for (i=0;i<=2000000;i++);
	
	apd_ClearLcd();
	apd_LCDSetFillPattern(APD_LCD_FILL_SOLID);//APD_LCD_FILL_DOT);	//APD_LCD_FILL_SOLID);	//fill type as SOLID
	apd_LCDSetColor(0x03df);	
	point.x=60;
	point.y=60;
	dim.width=220;
	dim.height=160;
	apd_LCDFillRect(&point,&dim);
//	while(1);

	for (i=0;i<=2000000;i++);
	apd_ClearLcd();
	i=0x1f;
	apd_LCDFillScr(i);
	for (i=0;i<=2000000;i++);
	apd_ClearLcd();
	i=0x1f001f;
	apd_LCDFillScr(i);
	for (i=0;i<=2000000;i++);
	
	apd_ClearLcd();
	i=0x3c0;
	apd_LCDFillScr(i);
	for (i=0;i<=2000000;i++);
	apd_ClearLcd();
	
	i=0x3c0;
	apd_LCDFillScr((i<<16)|i);
	for (i=0;i<=2000000;i++);
	apd_ClearLcd();
	
	i=0x7800;
	apd_LCDFillScr(i);
	for (i=0;i<=2000000;i++);
	apd_ClearLcd();
	i=0x7800;
	i=(i<<16)|i;
	apd_LCDFillScr(i);
	for (i=0;i<=2000000;i++);
	apd_ClearLcd();
	goto wait00;
		
	while(1);
	InitUART();
	

	
	while(1);
	
}


void C_int_handler(void)
{
	int outdata;
	APD_LCD_POINT point;
	point.x=20;
	point.y=50;
	if (apd_INTCChkIRQStatus(APD_INTC_TIMER0))
	{
		apd_TIMERClrIntr(APD_TIMER0);
		COUNTDATA();
	}
	if (apd_INTCChkIRQStatus(APD_INTC_UART0))
	{
		if(apd_UARTIsRxIntr(APD_UART_CH0))//if receive make interrupt
			{			  //then read data and display
				outdata=apd_SIORead(APD_UART_CH0);
				apd_UARTClrIntrReg(APD_UART_CH0, 0x08);	//clear receive interrupt flag
			}

	}
	if (apd_INTCChkIRQStatus(APD_INTC_INT1))
	{
		apd_INTCClrIntr(APD_INTC_INT1);
		IntKey();		
	}
	apd_INTCClrIntr(APD_INTC_TIMER0);
	apd_INTCClrIntr(APD_INTC_UART0);
	return;
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -