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

📄 main.c.bak

📁 做的是LCD液晶显示实验
💻 BAK
字号:
/* ********************************************************** *  main.c *  Copyright(C) 2001-2002 Triscend Corporation. All Rights Reserved. *  This file is licensed under the terms of Triscend SDK License Agreement. ********************************************************** */#include <a7hal.h>#include <stdio.h>#include <stdlib.h>#include "main.h"#include "syy.h"#include "grass.h"#define keyctrl 	*( ( unsigned char * ) KEYCONTROLLINE )#define keystat  	*( ( unsigned char * ) KEYSTATUSLINE )#define mseqrst  	*( ( unsigned char * ) mseqreset )#define pwmcnt  	*( ( unsigned char * ) PWMCOUNT )#define lcden	  	*( ( unsigned char * ) lcdenable )#define lcdrst	 	*( ( unsigned char * ) lcdreset )#define	DMA_SEL_REG_LCD		*( ( unsigned long * ) DMATFTLCD )#define DMA_IRQ_LCD		A7HAL_INT_LVL_DMA1#define	DMA_CHANNEL_LCD     	1#define MAX_DESCRIPTORS		4#define DMA1_CONTRL_REG 	*( ( unsigned long * )  0xD1010840)#define DMA1_IN_ENABLE_REG 	*( ( unsigned long * )  0xD1010844)#define DMA1_SRC_ADR_REG 	*( ( unsigned long * )  0xD1010854)#define DMA1_DST_ADR_REG 	*( ( unsigned long * )  0xD1010858)#define DMA1_TRS_CNT_REG 	*( ( unsigned long * )  0xD101085c)#define DMA0_CONTRL_DISEN 	0x00000000#define DMA0_CONTRL_EN 		0x11111111#define DMA1_CONTRL_DISEN 	0x22222222#define DMA1_CONTRL_EN 		0x33333333#define DMA2_CONTRL_DISEN 	0x44444444#define DMA2_CONTRL_EN 		0x55555555#define DMA3_CONTRL_DISEN 	0x66666666#define DMA3_CONTRL_EN 		0x77777777//Data definitionsstatic a7hal_dma_mem_to_io descriptors[3];unsigned int LCDDataBuf[38400]; //0x25800 LENGTH IN BYTE///changes for dubblebuffer///unsigned int LCDDataBuf1[38400]; //0x25800 LENGTH IN BYTEunsigned int *pLCDDataBuf;unsigned char bLCDDataChange;///changes for dubblebuffer/////For DMA void initDescriptors( void );void initDMA( int channel );void StartDisplayDMA( void );void DMA1TransferDone( unsigned long channel );/*  Watchdog Interrupt Handler */void watchdogISR( unsigned long param ){    a7hal_watchdog_clearInt(  );}/* *  Timer Interrupt Handler */void timer0_ISR( unsigned long whichTimer ){        pwmcnt = 0x80;        /*if(pwmcnt==255)        pwmcnt = 0x01;    else        pwmcnt = pwmcnt+1;    */    	    /*    printf( "keyctrl = 0x%x \n" ,keyctrl);    printf( "keystat = 0x%x \n" ,keystat);    printf( "mseqrst = 0x%x \n" ,mseqrst);    printf( "pwmcnt = 0x%x \n" ,pwmcnt);*/    a7hal_timer_clearInt( whichTimer );}/* *  Timer1 Interrupt Handler */void timer1_ISR( unsigned long whichTimer ){    a7hal_timer_clearInt( A7HAL_ICU_TIMER1 );}/* *  IRQ1 Interrupt Handler */void irq0_ISR(  ){    //a7hal_led_write( a7hal_led_read(  ) + 1 );    a7hal_timer_clearInt( A7HAL_ICU_CSL0 );}/* *  IRQ1 Interrupt Handler */void irq1_ISR(  ){    //a7hal_led_write( a7hal_led_read(  ) + 1 );    a7hal_timer_clearInt( A7HAL_ICU_CSL1 );    printf( "keystat = 0x%x\n",keystat);}/* *  IRQ2 Interrupt Handler */void irq2_ISR(  ){    a7hal_icu_intDisable( A7HAL_ICU_CSL2 );    //a7hal_icu_intEnable( A7HAL_ICU_TIMER1 );    //a7hal_timer_start( 0x50, 1, A7HAL_DIV_256 | A7HAL_PERIODIC );}/* *  UART0 Receive Interrupt Handler */void uart0_ISR( unsigned long whichTimer ){    //a7hal_icu_clearInt( A7HAL_ICU_SERIAL0 );    char ch;    //a7hal_uart_setRxInt (0,  OFF);     ch = a7hal_uart_getChar (0);    //a7hal_uart_putChar (0, ch);    a7hal_timer_clearInt( A7HAL_ICU_SERIAL0 );    printf( "received\n");}/* *  UART0 Receive Interrupt Handler */void uart1_ISR( unsigned long whichTimer ){    //a7hal_icu_clearInt( A7HAL_ICU_SERIAL1 );    char ch;        ch = a7hal_uart_getChar (1);    //a7hal_uart_putChar (1, ch);    printf( "%c",ch);}int main(  ){	    long lcdtmp;    long i;    unsigned char *imagedata;    unsigned char data1,data2,data3,data4;    char *src;        /* Enable the uart1 interrupt  */    a7hal_uart_init ();    //a7hal_uart_setBaud (0, 9600);    //a7hal_uart_setBaud (1, 9600);    a7hal_uart_setFIFO (1, A7HAL_FIFO_1_BYTE );    a7hal_uart_setRxInt (1,  ON);     a7hal_icu_intConnect( uart1_ISR, A7HAL_ICU_SERIAL1 , 0 );    a7hal_icu_intEnable( A7HAL_ICU_SERIAL1 );    printf( "\n\rHello Chen Li Feng !\n" );    printf( "Uart Init Finished .\n" );    //for(i=0;     i<600 ; i++){	LCDDataBuf[i] = 0xffffffff; }//white    for(i=0; i<9600; i++){	LCDDataBuf[i] = 0x00000000; }//black    for(i=9600;  i<19200; i++){	LCDDataBuf[i] = 0xf800f800; }//blue    for(i=19200; i<28800; i++){	LCDDataBuf[i] = 0x07e007e0; }//green    for(i=28800; i<38400; i++){	LCDDataBuf[i] = 0x001f001f; }//red    ///changes for dubblebuffer///    for(i=0;     i<38400; i++){	LCDDataBuf1[i] = image[i]; }//image	pLCDDataBuf = &(LCDDataBuf[0]);	bLCDDataChange = 0;///changes for dubblebuffer///    /* Enable the irq1 interrupt  */    a7hal_icu_intConnect( irq0_ISR, A7HAL_ICU_CSL0, 0 );    a7hal_icu_intEnable( A7HAL_ICU_CSL0 );    printf( "Irq0 Init Finished .\n" );         /* Enable the irq1 interrupt  */    a7hal_icu_intConnect( irq1_ISR, A7HAL_ICU_CSL1, 0 );    a7hal_icu_intEnable( A7HAL_ICU_CSL1 );    printf( "Irq1 Init Finished .\n" );         /* Enable the irq2 interrupt  */    a7hal_icu_intConnect( irq2_ISR, A7HAL_ICU_CSL2, 0 );    a7hal_icu_intEnable( A7HAL_ICU_CSL2 );    printf( "Irq2 Init Finished .\n" );        /* Connect an ISR for the FIQ */    a7hal_icu_intSteer( A7HAL_INT_LVL_TIMER0 );    a7hal_icu_intConnect( timer0_ISR, A7HAL_INT_LVL_FIQ, 0 );    /* Enable the timer interrupt and the FIQ */    a7hal_icu_intEnable( A7HAL_INT_LVL_TIMER0 );    a7hal_icu_intEnable( A7HAL_INT_LVL_FIQ );    /* Start the timer */    a7hal_timer_start( 0x8000, 0, A7HAL_DIV_256 | A7HAL_PERIODIC );    a7hal_timer_stop( 0 );    /* Enable the timer1 interrupt  */    a7hal_icu_intConnect( timer1_ISR, A7HAL_ICU_TIMER1, 0 );    //a7hal_icu_intEnable( A7HAL_ICU_TIMER1 );    printf( "Timer Init Finished .\n" );               /*LCD init*/    lcden = 0;    lcden = 1;    lcdrst = 1;        /*LCD DMA init*/    initDMA( DMA_CHANNEL_LCD );    initDescriptors(  );    StartDisplayDMA(  );    /*    DMA1_CONTRL_REG = 0x02803;	//0010 1000 0010 0011    DMA_SEL_REG_LCD = 0x33333333;    DMA1_CONTRL_REG = 0x02802;	//0010 1000 0010 0010    DMA1_IN_ENABLE_REG = 0x00;    DMA1_SRC_ADR_REG = ( unsigned long )(&LCDDataBuf[2]);	// set transfer source address    DMA1_TRS_CNT_REG = 0xfff8;	//set the number of bytes to transfer minus one    DMA1_CONTRL_REG |= 0x004;	//initialize a tansfer    printf( "LCD DMA Init Finished .\n" );*/        /*Init Finished*/        pwmcnt = 0x80;    mseqrst = 0xff;    src = ( char * ) malloc( 128 );    mseqrst = 0x00;        printf( "Turn on back light.\n" );        printf( " TFT lcd witn DMA start working ...\n" );    lcdrst = 0;    keyctrl = 0;        for ( ;; )    {    		    printf( " Press any key to continue ...\n" );	    gets( src );///changes for dubblebuffer///		if(	bLCDDataChange == 1)		{			bLCDDataChange = 0;			pLCDDataBuf = &(LCDDataBuf1[0]);		}		else		{			bLCDDataChange = 1;			pLCDDataBuf = &(LCDDataBufl[0]);		}///changes for dubblebuffer///    }            for ( ;; )    {	//DMAx_CUR_TRANS_CNT_REG -- specify the number remaining to transfer	//DMAx_CUR_DEST_ADDR_REG -- current trasfer destination address		//wait until the previous transfer have started.	//DMAx INIT Bit is auto cleared by hard ware/*	while( (DMA1_CONTRL_REG & 0x04) != 0 ) ; 	DMA1_SRC_ADR_REG = (( unsigned long )(&LCDDataBuf[0x4000])); 	DMA1_TRS_CNT_REG = 0xffff; 	DMA1_CONTRL_REG |= 0x004;	//initialize a tansfer 		while( (DMA1_CONTRL_REG & 0x04) != 0 ) ; 	DMA1_SRC_ADR_REG = (( unsigned long )(&LCDDataBuf[0x8000])); 	DMA1_TRS_CNT_REG = 0x57ff; 	DMA1_CONTRL_REG |= 0x004;	//initialize a tansfer 	    while( (DMA1_CONTRL_REG & 0x04) != 0 ) ;	DMA1_SRC_ADR_REG = ( unsigned long )(&LCDDataBuf[0]); 	DMA1_TRS_CNT_REG = 0xffff; 	DMA1_CONTRL_REG |= 0x004;	//initialize a tansfer*/	//DMA_SEL_REG_LCD = 0x22222222;	//close DMA	    }    }void Delay(int period){	int i,j;	long value;	for(i=0;i<period;i++)	{		for(j=0;j<period;j++)		{			value = i*j;		}	}}void initDescriptors( void ){//0x25800 LENGTH IN BYTE    //memset( &descriptors[0], 0, sizeof( descriptors ) );///changes for dubblebuffer///        printf( "descriptors address = 0x%x \n", (&descriptors[0]));    //Start a transfer using the next descriptor in the descriptor table.    descriptors[0].control = A7HAL_DMA_NEW;    descriptors[0].addr = ( unsigned long )(&pLCDDataBuf[0x000]);//0x00000    descriptors[0].count = 0xffff;    descriptors[0].control &= ~A7HAL_DMA_INTERRUPT;    descriptors[0].control |= A7HAL_DMA_BUFFER_FULL;    descriptors[0].control &= ~A7HAL_DMA_CONTINUOUS;        //Start a transfer using the next descriptor in the descriptor table.    descriptors[1].control = A7HAL_DMA_NEW;    descriptors[1].addr = (( unsigned long )(&pLCDDataBuf[0x4000]));//0x10000    descriptors[1].count = 0xffff;    descriptors[1].control &= ~A7HAL_DMA_INTERRUPT;    descriptors[1].control |= A7HAL_DMA_BUFFER_FULL;    descriptors[1].control &= ~A7HAL_DMA_CONTINUOUS;    //Start a transfer using the first descriptor in the descriptor table.   // descriptors[2].control = A7HAL_DMA_START;    descriptors[2].addr = (( unsigned long )(&pLCDDataBuf[0x8000]));//0x20000    descriptors[2].count = 0x57ff;    descriptors[2].control |= A7HAL_DMA_INTERRUPT;    //descriptors[2].control &= ~A7HAL_DMA_INTERRUPT;    descriptors[2].control |= A7HAL_DMA_BUFFER_FULL;    //descriptors[2].control |=   A7HAL_DMA_RESTART;    //Automatically continue to the next descriptor in the descriptor table     descriptors[2].control &= ~A7HAL_DMA_CONTINUOUS;///changes for dubblebuffer///}void initDMA( int channel ){    /* Set up the DMA for a transfer to the PWM */    DMA_SEL_REG_LCD = DMA1_CONTRL_EN;    a7hal_dma_setProperty( A7HAL_DMA_ALL_BITS, 0, channel );			       a7hal_dma_setProperty(     			   A7HAL_DMA_METHOD_BIT		//    			 | A7HAL_DMA_DIRECTION_BIT	//    			 | A7HAL_DMA_SIZE_BIT		//    			 | A7HAL_DMA_SRC_MODE_BIT     			 | A7HAL_DMA_DST_MODE_BIT    			 | A7HAL_DMA_BUFF_STAT_FREEZE_BIT ,    			 			   A7HAL_DMA_METHOD_DESCRIPTOR			 | A7HAL_DMA_MEM_TO_DEV			 | A7HAL_DMA_SIZE_WORD			 | A7HAL_DMA_SRC_INC_DST_NONE			 | A7HAL_DMA_BUFF_STAT_FREEZE,			 			   channel );    //A7HAL_INT_DESC  Descriptor interrupt.     a7hal_dma_intEnable( DMA_CHANNEL_LCD, A7HAL_INT_DESC, A7HAL_INT_DESC );    /* Setup and enable the DMA interrupt */    a7hal_icu_intConnect( DMA1TransferDone, DMA_IRQ_LCD, DMA_CHANNEL_LCD );        a7hal_icu_intEnable( DMA_IRQ_LCD );//DMA1_IN_ENABLE_REG = 0x00;          //DMA1_CONTRL_REG |= A7HAL_DMA_BROADCAST_ENABLE;    //printf( "LCD DMA Init Finished .\n" );}void StartDisplayDMA( void ){    printf( "\n Start LCD Data transfer\n" );    a7hal_dma_abort( DMA_CHANNEL_LCD );    a7hal_dma_setDescriptorAddress( DMA_CHANNEL_LCD, ( void * ) &descriptors[0] );    a7hal_dma_enable( DMA_CHANNEL_LCD );        a7hal_dma_start( DMA_CHANNEL_LCD );//DMA1_CONTRL_REG |= 0x004;	//initialize dma    //a7hal_dma_broadcast( DMA_CHANNEL_LCD );}void DMA1TransferDone( unsigned long channel ){    a7hal_dma_clearInt( channel, a7hal_dma_getIntStatus( channel ) );///changes for dubblebuffer///    descriptors[0].addr = ( unsigned long )(&pLCDDataBuf[0x000]);//0x00000    descriptors[1].addr = ( unsigned long )(&pLCDDataBuf[0x4000]);//0x00000    descriptors[2].addr = ( unsigned long )(&pLCDDataBuf[0x8000]);//0x00000///changes for dubblebuffer///    descriptors[0].control |= A7HAL_DMA_BUFFER_FULL;    descriptors[1].control |= A7HAL_DMA_BUFFER_FULL;    descriptors[2].control |= A7HAL_DMA_BUFFER_FULL;    a7hal_dma_start( DMA_CHANNEL_LCD );//DMA1_CONTRL_REG |= 0x004;	//initialize dma    //printf( "LCD DMA trasfer Finished .\n" );}

⌨️ 快捷键说明

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