|
////////////////////////////////////////
汇编程序
////////////////////////////////////////
/***********************************************************************/
/***名称:全彩LED灯珠颜色跳变 *****************************************/
/***功能:红色,(橙色黄色),绿色,青色,蓝色,紫色,白色,红色 循环显示间隔1S */
/***********************************************************************/
/*---------------------------------------------------------------------*/
/*-- 端口定义 ---------------------------------------*/
/*---------------------------------------------------------------------*/
PORT_2 EQU P2
PORT_1 EQU P1
LED_RED EQU P1.0
LED_GREEN EQU P1.1
LED_BLUE EQU P1.2
DEL_TEMP1 EQU R7
DEL_TEMP2 EQU R6
DEL_TEMP3 EQU R5
/*---------------------------------------------------------------------*/
/*-- 程序开始 ---------------------------------------*/
/*---------------------------------------------------------------------*/
ORG 0000H
SJMP MAIN
ORG 0030H
/*---------------------------------------------------------------------*/
/*-- 主程序 ---------------------------------------*/
/*---------------------------------------------------------------------*/
MAIN: MOV PORT_2,#00H //端口初始化
MOV PORT_1,#00H
LOOP: MOV PORT_1,#01H
CALL DELAY_1S //延时1S
MOV PORT_1,#03H
CALL DELAY_1S //延时1S
MOV PORT_1,#02H
CALL DELAY_1S //延时1S
MOV PORT_1,#06H
CALL DELAY_1S //延时1S
MOV PORT_1,#4H
CALL DELAY_1S //延时1S
MOV PORT_1,#5H
CALL DELAY_1S //延时1S
MOV PORT_1,#7H
CALL DELAY_1S //延时1S
SJMP LOOP
/*---------------------------------------------------------------------*/
/*-- 延时程序 ---------------------------------------*/
/*---------------------------------------------------------------------*/
DELAY_1S: MOV DEL_TEMP1,#8
DEL1: MOV DEL_TEMP2,#250
DEL2: MOV DEL_TEMP3,#248
DEL3: DJNZ DEL_TEMP3,DEL3
DJNZ DEL_TEMP2,DEL2
DJNZ DEL_TEMP1,DEL1
RET
/*---------------------------------------------------------------------*/
/*-- 程序结束 ---------------------------------------*/
/*---------------------------------------------------------------------*/
END
回复31帖
2014/04/16 20:34:23 32帖 yueyunno1 师长
/////////////////////////////////////////////////////////////
C语言程序
/////////////////////////////////////////////////////////////
/***********************************************************************/
/***名称:全彩LED灯珠颜色跳变 *****************************************/
/***功能:红色,(橙色黄色),绿色,青色,蓝色,紫色,白色,红色 循环显示间隔1S */
/***********************************************************************/
#include<reg51.h>
typedef unsigned char U8;
typedef unsigned int U16;
/*---------------------------------------------------------------------*/
/*-- 端口定义 ---------------------------------------*/
/*---------------------------------------------------------------------*/
#define PORT_2 P2
#define PORT_1 P1
sbit LED_RED =P1^0;
sbit LED_GREEN=P1^1;
sbit LED_BLUE =P1^2;
/*---------------------------------------------------------------------*/
/*-- 延时子程序 ---------------------------------------*/
/*---------------------------------------------------------------------*/
void DELAY_1MS(U16 z)
{
U16 x,y;
for(x=z;x>0;x--)
for(y=123;y>0;y--);
}
/*---------------------------------------------------------------------*/
/*-- 主程序 ---------------------------------------*/
/*---------------------------------------------------------------------*/
void main()
{
PORT_2=0X00;
while(1)
{
PORT_1=0x01;
DELAY_1MS(1000);
PORT_1=0x03;
DELAY_1MS(1000);
PORT_1=0x02;
DELAY_1MS(1000);
PORT_1=0x06;
DELAY_1MS(1000);
PORT_1=0x04;
DELAY_1MS(1000);
PORT_1=0x05;
DELAY_1MS(1000);
PORT_1=0x07;
DELAY_1MS(1000);
}
}
/*---------------------------------------------------------------------*/
/*-- 程序结束 ---------------------------------------*/
/*---------------------------------------------------------------------*/
|
|