您的位置:

控制系统c语言,c语言控制plc

本文目录一览:

操作系统的课程设计~进程控制系统~用C语言编写的

补充:

这个程序当然可以在WINDOWS下编辑了.

不过编译就必须要UNIX了.

下面的程序假设你的当前目录有一个helloworld程序,

这个你会写吧?

:)

#include

stdio.h

#include

unistd.h

#include

sys/wait.h

int

main()

{

int

pid;

int

status;

pid

=

fork();

if

(pid

==

0)

{

/*

child

process

*/

execve("./helloworld",

NULL,

NULL);

}

else

if

(pid

0)

{

/*

failed

to

fork,

print

error

message

*/

printf("fork

error,

errno

=

%d\n",

errno);

}

else

{

waitpid(pid,status,0)

}

return

0;

}

基于单片机的作息时间控制系统C语言程序

#includereg52.h

#define uchar unsigned char

#define uintunsigned int

sbit E=P3^4;

sbit RS=P3^5;

sbit key1=P2^4;

sbit key2=P2^5;

sbit key3=P2^6;

sbit key4=P2^7;

sbit mbkey=P2^2;

sbit beep=P2^3;

uchar count,shi=1,fen=59,miao=58,key1num,flag,flag1,xqnum;//flag闹钟

uchar key2num,jinzhi=3,naonum=1,ms,mbmiao,mbfen,mbkeynum,num; //ms秒表进数,mbmiao.mbfen秒表的秒.分key2num是key5的计数jinzhi进制转换参数

uint nian=2009,yue=11,ri=19,count2;

uchar code table[]="2012-6-06 WED";

uchar code table1[]="24d 01:59:58 ON ";

uchar code table2[]="MON,TUE,WED,THU,FRI,SAT,SUN";

uchar code table3[]="am ,pm ,24d";

uchar code table4[]="ON ,OFF";

uchar code table5[]="00:00:00 mb ";

void delay(uint z)

{

uint x,y;

for(x=z;x0;x--)

for(y=110;y0;y--);

}

void di(uint x)//蜂鸣器发声函数

{

beep=0;

delay(x);

beep=1;

}

void write_com(uchar com)//给写液晶命令

{

RS=0;

P0=com;

delay(5);

E=1;

delay(5);

E=0;

}

void write_date(uchar date)//给液晶写数据

{

RS=1;

P0=date;

delay(5);

E=1;

delay(5);

E=0;

}

void init()//初始化函数

{

uchar num;

E=0;

write_com(0x38);

write_com(0x0c);

write_com(0x06);

write_com(0x01);//清零

write_com(0x80);

for(num=0;num16;num++)

{

write_date(table[num]);

delay(20);

}

write_com(0x80+0x40);//第二行

for(num=0;num16;num++)

{

write_date(table1[num]);

delay(20);

}

TMOD=0X01;

TH0=(65536-50000)/256;

TL0=(65536-50000)%256;

EA=1;

ET0=1;

TR0=1;

TH1=(65536-10000)/256;

TL1=(65536-10000)%256;

ET1=0;

TR1=0;

}

void write_nian(uchar add , uint date)//年显示函数

{

uchar qian,bai,shi,ge;

qian=date/1000;

bai=(date-1000*qian)/100;

shi=(date-qian*1000-bai*100)/10;

ge=date%10;

write_com(0x80+add);

write_date(0x30+qian);

write_date(0x30+bai);

write_date(0x30+shi);

write_date(0x30+ge);

}

void write_yue(uchar add , uchar date)//月显示函数

{

uchar shi,ge;

shi=date/10;

ge=date%10;

write_com(0x80+add);

write_date(0x30+shi);

write_date(0x30+ge);

}

void write_ri(uchar add , uchar date)//日显示函数

{

uchar shi,ge;

shi=date/10;

ge=date%10;

write_com(0x80+add);

write_date(0x30+shi);

write_date(0x30+ge);

}

void write_sfm(uchar add ,uchar date)//秒显示函数

{

uchar shi,ge;

shi=date/10;

ge=date%10;

write_com(0x80+0x40+add);

write_date(0x30+shi);

write_date(0x30+ge);

}

