流程图:
仿真图:
源代码:
//-----------------------------------------------------------------
// 名称: 闪烁的LED
//-----------------------------------------------------------------
// 说明: LED按设定的时间间隔闪烁
//-----------------------------------------------------------------
#include <pic.h>
#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 <stdlib.h>
#include <math.h>
#define _RESERVED1(x) int temp1 = (x);
#define _RESERVED2(x) int temp2 = (x);
#define _ICD(x) _FICD(x);
//Configuration data
//Internal functions
#include "F:\Program Files\Matrix Multimedia\Flowcode PIC24&dsPIC V4\FCD\internals.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;
}