微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > PIC单片机让一个灯闪烁程序

PIC单片机让一个灯闪烁程序

时间:11-30 来源:互联网 点击:
具体介绍:让一个灯闪烁,亮500ms后关闭500ms

流程图:


仿真图:



源代码:
//-----------------------------------------------------------------
// 名称: 闪烁的LED
//-----------------------------------------------------------------
// 说明: LED按设定的时间间隔闪烁
//-----------------------------------------------------------------
#include
#define _XTAL_FREQ 4000000UL
#define LED RC5 //定义LED
//-----------------------------------------------------------------
// 主程序
//-----------------------------------------------------------------
void main()
{
TRISC = 0x00; //设置整个PORTC端口为输出(或设置TRISC5 = 0;)
PORTC = 0xFF; //初始时输出全1

while(1)
{

}
}
flowcode软件用流程图导出的源代码:
#define MX_PIC_16BIT

//Defines for microcontroller
#define P30F2011
#define MX_CLKS_PER_INST 4
#define MX_SPI1
#define MX_SPI1_PORT_B
#define MX_SPI1_SDI 5
#define MX_SPI1_SDO 4
#define MX_SPI1_SCK 6
#define MX_UART1
#define MX_UART1_PORT_B
#define MX_MI2C1
#define MX_I2C1_PORT_B
#define MX_I2C1_SDA 5
#define MX_I2C1_SCL 4
#define MX_PWM
#define MX_PWM_PORT_D
#define MX_PWM_CNT 2
#define MX_PWM_1 0
#define MX_PWM_2 7

//Functions
#define MX_Fosc 48000000

#include "../support/dsPIC30F/h/p30fxxxx.h"
#include
#include

#define _RESERVED1(x) int temp1 = (x);
#define _RESERVED2(x) int temp2 = (x);
#define _ICD(x) _FICD(x);

//Configurationdata

//Internal functions
#include "F:Program FilesMatrix MultimediaFlowcode PIC24&dsPIC V4FCDinternals.h"

//Macro function declarations

//Variable declarations

//Macro implementations

int main()
{

ADPCFG = 0xffff;
while (1)
{
TRISC = TRISC & 0xdfff;
if ((0<8))
PORTC = (LATC & 0xdfff) | 0x2000;
else
PORTC = LATC & 0xdfff;
delay_ms(255);
delay_ms(245);

TRISC = TRISC & 0xdfff;
if ((1<8))
PORTC = (LATC & 0xdfff) | 0x2000;
else
PORTC = LATC & 0xdfff;

delay_ms(255);
delay_ms(245);
}

mainendloop: goto mainendloop;
return 0;
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top