alvin7890 alvin7890
关注数: 176 粉丝数: 409 发帖数: 8,581 关注贴吧数: 61
PIC12F1572 简单IO控制学习程序 12F1572是个比较新的PIC单片机产品。它小型,只有8只脚,6个GPIO, 很有实力,包含功能有ADC,PWM,UART,等等。两天前有个机会与网友学习这个单片机,用MPLABX IDE 编写了下面这个最简单的程序,发在这里与大家分享 #include <xc.h> #include <pic12f1572.h> // CONFIG1 #pragma config FOSC = INTOSC // INTOSC oscillator; I/O function on CLKIN pin #pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled) #pragma config PWRTE = ON // Power-up Timer Enable (PWRT disabled) #pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is digital input) #pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled) #pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled) #pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin) // CONFIG2 #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off) #pragma config PLLEN = OFF // 4x PLL disabled #pragma config STVREN = OFF // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will not cause a Reset) #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.) #pragma config LPBOREN = OFF // Low Power Brown-out Reset enable bit (LPBOR is disabled) #pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming) #define _XTAL_FREQ 4000000 // to let compiler know the int OSC freq = 4MHz void main(void) { //OSCCON: OSCILLATOR CONTROL REGISTER setting SPLLEN=0; // 0 = 4x PLL is disabled OSCCONbits.IRCF = 0b1101; // Internal Oscillator Frequency Select bits, 1101 = 4 MHz HF SCS0=0; //1x = Internal oscillator block SCS1=1; // 1x = Internal oscillator block ANSELA=0x00; // set all GPIO pins to digital I/O TRISA = 0b00101000; // RA5 and RA3 as input pins, RA4, RA2 and RA1 as output pins PORTA=0x00; // start with all GPIO pins cleared ODCONA = 0x00; // 0 = Port pin operates as standard push-pull drive (able to source and sink current) SLRCONA = 0x00; // 0 = Port pin slews at maximum rate while(1){ // RA4=1; LATA4 = 1; __delay_ms(10000); // 10 seconds delay // RA4=0; LATA4 = 0; __delay_ms(8000); // 8 seconds delay } }
1 下一页