标题: pic16f505单片机的代码哪里错误? [打印本页]

作者: hjx5548    时间: 2023-2-18 21:37
标题: pic16f505单片机的代码哪里错误?
#include "pic.h"
//__CONFIG(INTIO&WDTDIS&BOREN);                        //PICC9.80版本配置字写法
//__CONFIG(FOSC_INTRCIO&WDTE_OFF&BOREN_ON&MCLRE_ON);                //PICC9.83版本配置字写法
/*使用内部RC振荡器,GP4和GP5用作普通IO,关闭看门狗,开启低电压复位,MCLR引脚用于复位功能
不同的编译器配置字会有些写法上的不同,需要注意*/
#define uchar unsigned char                //无符号字符型简写成uchar
#define uint unsigned int                //无符号整形简写成uint
void delay(uint m);                                //函数声明

void delay(uint m)
{
           uint a,b;
    for(b=m;b>0;b--)
    {
            for(a=110;a>0;a--);
    }
}

void main(void)
{
//        ANS2=0;                        //GP2设为数字IO
        TRISB = 0;                //GP2设为输出

   // PORTB = 0x38;                //GP2设为输出0011 1000

//        RB2 = 0 ;                //点亮LED灯
//   delay(500);
        while(1)
        {
        RB2 = 0 ;                //点亮LED灯
    RB0 = 0 ;
    delay(100);        delay(100);        delay(100);        delay(100);        delay(100);                RB2 = 1 ;
        }
}
作者: 飞云居士    时间: 2023-2-27 10:02
RB2 = 0 ;                //点亮LED灯

delay(100);        
delay(100);        
delay(100);        
delay(100);        
delay(100);               
RB2 = 1 ;//熄灭LED灯

当循环回去时,灯立马又亮了。如要闪烁,在灯熄灭后,也需要延时一段时间。
如:
RB2 = 0 ;                //点亮LED灯

delay(100);        
delay(100);        
delay(100);        
RB2 = 1 ;//熄灭LED灯
delay(100);        
delay(100);               
delay(100);        
            






欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1