㈠ 向51单片机里写发出脉冲信号的c程序怎么编啊
//用ADC0808控制PWM输出
//通过可变电阻调节脉冲宽度
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit CLK =P2^4;
sbit ST=P2^5;
sbit EOC=P2^6;
sbit OE=P2^7;
sbit PWM=P3^0;
//延时
void Delay(uchar x)
{
uchar i;
while(x--)
for(i=0;i<40;i++);
}
void main()
{
uchar Val;
TMOD=0x02;//定时器T0工作于方式2自动重装8位计数器
TH0=0x14;
TL0=0x00;
IE=0x82; //允许T0中断
TR0=1; //启动定时器
while(1)
{
ST=0;ST=1;ST=0; //启动A/D转换
while(!EOC); //等待转换完成
OE=1;
Val=P1; //读取转换结果
OE=0;
if(Val==0) //PWM输出占空比为0
{
PWM=0;
Delay(0xff);
continue;}
if(Val==0xFF) // PWM输出占空比为100%
{
PWM=1;
Delay(0xff);
continue;
}
PWM=1;
Delay(Val); //PWM输出占空比
PWM=0;
Delay(0xff-Val);
}
}
//--------------------------------
//T0定时器中断给ADC0808提供时钟信号
//---------------------------------
void Timer0_INT() interrupt 1
{
CLK=!CLK; //ADC0808时钟
}
能看明白吗?我也是刚学的,照书上写的
㈡ 如何用c语言实现3秒的脉冲
输出高电平,延时(脉宽),输出
低电平
,延时至三秒(周期).
重复上述步骤.
㈢ 求一个用51单片机C语言写出脉冲信号
去买本单片机编程的书看看,这种基本的程序,上边都有
㈣ 如何编程实现51单片机每隔 t 时间发出一个脉冲求C语言详细编程。。。
给你个基本框架,根据你的具体要求再修改吧。使用定时1中断实现,精度比较高。
#include <reg52.h>
#define PERIODH (65536l-10000l)/0X100 //设10ms中断1次TH1初值
#define PERIODL (65536l-10000l)%0X100 //设10ms中断1次TL1初值
sbit P1_1 = 0x91; //假设从P1.1输出脉冲
unsigned int iCount; //延时间隔时间变量
unsigned int iPulseCount; //脉冲脉宽时间变量
void timer1() interrupt 3 using 1
{//定时器每0.01秒一次中断
TH1 = PERIODH;
TL1 = PERIODL;
if(iCount)
{//计数未到0,计数器-1
iCount--;
}
if(iPulseCount)
{//计数未到0,计数器-1
iPulseCount--;
}
}
main()
{
TMOD = 0X10;//方式1
EA = 1;//总中断允许
ET1 = 1;//定时器1中断允许
TR1 = 1;//启动定时器1
P1_1 = 0; //脉冲输出端口,假设输出正脉冲,预置为低电平
while(1)
{
iCount = 200;//每间隔200*10ms = 2秒一个脉冲,t值变化改此处
while(iCount);//等待2秒中
P1_1 = 1; //置为高电平,输出正脉冲
iPulseCount = 10;//每间隔10*10ms = 100ms一个脉冲,脉宽变化改此处
while(iPulseCount);//高电平保持100ms
P1_1 = 0; //置为低电平,输出正脉冲结束
}
}
㈤ 求一个用51单片机来编写发脉冲信号的c语言程序,带注译,新手
给引脚1、和0 就是脉冲,,,,,,时间就是由需求决定
——————————————————
㈥ 如何写一个单片机输入上升沿和下降沿的脉冲输出信号的c语言程序
这个简单,从低到高就是上升输出,重高到低就是下降输出
#include<reg51.h>
sbit pluse=P1^0;
main()
{
int i;
while(1)
{
pluse=0; //此时为下降输出
i=100;
while(i--);
pluse=1; //此时为上升输出
i=100;
while(i--);
}
}
㈦ c语言编写单片机计数脉冲
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uint times,freq;
sbit p35=P3^5;
main()
{
TMOD=0x01;
TH0=0;
TL0=0;
while(1)
{
while(p35);
TR0=1;
while(!p35);
while(p35);
TR0=0;
times=TH0*256+TL0;
freq=1000000/times;
//处理频率,自己做
}
}
㈧ C语言里用什么语句实现脉冲
随便你输入那一天都能算星期几
#include<time.h>
#include<stdio.h>
#include<conio.h>
#include<stddef.h>
#define BIG 1
#define SMALL 2
void info()
{
textcolor(RED);
gotoxy(37,11);
puts("WEEKDAY");
}
int runyear(int year) /*判断是否为闰年*/
{
return !(year%4)&&year%100||!(year%400);
}
void main()
{
int year,month,day,yeardata,monthdata;
char *weekday;
time_t lt;
struct tm *ptr;
lt=time(NULL);
do
{
clrscr();
info();
gotoxy(18,15);
printf("Please Input The Year: ");
scanf("%d",&year);
}while(year<0||year>9999);
yeardata=runyear(year);
do
{
clrscr();
info();
gotoxy(18,15);
printf("Please Input The Month:");
scanf("%d",&month);
}while(month<1||month>12);
switch(month) /*大小月,2月*/
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: monthdata=BIG; break;
case 4:
case 6:
case 9:
case 11: monthdata=SMALL; break;
case 2: monthdata=3; break;
}
l1:
clrscr();
info();
gotoxy(18,15);
printf("Please Input The Day:");
scanf("%d",&day);
if(monthdata==BIG)/*大月*/
{
if(day<1||day>31)
goto l1;
}
if(monthdata==SMALL)/*小月*/
{
if(day<1||day>30)
goto l1;
}
if(yeardata==0&&monthdata==3)/*平年2月*/
{
if(day<1||day>28)
goto l1;
}
if(yeardata==1&&monthdata==3)/*闰年2月*/
{
if(day<1||day>29)
goto l1;
}
ptr=localtime(lt);
weekday=asctime(ptr);
ptr->tm_mday=day;
ptr->tm_mon=month;
ptr->tm_year=year;
weekday=asctime(ptr);
clrscr();
gotoxy(13,30);
puts(weekday);
}
㈨ c语言脉冲发生器
你说的是单片机C编程吧,不知道你要的脉冲频分是多少,也不知道你用的是哪种单片机,只能给你个思路.
while(1)
{
定时1;
输出高电平信号;
定时2;
输出低电平信号;
}
定时1和定时2要自己控制,可用单片机的定时器做,也可以用循环做.
㈩ 用C语言或汇编实现PWM(产生1K,2K...10K脉冲)
可以采用带PWM的单片机或者用定时。