|
对于新手入门
要学会点亮LED灯
以下就是代码分享
供大家交流学习
单片机源程序如下:
- /*头文件*/
- #include <reg52.h>
- #include <intrins.h>
- #define uint unsigned int
- #define uchar unsigned char
- sbit P10 = P1^0; /*定义发光二极管LED端口*/
- sbit P11 = P1^1;
- sbit P12 = P1^2;
- sbit P13 = P1^3;
- sbit P14 = P1^4;
- sbit P15 = P1^5;
- sbit P16 = P1^6;
- sbit P17 = P1^7;
- /*1MS为单位的延时程序*/
- void delay_1ms(uchar x)
- {
- uchar j;
- while(x--){
- for(j=0;j<125;j++)
- {;}
- }
- }
- void main()
- {
- while(1){
- P10 = 1;P11 = 1;P12 = 1;P13 = 1;P14 = 1;P15 = 1;P16 = 1;P17 = 0; /*点亮P1.7*/
- delay_1ms(200);delay_1ms(200); /*延时*/
- P10 = 1;P11 = 1;P12 = 1;P13 = 1;P14 = 1;P15 = 1;P16 = 0;P17 = 0; /*再点亮P1.6*/
- delay_1ms(200);delay_1ms(200); /*延时*/
- P10 = 1;P11 = 1;P12 = 1;P13 = 1;P14 = 1;P15 = 0;P16 = 0;P17 = 0; /*再点亮P1.5*/
- delay_1ms(200);delay_1ms(200); /*延时*/
- P10 = 1;P11 = 1;P12 = 1;P13 = 1;P14 = 0;P15 = 0;P16 = 0;P17 = 0; /*再点亮P1.4*/
- delay_1ms(200);delay_1ms(200); /*延时*/
- P10 = 1;P11 = 1;P12 = 1;P13 = 0;P14 = 0;P15 = 0;P16 = 0;P17 = 0; /*再点亮P1.3*/
- delay_1ms(200);delay_1ms(200); /*延时*/
- P10 = 1;P11 = 1;P12 = 0;P13 = 0;P14 = 0;P15 = 0;P16 = 0;P17 = 0; /*再点亮P1.2*/
- delay_1ms(200);delay_1ms(200); /*延时*/
- P10 = 1;P11 = 0;P12 = 0;P13 = 0;P14 = 0;P15 = 0;P16 = 0;P17 = 0; /*再点亮P1.1*/
- delay_1ms(200);delay_1ms(200); /*延时*/
- P10 = 0;P11 = 0;P12 = 0;P13 = 0;P14 = 0;P15 = 0;P16 = 0;P17 = 0; /*再点亮P1.0*/
- delay_1ms(200);delay_1ms(200); /*延时*/
- P10 = 1;P11 = 1;P12 = 1;P13 = 1;P14 = 1;P15 = 1;P16 = 1;P17 = 1; /*LED全灭*/
- delay_1ms(200);delay_1ms(200); /*延时*/
- }
- }
复制代码
所有资料51hei提供下载:
LED灯逐个增加点亮.zip
(900 Bytes, 下载次数: 3)
|
|