源程序如下请高手指导!!!!
#include<pic.h>
//#include <pic16f877a.h>
#define uint unsigned int
#define uchar unsigned char
/*======================================================
;*******************************************************
;MCU config :initial mcu config
;CP=1,DEBUG=Enable,WRT1、WRT0=11,CPD=1,LVP=1
;BOREN=1,PWRTEN=0,WDTEN=0,FOSC1、FOSC0=10
;Preparation time :2013-12-26
;******************************************************/
__CONFIG(FOSC_HS & WDTE_OFF & PWRTE_ON & BOREN_ON & LVP_ON & CPD_OFF & WRT_OFF & DEBUG_ON & CP_OFF);
//2007H[page:144]
//__CONFIG(0x3f72); //2007H[page:144]
/***********************************************************************************
bit 13 CP: Flash Program Memory Code Protection bit
1 = Code protection off
0 = All program memory code-protected
bit 12 Unimplemented: Read as ‘1’
bit 11 DEBUG: In-Circuit Debugger Mode bit
1 = In-Circuit Debugger disabled, RB6 and RB7 are general purpose I/O pins
0 = In-Circuit Debugger enabled, RB6 and RB7 are dedicated to the debugger
bit 10-9 WRT1:WRT0 Flash Program Memory Write Enable bits
For PIC16F876A/877A:
11 = Write protection off; all program memory may be written to by EECON control
10 = 0000h to 00FFh write-protected; 0100h to 1FFFh may be written to by EECON control
01 = 0000h to 07FFh write-protected; 0800h to 1FFFh may be written to by EECON control
00 = 0000h to 0FFFh write-protected; 1000h to 1FFFh may be written to by EECON control
For PIC16F873A/874A:
11 = Write protection off; all program memory may be written to by EECON control
10 = 0000h to 00FFh write-protected; 0100h to 0FFFh may be written to by EECON control
01 = 0000h to 03FFh write-protected; 0400h to 0FFFh may be written to by EECON control
00 = 0000h to 07FFh write-protected; 0800h to 0FFFh may be written to by EECON control
bit 8 CPD: Data EEPROM Memory Code Protection bit
1 = Data EEPROM code protection off
0 = Data EEPROM code-protected
bit 7 LVP: Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit
1 = RB3/PGM pin has PGM function; low-voltage programming enabled
0 = RB3 is digital I/O, HV on MCLR must be used for programming
bit 6 BOREN: Brown-out Reset Enable bit
1 = BOR enabled
0 = BOR disabled
bit 5-4 Unimplemented: Read as ‘1’
bit 3 PWRTEN: Power-up Timer Enable bit
1 = PWRT disabled
0 = PWRT enabled
bit 2 WDTEN: Watchdog Timer Enable bit
1 = WDT enabled
0 = WDT disabled
bit 1-0 FOSC1:FOSC0: Oscillator Selection bits
11 = RC oscillator
10 = HS oscillator
01 = XT oscillator
00 = LP oscillator
***********************************************************************************/
void initMcu(void);
void main(void)
{
initMcu();
while(1)
{
asm("nop");
asm("nop");
}
}//main
/*======================================================
;*******************************************************
;Drive Mode :interrupt time0
;Use :
;Software Version :V1.0.0
;Preparation time :2013-12-26
;******************************************************/
void interrupt entry(void)
{
if(T0IE&&T0IF){ //Timer0 interrupt
T0IF = 0; //Clear Timer0 INT flag
TMR0 = (256-100); //Reload the Timer0 value
PORTD =~ PORTD;
}//Timer0 interrupt
}//interrupt time0
/*======================================================
;*******************************************************
;Drive Mode :initial mcu
;Use :initMcu();
;Software Version :V1.0.0
;Preparation time :2013-12-26
;******************************************************/
void initMcu(void)
{
OPTION_REG = 0x07; //0081H,0181H[page:23]
PCON = 0x03; //008eH[page:29]
EECON1 = 0x80; //018cH[page:34]
PORTA = 0x00; //0005H[page:41]
TRISA = 0x00; //0085H[page:41]
PORTB = 0x00; //0006H,0106H[page:44]
TRISB = 0x00; //0086H,0186H[page:44]
PORTC = 0x00; //0007H[page:46]
TRISC = 0x00; //0087H[page:46]
PORTD = 0x00; //0008H[page:48]
TRISD = 0x00; //0088H[page:48]
PORTE = 0x00; //0009H[page:49]
TRISE = 0x00; //0089H[page:50]
//CCPR1L = 0x00; //0015H[page:63]
//CCPR1H = 0x00; //0016H[page:63]
CCP1CON = 0x00; //0017H[page:64,68]
//CCPR2L = 0x00; //001bH[page:63]
//CCPR2H = 0x00; //001cH[page:63]
CCP2CON = 0x00; //001dH[page:64,68]
SSPSTAT = 0x00; //0094H[page:72](SPI)
SSPCON =0x00; //0014H[page:73](SPI)
SSPSTAT = 0x00; //0094H[page:81](IIC)
SSPCON = 0x00; //0014H[page:84](IIC)
SSPCON2 = 0x00; //0091H[page:83](IIC)
TXSTA = 0x00; //0098H[page:111]
RCSTA = 0x00; //0018H[page:112]
SPBRG = 0x00; //0099H[page:113]
ADCON0 = 0x80; //001fH[page:127]
ADCON1 = 0xc0; //009fH[page:128]
CMCON = 0x00; //009cH[page:135]
CVRCON = 0x00; //009dH[page:141]
TMR0 = (256-125); //0001H[page:53]
TMR1L = 0x00; //000eH[page:62]
TMR1H = 0x00; //000fH[page:62]
T1CON = 0x00; //0010H[page:57]
TMR2 = (256-125); //0011H[page:61]
T2CON = 0x00; //0010H[page:61]
INTCON = 0xa0; //000bH,008bH,0010bH,018bH[page:24]
PIE1 = 0x00; //008cH[page:25]
PIE2 = 0x00; //008dH[page:27]
PIR1 = 0x00; //000cH[page:26]
PIR2 = 0x00; //000dH[page:28]
}//mcu init
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>