8051单片机的proteus仿真AD转换实验?
请问怎么添加代码让AD转换输出的结果显示在数码管上呀?比如3.557这样的我目前代码如下:#include"STC15.H"typedefunsignedcharu8;t...
请问怎么添加代码让AD转换输出的结果显示在数码管上呀?比如3.557这样的我目前代码如下:#include "STC15.H"typedef unsigned char u8;typedef unsigned int u16;typedef unsigned long int u32;#define FOSC 11059200L#define BAUD 9600L#define VCC 4999L#define ADC_POWER 0x80#define ADC_FLAG 0x10#define ADC_START 0x08#define ADC_SPEEDLL 0x00#define ADC_SPEEDL 0x20#define ADC_SPEEDH 0x40#define ADC_SPEEDHH 0x60#define ADC_CHANNEL0 0#define ADC_CHANNEL1 1#define ADC_CHANNEL2 2#define ADC_CHANNEL3 3 #define ADC_CHANNEL4 4#define ADC_CHANNEL5 5 #define ADC_CHANNEL6 6 #define ADC_CHANNEL7 7 void Pin_Mode(void);void Delay_nms(u16 n);void ADC_Initial(void);void SEG7_1Bit_Display(u8,u8);u8 code Duan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff}u16 ADCvalue =0;u8 ADCChannel;u32 Vin=0; void main(){ ADCChannel = ADC_CHANNEL1; Pin_Mode(); ADC_Initial(); while (1){ Vin = VCC * ADCvalue/1023; Delay_nms(500); }}void ADC_ISR(void) interrupt 5{ ADC_CONTR &= ~(ADC_FLAG | ADC_START); ADCvalue = (ADC_RES << 2)|(ADC_RESL & 0x03); ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ADC_START | ADCChannel;}void Pin_Mode(void){ P1M1 = 0x00; P1M0 = 0x00; P0M1 = 0x00; P0M0 = 0x00; P2M1 = 0x00; P2M0 = 0x00;}void ADC_Initial(void){ P1ASF = 0xff; ADC_RES = 0; ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ADC_START | ADCChannel; Delay_nms(2); EADC = 1; EA = 1;}void Delay_nms(u16 nms){ u16 i,t; for(i=0;i<nms;i++){ for(t=0;t<1080;t++); }}void SEG7_1Bit_Display(u8 Num,u8 position){ P2=0xff; P0=~SEG_Code[Num]; P2=Bit_Code[position-1]; if(Position == 3) P0 |= 0x80;}
展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询