PIC单片机让一个灯闪烁程序
流程图:
仿真图:
源代码:
//-----------------------------------------------------------------
// 名称: 闪烁的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;
}
PIC单片机闪烁程 相关文章:
- PIC单片机闪烁程序(11-29)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)