单片机方波幅度调节c语言,为什么我用单片机做的频率可调的方波输出会有尖刺,而且会断...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include"reg52.h"

#define uchar unsigned char

#define uint unsigned int

sbit U5_C = P3^6;

sbit U6_C = P3^7;

sbit beep = P3^4;

sbit K1 = P3^2;

sbit K2 = P3^3;

sbit JS = P3^5;

sbit sc = P3^5;

uchar shuju;

uchar ten;

uchar code duan[18] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff,0xbf};

uint code dshi[99]={50000,25000,16667,12500,10000,8333,7143,6250,5556,5000,4545,4167,3846,3571,3333,3125,2941,2778,2632,2500,2381,2273,2174,2083,2000,1923,1852,1786,1724,1667,1613,1563,1515,1471,1429,1389,1351,1316,1282,1250,1220,1190,1163,1136,1111,1087,1064,1042,1020,1000,980,961,943,926,909,893,877,862,848,834,820,806,794,782,769,758,747,736,725,715,704,695,685,676,667,658,650,641,633,625,618,610,603,595,};

uchar disp_sbuf[8];

void key1();

void key2();

void display();

void disp_drv();

void intion();

void delay(unsigned int i)

{

unsigned int m,n;

for (m = i;m > 0;m--)

for(n = 90;n > 0;n--);

}

void main()

{

intion();

while(1)

{

key1();

key2();

disp_drv();

display();

}

}

void key1()

{

if(K1==0)

{

delay(20);

if(K1==0)

{

while(!K1)

{

beep = 0;

disp_drv();

display();

}

beep = 1;

shuju++;

if (shuju > 99)

shuju = 1;

}

}

}

void key2()

{

if(K2==0)

{

delay(20);

if(K2==0)

{

while(!K2)

{

beep = 0;

disp_drv();

display();

}

beep = 1;

shuju--;

if(shuju < 1)

shuju = 99;

}

}

}

void disp_drv()

{

uchar i,wei = 0x80;

for(i = 0;i < 8;i++)

{

P0 = duan[disp_sbuf[i]];

U5_C = 1;

U5_C = 0;

P2 = wei;

U6_C = 1;

U6_C = 0;

delay(1);

wei = wei >> 1;

}

}

void display()

{

disp_sbuf[7] = shuju/10;

disp_sbuf[6] = shuju%10;

disp_sbuf[5] = 17;

disp_sbuf[4] = 17;

disp_sbuf[3] = 17;

disp_sbuf[2] = 17;

disp_sbuf[1] = shuju/10;

disp_sbuf[0] = shuju%10;

}

void intion()

{

TMOD = 0x01;

TH0 = (65536-10000) / 256;

TL0 = (65536-10000) % 256;

TR0 = 1;

ET0 = 1;

EA = 1;

}

void time0() interrupt 1

{

TH0 = (65536-dshi[shuju]) / 256;

TL0 = (65536-dshi[shuju]) % 256;

if(ten++>10)

{

ten=0;

sc=!sc;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值