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

📄 main.c

📁 基于三星ARM 44BO的AD采样试验.ADS下编译
💻 C
字号:
#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"
#include "..\inc\myplmm.h"

#define dangliang 0.0024414

#define XTOTAL 320
#define YTOTAL 240
#define EVERYX 32
#define HIGHB 32
;
#define SCR_XSIZE 	(320)  
#define SCR_YSIZE 	(240)

#define LCD_XSIZE 	(320)
#define LCD_YSIZE 	(240)

#define M5D(n) ((n) & 0x1fffff)
///////////////////////////////////////////////////////////////
#define ARRAY_SIZE_MONO 	(SCR_XSIZE/8*SCR_YSIZE)
#define ARRAY_SIZE_G4   	(SCR_XSIZE/4*SCR_YSIZE)
#define ARRAY_SIZE_G16  	(SCR_XSIZE/2*SCR_YSIZE)
#define ARRAY_SIZE_COLOR 	(SCR_XSIZE/1*SCR_YSIZE)

#define HOZVAL			(LCD_XSIZE/4-1)
#define HOZVAL_COLOR		(LCD_XSIZE*3/8-1)
#define LINEVAL			(LCD_YSIZE-1)
#define MVAL			(13)
///////////////////////////////////////////////////////////////
#define CLKVAL_MONO 		(13)  //60Mhz, CLKVAL=19 ->78.6Hz
#define CLKVAL_G4 		(13)  //60Mhz, CLKVAL=19 ->78.6Hz
#define CLKVAL_G16 		(13)  //60Mhz, CLKVAL=19 ->78.6Hz
#define CLKVAL_COLOR 		(10)  //60Mhz, CLKVAL=19 ->78.6Hz
/*************************************************/

unsigned int (*frameBuffer1)[SCR_XSIZE/32];
unsigned int (*frameBuffer4)[SCR_XSIZE/16];
unsigned int (*frameBuffer16)[SCR_XSIZE/8];
unsigned int (*frameBuffer256)[SCR_XSIZE/4];

void ad_init(void);
void displaylcd32(unsigned int x, unsigned int y, char num,char type);
void clear(void);
void Lcd_kb_MonoInit(void);


void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);      
void HaltDabort(void);

