找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

新手求助,万谢!

[复制链接]
admin 发表于 2012-9-2 09:17:49 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
我用c写了一个程序,主要是从别人的程序借鉴,
但就是显示不了我每次输入的pwm占空比的转速,因为是期末的项目,焦急啊~
这是我的程序:
#include<reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit DAT_595_PIN = P0^2;
sbit SCK_595_PIN = P0^0;
sbit RCK_595_PIN = P0^1;
sbit S_out = P2^0;
uchar code num_buf[10]= {0xf5,0x05,0xb3,0x97,0x47,0xd6,0xf6,0x85,0xf7,0xd7};
uchar code bit_buf[4] = {0xfd,0xfb,0xf7,0xfe};
uchar data dis_buf[4] = {1,2,3,4};
uint C_2ms;
uchar C_pwmH,C_pwmL;
uint C_speed,m,n,t;
bit F_deal,sta;
void Timer0_int(void) interrupt 1
{
++t;
if(t==50)
S_out=0;
if(t==100)
{
t=0;
S_out=1;
}
}
void display(void)
{
uchar i,j;uint dat;
for(i=0;i<4;i++)
{
RCK_595_PIN=0;
dat =bit_buf;
dat =dat<<8;
dat |= num_buf[dis_buf];

for(j=0;j<16;j++)
{
SCK_595_PIN = 0;
if(dat & 0x8000){ DAT_595_PIN = 1;}
else{ DAT_595_PIN = 0;}
dat=dat<<1;
SCK_595_PIN = 1;
}
RCK_595_PIN = 1;
}
}
speed_deal(void) interrupt 0
{
uint tmp,k,sum;
m++;
if(m==20)
{
TR1=0;
TL1=256-92;
TH1=256-92;
TR1=1;
C_speed=(uint)(6*1000000/n);
sum+=C_speed;
m=0;
n=0;
k++;
if(k==4)
{
C_speed=sum/4;
sum=0;
k=0;
tmp = C_speed;
dis_buf[0]=tmp/1000;
tmp%=1000;
dis_buf[1]=tmp/100;
tmp%=100;
dis_buf[2]=tmp/10;
dis_buf[3]=tmp%10;
}
}
}
Time() interrupt 3 using 1
{
n++;
}
void main(void)
{
TH0=256-92;TL0=256-92;TH1=256-92,TL1=256-92;TMOD=0x22;ET0=1;ET1=1;EX0=1;EA=1;
TR0=1;TR1=1;
while(1)
{
display();
}
}
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-24 12:36 , Processed in 0.056984 second(s), 10 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表