您的位置 首页 芯闻

深化了解ARM系统架构(S3C6410)—ad转化实例

本实例是把采集的ad数据转化后显示在lcd屏上,在这直接把自己调试好的源码贴出来ad转化器相关代码:[cpp]viewplaincopyprint?voidadc_ini…

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

ad转化器相关代码:

[cpp]view plaincopyprint?

  1. voidadc_init()
  2. {
  3. charpreScaler=66500000/25000001;//PCLK=66M
  4. rADCCON=(1<<14)|(preScaler<<6)|(0<<3)|(0<<2);//通道AIN0
  5. //rADCCON=0x44c1;//通道AIN0
  6. }
  7. intread_adc()
  8. {
  9. rADCCON|=0x01;//startADC
  10. while(rADCCON&0x1);//checkifEnable_startislow
  11. while(!(rADCCON&0x8000));//checkifEC(EndofConversion)flagishigh
  12. return((int)rADCDAT0&0x3ff);
  13. }
  14. voiddelay_adc()
  15. {
  16. inti,j;
  17. for(i=0;i<10000000;i++)
  18. for(j=0;j>10000000;j++);
  19. }

lcd相关代码:

初始化子程序:

[cpp]view plaincopyprint?

  1. voidLCD_Init(void)
  2. {
  3. //设置LCD调光
  4. //rGPFCON|=(1<<30);//设置LCD调光管脚GPF15(PWM1)为输出
  5. //rGPFDAT|=(1<<15);//rGPFDAT=0x00002000;
  6. //rGPFPUD&=~(1<<30);//rGPFPUD=0x00000000;
  7. //设置VD0~15
  8. rGPICON=0xaaaaaaaa;//设置GPI0~15为LCDVD0~15
  9. rGPIPUD=0xffffffff;
  10. //设置VD16~23和HSYNC、VSYNC、VDEN、VCLK
  11. rGPJCON=0x00aaaaaa;
  12. rGPJPUD=0xffffffff;
  13. rWINCON0&=~(1<<0);
  14. //LCD寄存器设置
  15. rSPCON&=(~0x3);
  16. rSPCON|=(1<<0);//设置RGBI/F装备
  17. rMIFPCON&=~(1<<3);//设置LCD支路为一般形式
  18. rVIDCON0=(0<<29)|(0<<26)|(0<<17)|(1<<16)|(9<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2);
  19. rVIDCON1=1<<7;//1=RGB类型LCD设备在VCLK上升沿得到视频数据
  20. //设置屏的时序
  21. rVIDTCON0=(0x00<<16)|(0x00<<8)|(0x02<<0);
  22. rVIDTCON1=(0x2d<<16)|(0x04<<8)|(0x06<<0);
  23. rVIDTCON2=(271<<11)|(479<<0);
  24. //设置窗口格局
  25. rWINCON0=11<<2;//设置24BPP
  26. //设置窗口方位
  27. rVIDOSD0A=(0<<11)|(0<<0);
  28. rVIDOSD0B=(479<<11)|(271<<0);
  29. rVIDOSD0C=(((480*272)&0xffffff)<<0);//4.3屏幕分辨率480*272
  30. //设置Window1的开端和完毕的缓存地址与地址在内存中的寄存地址以及缓存的巨细
  31. rVIDW00ADD0B0=((addr>>24)<<24)|(addr&0xffffff);
  32. rVIDW00ADD1B0=(addr&0xffffff+480*272);
  33. rVIDW00ADD2=(0<<13)|(480<<0);
  34. //设置颤动
  35. rDITHMODE=(1<<5)|(1<<3)|(1<<1)|(1<<0);
  36. //开显现
  37. rVIDCON0|=(3<<0);
  38. rWINCON0|=(1<<0);
  39. }

lcd字符显现子程序:

[cpp]view plaincopyprint?

  1. voidPaint_text(unsignedintx,unsignedinty,unsignedintcolor,unsignedcharch[],unsignedintlengx,intlengy){
  2. inti,j,test,t=-1;
  3. for(i=0;i<lengy;i++){
  4. for(j=0;j<lengx;j++){
  5. if(j%8==0){
  6. test=0x80;
  7. t++;
  8. }
  9. if(ch[t]&test)
  10. LCD_BUFFER[y+i][x+j]=color;
  11. else
  12. LCD_BUFFER[y+i][x+j]=0xffffff;
  13. test>>=1;
  14. }
  15. }
  16. }

头文件中字符数据界说:

[cpp]view plaincopyprint?

  1. unsignedcharcharnum[10][16]={
  2. {0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},
  3. {0x00,0x00,0x00,0x10,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00},
  4. {0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x04,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00},
  5. {0x00,0x00,0x00,0x3C,0x42,0x42,0x04,0x18,0x04,0x02,0x02,0x42,0x44,0x38,0x00,0x00},
  6. {0x00,0x00,0x00,0x04,0x0C,0x14,0x24,0x24,0x44,0x44,0x7E,0x04,0x04,0x1E,0x00,0x00},
  7. {0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x58,0x64,0x02,0x02,0x42,0x44,0x38,0x00,0x00},
  8. {0x00,0x00,0x00,0x1C,0x24,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x24,0x18,0x00,0x00},
  9. {0x00,0x00,0x00,0x7E,0x44,0x44,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00},
  10. {0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00},
  11. {0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x26,0x1A,0x02,0x02,0x24,0x38,0x00,0x00}};
  12. unsignedcharcharnumc[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x22,0x40,0x40,0x40,0x22,0x1C,0x00,0x00};
  13. unsignedcharcharnumo[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00};
  14. unsignedcharcharnumn[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xDC,0x62,0x42,0x42,0x42,0x42,0xE7,0x00,0x00};
  15. unsignedcharcharnumv[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x28,0x10,0x10,0x00,0x00};
  16. unsignedcharcharnume[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x7E,0x40,0x40,0x42,0x3C,0x00,0x00};
  17. unsignedcharcharnumr[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xEE,0x32,0x20,0x20,0x20,0x20,0xF8,0x00,0x00};
  18. unsignedcharcharnums[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x42,0x40,0x3C,0x02,0x42,0x7C,0x00,0x00};
  19. unsignedcharcharnumi[]={0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x70,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00};

主函数程序:

[cpp]view plaincopyprint?

  1. adc_init();
  2. LCD_Init();
  3. Paint_background(0xffffff,0,0,480,272);
  4. while(1)
  5. {
  6. adc_data=read_adc();
  7. adc_data=(adc_data*32226);
  8. adc_data_tmp[0]=adc_data/100000/100;
  9. //adc_data_tmp[1]=((adc_data/100)0000)/10000;
  10. adc_data_tmp[1]=adc_data000000/1000000;
  11. adc_data_tmp[2]=adc_data00000/100000;
  12. adc_data_tmp[3]=adc_data0000/10000;
  13. adc_data_tmp[4]=adc_data000/1000;
  14. adc_data_tmp[5]=adc_data00/100;
  15. adc_data_tmp[6]=adc_data0/10;
  16. adc_data_tmp[7]=adc_data;
  17. Paint_text(124+8*0,20,0x0,charnum[adc_data_tmp[0]],8,16);
  18. Paint_text(124+8*1,20,0x0,charnum[adc_data_tmp[1]],8,16);
  19. Paint_text(124+8*2,20,0x0,charnum[adc_data_tmp[2]],8,16);
  20. Paint_text(124+8*3,20,0x0,charnum[adc_data_tmp[3]],8,16);
  21. Paint_text(124+8*4,20,0x0,charnum[adc_data_tmp[4]],8,16);
  22. Paint_text(124+8*5,20,0x0,charnum[adc_data_tmp[5]],8,16);
  23. Paint_text(124+8*6,20,0x0,charnum[adc_data_tmp[6]],8,16);
  24. Paint_text(124+8*7,20,0x0,charnum[adc_data_tmp[7]],8,16);
  25. delay_adc();
  26. }

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/news/xinwen/276972.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部