void Main(void)
{
  float value=0;
  int chance=0;
  unsigned int i=0;
  U32  Xall=0,Yall=0;
  U32 Pt[6];
  int j=0, k=0;
  char num=0;
    rSYSCFG=SYSCFG_8KB;
#if (PLLON==1)
    ChangePllValue(PLL_M,PLL_P,PLL_S);
#endif

    Isr_Init();
    Port_Init();
    Uart_Init(0,115200);
    Uart_Select(0);
    Delay(1000);  //calibrate Delay()
 
 Uart_Printf("现在开始 A/D 采样测试\n");
  Uart_Printf("请选择采样通道号 (0----7)\n");


    chance =(char) (Uart_GetIntNum()& 0xf);
    Lcd_kb_MonoInit();
    ad_init();
    clear();
    while(!(Uart_GetKey()))
        {
    	 rADCCON=chance<<2;			// AIN0----AIN7,   always is 3
	 for(i=0;i<1000;i++);		//delay to set up the next channel
	 for(i=0;i<5;i++)
	    {
	     rADCCON|=0x1;		// Start X-position conversion
	     for(j=0;j<1000;j++);
	     while(rADCCON & 0x1);	// Check if Enable_start is low
    	     while(!(rADCCON & 0x40));	// Check ECFLG
	     Pt[i]=(0x3ff&rADCDAT);
	     for(j=0;j<1000;j++);
	     }
	Pt[5]=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;
	j=0;
	value = Pt[5]* dangliang; 
	num = (char) value;
	displaylcd32(100+j*32, 120, num, 1);
	j++;
	displaylcd32(100+j*32, 120, 16, 1);              //   dop
	j++;
	num = (value *10) - ((char) value)*10  ;
	displaylcd32(100+j*32, 120, num, 1);
	j++;
	num = ((value *100) - ((char) value)*100)-num*10  ;
	displaylcd32(100+j*32, 120, num, 1);
	j++;
	displaylcd32(100+j*32, 120, 17, 1);              //v
	Uart_Printf("get data = %lf\n", value);
	for(i=0;i<10000;i++);
  }
 rADCCON=rADCCON & 0x7e;
 rCLKCON=0x6ff8;    // close  A/D
 Uart_Printf(" test is end !! \n"); 

}
//////////////////////////////////////////////////////////////////////////////////////////
void Lcd_kb_MonoInit(void)
{
         #define MVAL_USED 0
     if((U32)frameBuffer256==0)
	{
	    frameBuffer256=(unsigned int (*)[SCR_XSIZE/4])malloc(ARRAY_SIZE_COLOR); 
	}

	rLCDCON1=(0)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);
	    // disable,8B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
	rLCDCON2=(LINEVAL)|(HOZVAL_COLOR<<10)|(10<<21);  
	    //LINEBLANK=10 (without any calculation) 
	rLCDSADDR1= (0x3<<27) | ( ((U32)frameBuffer256>>22)<<21 ) | M5D((U32)frameBuffer256>>1);
	    // 256-color, LCDBANK, LCDBASEU
	rLCDSADDR2= M5D(((U32)frameBuffer256+(SCR_XSIZE*(LINEVAL+1)))>>1) | (MVAL<<21);
	rLCDSADDR3= (LCD_XSIZE/2) | ( ((SCR_XSIZE-LCD_XSIZE)/2)<<9 );

	//The following value has to be changed for better display.

	rREDLUT  =0xfdb97531;
	rGREENLUT=0xfdb97531;
	rBLUELUT =0xfb73;

	rDITHMODE=0x0;
	rDP1_2 =0xa5a5;      
	rDP4_7 =0xba5da65;
	rDP3_5 =0xa5a5f;
	rDP2_3 =0xd6b;
	rDP5_7 =0xeb7b5ed;
	rDP3_4 =0x7dbe;
	rDP4_5 =0x7ebdf;
	rDP6_7 =0x7fdfbfe;

	rLCDCON1=(1)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);
} 

