现在的位置: 首页 > 综合 > 正文

S5pc100裸奔全攻略之ADC

2013年05月07日 ⁄ 综合 ⁄ 共 1530字 ⁄ 字号 评论关闭

 

作者:赵孝强,华清远见嵌入式学院讲师。

以下是s5pc100的不带系统ADC的驱动程序,需要head.S,map.lds,Makefile,s5pc100.h,uart.c,uart.h文件,用v7交叉工具链,以上文件可在www.farsight.com.cn下载到。

#include "s5pc100.h"
        #include "uart.h"
        unsigned char table[10]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
        int main()
        {
                unsigned short int temp = 0;
                unsigned int a;
                unsigned char bit4,bit3,bit2,bit1;
                int count;
                ADC.ADCMUX = 0;
                ADC.ADCCON = ( 1<<16 | 1<<14 | 0xff<<6 | 0<<2 | 1<<1 ) ;
                temp = ADC.ADCDAT0 & 0XFFF;
                uart0_init();
                a = MEM.MEMCONTROL >> 8;
                uart_sendbyte((unsigned char)a);
                while(1)
                {
                        while(!(ADC.ADCCON & 0X8000));
                        temp = ADC.ADCDAT0 & 0XFFF;
                        temp = 3.3 * 1000 * temp/ 0xfff;
                        bit4 = temp/1000;
                        uart_sendbyte(table[bit4]);
                        bit3 = (temp%1000)/100;
                        uart_sendbyte(table[bit3]);
                        bit2 = ((temp%1000)%100)/10;
                        uart_sendbyte(table[bit2]);
                        bit1 = ((temp%1000)%100)%10;
                        uart_sendbyte(table[bit1]);
                        uart_sendstring("mV");
                        uart_sendbyte('\n');
                        for(count = 1000000; count != 0; count--);
                }
                return 0;
        }

 

【上篇】
【下篇】

抱歉!评论已关闭.