编程语言有哪些
常见的计算机编程语言有:
编程语言一、C语言
编程语言二、java
编程语言三、c++
编程语言四、php
编程语言五、c#
求51单片机C语言程序编程思路
#include 《AT89X51.H》
//假定继电器是安装在P3.5,按键分别安装在P3.6, P3.7,时钟频率12MHz
sbit sw1=P3^6;
sbit sw2=P3^7;
sbit relay=P3^5;
void SetupTimer0()
{
TMOD &= 0XF0; //仅保留T1信息
TMOD |= 0X02; //设置T0: 定时功能,方式2,自动重载8位定时器/计数器
TH0 = 256-250;//定时每0.25ms中断一次
TL0 = 256-250;
TR0 = 1; //开启定时器
ET0 = 1; //定时器0中断打开
}
data unsigned char us250;
data unsigned int relay_timer;
void Timer0_ISR() interrupt 1 //定时中断服务程序,为按键消抖服务
{
//如果一个动作过程刚刚开始,则设定继电器延时3000ms,并打开继电器
if (0==relay_timer && 0==sw1) {relay_timer=3000; relay=1;}
if (++us250》=4) //250us中断一次,每四次得到1ms
{
us250=0;
if(relay_timer==0) relay=0; //如继电器延时为0,则关继电器
else --relay_timer; //否则继电器延时递减
}
//如果当前正处于一个动作过程且有sw2按下,则修改继电器延时为1000ms
if (relay_timer && 0==sw2) relay_timer=1000;
}
void main()
{
us250=0;
relay_timer=0;
relay=0;
SetupTimer0();
EA = 1; //全局中断打开
while(1); //所有的动作均在中断函数内完成
}
单片机C语言编程
KEY4 EQU 30H
KEY2 EQU 31H
ORG 0000H
LJMP MAIN
ORG 0030H
MAIN:
CLR EA
MOV SP,#5FH
MOV KEY2,#0
MOV KEY4,#0
LOOP:
JB P1.0,LOOP
MOV R7,#10
LCALL DELAY
JB P1.0,LOOP
JNB P1.0,$
MOV P3,#0C0H
LOOP0:
LCALL KEYDEAL
MOV A,KEY4
JNZ LOOP41
MOV A,P3
ANL A,#0F0H
ORL A,#0EH
MOV P3,A
SJMP LOOP21
LOOP41:
DEC A
JNZ LOOP42
MOV A,P3
ANL A,#0F0H
ORL A,#0DH
MOV P3,A
SJMP LOOP21
LOOP42:
DEC A
JNZ LOOP43
MOV A,P3
ANL A,#0F0H
ORL A,#0BH
MOV P3,A
SJMP LOOP21
LOOP43:
DEC A
JNZ LOOP21
MOV A,P3
ANL A,#0F0H
ORL A,#07H
MOV P3,A
LOOP21:
MOV A,KEY2
JNZ LOOP22
MOV A,P3
ANL A,#0FH
ORL A,#20H
MOV P3,A
SJMP LOOP3
LOOP22:
DEC A
JNZ LOOP3
MOV A,P3
ANL A,#0FH
ORL A,#10H
MOV P3,A
LOOP3:
LJMP LOOP0
;----------------------------
DELAY:
MOV R2,#2
DLY1:
MOV R3,#250
DJNZ R3,$
DJNZ R2,DLY1
DJNZ R7,DELAY
RET
;-----------------------------
KEYDEAL:
JB P1.1,KEYEN1
MOV R7,#10
LCALL DELAY
JB P1.1,KEYEN1
JNB P1.1,$
INC KEY4
MOV A,KEY4
ANL A,#03H
MOV KEY4,A
KEYEN1:
JB P1.2,KEYEN2
MOV R7,#10
LCALL DELAY
JB P1.2,KEYEN2
JNB P1.2,$
INC KEY2
MOV A,KEY2
ANL A,#01H
MOV KEY2,A
KEYEN2:
RET
;-----------------------------
END