Last active
July 18, 2018 04:25
-
-
Save sakakendo/adb7b2d6496f3f7fd5fb24da1cc42ac5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <3694.h> | |
int main (void){ | |
/*初期化*/ | |
//IO.PMR5.BYTE&=0xe7; | |
IO.PCR8|=0xff; | |
/*値の設定*/ | |
IO.PDR8.BYTE|=0x40; | |
IO.PDR8.BYTE&=0xff; | |
IO.PDR8.BIT.B6=1; | |
IO.PDR8.BIT.B7=1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <3694.h> | |
void msecWait(unsigned long length){ | |
volatile int i=0,j=0; | |
for(j=0;j<length;j++){ | |
for(i=0;i<714;i++); | |
} | |
} | |
int main(){ | |
long int cnt=0; | |
IO.PCR8|=0xff; | |
IO.PDR8.BYTE|=0x40; | |
IO.PDR8.BYTE&=0xff; | |
IO.PDR8.BIT.B6=1; | |
IO.PDR8.BIT.B7=1; | |
msecWait(1); | |
while(1){ | |
if(cnt%2==1){ | |
IO.PDR8.BIT.B6=1; | |
IO.PDR8.BIT.B7=0; | |
msecWait(1); | |
}else if(cnt%2==0){ | |
IO.PDR8.BIT.B6=0; | |
IO.PDR8.BIT.B7=1; | |
msecWait(1); | |
} | |
cnt++; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <3694.h> | |
#include"ltrc_lib.h" | |
void msecWait(unsigned long length){ | |
volatile int i=0,j=0; | |
for(j=0;j<length;j++){ | |
for(i=0;i<714;i++); | |
} | |
} | |
int main(){ | |
long int cnt=0; | |
IO.PCR8|=0xff; | |
IO.PDR8.BYTE|=0x40; | |
IO.PDR8.BYTE&=0xff; | |
initSCI3(); | |
SCI3printf(" hello h8 3694\n"); | |
while(1){ | |
if(cnt%4==0){ | |
IO.PDR8.BIT.B6=0; | |
IO.PDR8.BIT.B7=0; | |
SCI3printf("LED1(B6):%d,LED2(B7):%d\n",IO.PDR8.BIT.B6,IO.PDR8.BIT.B7); | |
msecWait(1000); | |
}else if(cnt%4==1){ | |
IO.PDR8.BIT.B6=1; | |
IO.PDR8.BIT.B7=0; | |
SCI3printf("LED1(B6):%d,LED2(B7):%d\n",IO.PDR8.BIT.B6,IO.PDR8.BIT.B7); | |
msecWait(1000); | |
}else if(cnt%4==2){ | |
IO.PDR8.BIT.B6=0; | |
IO.PDR8.BIT.B7=1; | |
SCI3printf("LED1(B6):%d,LED2(B7):%d\n",IO.PDR8.BIT.B6,IO.PDR8.BIT.B7); | |
msecWait(1000); | |
}else if(cnt%4==3){ | |
IO.PDR8.BIT.B6=1; | |
IO.PDR8.BIT.B7=1; | |
SCI3printf("LED1(B6):%d,LED2(B7):%d\n",IO.PDR8.BIT.B6,IO.PDR8.BIT.B7); | |
msecWait(1000); | |
} | |
cnt++; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include"ltrc_lib.h" | |
unsigned count=0; | |
const int t=9766; | |
int duty1=0,duty2=100; | |
unsigned flag=0; | |
#define setCCR_I() asm volatile("orc.b #0x80,CCR") | |
#define clearCCR_I() asm volatile("andc.b #0x7f,CCR") | |
void msecWait(unsigned long length){ | |
volatile int i=0,j=0; | |
for(j=0;j<length;j++){ | |
for(i=0;i<714;i++); | |
} | |
} | |
#pragma interrupt | |
void int_timera(void){ | |
//割り込み時に実行する処理 | |
if(count==0||count==t||count==2*t){ | |
flag=1; | |
} | |
count++; | |
if(count >= 3*t)count = 0; | |
IRR1.BIT.IRRTA = 0; | |
/********** LED点灯 **********/ | |
if(count%100<=duty1){ | |
IO.PDR8.BIT.B6=1; | |
}else { | |
IO.PDR8.BIT.B6=0; | |
} | |
if(count%100<=duty2){ | |
IO.PDR8.BIT.B7=1; | |
}else{ | |
IO.PDR8.BIT.B7=0; | |
} | |
/******************************/ | |
} | |
int main() | |
{ | |
//interupt | |
clearCCR_I(); //割り込みマスクのクリア:割り込み許可 | |
TA.TMA.BYTE = 0x07; //タイマ設定 | |
IRR1.BIT.IRRTA = 0; //タイマー割込みフラグのリセット | |
IENR1.BIT.IENTA = 1; //割り込み許可 | |
//setCCR_I(); //割り込みマスクのセット:割り込み無視 | |
IO.PCR8 |= 0xff; | |
IO.PDR8.BYTE |= 0x40; | |
IO.PDR8.BYTE &= 0xff; | |
//serial | |
initSCI3(); | |
SCI3printf(" hello h8 3694\n"); | |
while(1){ | |
/********** DUTY比設定 **********/ | |
SCI3printf(""); | |
if(count < t){ | |
duty1=20; | |
duty2=90; | |
}else if(t <= count && count < 2*t){ | |
duty1=50; | |
duty2=50; | |
}else if(2*t <= count){ | |
duty1=80; | |
duty2=10; | |
} | |
if(flag==1){ | |
SCI3printf("DUTY1=%d DUTY2=%d\n",duty1,duty2); | |
flag=0; | |
}s | |
/******************************/ | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <3694.h> | |
#include "ltrc_lib.h" | |
#define setCCR_I() asm volatile("orc.b #0x80,CCR") | |
#define clearCCR_I() asm volatile("andc.b #0x7f,CCR") | |
void msecWait(unsigned long length){ | |
volatile int i=0,j=0; | |
for(j=0;j<length;j++){ | |
for(i=0;i<714;i++); | |
} | |
} | |
int retDuty(unsigned int duty) | |
{ | |
duty=(unsigned int)duty*6.25; | |
if(duty==TW.GRA){ duty--;} | |
if(duty==0){ duty++;} | |
return duty; | |
} | |
int main(void) | |
{ | |
int i=0; | |
int pwmb[]={100,80,50,20,0}; | |
int pwmc[]={0,20,50,80,100}; | |
initSCI3(); | |
IO.PDR8.BYTE|=0x40; | |
IO.PDR8.BYTE&=0xff; | |
TW.TMRW.BYTE=0x03;/*0x4b;*/ | |
TW.TCRW.BYTE=0xb6; | |
TW.TIERW.BYTE=0x70; | |
TW.TCNT=0x0000; | |
TW.GRA=625/*500*/; | |
TW.GRB=0; | |
TW.GRC=0; | |
TW.TMRW.BIT.CTS=1; | |
while(1){ | |
for(i=0;i<5;i++){ | |
TW.GRB=retDuty(pwmb[i]); | |
TW.GRC=retDuty(pwmc[i]); | |
SCI3printf("%d %d %d FTIOB %d%% FTIOC %d%%\n",i,TW.GRB,TW.GRC,pwmb[i],pwmc[i]); | |
msecWait(3000); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <3694.h> | |
#include "ltrc_lib.h" | |
#define setCCR_I() asm volatile("orc.b #0x80,CCR") | |
#define clearCCR_I() asm volatile("andc.b #0x7f,CCR") | |
void msecWait(unsigned long length){ | |
volatile int i=0,j=0; | |
for(j=0;j<length;j++)#include <3694.h> | |
#include "ltrc_lib.h" | |
#define setCCR_I() asm volatile("orc.b #0x80,CCR") | |
#define clearCCR_I() asm volatile("andc.b #0x7f,CCR") | |
#define R_MOTOR 1 | |
#define L_MOTOR 0 | |
void msecWait(unsigned long length){ | |
volatile int i=0,j=0; | |
for(j=0;j<length;j++){ | |
for(i=0;i<714;i++); | |
} | |
} | |
int retDuty(unsigned int duty) | |
{ | |
duty=(unsigned int)duty*6.25; | |
if(duty==TW.GRA){ duty--;} | |
if(duty==0){ duty++;} | |
return duty; | |
} | |
void brake(int pin){ | |
if(pin==0){ | |
IO.PDR1.BYTE|=0x02; | |
TW.GRB=retDuty(100); | |
/* SCI3printf("brake %d\n",pin);*/ | |
} | |
if(pin==1){ | |
IO.PDR1.BYTE|=0x04; | |
TW.GRC=retDuty(100); | |
/* SCI3printf("brake %d\n",pin);*/ | |
} | |
} | |
void dutySet(int pin, int duty) | |
{ | |
static int sb,sc; | |
/* IO.PDR1.BYTE&=~0x06;*/ | |
if(pin==0){ | |
if(duty==-1) brake(pin); | |
else{ | |
TW.GRB=retDuty(duty); | |
IO.PDR1.BYTE&=~0x02; | |
} | |
sb=duty; | |
} | |
if(pin==1){ | |
if(duty==-1){ | |
brake(pin); | |
}else{ | |
TW.GRC=retDuty(duty); | |
IO.PDR1.BYTE&=~0x04; | |
} | |
sc=duty; | |
} | |
} | |
int main(void) | |
{ | |
int i=0; | |
int pwmb[]={0,100 ,100,0,50,0,-1,0,100,0,-1}; | |
int pwmc[]={0,100,0,100,50,0,-1,0,100,0,-1}; | |
int pwmt[]={1,2000,2000,2000,2000, 1,2000,1,2000, 1,2000}; | |
initSCI3(); | |
IO.PMR1.BYTE|=0x00; | |
IO.PCR1=0x06; | |
IO.PDR8.BYTE|=0x0c; | |
TW.TMRW.BYTE=0x4b; | |
TW.TCRW.BYTE=0xb6; | |
TW.TIERW.BYTE=0x70; | |
TW.TCNT=0x0000; | |
TW.GRA=625; | |
TW.GRB=0; | |
TW.GRC=0; | |
TW.TMRW.BIT.CTS=1; | |
while(1){ | |
for(i=0;i<11;i++){ | |
dutySet(0,pwmc[i]); | |
dutySet(1,pwmb[i]); | |
SCI3printf("%d left:%-4d right:%-4d time :%d \n ",i,pwmc[i],pwmb[i],pwmt[i]); | |
msecWait(pwmt[i]); | |
} | |
} | |
} | |
{ | |
for(i=0;i<714;i++); | |
} | |
} | |
int retDuty(unsigned int duty) | |
{ | |
duty=(unsigned int)duty*6.25; | |
if(duty==TW.GRA){ duty--;} | |
if(duty==0){ duty++;} | |
return duty; | |
} | |
/*void dutySet(unsigned int b, unsigned int c)*/ | |
void dutySet(int b, int c) | |
{ | |
SCI3printf("duty%d %dn\n",b,c); | |
if(b==-1 && c==-1) { | |
IO.PDR1.BYTE|=0x06; | |
TW.GRB=retDuty(100); | |
TW.GRC=retDuty(100); | |
SCI3printf("brake\n"); | |
}else{ | |
IO.PDR1.BYTE&=~0x06; | |
TW.GRB=retDuty(b); | |
TW.GRC=retDuty(c); | |
} | |
} | |
int main(void) | |
{ | |
int i=0; | |
int pwmb[]={0,100 ,100,0,50,0,-1,0,100,0,-1}; | |
int pwmc[]={0,100,0,100,50,0,-1,0,100,0,-1}; | |
int pwmt[]={1,2000,2000,2000,2000, 1,2000,1,2000, 1,2000}; | |
initSCI3(); | |
IO.PMR1.BYTE|=0x00; | |
IO.PCR1=0x06; | |
IO.PDR8.BYTE|=0x0c; | |
TW.TMRW.BYTE=0x4b; | |
TW.TCRW.BYTE=0xb6; | |
TW.TIERW.BYTE=0x70; | |
TW.TCNT=0x0000; | |
TW.GRA=625; | |
TW.GRB=0; | |
TW.GRC=0; | |
TW.TMRW.BIT.CTS=1; | |
while(1){ | |
for(i=0;i<11;i++){ | |
dutySet(pwmc[i],pwmb[i]); | |
SCI3printf("%d left:%-4d right:%-4d time :%d\n",i,pwmc[i],pwmb[i],pwmt[i]); | |
/* msecWait(1000*pwmt[i]);*/ | |
msecWait(pwmt[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment