我用STC15F2K60S2做的调频调压电路
下面是C语言代码- #include "reg51.h"
- #include "intrins.h"
- #define GPIO_DIG P0
- #define GPIO_PLACE P2
- typedef unsigned char BYTE;
- typedef unsigned int WORD;
- sfr P0M1 = 0X93;
- sfr P0M0 = 0X94;
- sfr P2M1 = 0x95;
- sfr P2M0 = 0x96;
- sfr AUXR = 0x8e;
- sfr ADC_CONTR = 0xBC;
- sfr ADC_RES = 0xBD;
- sfr ADC_LOW2 = 0xBE;
- sfr P1ASF = 0x9D;
- sfr auxr=0x8e;
- WORD uu=160,x,shu=60,xue=10000;
- BYTE anjian;
- unsigned int num;
- float vin;
- unsigned int ooo,qian,bai,shi,ge;
- unsigned char code DIG_PLACE[] = {0x07,0x0b,0x0d,0x0e };
- unsigned char code DIG_CODE[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x80};
- unsigned char j=0;
- unsigned int k;
- BYTE ch =0x01;
- sbit q35=P3^5;
- sbit q36=P3^6;
- sbit q34=P3^7;
- sbit q37=P3^4;
- sbit anjian2=P1^7;
- sbit anjian3=P1^6;
- bit flag=0;
- bit flag1;
- void Delay(WORD n)
- {
- WORD x;
- while (n--)
- {
- x = 5000;
- while (x--);
- }
- }
- void adc_isr() interrupt 5 using 1
- {
- ADC_CONTR &= !0x10;
- num=ADC_RES;
- num=num<<2|ADC_LOW2;
- ADC_CONTR = 0x80 | 0x00 | 0x08 | ch;
- }
- void InitADC()
- {
- P1ASF = 0x03;
- ADC_RES = 0;
- ADC_CONTR = 0x80 | 0x00 | 0x08 | ch;
- Delay(2);
- }
- void DigDisplay(unsigned char n, unsigned char number)
- {
- GPIO_PLACE = DIG_PLACE[n];
- GPIO_DIG = DIG_CODE[number];
- for(n=10;n--;n>0);
- GPIO_DIG = 0x00;
- }
- void main()
- {
- q34=0;
- q36=0;
- q37=1;
- q35=1;
-
- P0M1 = 0x00;
- P0M0 = 0xFF;
- P2M1 = 0x00;
- P2M0 = 0xff;
- InitADC();
- IE = 0xa0;
- AUXR |= 0x80;
- TMOD = 0x00;
- TR0 = 1;
- while (1)
- {
- uu=xue/shu;
- if(!anjian2)
- {
- Delay(10);
- if(!anjian2)
- {
- shu--;
- if(shu<=1)
- {
- shu =1;
- }
-
- }
- }
- if(!anjian3)
- {
- Delay(10);
- if(!anjian3)
- {
- shu++;
- if(shu>=99)
- {
- shu=99;
- }
- }
- }
- EA=1;
- ET1=1;
- TR1=1;
- TMOD=0x10;
- vin=num*5.0/1024;
- ooo=(int)(vin*10);
- ge=ooo%10;
- shi=ooo/10%10;
- bai=shu%10;
- qian=shu/10%10;
- DigDisplay(3,shi);
- DigDisplay(2,ge);
- DigDisplay(1,qian);
- DigDisplay(0,bai);
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
全部资料51hei下载地址:
STC15F2k60s.doc
(19.5 KB, 下载次数: 35)
|