这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 企业专区 » Renesas » campozeng的进程帖★基于RL78/G13的双向信息监测传送系统项目总结

共104条 3/11 1 2 3 4 5 6 ›| 跳转至
院士
2012-08-28 13:37:59     打赏
21楼
嘿嘿,就是這個意思。
話說我的五筆輸入法也可以直接輸出來繁體字~~

工程师
2012-08-28 16:45:22     打赏
22楼
用Applilet3生成蜂鳴器代碼并成功驅動

太方便了,都完全不用自己寫代碼。

1、设置系统时钟,注意WDT的设置,如果没有关闭,程序中要加入喂狗。



2、根据你要驱动的蜂鸣器的特性,设置输出频率


3、生成代码

工程师
2012-08-29 08:02:04     打赏
23楼
精彩不斷,精彩繼續,請大家多多支持

工程师
2012-08-30 18:59:56     打赏
24楼

超炫幻彩跑马灯

視頻:http://v.eepw.com.cn/video/play/id/1935



RL78/G13 开发板做的超炫幻彩跑马灯,可以随意调整模式,速度,颜色

用了八個RGB三色共陽LED
R LED連接到P2
G LED連接到P1
B LED連接到P7

三個接鍵連接到P00/P01/P02 用于選擇模式/顏色/速度/亮度

視頻正在上傳中,稍候登場





程序如下:

定義以下文件頭:
#define KeyPort           P0

#define NoKeyData         0x07
#define Key1Data          0x06
#define Key2Data          0x05
#define Key3Data          0x03
#define Key12Data         0x04
#define MODE_STEP         300
#define RedLedPort        P2
#define GreenLedPort      P1
#define BlueLedPort       P7

#define MAX_LED_MODE                      10
#define LED_OFF                           0xff
#define MAX_COLOUR_MODE                   8
#define MAX_SPEED                         500
#define MIN_SPEED                         5000
#define FLASH_SPEED_STEP                  300
#define MAX_BRIGHTNESS_RATE               5


定議以下寄存器:
unsigned char LedTimerCount;
unsigned char LedOnCount;
unsigned int LedStepCount;
unsigned char Direction=0;
unsigned char LedMode;
unsigned char ColourMode;
unsigned char RedLedOnCount;
unsigned char GreenLedOnCount;
unsigned char BlueLedOnCount;
unsigned char RedPortData;
unsigned char GreenPortData;
unsigned char BluePortData;
unsigned short FLashSpeed;
unsigned char BrightnessRate;

unsigned char KeySave;
unsigned char KeyBuffer;

/***************config RGB colour*************/
const unsigned char RGBData[MAX_COLOUR_MODE][3]=
{
  100,0,0,
  80,50,10,
  90,80,0,
  10,100,0,
  0,0,100,
  10,100,20,
  100,40,70,
  100,100,100
};


LED上電初始化程序:

/******setup default mode***********/
void SetupLed(void)
{
    ADPC=0x01;
    PU7=0xff;
    PM7=0x00;
    PU1=0xff;
    PM1=0x00;
    PM2=0x00;
    RedLedPort=LED_OFF;                 //set red off
    GreenLedPort=LED_OFF;               //set green off
    BlueLedPort=LED_OFF;                //set blueoff
    LedMode=0;                          //set default led mode
    ColourMode=1;                       //set default led colour
    RedPortData=0x80;                   //set default red led status
    GreenPortData=0x80;                 //set default green led status
    BluePortData=0x80;                  //set default blue led status
    FLashSpeed=2000;                    //set default flash speed
    BrightnessRate=2;                   //set default led brightness rate
}


定時器中斷程序如下:

#pragma vector = INTTM00_vect
__interrupt void MD_INTTM00(void)
{
 /* Start user code. Do not edit comment generated here */
  //unsigned char Temp;
  TMIF00 = 0U;
  LedStepCount++;
  if(LedStepCount>FLashSpeed)
  {
     LedStepCount=0;
     switch (LedMode)
    {
      case 0:
      {
        RedPortData >>=1;
        if(RedPortData==0x00)RedPortData=0x80;
        GreenPortData >>=1;
        if(GreenPortData==0x00)GreenPortData=0x80;
        BluePortData >>=1;
        if(BluePortData==0x00)BluePortData=0x80;
        break;
      }
      case 1:
      {
        RedPortData <<=1;
        if(RedPortData==0x00)RedPortData=0x01;
        GreenPortData <<=1;
        if(GreenPortData==0x00)GreenPortData=0x01;
        BluePortData <<=1;
        if(BluePortData==0x00)BluePortData=0x01;
        break;
      }
      case 2:
      {
        RedPortData ^=0xff;
        BluePortData ^=0xff;
        GreenPortData ^=0xff;
        break;
      }
      case 3:
      {
        ColourMode++;
        if(ColourMode>(MAX_COLOUR_MODE-1))
        {
          ColourMode=0;
        }
        break;
      }
      case 4:
      {
        if(Direction==0)
        {
            RedPortData >>=1;
            if(RedPortData==0x00)
            {
              RedPortData=0x01;
              Direction=1;
            }
            GreenPortData >>=1;
            if(GreenPortData==0x00)GreenPortData=0x01;
             BluePortData >>=1;
            if(BluePortData==0x00)BluePortData=0x01;
        }
        else
        {
            RedPortData <<=1;
            if(RedPortData==0x00)
            {
             RedPortData=0x80;
              Direction=0;
            }
            GreenPortData <<=1;
            if(GreenPortData==0x00)GreenPortData=0x80;
            BluePortData <<=1;
            if(BluePortData==0x00)BluePortData=0x80;
        }
        break;
      }
      case 5:
      {
        RedPortData ^=0xff;
        RedPortData >>=1;
        if(RedPortData==0x00)RedPortData=0x80;
        RedPortData ^=0xff;
        GreenPortData ^=0xff;
        GreenPortData >>=1;
        if(GreenPortData==0x00)GreenPortData=0x80;
        GreenPortData ^=0xff;
        BluePortData ^=0xff;
        BluePortData >>=1;
        if(BluePortData==0x00)BluePortData=0x80;
        BluePortData ^=0xff;
        break;
      }
      case 6:
      {
        if(Direction==0)
        {
         
          if(RedPortData==0xff)
          {
            Direction=1;
            RedPortData=0xfe;
          }
          else
          {
            RedPortData >>=1;
            RedPortData |= 0x80;
          }
         
          if(GreenPortData==0xff)
          {
            Direction=1;
            GreenPortData=0xfe;
          }
          else
          {
            GreenPortData >>=1;
            GreenPortData |= 0x80;
          }
         
          if(BluePortData==0xff)
          {
            Direction=1;
            BluePortData=0xfe;
          }
          else
          {
              BluePortData >>=1;
              BluePortData |= 0x80;
          }
        }
        else
        {
         
           if(RedPortData==0x00)
           {
             Direction=0;
             RedPortData=0x80;
           }
           else
           {
              RedPortData <<=1;
           }
          
           if(GreenPortData==0x00)
           {
             Direction=0;
             GreenPortData=0x80;
           }
           else
           {
             GreenPortData <<=1;
           }
          
           if(BluePortData==0x00)
           {
             Direction=0;
             BluePortData=0x80;
           }
           else
           {
             BluePortData <<=1;
           }
        }
        break;
      }
      default:
      {
        RedPortData >>=1;
        if(RedPortData==0x00)RedPortData=0x80;
        GreenPortData >>=1;
        if(GreenPortData==0x00)GreenPortData=0x80;
        BluePortData >>=1;
        if(BluePortData==0x00)BluePortData=0x80;
        break;
      }
    }
  }
 
  RedLedOnCount=RGBData[ColourMode][0];
  GreenLedOnCount=RGBData[ColourMode][1];
  BlueLedOnCount=RGBData[ColourMode][2];
  RedLedOnCount /= BrightnessRate;
  GreenLedOnCount /= BrightnessRate;
  BlueLedOnCount /= BrightnessRate;
 
  /**********PWM Timer Control*********/
  LedTimerCount++;
  if(LedTimerCount>100)
  {
      LedTimerCount=0;
  }
 
  /*****Red LED control*********/
  if(LedTimerCount>=RedLedOnCount)
  {
      RedLedPort=LED_OFF;               //off
  }
  else
  {
      RedLedPort=RedPortData;
  } 
   /*****Green LED control*********/
  if(LedTimerCount>=GreenLedOnCount)
  {
      GreenLedPort=LED_OFF;           //off
  }
  else
  {
      GreenLedPort=GreenPortData;
  }
 
   /*****Blue LED control*********/
  if(LedTimerCount>=BlueLedOnCount)
  {
      BlueLedPort=LED_OFF;           //off
  }
  else
  {
      BlueLedPort=BluePortData;
  } 
}
按鍵處理程序:

/*
**-----------------------------------------------------------------------------
**
**  Abstract:
** This function initializes Key.
**
**  Parameters:
** None
**
**  Returns:
** None
**
**-----------------------------------------------------------------------------
*/
void ConfigKey(void)
{
    PMC0=0x00;
    PU0=0xff;          //set pull high
    PM0=0xff;          //set input
}

 

void DelayMs(unsigned short MS)
{
    unsigned short i,j;
    for(j=0;j<MS;j++)
    {
      for(i=0;i<200;i++)
      {
         ;
      }
    }
}

/*
**-----------------------------------------------------------------------------
**
**  Abstract:
** This function Scan key.
**
**  Parameters:
** None
**
**  Returns:
** None
**
**-----------------------------------------------------------------------------
*/
unsigned char ScanKey(void)
{
  unsigned char TempData,TempData1,KeyCode;
  TempData=KeyPort;
  TempData &=NoKeyData;
  KeyCode=NoKeyData;
  if(TempData !=NoKeyData )
  {
      DelayMs(50);
      TempData1=KeyPort;
      TempData1 &=NoKeyData;
      if(TempData==TempData1)
      {
          KeyCode=TempData;
      }
  }
  return(KeyCode);
}

/*
**-----------------------------------------------------------------------------
**
**  Abstract:
** This function handle key function.
**
**  Parameters:
** None
**
**  Returns:
** None
**
**-----------------------------------------------------------------------------
*/
void HandleKey(void)
{
   KeySave=ScanKey();
   if(KeySave!=KeyBuffer && KeySave==Key1Data)
   {
      LedMode++;                              //change LED mode
      if(LedMode>MAX_LED_MODE)
      {
          LedMode=0;
      }
      switch (LedMode)
      {
        case 0:                               //set mode 0 default status
        {
          RedPortData=0x80;                   //set default red led status
          GreenPortData=0x80;                 //set default green led status
          BluePortData=0x80;                  //set default blue led status
          break;
        }
        case 1:                               //set mode 1 default status
        {
          RedPortData=0x01;                   //set default red led status
          GreenPortData=0x01;                 //set default green led status
          BluePortData=0x01;                  //set default blue led status
          break;
        }
        case 2:                               //set mode 2 default status
        {
           RedPortData=0x00;                   //set default red led status
           GreenPortData=0x00;                 //set default green led status
           BluePortData=0x00;                  //set default blue led status
           break;
        }
        case 3:                               //set mode 3 default status
        {
           RedPortData=0x00;                   //set default red led status
           GreenPortData=0x00;                 //set default green led status
           BluePortData=0x00;                  //set default blue led status
           break;
        }
        case 4:                               //set mode 4 default status
        {
           RedPortData=0x01;                   //set default red led status
          GreenPortData=0x01;                 //set default green led status
          BluePortData=0x01;                  //set default blue led status
          break;
        }
        case 5:                               //set mode 5 default status
        {
          RedPortData=0x80;                   //set default red led status
          GreenPortData=0x80;                 //set default green led status
          BluePortData=0x80;                  //set default blue led status
          break;
        }
        case 6:                               //set mode 6 default status
        {
          RedPortData=0x80;                   //set default red led status
          GreenPortData=0x80;                 //set default green led status
          BluePortData=0x80;                  //set default blue led status
          Direction=0;
          break;
        }
        default:
        {
          RedPortData=0x80;                   //set default red led status
          GreenPortData=0x80;                 //set default green led status
          BluePortData=0x80;                  //set default blue led status
          break;
        }
      }
   }
   else if(KeySave!=KeyBuffer && KeySave==Key2Data)           //change led colour
   {
      ColourMode++;
      if(ColourMode>(MAX_COLOUR_MODE-1))
      {
          ColourMode=0;
      }
   }
   else if(KeySave!=KeyBuffer && KeySave==Key3Data)           //change flash speed
   {
       FLashSpeed +=FLASH_SPEED_STEP;
       if(FLashSpeed > MIN_SPEED)
       {
          FLashSpeed=MAX_SPEED;
       }
   }
   else if(KeySave!=KeyBuffer && KeySave==Key12Data)         //change brightness
   {
       BrightnessRate++;
       if(BrightnessRate > MAX_BRIGHTNESS_RATE)
       {
          BrightnessRate=1;
       }
   }
   KeyBuffer=KeySave;
}


助工
2012-08-30 20:03:33     打赏
25楼
能不能上源程序啊!方便大家学习啊。

工程师
2012-08-30 20:12:14     打赏
26楼
核心的代碼已經貼出來,如有需要更詳細的,請留下email并注明要什麽代碼,我會發給你

工程师
2012-08-30 21:26:49     打赏
27楼
楼主,能不能把您的有关LED等的程序给小弟啊,在此先谢谢了1136029879@qq.com,本人邮箱

工程师
2012-08-31 08:20:44     打赏
28楼
跑馬燈程序已經發送至你郵箱,請注意查收

工程师
2012-08-31 08:55:30     打赏
29楼

GPIO INTP/KeyBoard INT 測試

先用Applilet生基礎代碼:



在中斷程序中實現RL78/G13開發板上的LED翻轉,中斷代碼如下:

/*

**-----------------------------------------------------------------------------

**
**  Abstract:

** This function is INTP0 interrupt service routine.

**
**  Parameters:

** None

**
**  Returns:

** None

**
**-----------------------------------------------------------------------------

*/

__interrupt void MD_INTP0(void)

{
 
    /* Start user code. Do not edit comment generated here */

    P7 ^=0x80;      
   /* End user code. Do not edit comment generated here */

}


/*
**-----------------------------------------------------------------------------
**
**  Abstract:
** This function is INTKR interrupt service routine.
**
**  Parameters:
** None
**
**  Returns:
** None
**
**-----------------------------------------------------------------------------
*/
__interrupt void MD_INTKR(void)
{
 /* Start user code. Do not edit comment generated here */
    P7 ^=0x80;
 /* End user code. Do not edit comment generated here */
}


高工
2012-08-31 09:29:42     打赏
30楼
AD+溫度傳感器+串口+上位機軟件實現溫度監控程序 跑马灯程序 能否发份给我琢磨下?454730977@qq.com 万分感谢

共104条 3/11 1 2 3 4 5 6 ›| 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]