各位大佬好,目前我需要实现的功能是通过51单片机对方波脉冲进行计数这是方波的发生电路:
这是产生的波形,方波峰值分别为-0.68V和3.24V:
这是单片机连接图,这里我选择P3.4/T0口作为输入方波的端口:
但当我把方波产生电路的输出端和单片机连接时,输出端的电平会被单片机拉高并且保持在3.38V左右:
这种情况下方波电路似乎就失效了,我不太明白为什么会导致这种结果,希望各位大佬能够帮我解答疑惑,谢谢。
代码如下,由于电压问题未解决,代码还没有完善:
/*************** writer:shopping.w ******************/
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
#define DATA P1
sbit OE = P2^5;
sbit EOC = P3^3;
sbit ST = P2^7;
sbit C1 = P3^0;
sbit C2 = P3^1;
sbit C3 = P3^2;
sbit OUT1 = P3^7;
sbit IN1 = P3^4;
uint display_data = 0; /*显示数据*/
uchar code LEDData[]=
{
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
};
uint count = 1;
//void T0Init()
//{
// TMOD=0x05;
// TH0=0XFF;
// TL0=0xFD;
// EA=1;
// ET0=1;
// TR0=1;
//}
void DelayMS(uint ms)
{
uchar i;
while(ms--)
{
for(i=0;i<120;i++);
}
}
void Display_Result(uint d)
{
P2 = 0xf7;
P0 = LEDData[d%10];
DelayMS(5);
P2 = 0xfb;
P0 = LEDData[d%100/10];
DelayMS(5);
P2 = 0xfd;
P0 = (LEDData[d/100]| 0x80);
DelayMS(5);
P2 = 0xfe;
P0 = LEDData[0];
DelayMS(5);
}
void main()
{
// T0Init();
C1 = 1;
C2 = 1;
C3 = 0;
OUT1 = 0;
IN1=1;
while(1)
{
OUT1 = ~OUT1;
ST = 0;
ST = 1;
ST = 0;
while(EOC == 0);
OE = 1;
display_data = ((5.0/255) * DATA) * 100;
//Display_Result(display_data);
Display_Result(count);
OE = 0;
//count = count+1;
}
}
//void T0_time() interrupt 1
//{
// count = count+1;
// TH0 = 0XFF;
// TL0 = 0XFD;
//}
|