⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lab2_solution.c

📁 MICROCHIP的18F系列单片机的一个DEMO程序
💻 C
字号:
#include <p18f8720.h>
#include <delays.h>

//#pragma romdata config
//_CONFIG_DECL (_OSC_HS_1H & _OSCS_OFF_1H, _PWRT_OFF_2L & _BOR_OFF_2L, _WDT_OFF_2H,_CONFIG3L_DEFAULT, _CCP2MUX_OFF_3H, _LVP_OFF_4L, _CONFIG5L_DEFAULT, _CONFIG5H_DEFAULT, _CONFIG6L_DEFAULT,_CONFIG6H_DEFAULT,_CONFIG7L_DEFAULT,_CONFIG7H_DEFAULT);
//#pragma romdata
unsigned char ch=0x01;
void tmr2 (void);

#pragma code high_vector_section=0x8
void high_vector (void)
{ _asm 
   goto tmr2 
  _endasm
}
#pragma code

#pragma interrupt tmr2
void tmr2 (void)
{ static int count = 0;
  unsigned char i;
  /* clear the timer interrupt flag */
  PIR1bits.TMR2IF = 0;
  /* if we've reached the repeat count, update the LEDs */
  if (count++ < 1000) return;
  else count = 0;
  { i=ch << 1;
    if(i) ch = ch | 0x01;
    PORTD=ch;
  }
}

void
main (void)
{ /* Make all bits on the Port D output bits for the LEDs */
  TRISD = 0;
  /* Reset Port D. Set just one bit to on. */
  PORTD = 1;
  /* clear the timer interrupt flag */
  PIR1bits.TMR2IF = 0; 
  /* enable the timer interrupt */
  PIE1bits.TMR2IE = 1;
  /* enable the timer */
  T2CONbits.TMR2ON = 1;
  /* enable interrupts for the timer */
  INTCONbits.GIE = 1;
  INTCONbits.PEIE = 1;
  while(1)
  {;}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -