#include
#define uchar unsigned char
#define uint unsigned int
unsigned char dspbuf[] = {16,16,16,16,16,16,16,16};
code unsigned char tab[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff,~0x40};
float fosc=12000000;
uchar qian,bai,shi,ge;
uchar dspcom = 0;
bit k1=0;
***it key1=P3^1;
***it key2=P3^2;
***it key3=P3^3;
***it OUT=P1^6;
***it OUT1=P1^7;
void seg_display();
void display(uchar X);
uchar zkb;
uint freq;
uchar tiMER0_L,TIMER0_H,TIMER1_L,TIMER1_H; //定时器0和1的定时初值;
void Delay10ms() //@12.000MHz
{
unsigned char i, j;
i = 117;
j = 184;
do
{
while (--j);
} while (--i);
}
void seg_display()
{
P2 = 0xe0;
P0 = 0xff; //消隐
P2= 0x00;
P2 = 0xc0;
P0 = 1 << dspcom;
P2 = 0x00;
P2 = 0xe0;
P0 = tab[dspbuf[dspcom]];
P2 = 0x00;
if (++dspcom == 8)
dspcom = 0;
}
void display(uchar X)
{
bai=X/100;
shi=X%100/10;
ge=X%10;
dspbuf[0]=bai;
dspbuf[1]=shi;
dspbuf[2]=ge;
}
void init()
{
freq=50; //频率
zkb=50; //占空比
TIMER0_L=0xE0;
TIMER0_H=0XB1;
TIMER1_L=0XF0;
TIMER1_H=0XD8;
TL0=0XE0;
TH1=0XD8;
TMOD=0X11;
IT0=1;
EX0=1;
ET0=1;
ET1=1;
EA=1;
TR0=1;
TR1=1;
}
void main()
{
init();
seg_display();
while(1)
{
if(k1==1)
{
display(freq);
k1=0;
}
}
}
void Timer0_freq() interrupt 1
{
TR1=1;
TL0=TIMER0_L;
TH0=TIMER0_H;
OUT=1;
OUT1=1;
}
void Timer1_zkb() interrupt 3
{
TR1=0;
TL1=TIMER1_L;
TH1=TIMER1_H;
OUT=0;
OUT1=0;
}
void keyscan() interrupt 0 using 1
{
float TF0,TZ1;
EX0=0;
if(key1==0)
{
Delay10ms();
if(key1==0)
{
while(!key1);
freq+=100;
if(freq>500) freq=50;
k1=1;
}
}
if(key2==0)
{
Delay10ms();
if(key2==0)
{
while(!key2);
zkb++;
if(zkb>100) zkb=1;
}
}
if(key3==0)
{
Delay10ms();
if(key3==0)
{
while(!key3);
zkb--;
if(zkb<1) zkb=50;
}
}
TF0=(65536-fosc/(12.0*freq));
TZ1=(65536-(fosc*zkb)/(12.0*100*freq));
TIMER0_H=(uint)TF0/256;
TIMER0_L=(uint)TF0%256;
TIMER1_H=(uint)TZ1/256;
TIMER1_L=(uint)TZ1%256;
EX0=1;
TR0=1;
TR1=1;
}
在这个程序里我实现了两路输出波形,但是最后 数码管上显示频率出问题了, 数码管上什么也没有,而且我按键加频率,频率也没反应。请问大佬,这是什么原因?
0
|
|
|
|