请高手解释以下STC内部adc转换中断服务程序什么意思
时间:10-02
整理:3721RD
点击:
- #include<reg52.h>
- sfr ADC_CONTR=0xbc;
- sfr P1ASF=0x9d;
- sfr ADC_RES=0xbd;
- #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_POSITION 1 //AD通道位置0-7
- #define NUX_DATA P0 //数码管段选
- #define NUX_SEG P2 //数码管位选
- void Delay_ms(unsigned int ms); //延时函数
- void InitADC(); //初始化AD功能
- unsigned int code Ttable[42][2]={// 热敏电阻的温度值(从2-43摄氏度),2℃对应25.7K;
- {2,257},{3,246},{4,236},{5,225},{6,216},
- {7,207},{8,198},{9,190},{10,182},{11,174},
- {12,167},{13,160},{14,154},{15,148},{16,142},
- {17,136},{18,131},{19,126},{20,121},{21,116},
- {22,112},{23,107},{24,103},{25,100},{26,96},
- {27,92},{28,89},{29,86},{30,82},{31,80},{32,77},
- {33,74},{34,71},{35,69},{36,66},{37,64},{38,62},
- {39,60},{40,58},{41,56},{42,54},{43,52}};
- unsigned char code TableDATA[13]={
- 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D,0x7D, 0x07, 0x7F, 0x6F/*0-9*/, 0x00/*无*/, 0x02, 0x39};
- unsigned char code TableSEG [4]={0xEF,0xDF,0xBF,0x7F};
- //数码管位置0-3
- unsigned char show[4];
- void Delay_ms(unsigned int ms)
- {
- for(;ms>0;ms--);
- }
- <font color="red">void Adc_isr() interrupt 5
- {
- unsigned char i;
- unsigned int m;
- m=ADC_RES;
- //计算此时热敏电阻阻值
- m=(100*m)/(255-m);
- //计算此时的温度值
- for(i=41;i<42;i--)
- {
- if(m >= Ttable[i][1] && m < Ttable[i-1][1])
- {
- show[0]=(Ttable[i][0]+1)/10;
- show[1]=(Ttable[i][0]+1)%10;
- show[2]=11;
- show[3]=12;
- break;
- }
- }
- ADC_CONTR=ADC_POWER|ADC_SPEEDLL|ADC_START|ADC_POSITION; //重新使能AD转换
- }</font>
- void InitADC()
- {
- P1ASF=0xff;
- ADC_RES=0;
- ADC_CONTR=ADC_POWER|ADC_SPEEDLL|ADC_START|1; //使能P11为AD输入
- IE=0xa0;
- Delay_ms(20);
- }
- main()
- {
- unsigned char i,j;
- InitADC();
- while(1)
- {
- for(j=255;j>0;j--)
- {
- for(i=0;i<4;i++)
- {
- NUX_SEG =TableSEG[3-i];
- NUX_DATA =TableDATA[show[i]];
- Delay_ms(100);
- NUX_DATA =0x00;
- }
- }
-
- }
- }
补充原理图如下!
stc12c5a60s2
我发现这个论坛没人回帖!