S5pc100裸奔全攻略之ADC

作者:赵孝强,华清远见嵌入式培训中心讲师。

以下是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;
        }

你可能感兴趣的:(ad)