void write_week(uchar week)//星期显示函数

{

uchar week_num;

week_num=week;

switch(week_num)

{

case 1:write_com(0x80+13);

write_date(table2[0]);

write_date(table2[1]);

write_date(table2[2]);

write_com(0x80+13);

break;

case 2:write_com(0x80+13);

write_date(table2[4]);

write_date(table2[5]);

write_date(table2[6]);

write_com(0x80+13);

break;

case 3:write_com(0x80+13);

write_date(table2[8]);

write_date(table2[9]);

write_date(table2[10]);

write_com(0x80+13);

break;

case 4:write_com(0x80+13);

write_date(table2[12]);

write_date(table2[13]);

write_date(table2[14]);

write_com(0x80+13);

break;

case 5:write_com(0x80+13);

write_date(table2[16]);

write_date(table2[17]);

write_date(table2[18]);

write_com(0x80+13);

break;

case 6:write_com(0x80+13);

write_date(table2[20]);

write_date(table2[21]);

write_date(table2[22]);

write_com(0x80+13);

break;

case 7:write_com(0x80+13);

write_date(table2[24]);

write_date(table2[25]);

write_date(table2[26]);

write_com(0x80+13);

break;

}

}

void write_jinzhi(uchar jinzhi)//jinzhi进制显示函数

{

uchar jznum;

jznum=jinzhi;

switch(jznum)

{

case 1:write_com(0x80+0x40+0);

write_date(table3[0]);

write_date(table3[1]);

write_date(table3[2]);

write_com(0x80+0x40+0);

break;

case 2:write_com(0x80+0x40+0);

write_date(table3[4]);

write_date(table3[5]);

write_date(table3[6]);

write_com(0x80+0x40+0);

break;

case 3:write_com(0x80+0x40+0);

write_date(table3[8]);

write_date(table3[9]);

write_date(table3[10]);

write_com(0x80+0x40+0);

break;

}

}

void write_nao(uchar nao)//闹钟开关显示函数

{

uchar naonum;

naonum=nao;

switch(naonum)

{

case 1:write_com(0x80+0x40+13);

write_date(table4[0]);

write_date(table4[1]);

write_date(table4[2]);

write_com(0x80+0x40+13);

break;

case 2:write_com(0x80+0x40+13);

write_date(table4[4]);

write_date(table4[5]);

write_date(table4[6]);

write_com(0x80+0x40+13);

break;

}

}

void keyboard()//按键扫描函数

