单片机调用库函数设置单片机延时;

2019-04-15 12:14发布

//单片机调用库函数设置单片机延时;
/——————————————————————/
/* — STC MCU Limited ———————————————*/
/* — STC12C56xx Series MCU IO Demo ——————————-*/
/* — Mobile: (86)13922805190 ————————————-*/
/* — Fax: 86-0513-55012956,55012947,55012969 ———————*/
/* — Tel: 86-0513-55012928,55012929,55012966———————-*/
/* — Web: www.STCMCU.com —————————————–*/
/* — Web: www.GXWMCU.com —————————————–*/
/* If you want to use the program or the program referenced in the */
/* article, please specify in which data and procedures from STC */
/——————————————————————/

include “STC15.H”

include “intrins.h”

/调用库函数时,必须包含这个头文件。_nop_ 在这里。/
sbit LED4 = P1^0; //led4
sbit LED5 = P1^1; //LED5
sbit LED2 = P2^6; //LED2
sbit LED3 = P2^7; //LED3
sbit LED6 = P1^6; //LED6?
void Delay1000ms();
void main()
{
unsigned char temp=AUXR1;
temp=P2M1; //P2.7口默认不认普通的IO口,必须设置为普通IO口。详见数据手册PDFpage401
P2M1=temp&0x7F;
temp = P2M0;
P2M0 = temp|0x80; while(1) { LED2 = 1; LED3 = 1; LED4 = 1; LED5 = 1; Delay1000ms(); LED2 = 0; LED3 = 0; LED4 = 0; LED5 = 0; Delay1000ms(); //注意 ,我首先没有加这条语句,LED是长灭状态,以为是延时函数未执行,后来加上了这个语句就行了。 // } 如果不加这条语句,就相当于灭了之后延时一会,就亮,亮完就急速灭了。就相当于长灭,肉眼看不到了。}
void Delay1000ms() //@11.0592MHz
{
unsigned char i, j, k; _nop_(); _nop_(); i = 43; j = 6; k = 203; do { do { while (--k); } while (--j); } while (--i); }