LGT8F328P 开发板arduino环境搭建:

LGT8F328P 开发板arduino环境搭建及中断程序

1. 在官网上下载 Arduino硬件支持包

http://www.lgtic.com/downloads/

 

Arduino开发平台相关

解压,把压缩包中..\Larduino_HSP_latest\Larduino_HSP_v3.6c\hardware\ 目录下的LGT 目录复制到  Arduino hardware "D:\Program Files (x86)\Arduino\hardware\" 目录下。

2. 参考如下博客,把芯片和下载器连接好

https://blog.csdn.net/XIUYING_MO/article/details/103942255

3. 打开Arduino,选择开发板

LGT8F328P 开发板arduino环境搭建及中断程序

4. 编程

4.1 中断程序

uint8_t IRPinSequence[] = {5, 4, 1, 0, 5, 4, 0 };
uint8_t IRPin[] = {C5, C4, C1, C0, B5, B4, B0 };

void iniIR() {
  uint8_t i;
 
  for (i = 0; i < IRPinCount; i++) {
    pinMode(IRPin[i], INPUT_PULLUP);
  }
  cli();    //关闭中断

   PCICR |= (1 << PCIE0) | (1 << PCIE1);   // 设置 PCIE0 以启用 PCMSK0 来测量状态变化并产生中断 侦测 PB
  for (i = 0; i < IRPinCount; i++) {
    PCMSK0 |= (1 << IRPinSequence[i]);   // 设置 引脚 来测量状态变化并产生中断, PB
    PCMSK1 |= (1 << IRPinSequence[i]);  // 设置 引脚 来测量状态变化并产生中断, PB

  }
 

  sei();                     // turn on interrupts

}

 

ISR (PCINT0_vect)// PB脚可以触发 PCINT0中断
{
  uint8_t changedbits;//设立一个无符号整数来记录寄存器的变化

  changedbits = PINB ^ PortB_history;
  PortB_history = PINB;

  uint8_t i = 0;

  if (changedbits & (1 << PINB0))
  {
    if (PINB & (1 << PINB0)) {  //上升沿
      i = 6;
      IRPinCallBack(i);
    }
  }

  if (changedbits & (1 << PINB1))
  {

  }

  if (changedbits & (1 << PINB2))
  {

  }

  if (changedbits & (1 << PINB3))
  {

  }
  if (changedbits & (1 << PINB4))
  {
    if (PINB &  (1 << PINB4)) {  //上升沿
      i = 5;
      IRPinCallBack(i);
    }
  }
  if (changedbits & (1 << PINB5))
  {
    if (PINB &  (1 << PINB5)) {  //上升沿
      i = 4;
      IRPinCallBack(i);
    }
  }
}

ISR (PCINT1_vect)// PC脚可以触发 PCINT1中断
{
  uint8_t changedbits;//设立一个无符号整数来记录寄存器的变化
  uint8_t i = 0;

  changedbits = PINC ^ PortC_history;
  PortC_history = PINC;


  if (changedbits & (1 << PINC0))
  {
    if (PINC &  (1 << PINC0)) {  //上升沿
      i = 3;
      IRPinCallBack(i);
    }
  }

  if (changedbits & (1 << PINC1))
  {
    if (PINC &  (1 << PINC1)) {  //上升沿
      i = 2;
      IRPinCallBack(i);
    }
  }

  if (changedbits & (1 << PINC2))
  {

  }


  if (changedbits & (1 << PINC3))
  {

  }

  if (changedbits & (1 << PINC4))
  {
    if (PINC & (1 << PINC4)) {  //上升沿
      i = 1;
      IRPinCallBack(i);
    }
  }

  if (changedbits & (1 << PINC5))
  {
    if (PINC &  (1 << PINC0)) {  //上升沿
      i = 0;
      IRPinCallBack(i);
    }
  }
}

ISR (PCINT2_vect)// PD脚可以触发 PCINT1中断?
{
  uint8_t changedbits;//设立一个无符号整数来记录寄存器的变化


  changedbits = PIND ^ PortD_history;
  PortD_history = PIND;


  if (changedbits & (1 << PIND0))
  {

  }

  if (changedbits & (1 << PIND1))
  {

  }

  if (changedbits & (1 << PIND2))
  {
    //    if ((~PIND) &  (1 << PIND2)) {  //下降沿
    //      USCallBack(1);
    //    }
  }


  if (changedbits & (1 << PIND3))
  {
    //    if ((~PIND) &  (1 << PIND3)) {  //下降沿
    //      USCallBack(2);
    //    }
  }

  if (changedbits & (1 << PIND4))
  {

  }

  if (changedbits & (1 << PIND5))
  {

  }
}
 

相关文章:

  • 2021-06-04
  • 2021-07-10
  • 2021-08-24
  • 2021-07-12
  • 2022-02-28
  • 2021-04-15
  • 2022-01-07
  • 2021-09-10
猜你喜欢
  • 2022-02-10
  • 2021-05-31
  • 2021-04-12
  • 2021-11-25
  • 2023-01-21
  • 2021-11-03
  • 2021-06-21
相关资源
相似解决方案