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;
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值