Easyrider83
Advanced Member level 5
- Joined
- Oct 11, 2011
- Messages
- 1,608
- Helped
- 374
- Reputation
- 748
- Reaction score
- 364
- Trophy points
- 1,363
- Location
- Tallinn, Estonia
- Activity points
- 8,575
Now it is time to review the code
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
/***********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIESREGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2011, 2017 Renesas Electronics Corporation. All rights reserved.
***********************************************************************************************************************/
/***********************************************************************************************************************
* File Name : r_main.c
* Version : CodeGenerator for RL78/G14 V2.05.00.03 [05 May 2017]
* Device(s) : R5F104BA
* Tool-Chain : CA78K0R
* Description : This file implements main function.
* Creation Date: 04/09/2017
***********************************************************************************************************************/
/***********************************************************************************************************************
Pragma directive
***********************************************************************************************************************/
/* Start user code for pragma. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
/***********************************************************************************************************************
Includes
***********************************************************************************************************************/
#include "r_cg_macrodriver.h"
#include "r_cg_cgc.h"
#include "r_cg_port.h"
#include "r_cg_adc.h"
#include "r_cg_timer.h"
/* Start user code for include. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
#include "r_cg_userdefine.h"
/***********************************************************************************************************************
Global variables and functions
***********************************************************************************************************************/
/* Start user code for global. Do not edit comment generated here */
//changable
/*#define B1 TRDGRB1
#define B2 TRDGRC1
#define B3 TRDGRD1*/
//#define DMx 4000
#define U1 P1.5
#define U2 P1.6
#define U3 P1.4
#define prd 4000
boolean pA,pB,pC,set,state,dir,stop,load,cc,bb,aa,volt,set1,ft,chak;
unsigned char amit_pos,reduce;
unsigned int ducycle,i,j,count,amit_adc,count1,current,voltage,todecide,abc,vcnt,ccnt,deccnt,dirc;
extern void dutychange(unsigned char,unsigned int);
void dclock(unsigned char *seq)
{
switch(*seq)
{
case 5:
U1=1;U2=0;U3=0;
dutychange(2,ducycle);
break;
case 1:
U1=1;U2=0;U3=0;
dutychange(3,ducycle);
break;
case 3:
U1=0;U2=1;U3=0;
dutychange(3,ducycle);
break;
case 2:
U1=0;U2=1;U3=0;
dutychange(1,ducycle);
break;
case 6:
U1=0;U2=0;U3=1;
dutychange(1,ducycle);
break;
case 4:
U1=0;U2=0;U3=1;
dutychange(2,ducycle);
break;
}
}
void danticlock(unsigned char *seq)
{
switch(*seq)
{
case 3: //0x02,0x04,0x06,0x01,0x03,0x05,
U1=1;U2=0;U3=0;
dutychange(2,ducycle);
break;
case 2:
U1=1;U2=0;U3=0;
dutychange(3,ducycle);
break;
case 6:
U1=0;U2=1;U3=0;
dutychange(3,ducycle);
break;
case 4:
U1=0;U2=1;U3=0;
dutychange(1,ducycle);
break;
case 5:
U1=0;U2=0;U3=1;
dutychange(1,ducycle);
break;
case 1:
U1=0;U2=0;U3=1;
dutychange(2,ducycle);
break;
}
}
void run()
{
ADS=3;
for(i=0;i<=100;i++);
amit_adc = (ADCR >> 6);
//softstart
todecide=amit_adc*4;
if(todecide>=(prd-20)){todecide=prd-20;}
abc++;
if(abc>=50)
{
abc=0;
{
if(todecide>=ducycle){ducycle=ducycle+5;}
if(todecide<ducycle){ducycle=ducycle-5;}
}
}
if((chak==0)&&(ft==0))
{
amit_pos=P6;
if((amit_pos==7)||(amit_pos==0))
{
amit_pos=1;
}
}
if(state==0)danticlock(&amit_pos);
else dclock(&amit_pos);
}
void Dev_Init()
{
ducycle=todecide=0;
R_TMR_RD1_Start();
R_ADC_Start();
}
/* End user code. Do not edit comment generated here */
void R_MAIN_UserInit(void);
/***********************************************************************************************************************
* Function Name: main
* Description : This function implements main function.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void main(void)
{
R_MAIN_UserInit();
/* Start user code. Do not edit comment generated here */
U1=0;U2=0;U3=0;
for(i=0;i<=60000;i++);
for(i=0;i<=60000;i++);
for(i=0;i<=60000;i++);
for(i=0;i<=60000;i++);
for(i=0;i<=60000;i++);
for(i=0;i<=60000;i++);
for(i=0;i<=2500;i++)
{
for(j=0;j<=6000;j++);
} //////////////
while (1U)
{
run();
}
/* End user code. Do not edit comment generated here */
}
/***********************************************************************************************************************
* Function Name: R_MAIN_UserInit
* Description : This function adds user code before implementing main function.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_MAIN_UserInit(void)
{
/* Start user code. Do not edit comment generated here */
EI();
Dev_Init();
if(P3.1==1)state=0;
else state=1;
/* End user code. Do not edit comment generated here */
}
/* Start user code for adding. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
dutychange(2,ducycle);