附上代码:就用过STM32的板子,周末学学PIC的配置
#include <stdio.h>
#include <stdlib.h>
#include <pic.h> //调用PIC16F87XA单片机的头文件
// CONFIG
#pragma config FOSC = EXTRC // Oscillator Selection bits (RC oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = ON // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#include <xc.h>
//根据选项,配置字应该如下所示:
__CONFIG(HS&WDTDIS&LVPDIS);
void delay(void);
int main(int argc, char** argv)
{
unsigned int i=0;
char data=0;
TRISD=0x00; //初始化RD7-RD0的输出方向
PORTD=0xFF; //初始化RD7-RD0的输出方向
//死循环,单片机初始化后,将一直运行这个死循环
while(1)
{
data=0xFE;
for(i=0;i<8;i++)
{
PORTD=data; //初始化RD7-RD0的数值
delay();
data=(data<<1)|0X01;
}
}
return (EXIT_SUCCESS);
}
void delay(void)
{
unsigned int a;
for(a=0;a<50000;a++);
}
|