深入理解ARM体系架构(S3C6410)---ad转化实例

本系列文章由张同浩编写转载请注明出处:http://blog.csdn.net/muge0913/article/details/7442627

邮箱:[email protected]



对于adc的功能大家都已经很熟悉了,以前我也写过关于S3C6410中ad的文章,如:http://blog.csdn.net/muge0913/article/details/7059241

本实例是把采集的ad数据转化后显示在lcd屏上,在这直接把自己调试好的源码贴出来


ad转化器相关代码:

void adc_init()
{
	/*设置分频时钟*/
	char preScaler = 66500000/2500000 - 1; //PCLK=66M		
    rADCCON = (1<<14)|(preScaler<<6)|(0<<3)|(0<<2);//通道AIN0
   // rADCCON =0x44c1;//通道AIN0
}
int read_adc()
{
   /*开始AD转换*/
   rADCCON |= 0x01; //start ADC
	
   while(rADCCON & 0x1);	//check if Enable_start is low
	
   /*检查转换是否结束*/
   while(!(rADCCON & 0x8000));	//check if EC(End of Conversion) flag is high
    
   return ( (int)rADCDAT0 & 0x3ff );
}

void delay_adc()
{
	int i,j;
	for(i=0;i<10000000;i++)
		for(j=0;j>10000000;j++);	
}

lcd相关代码:

初始化子程序:

void LCD_Init(void) 
{

	//设置LCD调光
	//rGPFCON |= (1<<30);  //设置LCD调光管脚GPF15(PWM1)为输出
	//rGPFDAT |= (1<<15);  //rGPFDAT =  0x00002000;
	//rGPFPUD &= ~(1<<30);  //rGPFPUD = 0x00000000;

	//设置VD0~15
	rGPICON = 0xaaaaaaaa;  //设置GPI0~15为LCD VD0~15
	rGPIPUD = 0xffffffff;


		
	//设置VD16~23和HSYNC、VSYNC、VDEN、VCLK
	rGPJCON = 0x00aaaaaa;
	rGPJPUD = 0xffffffff;
	rWINCON0 &= ~(1<<0);

	//LCD寄存器设置
	rSPCON &= (~0x3);
	rSPCON |= (1<<0);  //设置RGBI/F配置
	rMIFPCON &= ~(1<<3);  //设置LCD支路为一般模式
	
	rVIDCON0 = (0<<29)|(0<<26)|(0<<17)|(1<<16)|(9<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2);
	rVIDCON1 = 1<<7;  //1=RGB类型LCD设备在VCLK上升沿得到视频数据
	
	//设置屏的时序
	rVIDTCON0 = (0x00<<16)|(0x00<<8)|(0x02<<0);
	rVIDTCON1 = (0x2d<<16)|(0x04<<8)|(0x06<<0);
	rVIDTCON2 = (271<<11)|(479<<0);

	//设置窗口格式
	rWINCON0 = 11<<2;  //设置24BPP

	//设置窗口位置
	rVIDOSD0A = (0<<11)|(0<<0);
	rVIDOSD0B = (479<<11)|(271<<0);
	rVIDOSD0C = (((480*272)&0xffffff)<<0);  //4.3屏幕分辨率480*272

	//设置Window1的开始和结束的缓存地址与地址在内存中的存放地址以及缓存的大小
	rVIDW00ADD0B0 = ((addr>>24)<<24)|(addr&0xffffff);
	rVIDW00ADD1B0 = (addr&0xffffff + 480*272);
	rVIDW00ADD2 = (0<<13)|(480<<0);

	//设置抖动
	rDITHMODE=(1<<5)|(1<<3)|(1<<1)|(1<<0);

	//开显示
	rVIDCON0 |= (3<<0);
	rWINCON0 |= (1<<0);
}

lcd字符显示子程序:

void Paint_text(unsigned int x, unsigned int y, unsigned int color, unsigned char ch[], unsigned int lengx,int lengy){
    int i, j, test, t = -1;         
    for(i = 0; i < lengy; i++){            
        for(j = 0; j < lengx; j++){         
            if(j%8 == 0){         
                test = 0x80;         
                t++;         
            }         
            if(ch[t] & test)         
                LCD_BUFFER[y+i][x+j] = color;
            else
            	LCD_BUFFER[y+i][x+j] = 0xffffff;
            
            test >>= 1;            
        }           
    }         
} 



头文件中字符数据定义:

unsigned char charnum[10][16]={
{0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},
{0x00,0x00,0x00,0x10,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00},
{0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x04,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00},
{0x00,0x00,0x00,0x3C,0x42,0x42,0x04,0x18,0x04,0x02,0x02,0x42,0x44,0x38,0x00,0x00},
{0x00,0x00,0x00,0x04,0x0C,0x14,0x24,0x24,0x44,0x44,0x7E,0x04,0x04,0x1E,0x00,0x00},
{0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x58,0x64,0x02,0x02,0x42,0x44,0x38,0x00,0x00},
{0x00,0x00,0x00,0x1C,0x24,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x24,0x18,0x00,0x00},
{0x00,0x00,0x00,0x7E,0x44,0x44,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00},
{0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00},
{0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x26,0x1A,0x02,0x02,0x24,0x38,0x00,0x00}};




unsigned char charnumc[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x22,0x40,0x40,0x40,0x22,0x1C,0x00,0x00};
unsigned char charnumo[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00};
unsigned char charnumn[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xDC,0x62,0x42,0x42,0x42,0x42,0xE7,0x00,0x00};
unsigned char charnumv[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x28,0x10,0x10,0x00,0x00};
unsigned char charnume[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x7E,0x40,0x40,0x42,0x3C,0x00,0x00};
unsigned char charnumr[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xEE,0x32,0x20,0x20,0x20,0x20,0xF8,0x00,0x00};
unsigned char charnums[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x42,0x40,0x3C,0x02,0x42,0x7C,0x00,0x00};
unsigned char charnumi[]={0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x70,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00};



主函数程序:

	adc_init();
	
	LCD_Init();
	Paint_background(0xffffff,0,0,480,272);
	
	
	while(1)
	{
	adc_data = read_adc();
	adc_data = (adc_data*32226);
	
	adc_data_tmp[0] = adc_data/100000/100;
	//adc_data_tmp[1] = ((adc_data/100)%100000)/10000;
	adc_data_tmp[1] = adc_data%10000000/1000000;
	adc_data_tmp[2] = adc_data%1000000/100000;
	adc_data_tmp[3] = adc_data%100000/10000;
	adc_data_tmp[4] = adc_data%10000/1000;
	adc_data_tmp[5] = adc_data%1000/100;
	adc_data_tmp[6] = adc_data%100/10;
	adc_data_tmp[7] = adc_data%10;
	
	
	Paint_text(124+8*0, 20, 0x0,charnum[adc_data_tmp[0]],8, 16);
	Paint_text(124+8*1, 20, 0x0,charnum[adc_data_tmp[1]],8, 16);
	Paint_text(124+8*2, 20, 0x0,charnum[adc_data_tmp[2]],8, 16);
	Paint_text(124+8*3, 20, 0x0,charnum[adc_data_tmp[3]],8, 16);
	Paint_text(124+8*4, 20, 0x0,charnum[adc_data_tmp[4]],8, 16);
	Paint_text(124+8*5, 20, 0x0,charnum[adc_data_tmp[5]],8, 16);
	Paint_text(124+8*6, 20, 0x0,charnum[adc_data_tmp[6]],8, 16);
	Paint_text(124+8*7, 20, 0x0,charnum[adc_data_tmp[7]],8, 16);
	delay_adc();
	
	}





程序下载地址:



你可能感兴趣的:(c,buffer,delay)