㈠ 向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的單片機或者用定時。