51开发板 程序1 单个LED闪烁

今日头条

1114人已加入

描述

1、延时函数

void delay(unsigned int i)//大约延时10us
{
while(i--);
}

2、预处理命令

typedef unsigned char uint;(后面要加分号)
/*重新定义一些常用的关键词,可以增强程序的可移植性,因为在不同的编译软件上面,C语言的数据类型的关键词的位宽是不一样的。*/
eg: typedef unsigned char U8;// u8表示char类型占用8位;用U8 来代替unsigned char; typedef是一个关键字,表示重新定义
typedef unsigned int U16;//u16表示int类型占用16位;用U16 来代替unsigned int; typedef是一个关键字,表示重新定义

3、函数的定义

函数的定义:

返回变量类型 函数名(输入变量类型)
{
	函数体;
}

如:
unsigned char read(unsigned char addr)
{
	unsigned char dat;//定义一个变量存放返回值
	(do anything you want);//函数中的程序。
	return dat;//返回函数的返回值
}

 

4程序:单个LED闪烁

#include 
typedef unsigned int U16;
typedef unsigned char u8;

sbit LED = P2^0;
void delay( U16 i)
 {
 while(i--);	
 }

void main()
{
	while(1)
	{
	   LED = 0;
	   delay(10000);
	   LED = 1;
	   delay(10000);
	}

}

审核编辑:符乾江

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分