/////////////////////////////////////////////////////////////////////////////////////////
/*************************  ********************************/
void displaylcd32(unsigned int x, unsigned int y, char num, char type)
{
    unsigned int *pbuffer,temp_data;
    unsigned int i=0, j=0, m=0;
     
    //clrscreen();
    pbuffer =(U32*) frameBuffer256;
    for(m=0; m<HIGHB; m++)
     { 
       i = (y+m)*XTOTAL*8/EVERYX+x*8/EVERYX;
	//Uart_Printf("the i is : %x   \n", i);
	if (type == 0)
		{
        temp_data = (Bitmap32[num][m*32] << 24) + (Bitmap32[num][m*32+1] << 16) + (Bitmap32[num][m*32+2] << 8) +(Bitmap32[num][m*32+3]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32[num][m*32+4] << 24) + (Bitmap32[num][m*32+5] << 16) + (Bitmap32[num][m*32+6] << 8) +(Bitmap32[num][m*32+7]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32[num][m*32+8] << 24) + (Bitmap32[num][m*32+9] << 16) + (Bitmap32[num][m*32+10] << 8) +(Bitmap32[num][m*32+11]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32[num][m*32+12] << 24) + (Bitmap32[num][m*32+13] << 16) + (Bitmap32[num][m*32+14] << 8) +(Bitmap32[num][m*32+15]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32[num][m*32+16] << 24) + (Bitmap32[num][m*32+17] << 16) + (Bitmap32[num][m*32+18] << 8) +(Bitmap32[num][m*32+19]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32[num][m*32+20] << 24) + (Bitmap32[num][m*32+21] << 16) + (Bitmap32[num][m*32+22] << 8) +(Bitmap32[num][m*32+23]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32[num][m*32+24] << 24) + (Bitmap32[num][m*32+25] << 16) + (Bitmap32[num][m*32+26] << 8) +(Bitmap32[num][m*32+27]);
       pbuffer[i]=temp_data;
	i++;
       temp_data = (Bitmap32[num][m*32+28] << 24) + (Bitmap32[num][m*32+29] << 16) + (Bitmap32[num][m*32+30] << 8) +(Bitmap32[num][m*32+31]);
       pbuffer[i]=temp_data;
	           }
	else 
		{
        temp_data = (Bitmap32_num[num][m*32] << 24) + (Bitmap32_num[num][m*32+1] << 16) + (Bitmap32_num[num][m*32+2] << 8) +(Bitmap32_num[num][m*32+3]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32_num[num][m*32+4] << 24) + (Bitmap32_num[num][m*32+5] << 16) + (Bitmap32_num[num][m*32+6] << 8) +(Bitmap32_num[num][m*32+7]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32_num[num][m*32+8] << 24) + (Bitmap32_num[num][m*32+9] << 16) + (Bitmap32_num[num][m*32+10] << 8) +(Bitmap32_num[num][m*32+11]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32_num[num][m*32+12] << 24) + (Bitmap32_num[num][m*32+13] << 16) + (Bitmap32_num[num][m*32+14] << 8) +(Bitmap32_num[num][m*32+15]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32_num[num][m*32+16] << 24) + (Bitmap32_num[num][m*32+17] << 16) + (Bitmap32_num[num][m*32+18] << 8) +(Bitmap32_num[num][m*32+19]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32_num[num][m*32+20] << 24) + (Bitmap32_num[num][m*32+21] << 16) + (Bitmap32_num[num][m*32+22] << 8) +(Bitmap32_num[num][m*32+23]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32_num[num][m*32+24] << 24) + (Bitmap32_num[num][m*32+25] << 16) + (Bitmap32_num[num][m*32+26] << 8) +(Bitmap32_num[num][m*32+27]);
       pbuffer[i]=temp_data;
	i++;
       temp_data = (Bitmap32_num[num][m*32+28] << 24) + (Bitmap32_num[num][m*32+29] << 16) + (Bitmap32_num[num][m*32+30] << 8) +(Bitmap32_num[num][m*32+31]);
       pbuffer[i]=temp_data;
		}
    	}	
}
/////////////////////////////////////////////////////////////////////////////////////////////
void clear(void)
{ 
     unsigned int *pbuffer;
     int i;
     
    pbuffer =(U32*) frameBuffer256;
    for(i = 0; i< (9600*8/4) ;i++)
    {
        pbuffer[i] = 0;

 }
}
/////////////////////////////////////////////////////////////////////////////////////////////
void ad_init(void)
{
   rEXTINT=0x22222222;
   rINTCON=0x5;
   
    rCLKCON=0x7ff8;
    rADCPSR=199;    //0x4;
}

//////////////////////////////////////////////////////////////////////////////////////////
void Isr_Init(void)
{
    U32 i;
    
    pISR_UNDEF=(unsigned)HaltUndef;
    pISR_SWI  =(unsigned)HaltSwi;
    pISR_PABORT=(unsigned)HaltPabort;
    pISR_DABORT=(unsigned)HaltDabort;
    
     for(i=_RAM_STARTADDRESS;i<(_RAM_STARTADDRESS+0x20);i+=4)
    {
	*((volatile unsigned *)i)=0xEA000000+0x1FFE;
    }

    rINTCON=0x5;	  // Non-vectored,IRQ enable,FIQ disable    

    rINTMOD=0x0;	  // All=IRQ mode
    rINTMSK|=BIT_GLOBAL|BIT_EINT3;	  // All interrupt is masked.
}


void HaltUndef(void)
{
    Uart_Printf("Undefined instruction exception!!!\n");
    while(1);
}

void HaltSwi(void)
{
    Uart_Printf("SWI exception!!!\n");
    while(1);
}

void HaltPabort(void)
{
    Uart_Printf("Pabort exception!!!\n");
    while(1);
}

void HaltDabort(void)
{
    Uart_Printf("Dabort exception!!!\n");
    while(1);
}

⌨️ 快捷键说明

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