PIC代码实例

2019-04-15 12:44发布

#include
void main(void)
{
}

多注意代码的注释部分 #include
//__CONFIG(XT & WDTDIS & PWRTDIS & BORDIS & LVPEN & WRTEN &DEBUGEN & DUNPROT & UNPROTECT);
__CONFIG (CP_OFF&WDTE_OFF& BOREN_OFF&PWRTE_OFF &FOSC_HS&WRT_OFF&LVP_OFF&CPD_OFF);
void init(void)
{
// port directions: 1=input, 0=output
TRISB = 0b00000000;
}
char counter;
void main(void)
{
counter = 0;
init();
while (1){
PORTB = counter;
_delay(10000);
counter++;
}
}
初始化函数
//Our new init function
void init(void)
{
PIE1 = 0b00000001;
INTCON = 0b01000000;
OPTION = 0b10000000;
TRISB = 0b00000000;
T1CON = 0b00110101;
}
修改调整主函数
#include
volatile char counter;
void main(void) {
counter = 0;
init();
ei();
while (1){
PORTB = counter;
}
}

//Our interrupt function
中断函数 #include
extern volatile char counter;
void interrupt my_isr(void){
if((TMR1IE)&&(TMR1IF)){
counter++;
TMR1IF=0;
}
}


热门文章