㈠ 瑞萨单片机2L系列的闪存操作是怎么样的,有人用过么,发个例程看看,1B我操作过
/************************************************************************************
Name: flash_write
Parameters: Write record data
Returns: Result (Complete or program error or erase error)
Description: Initial setting of SFR registers
************************************************************************************/
unsigned char flash_write(unsigned char *write_addr,unsigned char *data,unsigned size){
unsigned char result = COMPLETE;
unsigned char i;
for(i = 0;i < size ;i++)
{
if(*(write_addr+i) != 0xff)
{
if(block_erase(write_addr + i) != COMPLETE)
{
result = result | PROGRAM_ERR;
return result;
}
//break;
}
}
for(i = 0;i < size ;i++)
{
if( data_write(write_addr, *data ) != COMPLETE ){
/* Program error occurence */
return result = result | PROGRAM_ERR; /* if program error */
//break;
}
/* Next write address update */
write_addr++;
}
return result;
}
unsigned char wflash_write(unsigned char *write_addr,unsigned char *data,unsigned size)
{
unsigned char result = COMPLETE;
unsigned char i;
/*
for(i = 0;i < (size * 2) ;i++)
{
if(*(write_addr+i) != 0xff)
{
if(block_erase(write_addr + i) != COMPLETE)
{
result = result | PROGRAM_ERR;
u1tb = '2';
return result;
}
//break;
}
}
*/
if( data_write(write_addr, 0xaa ) != COMPLETE ){
/* Program error occurence */
//u1tb = '3';
return result = result | PROGRAM_ERR; /* if program error */
//break;
}
write_addr++;
if( data_write(write_addr, 0xaa) != COMPLETE ){
/* Program error occurence */
//u1tb = '4';
return result = result | PROGRAM_ERR; /* if program error */
//break;
}
write_addr++;
for(i = 0;i < (size*2) ;i++)
{
if( data_write(write_addr, *data ) != COMPLETE ){
/* Program error occurence */
//u1tb = '5';
return result = result | PROGRAM_ERR; /* if program error */
//break;
}
/*
write_addr++;
if( data_write(write_addr, (unsigned char)((*data) >> 8)) != COMPLETE ){
// Program error occurence
//u1tb = '6';
return result = result | PROGRAM_ERR; // if program error
//break;
}
// Next write address update
*/
write_addr++;
data++;;
}
return result;
}
/************************************************************************************
Name: block_erase
Parameters: Erase block address
Returns: Erase result
Description: Block erase
************************************************************************************/
unsigned char block_erase(unsigned char *ers_addr){
unsigned char erase_result;
/* If use interrupt then clear i flag... */
/* asm("fclr i "); */
/* flash control register set */
fmr0 = 0x01;
asm(" "); /* Description for preventing the abbreviation by optimization */
fmr0 = 0x03; /* CPU rewrite enable */
fmr1 = 0x80;
asm(" "); /* Description for preventing the abbreviation by optimization */
fmr1 = 0x82; /* EW1 mode */
*ers_addr = 0x20; /* Block erase command write */
*ers_addr = 0xd0; /* Block erase command write */
while( fmr00 != 1 ); /* Ready check */
/* Erase status check */
if( fmr07 == 1 ){
*ers_addr = 0x50; /* Clear stutus register */
erase_result = ERASE_ERR;
}else{
erase_result = COMPLETE;
}
/* flash control register reset */
fmr0 = 0x01; /* CPU rewrite disable */
/* If use interrupt then set i flag... */
/* asm("fset i "); */
return erase_result;
}
/************************************************************************************
Name: data_write
Parameters: Record data address
Returns: Program result
Description: Record program
************************************************************************************/
unsigned char data_write( unsigned char *write_addr,unsigned char write_data){
unsigned char program_result = COMPLETE;
int i; /* loop counter */
/* If use interrupt then clear i flag... */
asm("fclr i ");
/* flash control register set */
fmr0 = 0x01;
asm(" "); /* Description for preventing the abbreviation by optimization */
fmr0 = 0x03; /* CPU rewrite enable */
fmr1 = 0x80;
asm(" "); /* Description for preventing the abbreviation by optimization */
fmr1 = 0x82; /* EW1 mode */
*write_addr = 0x40;
*write_addr = write_data;
while( fmr00 != 1 ); /* Ready check */
/* Program status check */
if( fmr06 == 1 ){
/* Program error */
*write_addr = 0x50; /* Clear stutus register */
program_result = PROGRAM_ERR;
// break;
}
// }
/* flash control register reset */
fmr0 = 0x01; /* CPU rewrite disable */
/* If use interrupt then set i flag... */
asm("fset i ");
return program_result;
}
void data_read(unsigned char *read_addr,unsigned char * read_temp,unsigned char size)
{
for(;size>0;size--)
{
*read_temp = *read_addr;
read_temp++;
read_addr++;
}
}
void wdata_read(unsigned char *read_addr,unsigned short * read_temp,unsigned char size)
{
unsigned i;
for(;size>0;size--)
{
*read_temp = *read_addr;
read_addr++;
*read_temp <<= 8;
*read_temp += *read_addr;
read_temp++;
read_addr++;
}
}
unsigned char WriteFlash(unsigned short *write_dat,unsigned char size)
{
//unsigned char low;
unsigned char *write_addr = 0;
unsigned short low,high,mid;
unsigned char program_result = COMPLETE;
high = NUM_OF_BLOCK;
low = 0;
mid = (high + low)/2;
while(mid < 63 && mid > 0)
{
write_addr = BLOCK_A + mid * SIZE_PRE_BLOCK;
//didn't write
if((*write_addr == 0xaa)&&(*(write_addr + 1) == 0xaa))
{
if((*(write_addr + SIZE_PRE_BLOCK) == 0xff)&&(*(write_addr + SIZE_PRE_BLOCK + 1) == 0xff))
{
write_addr += SIZE_PRE_BLOCK;
//u1tb = '6';
break;
}
else
{
low = mid;
}
}
//is 0xff
else
if((*(write_addr - SIZE_PRE_BLOCK) == 0xaa)&&(*(write_addr - SIZE_PRE_BLOCK + 1) == 0xaa))
{
//u1tb = '7';
break;
}
else
{
high = mid;
}
mid = (high + low)/2;
}
//说明所有的闪存都写满了
u1tb = mid;
if(mid == 63)
{
//将整个闪存都清零
if(block_erase(BLOCK_A+SIZE_PRE_BLOCK) != COMPLETE)
{
program_result = program_result | ERASE_ERR;
return program_result;
}
if(block_erase(BLOCK_B+SIZE_PRE_BLOCK) != COMPLETE);
{
program_result = program_result | ERASE_ERR;
return program_result;
}
write_addr = BLOCK_A;
}
else if(mid == 0)
{
write_addr = BLOCK_A;
}
/*
else
{
write_addr = BLOCK_A + mid * SIZE_PRE_BLOCK;
}
*/
if(wflash_write(write_addr,(unsigned char *)write_dat,size) != COMPLETE)
{program_result = program_result | PROGRAM_ERR;
//u1tb = '1';
}
return program_result;
}
void ReadFlash(unsigned short * read_temp,unsigned char size)
{
unsigned char *write_addr,temp1,temp2;
unsigned short low,high,mid;
high = NUM_OF_BLOCK;
low = 0;
mid = (high + low)/2;
temp1 = *write_addr;
temp2 = (*write_addr+1);
while(mid < 63 && mid > 0)
{
write_addr = BLOCK_A + mid * SIZE_PRE_BLOCK;
//didn't write
//temp1 = *write_addr;
//temp2 = *(write_addr+1);
if((*write_addr == 0xaa)&&(*(write_addr+1) == 0xaa))
{
//temp1 = *write_addr+SIZE_PRE_BLOCK;
//temp2 = *(write_addr+SIZE_PRE_BLOCK+1);
if((*(write_addr+SIZE_PRE_BLOCK) == 0xff)&&(*(write_addr+SIZE_PRE_BLOCK+1) == 0xff))
{
break;
}
else
{
low = mid;
}
}
//is 0xff
else
{
//temp1 = *write_addr-SIZE_PRE_BLOCK;
//temp2 = *(write_addr-SIZE_PRE_BLOCK+1);
if((*(write_addr - SIZE_PRE_BLOCK) == 0xaa)&&(*(write_addr - SIZE_PRE_BLOCK + 1) == 0xaa))
{
write_addr -= SIZE_PRE_BLOCK;
break;
}
else
{
high = mid;
}
}
//u1tb = mid;
mid = (high + low)/2;
}
u1tb = mid;
if(mid >= 63)
write_addr += SIZE_PRE_BLOCK;
else if(mid == 0)
write_addr = BLOCK_A;
write_addr += 2;
data_read(write_addr,((unsigned char *)read_temp),size);
}
你可以参考一下
㈡ 瑞萨单片机怎样新建一个工程
如果你用官方提供的软件 一打开软件接口就提示你 建 立新工程了
软件:High-performance Embedded Workshop
㈢ 瑞萨单片机
你说的是瑞萨的哪个族的单片机,不同的族指令也不一样的,还有个问题就是如果datasheet说明不够详细的话,那估计没有比datasheet更详细的了,给你个建议,可以去瑞萨的官网查找相关的汇编例程,看看例程中的实现方法,会对你理解指令有帮助的。还有就是想看懂指令,就要把单片机的底层了解透彻。
㈣ 瑞萨单片机的输入捕捉功能
看R8C的技术手册,RC作为タイマモード(インプットキャプチャ机能)时。“インプットキャプチャ入力端子选択
TRCIOA、TRCIOB、TRCIOC、TRCIOD端子のいずれか1本または复数本”(datasheet的19.4章P333)这说明是可以同时进行比较使用的,但是你想要四个通道的话就要使用“TRCCR1レジスタのCCLRビットが“0”(フリーランニング动作)”它的计数频率就是1/fk×65536了。然后就看你的TRCIOR0和TRCIOR1对每个引脚是上沿捕捉还是下沿或者双边了。当然其他寄存器也是设置了。当它扑捉到引脚的信号时候TRC寄存器的值会存到相应的TRCGRi(i = A,B,C,D)寄存器,当然你不能使用它的缓冲功能了。比较仓促的回答,希望能给你些许帮助,详细还是看看它的datasheet吧。
㈤ 2013电赛瑞萨单片机RL78G13的五路AD转换方法
每1ms读取一次,每次读时,读上一次的初始化的那一路数据,读完后,初始化下一路。
这个单片机的AD很麻烦,定时器也不好使。还没有真正的EEPROM。就是价位低点,ROM大点。其它真不怎么样。
做个电赛建议换ATMEGA吧。
㈥ 请问有哪位高手学过瑞萨单片机的,我最近接到一个小项目,需要用到瑞萨单片机,能否给我发一点资料。
瑞萨单片机也得分型号啊,我学过M16C,M32C,SH7125等,只是了解一点,你学那一款?公司用的话公司会给你们资料的!
㈦ 学会51单片机之后转学瑞萨78K0单片机容易吗
瑞萨78K0我没有使用过,不过我目前正在使用瑞萨RL78系列,为解决汽车仪表方案的MCU。
根据我使用单片机的经验,自学51单片机是肯定可以为其他系列的单片机提供帮助的。
不论学习哪种单片机,一上来就听老师讲课,没有系统地学过大学计算机基础、C语言、一些数电模电基础,是肯定会云里雾里的,何况小日本的单片机我觉得没那么容易上手。
我现在使用的这个系列有代码生成器,不过没基础的人即使有这个东西也没办法真正的玩转起来。
现在大学的课程没以前那样子以前那样以传授知识为主了,多数是任务式的,有些老师自己不懂还要糊弄学生,当然这是极个别的现象。
你尽量多花时间和精力学习51和瑞萨的,单片机都是一通百通的,弄懂了单片机的工作原理,和寄存器配置,学会查看datasheet,多去找一些官方的例程(而不是到网上随处下载的那种,很多都不负责任地误人子弟的东西)来琢磨。
祝你成功。
㈧ 瑞萨单片机怎么操作eeprom
片内的还是片外的?按标准I2C时序操作就行。
㈨ 有用瑞萨单片机的大神吗求助解决问题,我从keil移植过来的程序,之前我写在.c和.h文件里,
查看是什么错误咯,然后一个个的改。涉及到寄存器的尤其要注意。
还有就是用户自定义的关键字,比如uchar,一定要把定义的地方也过来。
㈩ 谁有瑞萨rl78/g12单片机的教程或c语言代码 急急急!
去年第一次听说这个系列的片子,好像只有官方上有教程