{

if(flag==1)

{

//闹钟暂停函数

if(key4==0)

{

delay(5);

if(key4==0)

{

while(!key4);

beep=1;

flag=0;

}

}

}

if(key1==0)

{

delay(5);//消斗

if(key1==0)

{

key1num++;

while(!key1);

//di(1);

if(key1num==1)

{

TR0=0;

write_com(0x80+0x40+10);

write_com(0x0f);//光标闪烁

}

if(key1num==2)

{

write_com(0x80+0x40+7);

}

if(key1num==3)

{

write_com(0x80+0x40+4);

}

if(key1num==4)

{

write_com(0x80+0x40);

}

if(key1num==5)

{

write_com(0x80+2);

}

if(key1num==6)

{

write_com(0x80+7);

}

if(key1num==7)

{

write_com(0x80+10);

}

if(key1num==8)

{

write_com(0x80+13);

}

if(key1num==9)

{

write_com(0x80+0x40+13);

}

if(key1num==10)

{

key1num=0;

write_com(0x0c);//光标停止闪烁

TR0=1;//打开定时器

}

}

}

if(key1num!=0)

{

if(key2==0)

{

delay(5);

if(key2==0)

{

while(!key2);//等待松手

di(100);

if(key1num==1)

{

miao++;

if(miao==60)

miao=0;

write_sfm(10,miao);

write_com(0x80+0x40+10);

}

if(key1num==2)

{

fen++;

if(fen==60)

fen=0;

write_sfm(7,fen);

write_com(0x80+0x40+7);

}

if(key1num==3)

{

shi++;

if(jinzhi==3)

{

if(shi==24)

shi=0;

}

else

{

if(shi12)

shi=shi-12;

}

write_sfm(4,shi);

write_com(0x80+0x40+4);

}

if(key1num==4)

{

jinzhi++;

if(jinzhi==4)

jinzhi=1;

write_jinzhi(jinzhi);

}

if(key1num==5)

{

nian++;

write_nian(2,nian);

write_com(0x80+2);

}

if(key1num==6)

{

yue++;

if(yue==13)

yue=1;

write_yue(7,yue);

write_com(0x80+7);

}

if(key1num==7)

{

ri++;

if(ri==32)

ri=1;

write_ri(10,ri);

write_com(0x80+10);

}

if(key1num==8)

{

xqnum++;

if(xqnum==8)

xqnum=1;

write_week(xqnum);

}

if(key1num==9)

{

naonum++;

if(naonum==3)

naonum=1;

write_nao(naonum);

}

if(key1num==10)

{

key1num=0;

write_com(0x0c);//光标停止闪烁

TR0=1;//打开定时器

}

}

}

if(key3==0)

{

delay(5);

if(key3==0)

{

while(!key3);

di(100);

if(key1num==1)

{

miao--;

if(miao==-1)

miao=59;

write_sfm(10,miao);

write_com(0x80+0x40+10);

}

if(key1num==2)

{

fen--;

if(fen==-1)

fen=59;

write_sfm(7,fen);

write_com(0x80+0x40+7);

}

if(key1num==3)

{

shi--;

/*if(shi==-1)

shi=23;*/

if(jinzhi==3)

{

if(shi==-1)

shi=23;

}

else

{

if(shi1)

shi=shi+12;

}

write_sfm(4,shi);

write_com(0x80+0x40+4);

}

if(key1num==4)

{

jinzhi--;

if(jinzhi==0)

jinzhi=3;

write_jinzhi(jinzhi);

}

if(key1num==5)

{

nian--;

write_nian(2,nian);

write_com(0x80+4);

}

if(key1num==6)

{

yue--;

if(yue==0)

yue=12;

write_yue(7,yue);

write_com(0x80+7);

}

if(key1num==7)

{

ri--;

if(ri==0)

ri=31;

write_ri(10,ri);

write_com(0x80+13);

/*if(key1num==8)

{

xqnum--;

if(xqnum==0)

xqnum=7;

write_week(xqnum);

write_com(0x80+10);

}

if(key1num==9)

{

naonum--;

if(naonum==0)

naonum=2;

write_nao(naonum);

write_com(0x80+0X40+13);

}

*/

}

}

}

}

}

void mbiao( )//秒表函数

{

if(mbkey==0)

{

mbkeynum++;

while(!mbkey);

if(mbkeynum==1)//关闭时钟定时器

{

TR0=0;

ET0=0;

write_com(0x80+0x40);

for(num=0;num16;num++)

write_date(table5[num]);

ms=0;

mbmiao=0;

mbfen=0;

TR1=0;

ET1=0;

}

if(mbkeynum==2)//打开秒表定时器关闭时钟定时器

{

TR1=1;

ET1=1;

TR0=0;

ET0=0;

}

if(mbkeynum==3)//关闭秒表定时器

{

TR1=0;

ET1=0;

TR0=0;

ET0=0;

}

if(mbkeynum==4)//显示时钟状态打开时钟定时器

{

TR0=1;

ET0=1;

TR1=0;

ET1=0;

write_sfm(10,miao);

write_sfm(7,fen);

write_sfm(4,shi);

write_jinzhi(jinzhi);

write_com(0x80+0x40+13);

write_date(' ');

write_date('O');

write_date('N');

mbkeynum=0;

}

}

}

void main()

{

init();

while(1)

{

keyboard();

mbiao();

if(count==20)//液晶变化

{

count=0;

miao++;

if(miao==60)

{

miao=0;

fen++;

if(fen==60)

{

fen=0;

shi++;

if(jinzhi==3)//24进制时钟

{

if(shi==24)

shi=0;

}

else

{

if(shi12)//12进制时钟

{

shi=shi-12;

jinzhi++;

if(jinzhi==3)

jinzhi=1;

}

}

write_sfm(4,shi);

write_jinzhi(jinzhi);

}

write_sfm(7,fen);

}

write_sfm(10,miao);

if(miao==0fen==0shi==0||(jinzhi==2shi==12fen==0miao==0))//日期和星期递变

{

write_com(0x80+9);

ri++;

if(ri==32)

{

ri=1;

yue++;

if(yue==13)

{

yue=1;

nian++;

write_nian(2,nian);

}

write_yue(7,yue);

}

write_ri(10,ri);

xqnum++;

write_week(xqnum);

}

if(fen==0miao=0miao=5)//整点报时

{

flag=1;

beep=~beep;

}

if(naonum==1shi==07fen==15miao=0miao=5)//闹钟

{

flag=1;

beep=~beep;

}

}

}

}

void timer0() interrupt 1//时钟定时器

{

TH0=(65536-50000)/256;

TL0=(65536-50000)%256;

count++;

}

void timer1() interrupt 3//秒表定时器

{

TH1=(65536100000)/256;

TL1=(65536100000)%256;

ms++;

write_sfm(10,ms);

if(ms==1*30)

{

mbmiao++;

write_sfm(7,mbmiao);

ms=0;

if(mbmiao==60)

{

mbmiao=0;

mbfen++;

write_sfm(4,mbfen);

}

}

}

关于单片机温度控制系统C语言程序中的按键设置程序,请求详细的介绍下按键的输入过程。while(1) { if(KeyFl

keyflag应该是判断某个按键按了几次,不安的时候为0

if(KeyFlag == 0)

{

}

按一次时执行

else if(KeyFlag == 1)

{

if(BUTTON_add == 0 KeyLock ==0)

{

}

if(BUTTON_reduce == 0 KeyLock ==0)

{

}

按二次时执行

else if(KeyFlag == 2){

if(BUTTON_add == 0 KeyLock ==0)

{

}

if(BUTTON_reduce == 0 KeyLock ==0)

{

}

一楼正解,主要按键扩展标志是用来节省资源的,用最少的按键实现最多的功能!

求电梯控制c语言程序,电梯控制系统c语言程序

本文目录一览: 1、用C语言如何描述电梯的运行机制? 2、c语言设定电梯程序 3、求电梯控制c语言程序 4、C语言一道编程题,关于电梯调度运行的。 5、关于电梯的C语言应用题求解答 6、用C语言编写一

2023-12-08
求电梯控制c语言程序,电梯控制系统c语言程序

本文目录一览: 1、用C语言如何描述电梯的运行机制? 2、c语言设定电梯程序 3、求电梯控制c语言程序 4、C语言一道编程题,关于电梯调度运行的。 5、关于电梯的C语言应用题求解答 6、用C语言编写一

2023-12-08
c语言编辑电梯,c语言电梯控制系统

2023-01-04
plc怎么用c语言,plc用c语言吗

2022-11-29
plc还c语言厉害,plc需要用到c语言吗

2022-11-27
控制系统c语言,c语言控制plc

2023-01-04
工业工程与c语言的联系,c语言在工业控制中的应用

2022-11-22
plc向c语言晋升,plc 高级语言

2023-01-04
c语言控制伺服,伺服控制工作原理

2023-01-03
c语言编辑plc,c语言编辑器有哪些

2023-01-04
c语言界面控制,c语言 控制台

2023-01-08
下垂控制c语言,c语言怎么控制移动

2023-01-04
c语言电气图纸,电气图中C

2022-11-26
c语言控制结构知识点,c语言程序控制结构

2023-01-06
c语言控制延时,C语言延时语句

2023-01-04
声卡c语言控制,声控灯c语言程序

2022-11-24
scl与c语言,scl和c语言

2023-01-07
c语言笔记讲解,c语言程序笔记

2022-11-23
c语言知识笔记,c语言最全笔记

2023-01-04
控制流c语言,C语言流是什么

2023-01-04